blob: 2883f378df89b8b8b0f73f469bc5614daed67101 [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;
Chris Craikcb4d6002012-09-25 12:00:29 -070071 mCurrentPositionStride = 0;
Romain Guyf3a910b42011-12-12 20:35:21 -080072 mCurrentTexCoordsPointer = this;
73
Romain Guy15bc6432011-12-13 13:11:32 -080074 mTexCoordsArrayEnabled = false;
75
Romain Guyb1d0a4e2012-07-13 18:25:35 -070076 glDisable(GL_SCISSOR_TEST);
Romain Guy586cae32012-07-13 15:28:31 -070077 scissorEnabled = false;
Romain Guy8f85e802011-12-14 19:23:32 -080078 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
79
Romain Guya1d3c912011-12-13 14:55:06 -080080 glActiveTexture(gTextureUnits[0]);
81 mTextureUnit = 0;
82
Romain Guy8ff6b9e2011-11-09 20:10:18 -080083 mRegionMesh = NULL;
84
85 blend = false;
86 lastSrcMode = GL_ZERO;
87 lastDstMode = GL_ZERO;
88 currentProgram = NULL;
89
90 mInitialized = true;
91}
92
Romain Guyb1d0a4e2012-07-13 18:25:35 -070093void Caches::initFont() {
94 fontRenderer = GammaFontRenderer::createRenderer();
95}
96
Romain Guydfa10462012-05-12 16:18:58 -070097void Caches::initExtensions() {
98 if (extensions.hasDebugMarker()) {
99 eventMark = glInsertEventMarkerEXT;
100 startMark = glPushGroupMarkerEXT;
101 endMark = glPopGroupMarkerEXT;
102 } else {
103 eventMark = eventMarkNull;
104 startMark = startMarkNull;
105 endMark = endMarkNull;
106 }
107
108 if (extensions.hasDebugLabel()) {
109 setLabel = glLabelObjectEXT;
110 getLabel = glGetObjectLabelEXT;
111 } else {
112 setLabel = setLabelNull;
113 getLabel = getLabelNull;
114 }
115}
116
117void Caches::initConstraints() {
118 GLint maxTextureUnits;
119 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
120 if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
121 ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
122 }
123
124 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
125}
126
Romain Guy4ff0cf42012-08-06 14:51:10 -0700127void Caches::initProperties() {
128 char property[PROPERTY_VALUE_MAX];
129 if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, NULL) > 0) {
130 INIT_LOGD(" Layers updates debug enabled: %s", property);
131 debugLayersUpdates = !strcmp(property, "true");
132 } else {
133 debugLayersUpdates = false;
134 }
Romain Guy7c450aa2012-09-21 19:15:00 -0700135
136 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, NULL) > 0) {
137 INIT_LOGD(" Overdraw debug enabled: %s", property);
138 debugOverdraw = !strcmp(property, "true");
139 } else {
140 debugOverdraw = false;
141 }
Romain Guy4ff0cf42012-08-06 14:51:10 -0700142}
143
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800144void Caches::terminate() {
145 if (!mInitialized) return;
146
147 glDeleteBuffers(1, &meshBuffer);
148 mCurrentBuffer = 0;
149
150 glDeleteBuffers(1, &mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700151 delete[] mRegionMesh;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800152 mRegionMesh = NULL;
153
154 fboCache.clear();
155
156 programCache.clear();
157 currentProgram = NULL;
158
159 mInitialized = false;
Romain Guy5b3b3522010-10-27 18:57:51 -0700160}
161
162///////////////////////////////////////////////////////////////////////////////
Romain Guyc15008e2010-11-10 11:59:15 -0800163// Debug
164///////////////////////////////////////////////////////////////////////////////
165
166void Caches::dumpMemoryUsage() {
Chet Haase9c1e23b2011-03-24 10:51:31 -0700167 String8 stringLog;
168 dumpMemoryUsage(stringLog);
Steve Block5baa3a62011-12-20 16:23:08 +0000169 ALOGD("%s", stringLog.string());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700170}
171
172void Caches::dumpMemoryUsage(String8 &log) {
173 log.appendFormat("Current memory usage / total memory usage (bytes):\n");
174 log.appendFormat(" TextureCache %8d / %8d\n",
175 textureCache.getSize(), textureCache.getMaxSize());
176 log.appendFormat(" LayerCache %8d / %8d\n",
177 layerCache.getSize(), layerCache.getMaxSize());
178 log.appendFormat(" GradientCache %8d / %8d\n",
179 gradientCache.getSize(), gradientCache.getMaxSize());
180 log.appendFormat(" PathCache %8d / %8d\n",
181 pathCache.getSize(), pathCache.getMaxSize());
182 log.appendFormat(" CircleShapeCache %8d / %8d\n",
Romain Guy01d58e42011-01-19 21:54:02 -0800183 circleShapeCache.getSize(), circleShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700184 log.appendFormat(" OvalShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800185 ovalShapeCache.getSize(), ovalShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700186 log.appendFormat(" RoundRectShapeCache %8d / %8d\n",
Romain Guy01d58e42011-01-19 21:54:02 -0800187 roundRectShapeCache.getSize(), roundRectShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700188 log.appendFormat(" RectShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800189 rectShapeCache.getSize(), rectShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700190 log.appendFormat(" ArcShapeCache %8d / %8d\n",
Romain Guy2fc941e2011-02-03 15:06:05 -0800191 arcShapeCache.getSize(), arcShapeCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700192 log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(),
Romain Guyc15008e2010-11-10 11:59:15 -0800193 dropShadowCache.getMaxSize());
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700194 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
195 const uint32_t size = fontRenderer->getFontRendererSize(i);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700196 log.appendFormat(" FontRenderer %d %8d / %8d\n", i, size, size);
Romain Guyc15008e2010-11-10 11:59:15 -0800197 }
Romain Guyd2ba50a2011-05-27 10:21:07 -0700198 log.appendFormat("Other:\n");
Chet Haase9c1e23b2011-03-24 10:51:31 -0700199 log.appendFormat(" FboCache %8d / %8d\n",
200 fboCache.getSize(), fboCache.getMaxSize());
201 log.appendFormat(" PatchCache %8d / %8d\n",
202 patchCache.getSize(), patchCache.getMaxSize());
Romain Guyc15008e2010-11-10 11:59:15 -0800203
204 uint32_t total = 0;
205 total += textureCache.getSize();
206 total += layerCache.getSize();
207 total += gradientCache.getSize();
208 total += pathCache.getSize();
209 total += dropShadowCache.getSize();
Romain Guy2fc941e2011-02-03 15:06:05 -0800210 total += roundRectShapeCache.getSize();
211 total += circleShapeCache.getSize();
212 total += ovalShapeCache.getSize();
213 total += rectShapeCache.getSize();
214 total += arcShapeCache.getSize();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700215 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
216 total += fontRenderer->getFontRendererSize(i);
Romain Guyc15008e2010-11-10 11:59:15 -0800217 }
218
Chet Haase9c1e23b2011-03-24 10:51:31 -0700219 log.appendFormat("Total memory usage:\n");
220 log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
Romain Guyc15008e2010-11-10 11:59:15 -0800221}
222
223///////////////////////////////////////////////////////////////////////////////
Romain Guyfe48f652010-11-11 15:36:56 -0800224// Memory management
225///////////////////////////////////////////////////////////////////////////////
226
227void Caches::clearGarbage() {
228 textureCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800229 pathCache.clearGarbage();
Romain Guy57066eb2011-01-12 12:53:32 -0800230
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700231 Vector<DisplayList*> displayLists;
232 Vector<Layer*> layers;
Romain Guy57066eb2011-01-12 12:53:32 -0800233
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700234 { // scope for the lock
235 Mutex::Autolock _l(mGarbageLock);
236 displayLists = mDisplayListGarbage;
237 layers = mLayerGarbage;
238 mDisplayListGarbage.clear();
239 mLayerGarbage.clear();
Romain Guy57066eb2011-01-12 12:53:32 -0800240 }
Romain Guybb0acdf2012-03-05 13:44:35 -0800241
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700242 size_t count = displayLists.size();
Romain Guybb0acdf2012-03-05 13:44:35 -0800243 for (size_t i = 0; i < count; i++) {
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700244 DisplayList* displayList = displayLists.itemAt(i);
Romain Guybb0acdf2012-03-05 13:44:35 -0800245 delete displayList;
246 }
Mathias Agopian17ef62c2012-09-25 22:52:40 -0700247
248 count = layers.size();
249 for (size_t i = 0; i < count; i++) {
250 Layer* layer = layers.itemAt(i);
251 delete layer;
252 }
253 layers.clear();
Romain Guy57066eb2011-01-12 12:53:32 -0800254}
255
Romain Guyada830f2011-01-13 12:13:20 -0800256void Caches::deleteLayerDeferred(Layer* layer) {
Romain Guy57066eb2011-01-12 12:53:32 -0800257 Mutex::Autolock _l(mGarbageLock);
Romain Guyada830f2011-01-13 12:13:20 -0800258 mLayerGarbage.push(layer);
Romain Guyfe48f652010-11-11 15:36:56 -0800259}
260
Romain Guybb0acdf2012-03-05 13:44:35 -0800261void Caches::deleteDisplayListDeferred(DisplayList* displayList) {
262 Mutex::Autolock _l(mGarbageLock);
263 mDisplayListGarbage.push(displayList);
264}
265
Romain Guybdf76092011-07-18 15:00:43 -0700266void Caches::flush(FlushMode mode) {
267 FLUSH_LOGD("Flushing caches (mode %d)", mode);
268
269 clearGarbage();
270
271 switch (mode) {
272 case kFlushMode_Full:
273 textureCache.clear();
274 patchCache.clear();
275 dropShadowCache.clear();
276 gradientCache.clear();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700277 fontRenderer->clear();
Romain Guy211efea2012-07-31 21:16:07 -0700278 dither.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700279 // fall through
280 case kFlushMode_Moderate:
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700281 fontRenderer->flush();
Romain Guyeca0ca22011-11-04 15:12:29 -0700282 textureCache.flush();
Romain Guybdf76092011-07-18 15:00:43 -0700283 pathCache.clear();
284 roundRectShapeCache.clear();
285 circleShapeCache.clear();
286 ovalShapeCache.clear();
287 rectShapeCache.clear();
288 arcShapeCache.clear();
Romain Guy6d7475d2011-07-27 16:28:21 -0700289 // fall through
290 case kFlushMode_Layers:
291 layerCache.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700292 break;
293 }
294}
295
Romain Guyfe48f652010-11-11 15:36:56 -0800296///////////////////////////////////////////////////////////////////////////////
Romain Guy5b3b3522010-10-27 18:57:51 -0700297// VBO
298///////////////////////////////////////////////////////////////////////////////
299
Romain Guyf3a910b42011-12-12 20:35:21 -0800300bool Caches::bindMeshBuffer() {
301 return bindMeshBuffer(meshBuffer);
Chet Haasedd78cca2010-10-22 18:59:26 -0700302}
303
Romain Guyf3a910b42011-12-12 20:35:21 -0800304bool Caches::bindMeshBuffer(const GLuint buffer) {
Romain Guy9bca4792010-10-25 18:42:25 -0700305 if (mCurrentBuffer != buffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -0700306 glBindBuffer(GL_ARRAY_BUFFER, buffer);
Romain Guy9bca4792010-10-25 18:42:25 -0700307 mCurrentBuffer = buffer;
Romain Guyf3a910b42011-12-12 20:35:21 -0800308 return true;
Chet Haasedd78cca2010-10-22 18:59:26 -0700309 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800310 return false;
Chet Haasedd78cca2010-10-22 18:59:26 -0700311}
312
Romain Guyf3a910b42011-12-12 20:35:21 -0800313bool Caches::unbindMeshBuffer() {
Romain Guy9bca4792010-10-25 18:42:25 -0700314 if (mCurrentBuffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -0700315 glBindBuffer(GL_ARRAY_BUFFER, 0);
Romain Guy9bca4792010-10-25 18:42:25 -0700316 mCurrentBuffer = 0;
Romain Guyf3a910b42011-12-12 20:35:21 -0800317 return true;
Chet Haasedd78cca2010-10-22 18:59:26 -0700318 }
Romain Guyf3a910b42011-12-12 20:35:21 -0800319 return false;
320}
321
Romain Guy15bc6432011-12-13 13:11:32 -0800322bool Caches::bindIndicesBuffer(const GLuint buffer) {
323 if (mCurrentIndicesBuffer != buffer) {
324 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
325 mCurrentIndicesBuffer = buffer;
326 return true;
327 }
328 return false;
329}
330
331bool Caches::unbindIndicesBuffer() {
332 if (mCurrentIndicesBuffer) {
333 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
334 mCurrentIndicesBuffer = 0;
335 return true;
336 }
337 return false;
338}
339
Romain Guy85ef80d2012-09-13 20:26:50 -0700340///////////////////////////////////////////////////////////////////////////////
341// Meshes and textures
342///////////////////////////////////////////////////////////////////////////////
343
Chris Craikcb4d6002012-09-25 12:00:29 -0700344void Caches::bindPositionVertexPointer(bool force, GLvoid* vertices, GLsizei stride) {
345 if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) {
346 GLuint slot = currentProgram->position;
Romain Guyf3a910b42011-12-12 20:35:21 -0800347 glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
348 mCurrentPositionPointer = vertices;
Chris Craikcb4d6002012-09-25 12:00:29 -0700349 mCurrentPositionStride = stride;
Romain Guyf3a910b42011-12-12 20:35:21 -0800350 }
351}
352
Chris Craikcb4d6002012-09-25 12:00:29 -0700353void Caches::bindTexCoordsVertexPointer(bool force, GLvoid* vertices) {
Romain Guyf3a910b42011-12-12 20:35:21 -0800354 if (force || vertices != mCurrentTexCoordsPointer) {
Chris Craikcb4d6002012-09-25 12:00:29 -0700355 GLuint slot = currentProgram->texCoords;
Romain Guyf3a910b42011-12-12 20:35:21 -0800356 glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, gMeshStride, vertices);
357 mCurrentTexCoordsPointer = vertices;
358 }
359}
360
361void Caches::resetVertexPointers() {
362 mCurrentPositionPointer = this;
363 mCurrentTexCoordsPointer = this;
364}
365
366void Caches::resetTexCoordsVertexPointer() {
367 mCurrentTexCoordsPointer = this;
Chet Haasedd78cca2010-10-22 18:59:26 -0700368}
369
Romain Guy15bc6432011-12-13 13:11:32 -0800370void Caches::enableTexCoordsVertexArray() {
371 if (!mTexCoordsArrayEnabled) {
372 glEnableVertexAttribArray(Program::kBindingTexCoords);
Romain Guyec31f832011-12-13 18:39:19 -0800373 mCurrentTexCoordsPointer = this;
Romain Guy15bc6432011-12-13 13:11:32 -0800374 mTexCoordsArrayEnabled = true;
375 }
376}
377
378void Caches::disbaleTexCoordsVertexArray() {
379 if (mTexCoordsArrayEnabled) {
380 glDisableVertexAttribArray(Program::kBindingTexCoords);
381 mTexCoordsArrayEnabled = false;
382 }
383}
384
Romain Guya1d3c912011-12-13 14:55:06 -0800385void Caches::activeTexture(GLuint textureUnit) {
386 if (mTextureUnit != textureUnit) {
387 glActiveTexture(gTextureUnits[textureUnit]);
388 mTextureUnit = textureUnit;
389 }
390}
391
Romain Guy85ef80d2012-09-13 20:26:50 -0700392///////////////////////////////////////////////////////////////////////////////
393// Scissor
394///////////////////////////////////////////////////////////////////////////////
395
Romain Guy8a4ac612012-07-17 17:32:48 -0700396bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
Romain Guy586cae32012-07-13 15:28:31 -0700397 if (scissorEnabled && (x != mScissorX || y != mScissorY ||
398 width != mScissorWidth || height != mScissorHeight)) {
399
Romain Guy35643dd2012-09-18 15:40:58 -0700400 if (x < 0) x = 0;
401 if (y < 0) y = 0;
402
Romain Guy8f85e802011-12-14 19:23:32 -0800403 glScissor(x, y, width, height);
404
405 mScissorX = x;
406 mScissorY = y;
407 mScissorWidth = width;
408 mScissorHeight = height;
Romain Guy8a4ac612012-07-17 17:32:48 -0700409
410 return true;
Romain Guy8f85e802011-12-14 19:23:32 -0800411 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700412 return false;
Romain Guy8f85e802011-12-14 19:23:32 -0800413}
414
Romain Guy8a4ac612012-07-17 17:32:48 -0700415bool Caches::enableScissor() {
Romain Guy586cae32012-07-13 15:28:31 -0700416 if (!scissorEnabled) {
417 glEnable(GL_SCISSOR_TEST);
418 scissorEnabled = true;
Romain Guy8a4ac612012-07-17 17:32:48 -0700419 return true;
Romain Guy586cae32012-07-13 15:28:31 -0700420 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700421 return false;
Romain Guy586cae32012-07-13 15:28:31 -0700422}
423
Romain Guy8a4ac612012-07-17 17:32:48 -0700424bool Caches::disableScissor() {
Romain Guy586cae32012-07-13 15:28:31 -0700425 if (scissorEnabled) {
426 glDisable(GL_SCISSOR_TEST);
427 scissorEnabled = false;
Romain Guy8a4ac612012-07-17 17:32:48 -0700428 return true;
Romain Guy586cae32012-07-13 15:28:31 -0700429 }
Romain Guy8a4ac612012-07-17 17:32:48 -0700430 return false;
Romain Guy586cae32012-07-13 15:28:31 -0700431}
432
433void Caches::setScissorEnabled(bool enabled) {
434 if (scissorEnabled != enabled) {
435 if (enabled) glEnable(GL_SCISSOR_TEST);
436 else glDisable(GL_SCISSOR_TEST);
437 scissorEnabled = enabled;
438 }
439}
440
Romain Guy82bc7a72012-01-03 14:13:39 -0800441void Caches::resetScissor() {
442 mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
443}
444
Romain Guy85ef80d2012-09-13 20:26:50 -0700445///////////////////////////////////////////////////////////////////////////////
446// Tiling
447///////////////////////////////////////////////////////////////////////////////
448
449void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool opaque) {
Romain Guy4285de32012-09-23 14:46:35 -0700450 if (extensions.hasTiledRendering() && !debugOverdraw) {
451 glStartTilingQCOM(x, y, width, height, (opaque ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
Romain Guy85ef80d2012-09-13 20:26:50 -0700452 }
453}
454
455void Caches::endTiling() {
Romain Guy4285de32012-09-23 14:46:35 -0700456 if (extensions.hasTiledRendering() && !debugOverdraw) {
Romain Guy2b7028e2012-09-19 17:25:38 -0700457 glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
Romain Guy85ef80d2012-09-13 20:26:50 -0700458 }
459}
460
461///////////////////////////////////////////////////////////////////////////////
462// Regions
463///////////////////////////////////////////////////////////////////////////////
464
Romain Guy5b3b3522010-10-27 18:57:51 -0700465TextureVertex* Caches::getRegionMesh() {
466 // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
467 if (!mRegionMesh) {
468 mRegionMesh = new TextureVertex[REGION_MESH_QUAD_COUNT * 4];
469
470 uint16_t* regionIndices = new uint16_t[REGION_MESH_QUAD_COUNT * 6];
471 for (int i = 0; i < REGION_MESH_QUAD_COUNT; i++) {
472 uint16_t quad = i * 4;
473 int index = i * 6;
474 regionIndices[index ] = quad; // top-left
475 regionIndices[index + 1] = quad + 1; // top-right
476 regionIndices[index + 2] = quad + 2; // bottom-left
477 regionIndices[index + 3] = quad + 2; // bottom-left
478 regionIndices[index + 4] = quad + 1; // top-right
479 regionIndices[index + 5] = quad + 3; // bottom-right
480 }
481
482 glGenBuffers(1, &mRegionMeshIndices);
Romain Guy15bc6432011-12-13 13:11:32 -0800483 bindIndicesBuffer(mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700484 glBufferData(GL_ELEMENT_ARRAY_BUFFER, REGION_MESH_QUAD_COUNT * 6 * sizeof(uint16_t),
485 regionIndices, GL_STATIC_DRAW);
486
487 delete[] regionIndices;
488 } else {
Romain Guy15bc6432011-12-13 13:11:32 -0800489 bindIndicesBuffer(mRegionMeshIndices);
Romain Guy5b3b3522010-10-27 18:57:51 -0700490 }
491
492 return mRegionMesh;
493}
494
Chet Haasedd78cca2010-10-22 18:59:26 -0700495}; // namespace uirenderer
496}; // namespace android