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