1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include <GLES2/gl2.h>
19 #include <EGL/egl.h>
20 #include <gl2ext.h>
21 #include <OpenGLRenderer.h>
22 #include "tilerenderer.h"
23
24 namespace android {
25 ANDROID_SINGLETON_STATIC_INSTANCE(uirenderer::TileRenderer) ;
26 namespace uirenderer {
27
TileRenderer()28 TileRenderer::TileRenderer() {
29 mIsTiled = false;
30 }
31
~TileRenderer()32 TileRenderer::~TileRenderer() {
33 }
34
startTileRendering(OpenGLRenderer * renderer,int left,int top,int right,int bottom)35 void TileRenderer::startTileRendering(OpenGLRenderer* renderer,
36 int left, int top,
37 int right, int bottom) {
38 int width = 0;
39 int height = 0;
40 GLenum status = GL_NO_ERROR;
41
42 if (renderer != NULL) {
43 renderer->getViewport(width, height);
44 }
45
46 if (!left && !right && !top && !bottom) {
47 left = 0;
48 top = 0;
49 right = width;
50 bottom = height;
51 }
52
53 if (!left && !right && !top && !bottom) {
54 //can't do tile rendering
55 ALOGE("can't tile render; drity region, width, height not available");
56 return;
57 }
58
59 int l = left, t = (height - bottom), w = (right - left), h = (bottom - top), preserve = 0;
60
61 if (l < 0 || t < 0) {
62 l = (l < 0) ? 0 : l;
63 t = (t < 0) ? 0 : t;
64 preserve = 1;
65 }
66
67 if (w > width || h > height) {
68 w = (w > width) ? width : w;
69 h = (h > height) ? height : h;
70 preserve = 1;
71 }
72
73 //clear off all errors before tiling, if any
74 while ((status = glGetError()) != GL_NO_ERROR);
75
76 if (preserve)
77 glStartTilingQCOM(l, t, w, h, GL_COLOR_BUFFER_BIT0_QCOM);
78 else
79 glStartTilingQCOM(l, t, w, h, GL_NONE);
80
81 status = glGetError();
82 if (status == GL_NO_ERROR)
83 mIsTiled = true;
84 }
85
endTileRendering(OpenGLRenderer *)86 void TileRenderer::endTileRendering(OpenGLRenderer*) {
87 if (!mIsTiled) {
88 return;
89 }
90 glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
91 mIsTiled = false;
92 GLenum status = GL_NO_ERROR;
93 while ((status = glGetError()) != GL_NO_ERROR);
94 }
95
96 }; // namespace uirenderer
97 }; // namespace android
98