Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 1 | /* |
| 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 Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 19 | #include <utils/Log.h> |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 20 | #include <utils/String8.h> |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 21 | |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 22 | #include "Caches.h" |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 23 | #include "DisplayListRenderer.h" |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 24 | #include "Properties.h" |
Romain Guy | 09b7c91 | 2011-02-02 20:28:09 -0800 | [diff] [blame] | 25 | #include "LayerRenderer.h" |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | #ifdef USE_OPENGL_RENDERER |
| 30 | using namespace uirenderer; |
| 31 | ANDROID_SINGLETON_STATIC_INSTANCE(Caches); |
| 32 | #endif |
| 33 | |
| 34 | namespace uirenderer { |
| 35 | |
| 36 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 37 | // Macros |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | #if DEBUG_CACHE_FLUSH |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 41 | #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 42 | #else |
| 43 | #define FLUSH_LOGD(...) |
| 44 | #endif |
| 45 | |
| 46 | /////////////////////////////////////////////////////////////////////////////// |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 47 | // Constructors/destructor |
| 48 | /////////////////////////////////////////////////////////////////////////////// |
| 49 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 50 | Caches::Caches(): Singleton<Caches>(), |
| 51 | mExtensions(Extensions::getInstance()), mInitialized(false) { |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 52 | init(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 53 | initFont(); |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 54 | initConstraints(); |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 55 | initProperties(); |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 56 | initStaticProperties(); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 57 | initExtensions(); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 58 | |
| 59 | mDebugLevel = readDebugLevel(); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 60 | ALOGD("Enabling debug mode %d", mDebugLevel); |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 63 | bool Caches::init() { |
| 64 | if (mInitialized) return false; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 65 | |
| 66 | glGenBuffers(1, &meshBuffer); |
| 67 | glBindBuffer(GL_ARRAY_BUFFER, meshBuffer); |
| 68 | glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW); |
| 69 | |
| 70 | mCurrentBuffer = meshBuffer; |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 71 | mCurrentIndicesBuffer = 0; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 72 | mCurrentPositionPointer = this; |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 73 | mCurrentPositionStride = 0; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 74 | mCurrentTexCoordsPointer = this; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 75 | mCurrentPixelBuffer = 0; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 76 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 77 | mTexCoordsArrayEnabled = false; |
| 78 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 79 | glDisable(GL_SCISSOR_TEST); |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 80 | scissorEnabled = false; |
Romain Guy | 8f85e80 | 2011-12-14 19:23:32 -0800 | [diff] [blame] | 81 | mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0; |
| 82 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 83 | glActiveTexture(gTextureUnits[0]); |
| 84 | mTextureUnit = 0; |
| 85 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 86 | mRegionMesh = NULL; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 87 | mMeshIndices = 0; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 88 | |
| 89 | blend = false; |
| 90 | lastSrcMode = GL_ZERO; |
| 91 | lastDstMode = GL_ZERO; |
| 92 | currentProgram = NULL; |
| 93 | |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 94 | mFunctorsCount = 0; |
| 95 | |
Romain Guy | c2a9721 | 2013-02-06 15:29:46 -0800 | [diff] [blame] | 96 | debugLayersUpdates = false; |
| 97 | debugOverdraw = false; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 98 | debugStencilClip = kStencilHide; |
Romain Guy | c2a9721 | 2013-02-06 15:29:46 -0800 | [diff] [blame] | 99 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 100 | patchCache.init(*this); |
| 101 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 102 | mInitialized = true; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 103 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 104 | resetBoundTextures(); |
| 105 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 106 | return true; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 109 | void Caches::initFont() { |
| 110 | fontRenderer = GammaFontRenderer::createRenderer(); |
| 111 | } |
| 112 | |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 113 | void Caches::initExtensions() { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 114 | if (mExtensions.hasDebugMarker()) { |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 115 | eventMark = glInsertEventMarkerEXT; |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 116 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 117 | startMark = glPushGroupMarkerEXT; |
| 118 | endMark = glPopGroupMarkerEXT; |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 119 | } else { |
| 120 | eventMark = eventMarkNull; |
| 121 | startMark = startMarkNull; |
| 122 | endMark = endMarkNull; |
| 123 | } |
| 124 | |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 125 | if (mExtensions.hasDebugLabel() && (drawDeferDisabled || drawReorderDisabled)) { |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 126 | setLabel = glLabelObjectEXT; |
| 127 | getLabel = glGetObjectLabelEXT; |
| 128 | } else { |
| 129 | setLabel = setLabelNull; |
| 130 | getLabel = getLabelNull; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void Caches::initConstraints() { |
| 135 | GLint maxTextureUnits; |
| 136 | glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits); |
| 137 | if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) { |
| 138 | ALOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT); |
| 139 | } |
| 140 | |
| 141 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); |
| 142 | } |
| 143 | |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 144 | void Caches::initStaticProperties() { |
| 145 | gpuPixelBuffersEnabled = false; |
| 146 | |
| 147 | // OpenGL ES 3.0+ specific features |
Romain Guy | 7f43076 | 2013-06-13 14:29:40 -0700 | [diff] [blame] | 148 | if (mExtensions.hasPixelBufferObjects()) { |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 149 | char property[PROPERTY_VALUE_MAX]; |
| 150 | if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) { |
| 151 | gpuPixelBuffersEnabled = !strcmp(property, "true"); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 156 | bool Caches::initProperties() { |
| 157 | bool prevDebugLayersUpdates = debugLayersUpdates; |
| 158 | bool prevDebugOverdraw = debugOverdraw; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 159 | StencilClipDebug prevDebugStencilClip = debugStencilClip; |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 160 | |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 161 | char property[PROPERTY_VALUE_MAX]; |
| 162 | if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, NULL) > 0) { |
| 163 | INIT_LOGD(" Layers updates debug enabled: %s", property); |
| 164 | debugLayersUpdates = !strcmp(property, "true"); |
| 165 | } else { |
| 166 | debugLayersUpdates = false; |
| 167 | } |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 168 | |
| 169 | if (property_get(PROPERTY_DEBUG_OVERDRAW, property, NULL) > 0) { |
| 170 | INIT_LOGD(" Overdraw debug enabled: %s", property); |
Romain Guy | 78dd96d | 2013-05-03 14:24:16 -0700 | [diff] [blame] | 171 | debugOverdraw = !strcmp(property, "show"); |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 172 | } else { |
| 173 | debugOverdraw = false; |
| 174 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 175 | |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 176 | // See Properties.h for valid values |
| 177 | if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, NULL) > 0) { |
| 178 | INIT_LOGD(" Stencil clip debug enabled: %s", property); |
| 179 | if (!strcmp(property, "hide")) { |
| 180 | debugStencilClip = kStencilHide; |
| 181 | } else if (!strcmp(property, "highlight")) { |
| 182 | debugStencilClip = kStencilShowHighlight; |
| 183 | } else if (!strcmp(property, "region")) { |
| 184 | debugStencilClip = kStencilShowRegion; |
| 185 | } |
| 186 | } else { |
| 187 | debugStencilClip = kStencilHide; |
| 188 | } |
| 189 | |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 190 | if (property_get(PROPERTY_DISABLE_DRAW_DEFER, property, "false")) { |
| 191 | drawDeferDisabled = !strcasecmp(property, "true"); |
| 192 | INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled"); |
| 193 | } else { |
| 194 | INIT_LOGD(" Draw defer enabled"); |
| 195 | } |
| 196 | |
| 197 | if (property_get(PROPERTY_DISABLE_DRAW_REORDER, property, "false")) { |
| 198 | drawReorderDisabled = !strcasecmp(property, "true"); |
| 199 | INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled"); |
| 200 | } else { |
| 201 | INIT_LOGD(" Draw reorder enabled"); |
| 202 | } |
| 203 | |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 204 | return (prevDebugLayersUpdates != debugLayersUpdates) || |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 205 | (prevDebugOverdraw != debugOverdraw) || |
| 206 | (prevDebugStencilClip != debugStencilClip); |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 209 | void Caches::terminate() { |
| 210 | if (!mInitialized) return; |
| 211 | |
| 212 | glDeleteBuffers(1, &meshBuffer); |
| 213 | mCurrentBuffer = 0; |
| 214 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 215 | glDeleteBuffers(1, &mMeshIndices); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 216 | delete[] mRegionMesh; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 217 | mMeshIndices = 0; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 218 | mRegionMesh = NULL; |
| 219 | |
| 220 | fboCache.clear(); |
| 221 | |
| 222 | programCache.clear(); |
| 223 | currentProgram = NULL; |
| 224 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 225 | assetAtlas.terminate(); |
| 226 | |
| 227 | patchCache.clear(); |
| 228 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 229 | mInitialized = false; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 233 | // Debug |
| 234 | /////////////////////////////////////////////////////////////////////////////// |
| 235 | |
| 236 | void Caches::dumpMemoryUsage() { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 237 | String8 stringLog; |
| 238 | dumpMemoryUsage(stringLog); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 239 | ALOGD("%s", stringLog.string()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void Caches::dumpMemoryUsage(String8 &log) { |
| 243 | log.appendFormat("Current memory usage / total memory usage (bytes):\n"); |
| 244 | log.appendFormat(" TextureCache %8d / %8d\n", |
| 245 | textureCache.getSize(), textureCache.getMaxSize()); |
| 246 | log.appendFormat(" LayerCache %8d / %8d\n", |
| 247 | layerCache.getSize(), layerCache.getMaxSize()); |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 248 | log.appendFormat(" RenderBufferCache %8d / %8d\n", |
| 249 | renderBufferCache.getSize(), renderBufferCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 250 | log.appendFormat(" GradientCache %8d / %8d\n", |
| 251 | gradientCache.getSize(), gradientCache.getMaxSize()); |
| 252 | log.appendFormat(" PathCache %8d / %8d\n", |
| 253 | pathCache.getSize(), pathCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 254 | log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(), |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 255 | dropShadowCache.getMaxSize()); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 256 | log.appendFormat(" PatchCache %8d / %8d\n", |
| 257 | patchCache.getSize(), patchCache.getMaxSize()); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 258 | for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) { |
| 259 | const uint32_t size = fontRenderer->getFontRendererSize(i); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 260 | log.appendFormat(" FontRenderer %d %8d / %8d\n", i, size, size); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 261 | } |
Romain Guy | d2ba50a | 2011-05-27 10:21:07 -0700 | [diff] [blame] | 262 | log.appendFormat("Other:\n"); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 263 | log.appendFormat(" FboCache %8d / %8d\n", |
| 264 | fboCache.getSize(), fboCache.getMaxSize()); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 265 | |
| 266 | uint32_t total = 0; |
| 267 | total += textureCache.getSize(); |
| 268 | total += layerCache.getSize(); |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 269 | total += renderBufferCache.getSize(); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 270 | total += gradientCache.getSize(); |
| 271 | total += pathCache.getSize(); |
| 272 | total += dropShadowCache.getSize(); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 273 | total += patchCache.getSize(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 274 | for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) { |
| 275 | total += fontRenderer->getFontRendererSize(i); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 278 | log.appendFormat("Total memory usage:\n"); |
| 279 | log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 283 | // Memory management |
| 284 | /////////////////////////////////////////////////////////////////////////////// |
| 285 | |
| 286 | void Caches::clearGarbage() { |
| 287 | textureCache.clearGarbage(); |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 288 | pathCache.clearGarbage(); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 289 | |
Mathias Agopian | 17ef62c | 2012-09-25 22:52:40 -0700 | [diff] [blame] | 290 | Vector<DisplayList*> displayLists; |
| 291 | Vector<Layer*> layers; |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 292 | |
Mathias Agopian | 17ef62c | 2012-09-25 22:52:40 -0700 | [diff] [blame] | 293 | { // scope for the lock |
| 294 | Mutex::Autolock _l(mGarbageLock); |
| 295 | displayLists = mDisplayListGarbage; |
| 296 | layers = mLayerGarbage; |
| 297 | mDisplayListGarbage.clear(); |
| 298 | mLayerGarbage.clear(); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 299 | } |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 300 | |
Mathias Agopian | 17ef62c | 2012-09-25 22:52:40 -0700 | [diff] [blame] | 301 | size_t count = displayLists.size(); |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 302 | for (size_t i = 0; i < count; i++) { |
Mathias Agopian | 17ef62c | 2012-09-25 22:52:40 -0700 | [diff] [blame] | 303 | DisplayList* displayList = displayLists.itemAt(i); |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 304 | delete displayList; |
| 305 | } |
Mathias Agopian | 17ef62c | 2012-09-25 22:52:40 -0700 | [diff] [blame] | 306 | |
| 307 | count = layers.size(); |
| 308 | for (size_t i = 0; i < count; i++) { |
| 309 | Layer* layer = layers.itemAt(i); |
| 310 | delete layer; |
| 311 | } |
| 312 | layers.clear(); |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 315 | void Caches::deleteLayerDeferred(Layer* layer) { |
Romain Guy | 57066eb | 2011-01-12 12:53:32 -0800 | [diff] [blame] | 316 | Mutex::Autolock _l(mGarbageLock); |
Romain Guy | ada830f | 2011-01-13 12:13:20 -0800 | [diff] [blame] | 317 | mLayerGarbage.push(layer); |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Romain Guy | bb0acdf | 2012-03-05 13:44:35 -0800 | [diff] [blame] | 320 | void Caches::deleteDisplayListDeferred(DisplayList* displayList) { |
| 321 | Mutex::Autolock _l(mGarbageLock); |
| 322 | mDisplayListGarbage.push(displayList); |
| 323 | } |
| 324 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 325 | void Caches::flush(FlushMode mode) { |
| 326 | FLUSH_LOGD("Flushing caches (mode %d)", mode); |
| 327 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 328 | switch (mode) { |
| 329 | case kFlushMode_Full: |
| 330 | textureCache.clear(); |
| 331 | patchCache.clear(); |
| 332 | dropShadowCache.clear(); |
| 333 | gradientCache.clear(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 334 | fontRenderer->clear(); |
Romain Guy | 211efea | 2012-07-31 21:16:07 -0700 | [diff] [blame] | 335 | dither.clear(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 336 | // fall through |
| 337 | case kFlushMode_Moderate: |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 338 | fontRenderer->flush(); |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 339 | textureCache.flush(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 340 | pathCache.clear(); |
Romain Guy | c5cbee7 | 2013-03-20 19:15:02 -0700 | [diff] [blame] | 341 | tasks.stop(); |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 342 | // fall through |
| 343 | case kFlushMode_Layers: |
| 344 | layerCache.clear(); |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 345 | renderBufferCache.clear(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 346 | break; |
| 347 | } |
Chet Haase | 6a2d17f | 2012-09-30 12:14:13 -0700 | [diff] [blame] | 348 | |
| 349 | clearGarbage(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 352 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 353 | // VBO |
| 354 | /////////////////////////////////////////////////////////////////////////////// |
| 355 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 356 | bool Caches::bindMeshBuffer() { |
| 357 | return bindMeshBuffer(meshBuffer); |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 360 | bool Caches::bindMeshBuffer(const GLuint buffer) { |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 361 | if (mCurrentBuffer != buffer) { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 362 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 363 | mCurrentBuffer = buffer; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 364 | return true; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 365 | } |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 366 | return false; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 369 | bool Caches::unbindMeshBuffer() { |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 370 | if (mCurrentBuffer) { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 371 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
Romain Guy | 9bca479 | 2010-10-25 18:42:25 -0700 | [diff] [blame] | 372 | mCurrentBuffer = 0; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 373 | return true; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 374 | } |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 378 | bool Caches::bindIndicesBuffer(const GLuint buffer) { |
| 379 | if (mCurrentIndicesBuffer != buffer) { |
| 380 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); |
| 381 | mCurrentIndicesBuffer = buffer; |
| 382 | return true; |
| 383 | } |
| 384 | return false; |
| 385 | } |
| 386 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 387 | bool Caches::bindIndicesBuffer() { |
| 388 | if (!mMeshIndices) { |
Romain Guy | 31e08e9 | 2013-06-18 15:53:53 -0700 | [diff] [blame^] | 389 | uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6]; |
| 390 | for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 391 | uint16_t quad = i * 4; |
| 392 | int index = i * 6; |
| 393 | regionIndices[index ] = quad; // top-left |
| 394 | regionIndices[index + 1] = quad + 1; // top-right |
| 395 | regionIndices[index + 2] = quad + 2; // bottom-left |
| 396 | regionIndices[index + 3] = quad + 2; // bottom-left |
| 397 | regionIndices[index + 4] = quad + 1; // top-right |
| 398 | regionIndices[index + 5] = quad + 3; // bottom-right |
| 399 | } |
| 400 | |
| 401 | glGenBuffers(1, &mMeshIndices); |
| 402 | bool force = bindIndicesBuffer(mMeshIndices); |
Romain Guy | 31e08e9 | 2013-06-18 15:53:53 -0700 | [diff] [blame^] | 403 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t), |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 404 | regionIndices, GL_STATIC_DRAW); |
| 405 | |
| 406 | delete[] regionIndices; |
| 407 | return force; |
| 408 | } |
| 409 | |
| 410 | return bindIndicesBuffer(mMeshIndices); |
| 411 | } |
| 412 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 413 | bool Caches::unbindIndicesBuffer() { |
| 414 | if (mCurrentIndicesBuffer) { |
| 415 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 416 | mCurrentIndicesBuffer = 0; |
| 417 | return true; |
| 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 422 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 423 | // PBO |
| 424 | /////////////////////////////////////////////////////////////////////////////// |
| 425 | |
| 426 | bool Caches::bindPixelBuffer(const GLuint buffer) { |
| 427 | if (mCurrentPixelBuffer != buffer) { |
| 428 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer); |
| 429 | mCurrentPixelBuffer = buffer; |
| 430 | return true; |
| 431 | } |
| 432 | return false; |
| 433 | } |
| 434 | |
| 435 | bool Caches::unbindPixelBuffer() { |
| 436 | if (mCurrentPixelBuffer) { |
| 437 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 438 | mCurrentPixelBuffer = 0; |
| 439 | return true; |
| 440 | } |
| 441 | return false; |
| 442 | } |
| 443 | |
| 444 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 445 | // Meshes and textures |
| 446 | /////////////////////////////////////////////////////////////////////////////// |
| 447 | |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 448 | void Caches::bindPositionVertexPointer(bool force, GLvoid* vertices, GLsizei stride) { |
| 449 | if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) { |
| 450 | GLuint slot = currentProgram->position; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 451 | glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices); |
| 452 | mCurrentPositionPointer = vertices; |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 453 | mCurrentPositionStride = stride; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 457 | void Caches::bindTexCoordsVertexPointer(bool force, GLvoid* vertices, GLsizei stride) { |
| 458 | if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) { |
Chris Craik | cb4d600 | 2012-09-25 12:00:29 -0700 | [diff] [blame] | 459 | GLuint slot = currentProgram->texCoords; |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 460 | glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices); |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 461 | mCurrentTexCoordsPointer = vertices; |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 462 | mCurrentTexCoordsStride = stride; |
Romain Guy | f3a910b4 | 2011-12-12 20:35:21 -0800 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
| 466 | void Caches::resetVertexPointers() { |
| 467 | mCurrentPositionPointer = this; |
| 468 | mCurrentTexCoordsPointer = this; |
| 469 | } |
| 470 | |
| 471 | void Caches::resetTexCoordsVertexPointer() { |
| 472 | mCurrentTexCoordsPointer = this; |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 475 | void Caches::enableTexCoordsVertexArray() { |
| 476 | if (!mTexCoordsArrayEnabled) { |
| 477 | glEnableVertexAttribArray(Program::kBindingTexCoords); |
Romain Guy | ec31f83 | 2011-12-13 18:39:19 -0800 | [diff] [blame] | 478 | mCurrentTexCoordsPointer = this; |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 479 | mTexCoordsArrayEnabled = true; |
| 480 | } |
| 481 | } |
| 482 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 483 | void Caches::disableTexCoordsVertexArray() { |
Romain Guy | 15bc643 | 2011-12-13 13:11:32 -0800 | [diff] [blame] | 484 | if (mTexCoordsArrayEnabled) { |
| 485 | glDisableVertexAttribArray(Program::kBindingTexCoords); |
| 486 | mTexCoordsArrayEnabled = false; |
| 487 | } |
| 488 | } |
| 489 | |
Romain Guy | a1d3c91 | 2011-12-13 14:55:06 -0800 | [diff] [blame] | 490 | void Caches::activeTexture(GLuint textureUnit) { |
| 491 | if (mTextureUnit != textureUnit) { |
| 492 | glActiveTexture(gTextureUnits[textureUnit]); |
| 493 | mTextureUnit = textureUnit; |
| 494 | } |
| 495 | } |
| 496 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 497 | void Caches::bindTexture(GLuint texture) { |
| 498 | if (mBoundTextures[mTextureUnit] != texture) { |
| 499 | glBindTexture(GL_TEXTURE_2D, texture); |
| 500 | mBoundTextures[mTextureUnit] = texture; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | void Caches::bindTexture(GLenum target, GLuint texture) { |
| 505 | if (mBoundTextures[mTextureUnit] != texture) { |
| 506 | glBindTexture(target, texture); |
| 507 | mBoundTextures[mTextureUnit] = texture; |
| 508 | } |
| 509 | } |
| 510 | |
Romain Guy | be1b127 | 2013-06-06 14:02:54 -0700 | [diff] [blame] | 511 | void Caches::deleteTexture(GLuint texture) { |
| 512 | // When glDeleteTextures() is called on a currently bound texture, |
| 513 | // OpenGL ES specifies that the texture is then considered unbound |
| 514 | // Consider the following series of calls: |
| 515 | // |
| 516 | // glGenTextures -> creates texture name 2 |
| 517 | // glBindTexture(2) |
| 518 | // glDeleteTextures(2) -> 2 is now unbound |
| 519 | // glGenTextures -> can return 2 again |
| 520 | // |
| 521 | // If we don't call glBindTexture(2) after the second glGenTextures |
| 522 | // call, any texture operation will be performed on the default |
| 523 | // texture (name=0) |
| 524 | |
| 525 | for (int i = 0; i < REQUIRED_TEXTURE_UNITS_COUNT; i++) { |
| 526 | if (mBoundTextures[i] == texture) { |
| 527 | mBoundTextures[i] = 0; |
| 528 | } |
| 529 | } |
| 530 | glDeleteTextures(1, &texture); |
| 531 | } |
| 532 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 533 | void Caches::resetBoundTextures() { |
| 534 | memset(mBoundTextures, 0, REQUIRED_TEXTURE_UNITS_COUNT * sizeof(GLuint)); |
| 535 | } |
| 536 | |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 537 | /////////////////////////////////////////////////////////////////////////////// |
| 538 | // Scissor |
| 539 | /////////////////////////////////////////////////////////////////////////////// |
| 540 | |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 541 | bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) { |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 542 | if (scissorEnabled && (x != mScissorX || y != mScissorY || |
| 543 | width != mScissorWidth || height != mScissorHeight)) { |
| 544 | |
Chet Haase | aa42c9a | 2012-10-16 17:36:16 -0700 | [diff] [blame] | 545 | if (x < 0) { |
| 546 | width += x; |
| 547 | x = 0; |
| 548 | } |
| 549 | if (y < 0) { |
| 550 | height += y; |
| 551 | y = 0; |
| 552 | } |
| 553 | if (width < 0) { |
| 554 | width = 0; |
| 555 | } |
| 556 | if (height < 0) { |
| 557 | height = 0; |
| 558 | } |
Romain Guy | 8f85e80 | 2011-12-14 19:23:32 -0800 | [diff] [blame] | 559 | glScissor(x, y, width, height); |
| 560 | |
| 561 | mScissorX = x; |
| 562 | mScissorY = y; |
| 563 | mScissorWidth = width; |
| 564 | mScissorHeight = height; |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 565 | |
| 566 | return true; |
Romain Guy | 8f85e80 | 2011-12-14 19:23:32 -0800 | [diff] [blame] | 567 | } |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 568 | return false; |
Romain Guy | 8f85e80 | 2011-12-14 19:23:32 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 571 | bool Caches::enableScissor() { |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 572 | if (!scissorEnabled) { |
| 573 | glEnable(GL_SCISSOR_TEST); |
| 574 | scissorEnabled = true; |
Romain Guy | 50ae66a | 2012-10-07 14:05:59 -0700 | [diff] [blame] | 575 | resetScissor(); |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 576 | return true; |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 577 | } |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 578 | return false; |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 581 | bool Caches::disableScissor() { |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 582 | if (scissorEnabled) { |
| 583 | glDisable(GL_SCISSOR_TEST); |
| 584 | scissorEnabled = false; |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 585 | return true; |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 586 | } |
Romain Guy | 8a4ac61 | 2012-07-17 17:32:48 -0700 | [diff] [blame] | 587 | return false; |
Romain Guy | 586cae3 | 2012-07-13 15:28:31 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | void Caches::setScissorEnabled(bool enabled) { |
| 591 | if (scissorEnabled != enabled) { |
| 592 | if (enabled) glEnable(GL_SCISSOR_TEST); |
| 593 | else glDisable(GL_SCISSOR_TEST); |
| 594 | scissorEnabled = enabled; |
| 595 | } |
| 596 | } |
| 597 | |
Romain Guy | 82bc7a7 | 2012-01-03 14:13:39 -0800 | [diff] [blame] | 598 | void Caches::resetScissor() { |
| 599 | mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0; |
| 600 | } |
| 601 | |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 602 | /////////////////////////////////////////////////////////////////////////////// |
| 603 | // Tiling |
| 604 | /////////////////////////////////////////////////////////////////////////////// |
| 605 | |
Romain Guy | f735c8e | 2013-01-31 17:45:55 -0800 | [diff] [blame] | 606 | void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard) { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 607 | if (mExtensions.hasTiledRendering() && !debugOverdraw) { |
Romain Guy | f735c8e | 2013-01-31 17:45:55 -0800 | [diff] [blame] | 608 | glStartTilingQCOM(x, y, width, height, (discard ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM)); |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
| 612 | void Caches::endTiling() { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 613 | if (mExtensions.hasTiledRendering() && !debugOverdraw) { |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 614 | glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM); |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 618 | bool Caches::hasRegisteredFunctors() { |
| 619 | return mFunctorsCount > 0; |
| 620 | } |
| 621 | |
| 622 | void Caches::registerFunctors(uint32_t functorCount) { |
| 623 | mFunctorsCount += functorCount; |
| 624 | } |
| 625 | |
| 626 | void Caches::unregisterFunctors(uint32_t functorCount) { |
| 627 | if (functorCount > mFunctorsCount) { |
| 628 | mFunctorsCount = 0; |
| 629 | } else { |
| 630 | mFunctorsCount -= functorCount; |
| 631 | } |
| 632 | } |
| 633 | |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 634 | /////////////////////////////////////////////////////////////////////////////// |
| 635 | // Regions |
| 636 | /////////////////////////////////////////////////////////////////////////////// |
| 637 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 638 | TextureVertex* Caches::getRegionMesh() { |
| 639 | // Create the mesh, 2 triangles and 4 vertices per rectangle in the region |
| 640 | if (!mRegionMesh) { |
Romain Guy | 31e08e9 | 2013-06-18 15:53:53 -0700 | [diff] [blame^] | 641 | mRegionMesh = new TextureVertex[gMaxNumberOfQuads * 4]; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | return mRegionMesh; |
| 645 | } |
| 646 | |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 647 | }; // namespace uirenderer |
| 648 | }; // namespace android |