blob: f0f72f9ef82238e80c6f94d28001007a2e9e4ce3 [file] [log] [blame]
Chet Haasedd78cca2010-10-22 18:59:26 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
Romain Guyc15008e2010-11-10 11:59:15 -080019#include <utils/Log.h>
Chet Haase9c1e23b2011-03-24 10:51:31 -070020#include <utils/String8.h>
Romain Guyc15008e2010-11-10 11:59:15 -080021
Chet Haasedd78cca2010-10-22 18:59:26 -070022#include "Caches.h"
Romain Guybb0acdf2012-03-05 13:44:35 -080023#include "DisplayListRenderer.h"
Romain Guye190aa62010-11-10 19:01:29 -080024#include "Properties.h"
Romain Guy09b7c912011-02-02 20:28:09 -080025#include "LayerRenderer.h"
Chet Haasedd78cca2010-10-22 18:59:26 -070026
27namespace android {
28
29#ifdef USE_OPENGL_RENDERER
30using namespace uirenderer;
31ANDROID_SINGLETON_STATIC_INSTANCE(Caches);
32#endif
33
34namespace uirenderer {
35
36///////////////////////////////////////////////////////////////////////////////
Romain Guybdf76092011-07-18 15:00:43 -070037// Macros
38///////////////////////////////////////////////////////////////////////////////
39
40#if DEBUG_CACHE_FLUSH
Steve Block5baa3a62011-12-20 16:23:08 +000041 #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guybdf76092011-07-18 15:00:43 -070042#else
43 #define FLUSH_LOGD(...)
44#endif
45
46///////////////////////////////////////////////////////////////////////////////
Chet Haasedd78cca2010-10-22 18:59:26 -070047// Constructors/destructor
48///////////////////////////////////////////////////////////////////////////////
49
Romain Guy8ff6b9e2011-11-09 20:10:18 -080050Caches::Caches(): Singleton<Caches>(), mInitialized(false) {
Romain Guy8ff6b9e2011-11-09 20:10:18 -080051 init();
Romain Guyb1d0a4e2012-07-13 18:25:35 -070052 initFont();
Romain Guydfa10462012-05-12 16:18:58 -070053 initExtensions();
54 initConstraints();
Romain Guy4ff0cf42012-08-06 14:51:10 -070055 initProperties();
Romain Guye190aa62010-11-10 19:01:29 -080056
57 mDebugLevel = readDebugLevel();
Steve Block5baa3a62011-12-20 16:23:08 +000058 ALOGD("Enabling debug mode %d", mDebugLevel);
Chet Haasedd78cca2010-10-22 18:59:26 -070059}
60
Romain Guy8ff6b9e2011-11-09 20:10:18 -080061void Caches::init() {
62 if (mInitialized) return;
63
64 glGenBuffers(1, &meshBuffer);
65 glBindBuffer(GL_ARRAY_BUFFER, meshBuffer);
66 glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);
67
68 mCurrentBuffer = meshBuffer;
Romain Guy15bc6432011-12-13 13:11:32 -080069 mCurrentIndicesBuffer = 0;
Romain Guyf3a910b42011-12-12 20:35:21 -080070 mCurrentPositionPointer = this;
71 mCurrentTexCoordsPointer = this;
72
Romain Guy15bc6432011-12-13 13:11:32 -080073 mTexCoordsArrayEnabled = false;
74
Romain Guyb1d0a4e2012-07-13 18:25:35 -070075 glDisable(GL_SCISSOR_TEST);
Romain Guy586cae32012-07-13 15:28:31 -070076 scissorEnabled = false;
Romain Guy8f85e802011-12-14 19:23:32 -080077 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
78
Romain Guya1d3c912011-12-13 14:55:06 -080079 glActiveTexture(gTextureUnits[0]);
80 mTextureUnit = 0;
81
Romain Guy8ff6b9e2011-11-09 20:10:18 -080082 mRegionMesh = NULL;
83
84 blend = false;
85 lastSrcMode = GL_ZERO;
86 lastDstMode = GL_ZERO;
87 currentProgram = NULL;
88
89 mInitialized = true;
90}
91
Romain Guyb1d0a4e2012-07-13 18:25:35 -070092void Caches::initFont() {
93 fontRenderer = GammaFontRenderer::createRenderer();
94}
95
Romain Guydfa10462012-05-12 16:18:58 -070096void Caches::initExtensions() {
97 if (extensions.hasDebugMarker()) {
98 eventMark = glInsertEventMarkerEXT;
99 startMark = glPushGroupMarkerEXT;
100 endMark = glPopGroupMarkerEXT;
101 } else {
102 eventMark = eventMarkNull;
103 startMark = startMarkNull;
104 endMark = endMarkNull;
105 }
106
107 if (extensions.hasDebugLabel()) {
108 setLabel = glLabelObjectEXT;
109 getLabel = glGetObjectLabelEXT;
110 } else {
111 setLabel = setLabelNull;
112 getLabel = getLabelNull;
113 }
114}
115
116void Caches::initConstraints() {
117 GLint maxTextureUnits;
118 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
119 if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
120 ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
121 }
122
123 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
124}
125
Romain Guy4ff0cf42012-08-06 14:51:10 -0700126void Caches::initProperties() {
127 char property[PROPERTY_VALUE_MAX];
128 if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, NULL) > 0) {
129 INIT_LOGD(" Layers updates debug enabled: %s", property);
130 debugLayersUpdates = !strcmp(property, "true");
131 } else {
132 debugLayersUpdates = false;
133 }
Romain Guy7c450aa2012-09-21 19:15:00 -0700134
135 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, NULL) > 0) {
136 INIT_LOGD(" Overdraw debug enabled: %s", property);
137 debugOverdraw = !strcmp(property, "true");
138 } else {
139 debugOverdraw = false;
140 }
Romain Guy4ff0cf42012-08-06 14:51:10 -0700141}
142
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800143void Caches::terminate() {
144 if (!mInitialized) return;
145
146 glDeleteBuffers(1, &meshBuffer);
147 mCurrentBuffer = 0;
148
149 glDeleteBuffers(1, &mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700150 delete[] mRegionMesh;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800151 mRegionMesh = NULL;
152
153 fboCache.clear();
154
155 programCache.clear();
156 currentProgram = NULL;
157
158 mInitialized = false;
Romain Guy5b3b3522010-10-27 18:57:51 -0700159}
160
161///////////////////////////////////////////////////////////////////////////////
Romain Guyc15008e2010-11-10 11:59:15 -0800162// Debug
163///////////////////////////////////////////////////////////////////////////////
164
165void Caches::dumpMemoryUsage() {
Chet Haase9c1e23b2011-03-24 10:51:31 -0700166 String8 stringLog;
167 dumpMemoryUsage(stringLog);
Steve Block5baa3a62011-12-20 16:23:08 +0000168 ALOGD("%s", stringLog.string());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700169}
170
171void Caches::dumpMemoryUsage(String8 &log) {
172 log.appendFormat("Current memory usage / total memory usage (bytes):\n");
173 log.appendFormat(" TextureCache %8d / %8d\n",
174 textureCache.getSize(), textureCache.getMaxSize());
175 log.appendFormat(" LayerCache %8d / %8d\n",
176 layerCache.getSize(), layerCache.getMaxSize());
177 log.appendFormat(" GradientCache %8d / %8d\n",
178 gradientCache.getSize(), gradientCache.getMaxSize());
179 log.appendFormat(" PathCache %8d / %8d\n",
180 pathCache.getSize(), pathCache.getMaxSize());
181 log.appendFormat(" CircleShapeCache %8d / %8d\n",
Romain Guy01d58e42011-01-19 21:54:02 -0800182 circleShapeCache.getSize(), circleShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700183 log.appendFormat(" OvalShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800184 ovalShapeCache.getSize(), ovalShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700185 log.appendFormat(" RoundRectShapeCache %8d / %8d\n",
Romain Guy01d58e42011-01-19 21:54:02 -0800186 roundRectShapeCache.getSize(), roundRectShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700187 log.appendFormat(" RectShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800188 rectShapeCache.getSize(), rectShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700189 log.appendFormat(" ArcShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800190 arcShapeCache.getSize(), arcShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700191 log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(),
Romain Guyc15008e2010-11-10 11:59:15 -0800192 dropShadowCache.getMaxSize());
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700193 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
194 const uint32_t size = fontRenderer->getFontRendererSize(i);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700195 log.appendFormat(" FontRenderer %d %8d / %8d\n", i, size, size);
Romain Guyc15008e2010-11-10 11:59:15 -0800196 }
Romain Guyd2ba50a2011-05-27 10:21:07 -0700197 log.appendFormat("Other:\n");
Chet Haase9c1e23b2011-03-24 10:51:31 -0700198 log.appendFormat(" FboCache %8d / %8d\n",
199 fboCache.getSize(), fboCache.getMaxSize());
200 log.appendFormat(" PatchCache %8d / %8d\n",
201 patchCache.getSize(), patchCache.getMaxSize());
Romain Guyc15008e2010-11-10 11:59:15 -0800202
203 uint32_t total = 0;
204 total += textureCache.getSize();
205 total += layerCache.getSize();
206 total += gradientCache.getSize();
207 total += pathCache.getSize();
208 total += dropShadowCache.getSize();
Romain Guy2fc941e2011-02-03 15:06:05 -0800209 total += roundRectShapeCache.getSize();
210 total += circleShapeCache.getSize();
211 total += ovalShapeCache.getSize();
212 total += rectShapeCache.getSize();
213 total += arcShapeCache.getSize();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700214 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
215 total += fontRenderer->getFontRendererSize(i);
Romain Guyc15008e2010-11-10 11:59:15 -0800216 }
217
Chet Haase9c1e23b2011-03-24 10:51:31 -0700218 log.appendFormat("Total memory usage:\n");
219 log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
Romain Guyc15008e2010-11-10 11:59:15 -0800220}
221
222///////////////////////////////////////////////////////////////////////////////
Romain Guyfe48f652010-11-11 15:36:56 -0800223// Memory management
224///////////////////////////////////////////////////////////////////////////////
225
226void Caches::clearGarbage() {
227 textureCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800228 pathCache.clearGarbage();
Romain Guy57066eb2011-01-12 12:53:32 -0800229
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700230 Vector<DisplayList*> displayLists;
231 Vector<Layer*> layers;
Romain Guy57066eb2011-01-12 12:53:32 -0800232
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700233 { // scope for the lock
234 Mutex::Autolock _l(mGarbageLock);
235 displayLists = mDisplayListGarbage;
236 layers = mLayerGarbage;
237 mDisplayListGarbage.clear();
238 mLayerGarbage.clear();
Romain Guy57066eb2011-01-12 12:53:32 -0800239 }
Romain Guybb0acdf2012-03-05 13:44:35 -0800240
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700241 size_t count = displayLists.size();
Romain Guybb0acdf2012-03-05 13:44:35 -0800242 for (size_t i = 0; i < count; i++) {
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700243 DisplayList* displayList = displayLists.itemAt(i);
Romain Guybb0acdf2012-03-05 13:44:35 -0800244 delete displayList;
245 }
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700246
247 count = layers.size();
248 for (size_t i = 0; i < count; i++) {
249 Layer* layer = layers.itemAt(i);
250 delete layer;
251 }
252 layers.clear();
Romain Guy57066eb2011-01-12 12:53:32 -0800253}
254
Romain Guyada830f2011-01-13 12:13:20 -0800255void Caches::deleteLayerDeferred(Layer* layer) {
Romain Guy57066eb2011-01-12 12:53:32 -0800256 Mutex::Autolock _l(mGarbageLock);
Romain Guyada830f2011-01-13 12:13:20 -0800257 mLayerGarbage.push(layer);
Romain Guyfe48f652010-11-11 15:36:56 -0800258}
259
Romain Guybb0acdf2012-03-05 13:44:35 -0800260void Caches::deleteDisplayListDeferred(DisplayList* displayList) {
261 Mutex::Autolock _l(mGarbageLock);
262 mDisplayListGarbage.push(displayList);
263}
264
Romain Guybdf76092011-07-18 15:00:43 -0700265void Caches::flush(FlushMode mode) {
266 FLUSH_LOGD("Flushing caches (mode %d)", mode);
267
268 clearGarbage();
269
270 switch (mode) {
271 case kFlushMode_Full:
272 textureCache.clear();
273 patchCache.clear();
274 dropShadowCache.clear();
275 gradientCache.clear();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700276 fontRenderer->clear();
Romain Guy211efea2012-07-31 21:16:07 -0700277 dither.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700278 // fall through
279 case kFlushMode_Moderate:
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700280 fontRenderer->flush();
Romain Guyeca0ca22011-11-04 15:12:29 -0700281 textureCache.flush();
Romain Guybdf76092011-07-18 15:00:43 -0700282 pathCache.clear();
283 roundRectShapeCache.clear();
284 circleShapeCache.clear();
285 ovalShapeCache.clear();
286 rectShapeCache.clear();
287 arcShapeCache.clear();
Romain Guy6d7475d2011-07-27 16:28:21 -0700288 // fall through
289 case kFlushMode_Layers:
290 layerCache.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700291 break;
292 }
293}
294
Romain Guyfe48f652010-11-11 15:36:56 -0800295///////////////////////////////////////////////////////////////////////////////
Romain Guy5b3b3522010-10-27 18:57:51 -0700296// VBO
297///////////////////////////////////////////////////////////////////////////////
298
Romain Guyf3a910b42011-12-12 20:35:21 -0800299bool Caches::bindMeshBuffer() {
300 return bindMeshBuffer(meshBuffer);
Chet Haasedd78cca2010-10-22 18:59:26 -0700301}
302
Romain Guyf3a910b42011-12-12 20:35:21 -0800303bool Caches::bindMeshBuffer(const GLuint buffer) {
Romain Guy9bca4792010-10-25 18:42:25 -0700304 if (mCurrentBuffer != buffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -0700305 glBindBuffer(GL_ARRAY_BUFFER, buffer);
Romain Guy9bca4792010-10-25 18:42:25 -0700306 mCurrentBuffer = buffer;
Romain Guyf3a910b42011-12-12 20:35:21 -0800307 return true;
Chet Haasedd78cca2010-10-22 18:59:26 -0700308 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800309 return false;
Chet Haasedd78cca2010-10-22 18:59:26 -0700310}
311
Romain Guyf3a910b42011-12-12 20:35:21 -0800312bool Caches::unbindMeshBuffer() {
Romain Guy9bca4792010-10-25 18:42:25 -0700313 if (mCurrentBuffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -0700314 glBindBuffer(GL_ARRAY_BUFFER, 0);
Romain Guy9bca4792010-10-25 18:42:25 -0700315 mCurrentBuffer = 0;
Romain Guyf3a910b42011-12-12 20:35:21 -0800316 return true;
Chet Haasedd78cca2010-10-22 18:59:26 -0700317 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800318 return false;
319}
320
Romain Guy15bc6432011-12-13 13:11:32 -0800321bool Caches::bindIndicesBuffer(const GLuint buffer) {
322 if (mCurrentIndicesBuffer != buffer) {
323 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
324 mCurrentIndicesBuffer = buffer;
325 return true;
326 }
327 return false;
328}
329
330bool Caches::unbindIndicesBuffer() {
331 if (mCurrentIndicesBuffer) {
332 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
333 mCurrentIndicesBuffer = 0;
334 return true;
335 }
336 return false;
337}
338
Romain Guy85ef80d2012-09-13 20:26:50 -0700339///////////////////////////////////////////////////////////////////////////////
340// Meshes and textures
341///////////////////////////////////////////////////////////////////////////////
342
Romain Guyf3a910b42011-12-12 20:35:21 -0800343void Caches::bindPositionVertexPointer(bool force, GLuint slot, GLvoid* vertices, GLsizei stride) {
344 if (force || vertices != mCurrentPositionPointer) {
345 glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
346 mCurrentPositionPointer = vertices;
347 }
348}
349
350void Caches::bindTexCoordsVertexPointer(bool force, GLuint slot, GLvoid* vertices) {
351 if (force || vertices != mCurrentTexCoordsPointer) {
352 glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, gMeshStride, vertices);
353 mCurrentTexCoordsPointer = vertices;
354 }
355}
356
357void Caches::resetVertexPointers() {
358 mCurrentPositionPointer = this;
359 mCurrentTexCoordsPointer = this;
360}
361
362void Caches::resetTexCoordsVertexPointer() {
363 mCurrentTexCoordsPointer = this;
Chet Haasedd78cca2010-10-22 18:59:26 -0700364}
365
Romain Guy15bc6432011-12-13 13:11:32 -0800366void Caches::enableTexCoordsVertexArray() {
367 if (!mTexCoordsArrayEnabled) {
368 glEnableVertexAttribArray(Program::kBindingTexCoords);
Romain Guyec31f832011-12-13 18:39:19 -0800369 mCurrentTexCoordsPointer = this;
Romain Guy15bc6432011-12-13 13:11:32 -0800370 mTexCoordsArrayEnabled = true;
371 }
372}
373
374void Caches::disbaleTexCoordsVertexArray() {
375 if (mTexCoordsArrayEnabled) {
376 glDisableVertexAttribArray(Program::kBindingTexCoords);
377 mTexCoordsArrayEnabled = false;
378 }
379}
380
Romain Guya1d3c912011-12-13 14:55:06 -0800381void Caches::activeTexture(GLuint textureUnit) {
382 if (mTextureUnit != textureUnit) {
383 glActiveTexture(gTextureUnits[textureUnit]);
384 mTextureUnit = textureUnit;
385 }
386}
387
Romain Guy85ef80d2012-09-13 20:26:50 -0700388///////////////////////////////////////////////////////////////////////////////
389// Scissor
390///////////////////////////////////////////////////////////////////////////////
391
Romain Guy8a4ac612012-07-17 17:32:48 -0700392bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
Romain Guy586cae32012-07-13 15:28:31 -0700393 if (scissorEnabled && (x != mScissorX || y != mScissorY ||
394 width != mScissorWidth || height != mScissorHeight)) {
395
Romain Guy35643dd2012-09-18 15:40:58 -0700396 if (x < 0) x = 0;
397 if (y < 0) y = 0;
398
Romain Guy8f85e802011-12-14 19:23:32 -0800399 glScissor(x, y, width, height);
400
401 mScissorX = x;
402 mScissorY = y;
403 mScissorWidth = width;
404 mScissorHeight = height;
Romain Guy8a4ac612012-07-17 17:32:48 -0700405
406 return true;
Romain Guy8f85e802011-12-14 19:23:32 -0800407 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700408 return false;
Romain Guy8f85e802011-12-14 19:23:32 -0800409}
410
Romain Guy8a4ac612012-07-17 17:32:48 -0700411bool Caches::enableScissor() {
Romain Guy586cae32012-07-13 15:28:31 -0700412 if (!scissorEnabled) {
413 glEnable(GL_SCISSOR_TEST);
414 scissorEnabled = true;
Romain Guy8a4ac612012-07-17 17:32:48 -0700415 return true;
Romain Guy586cae32012-07-13 15:28:31 -0700416 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700417 return false;
Romain Guy586cae32012-07-13 15:28:31 -0700418}
419
Romain Guy8a4ac612012-07-17 17:32:48 -0700420bool Caches::disableScissor() {
Romain Guy586cae32012-07-13 15:28:31 -0700421 if (scissorEnabled) {
422 glDisable(GL_SCISSOR_TEST);
423 scissorEnabled = false;
Romain Guy8a4ac612012-07-17 17:32:48 -0700424 return true;
Romain Guy586cae32012-07-13 15:28:31 -0700425 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700426 return false;
Romain Guy586cae32012-07-13 15:28:31 -0700427}
428
429void Caches::setScissorEnabled(bool enabled) {
430 if (scissorEnabled != enabled) {
431 if (enabled) glEnable(GL_SCISSOR_TEST);
432 else glDisable(GL_SCISSOR_TEST);
433 scissorEnabled = enabled;
434 }
435}
436
Romain Guy82bc7a72012-01-03 14:13:39 -0800437void Caches::resetScissor() {
438 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
439}
440
Romain Guy85ef80d2012-09-13 20:26:50 -0700441///////////////////////////////////////////////////////////////////////////////
442// Tiling
443///////////////////////////////////////////////////////////////////////////////
444
445void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool opaque) {
Romain Guy4285de32012-09-23 14:46:35 -0700446 if (extensions.hasTiledRendering() && !debugOverdraw) {
447 glStartTilingQCOM(x, y, width, height, (opaque ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
Romain Guy85ef80d2012-09-13 20:26:50 -0700448 }
449}
450
451void Caches::endTiling() {
Romain Guy4285de32012-09-23 14:46:35 -0700452 if (extensions.hasTiledRendering() && !debugOverdraw) {
Romain Guy2b7028e2012-09-19 17:25:38 -0700453 glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
Romain Guy85ef80d2012-09-13 20:26:50 -0700454 }
455}
456
457///////////////////////////////////////////////////////////////////////////////
458// Regions
459///////////////////////////////////////////////////////////////////////////////
460
Romain Guy5b3b3522010-10-27 18:57:51 -0700461TextureVertex* Caches::getRegionMesh() {
462 // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
463 if (!mRegionMesh) {
464 mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4];
465
466 uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6];
467 for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) {
468 uint16_t quad = i * 4;
469 int index = i * 6;
470 regionIndices[index ] = quad; // top-left
471 regionIndices[index + 1] = quad + 1; // top-right
472 regionIndices[index + 2] = quad + 2; // bottom-left
473 regionIndices[index + 3] = quad + 2; // bottom-left
474 regionIndices[index + 4] = quad + 1; // top-right
475 regionIndices[index + 5] = quad + 3; // bottom-right
476 }
477
478 glGenBuffers(1, &mRegionMeshIndices);
Romain Guy15bc6432011-12-13 13:11:32 -0800479 bindIndicesBuffer(mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700480 glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
481 regionIndices, GL_STATIC_DRAW);
482
483 delete[] regionIndices;
484 } else {
Romain Guy15bc6432011-12-13 13:11:32 -0800485 bindIndicesBuffer(mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700486 }
487
488 return mRegionMesh;
489}
490
Chet Haasedd78cca2010-10-22 18:59:26 -0700491}; // namespace uirenderer
492}; // namespace android