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 | |
| 19 | #include "Caches.h" |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 20 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 21 | #include "GammaFontRenderer.h" |
Romain Guy | 09b7c91 | 2011-02-02 20:28:09 -0800 | [diff] [blame] | 22 | #include "LayerRenderer.h" |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 23 | #include "Properties.h" |
| 24 | #include "renderstate/RenderState.h" |
ztenghui | 63d41ab | 2014-02-14 13:13:41 -0800 | [diff] [blame] | 25 | #include "ShadowTessellator.h" |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 26 | |
| 27 | #include <utils/Log.h> |
| 28 | #include <utils/String8.h> |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 31 | namespace uirenderer { |
| 32 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 33 | Caches* Caches::sInstance = nullptr; |
| 34 | |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 35 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 36 | // Macros |
| 37 | /////////////////////////////////////////////////////////////////////////////// |
| 38 | |
| 39 | #if DEBUG_CACHE_FLUSH |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 40 | #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 41 | #else |
| 42 | #define FLUSH_LOGD(...) |
| 43 | #endif |
| 44 | |
| 45 | /////////////////////////////////////////////////////////////////////////////// |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 46 | // Constructors/destructor |
| 47 | /////////////////////////////////////////////////////////////////////////////// |
| 48 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 49 | Caches::Caches(RenderState& renderState) |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 50 | : gradientCache(mExtensions) |
| 51 | , patchCache(renderState) |
| 52 | , programCache(mExtensions) |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 53 | , dither(*this) |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 54 | , mRenderState(&renderState) |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 55 | , mInitialized(false) { |
| 56 | INIT_LOGD("Creating OpenGL renderer caches"); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 57 | init(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 58 | initFont(); |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 59 | initConstraints(); |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 60 | initProperties(); |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 61 | initStaticProperties(); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 62 | initExtensions(); |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 63 | initTempProperties(); |
Romain Guy | e190aa6 | 2010-11-10 19:01:29 -0800 | [diff] [blame] | 64 | |
| 65 | mDebugLevel = readDebugLevel(); |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 66 | ALOGD_IF(mDebugLevel != kDebugDisabled, |
| 67 | "Enabling debug mode %d", mDebugLevel); |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 70 | bool Caches::init() { |
| 71 | if (mInitialized) return false; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 72 | |
John Reck | fbc8df0 | 2014-11-14 16:18:41 -0800 | [diff] [blame] | 73 | ATRACE_NAME("Caches::init"); |
| 74 | |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 75 | mRegionMesh = nullptr; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 76 | mProgram = nullptr; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 77 | |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 78 | mFunctorsCount = 0; |
| 79 | |
Romain Guy | c2a9721 | 2013-02-06 15:29:46 -0800 | [diff] [blame] | 80 | debugLayersUpdates = false; |
| 81 | debugOverdraw = false; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 82 | debugStencilClip = kStencilHide; |
Romain Guy | c2a9721 | 2013-02-06 15:29:46 -0800 | [diff] [blame] | 83 | |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 84 | patchCache.init(); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 85 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 86 | mInitialized = true; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 87 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 88 | mPixelBufferState = new PixelBufferState(); |
| 89 | mTextureState = new TextureState(); |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 90 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 91 | return true; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 94 | void Caches::initFont() { |
| 95 | fontRenderer = GammaFontRenderer::createRenderer(); |
| 96 | } |
| 97 | |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 98 | void Caches::initExtensions() { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 99 | if (mExtensions.hasDebugMarker()) { |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 100 | eventMark = glInsertEventMarkerEXT; |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 101 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 102 | startMark = glPushGroupMarkerEXT; |
| 103 | endMark = glPopGroupMarkerEXT; |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 104 | } else { |
| 105 | eventMark = eventMarkNull; |
| 106 | startMark = startMarkNull; |
| 107 | endMark = endMarkNull; |
| 108 | } |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void Caches::initConstraints() { |
Romain Guy | dfa1046 | 2012-05-12 16:18:58 -0700 | [diff] [blame] | 112 | glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); |
| 113 | } |
| 114 | |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 115 | void Caches::initStaticProperties() { |
| 116 | gpuPixelBuffersEnabled = false; |
| 117 | |
| 118 | // OpenGL ES 3.0+ specific features |
Romain Guy | 7f43076 | 2013-06-13 14:29:40 -0700 | [diff] [blame] | 119 | if (mExtensions.hasPixelBufferObjects()) { |
Romain Guy | f9f0016 | 2013-05-09 11:50:12 -0700 | [diff] [blame] | 120 | char property[PROPERTY_VALUE_MAX]; |
| 121 | if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) { |
| 122 | gpuPixelBuffersEnabled = !strcmp(property, "true"); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 127 | bool Caches::initProperties() { |
| 128 | bool prevDebugLayersUpdates = debugLayersUpdates; |
| 129 | bool prevDebugOverdraw = debugOverdraw; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 130 | StencilClipDebug prevDebugStencilClip = debugStencilClip; |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 131 | |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 132 | char property[PROPERTY_VALUE_MAX]; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 133 | if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, nullptr) > 0) { |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 134 | INIT_LOGD(" Layers updates debug enabled: %s", property); |
| 135 | debugLayersUpdates = !strcmp(property, "true"); |
| 136 | } else { |
| 137 | debugLayersUpdates = false; |
| 138 | } |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 139 | |
Romain Guy | 627c6fd | 2013-08-21 11:53:18 -0700 | [diff] [blame] | 140 | debugOverdraw = false; |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 141 | if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) { |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 142 | INIT_LOGD(" Overdraw debug enabled: %s", property); |
Romain Guy | 627c6fd | 2013-08-21 11:53:18 -0700 | [diff] [blame] | 143 | if (!strcmp(property, "show")) { |
| 144 | debugOverdraw = true; |
| 145 | mOverdrawDebugColorSet = kColorSet_Default; |
| 146 | } else if (!strcmp(property, "show_deuteranomaly")) { |
| 147 | debugOverdraw = true; |
| 148 | mOverdrawDebugColorSet = kColorSet_Deuteranomaly; |
| 149 | } |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 150 | } |
Romain Guy | 5bb3c73 | 2012-11-29 17:52:58 -0800 | [diff] [blame] | 151 | |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 152 | // See Properties.h for valid values |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 153 | if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) { |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 154 | INIT_LOGD(" Stencil clip debug enabled: %s", property); |
| 155 | if (!strcmp(property, "hide")) { |
| 156 | debugStencilClip = kStencilHide; |
| 157 | } else if (!strcmp(property, "highlight")) { |
| 158 | debugStencilClip = kStencilShowHighlight; |
| 159 | } else if (!strcmp(property, "region")) { |
| 160 | debugStencilClip = kStencilShowRegion; |
| 161 | } |
| 162 | } else { |
| 163 | debugStencilClip = kStencilHide; |
| 164 | } |
| 165 | |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 166 | if (property_get(PROPERTY_DISABLE_DRAW_DEFER, property, "false")) { |
| 167 | drawDeferDisabled = !strcasecmp(property, "true"); |
| 168 | INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled"); |
| 169 | } else { |
Chris Craik | 58ddced | 2014-07-16 19:11:46 -0700 | [diff] [blame] | 170 | drawDeferDisabled = false; |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 171 | INIT_LOGD(" Draw defer enabled"); |
| 172 | } |
| 173 | |
| 174 | if (property_get(PROPERTY_DISABLE_DRAW_REORDER, property, "false")) { |
| 175 | drawReorderDisabled = !strcasecmp(property, "true"); |
| 176 | INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled"); |
| 177 | } else { |
Chris Craik | 58ddced | 2014-07-16 19:11:46 -0700 | [diff] [blame] | 178 | drawReorderDisabled = false; |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 179 | INIT_LOGD(" Draw reorder enabled"); |
| 180 | } |
| 181 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 182 | return (prevDebugLayersUpdates != debugLayersUpdates) |
| 183 | || (prevDebugOverdraw != debugOverdraw) |
| 184 | || (prevDebugStencilClip != debugStencilClip); |
Romain Guy | 4ff0cf4 | 2012-08-06 14:51:10 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 187 | void Caches::terminate() { |
| 188 | if (!mInitialized) return; |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 189 | mRegionMesh.release(); |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 190 | |
| 191 | fboCache.clear(); |
| 192 | |
| 193 | programCache.clear(); |
Chris Craik | 3472568 | 2015-02-05 09:06:30 -0800 | [diff] [blame] | 194 | mProgram = nullptr; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 195 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 196 | patchCache.clear(); |
| 197 | |
Romain Guy | 46bfc48 | 2013-08-16 18:38:29 -0700 | [diff] [blame] | 198 | clearGarbage(); |
| 199 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 200 | delete mPixelBufferState; |
| 201 | mPixelBufferState = nullptr; |
| 202 | delete mTextureState; |
| 203 | mTextureState = nullptr; |
Romain Guy | 8ff6b9e | 2011-11-09 20:10:18 -0800 | [diff] [blame] | 204 | mInitialized = false; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 207 | void Caches::setProgram(const ProgramDescription& description) { |
| 208 | setProgram(programCache.get(description)); |
| 209 | } |
| 210 | |
| 211 | void Caches::setProgram(Program* program) { |
| 212 | if (!program || !program->isInUse()) { |
| 213 | if (mProgram) { |
| 214 | mProgram->remove(); |
| 215 | } |
| 216 | if (program) { |
| 217 | program->use(); |
| 218 | } |
| 219 | mProgram = program; |
| 220 | } |
| 221 | } |
| 222 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 223 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 224 | // Debug |
| 225 | /////////////////////////////////////////////////////////////////////////////// |
| 226 | |
Romain Guy | 627c6fd | 2013-08-21 11:53:18 -0700 | [diff] [blame] | 227 | uint32_t Caches::getOverdrawColor(uint32_t amount) const { |
| 228 | static uint32_t sOverdrawColors[2][4] = { |
| 229 | { 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000 }, |
| 230 | { 0x2f0000ff, 0x4fffff00, 0x5fff8ad8, 0x7fff0000 } |
| 231 | }; |
| 232 | if (amount < 1) amount = 1; |
| 233 | if (amount > 4) amount = 4; |
| 234 | return sOverdrawColors[mOverdrawDebugColorSet][amount - 1]; |
| 235 | } |
| 236 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 237 | void Caches::dumpMemoryUsage() { |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 238 | String8 stringLog; |
| 239 | dumpMemoryUsage(stringLog); |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 240 | ALOGD("%s", stringLog.string()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void Caches::dumpMemoryUsage(String8 &log) { |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 244 | uint32_t total = 0; |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 245 | log.appendFormat("Current memory usage / total memory usage (bytes):\n"); |
| 246 | log.appendFormat(" TextureCache %8d / %8d\n", |
| 247 | textureCache.getSize(), textureCache.getMaxSize()); |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 248 | log.appendFormat(" LayerCache %8d / %8d (numLayers = %zu)\n", |
| 249 | layerCache.getSize(), layerCache.getMaxSize(), layerCache.getCount()); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 250 | if (mRenderState) { |
| 251 | int memused = 0; |
John Reck | 5799801 | 2015-01-29 10:17:57 -0800 | [diff] [blame] | 252 | for (std::set<Layer*>::iterator it = mRenderState->mActiveLayers.begin(); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 253 | it != mRenderState->mActiveLayers.end(); it++) { |
| 254 | const Layer* layer = *it; |
| 255 | log.appendFormat(" Layer size %dx%d; isTextureLayer()=%d; texid=%u fbo=%u; refs=%d\n", |
| 256 | layer->getWidth(), layer->getHeight(), |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 257 | layer->isTextureLayer(), layer->getTextureId(), |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 258 | layer->getFbo(), layer->getStrongCount()); |
John Reck | 88f5fc7 | 2014-11-03 10:32:24 -0800 | [diff] [blame] | 259 | memused += layer->getWidth() * layer->getHeight() * 4; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 260 | } |
| 261 | log.appendFormat(" Layers total %8d (numLayers = %zu)\n", |
| 262 | memused, mRenderState->mActiveLayers.size()); |
| 263 | total += memused; |
| 264 | } |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 265 | log.appendFormat(" RenderBufferCache %8d / %8d\n", |
| 266 | renderBufferCache.getSize(), renderBufferCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 267 | log.appendFormat(" GradientCache %8d / %8d\n", |
| 268 | gradientCache.getSize(), gradientCache.getMaxSize()); |
| 269 | log.appendFormat(" PathCache %8d / %8d\n", |
| 270 | pathCache.getSize(), pathCache.getMaxSize()); |
Chris Craik | 05f3d6e | 2014-06-02 16:27:04 -0700 | [diff] [blame] | 271 | log.appendFormat(" TessellationCache %8d / %8d\n", |
| 272 | tessellationCache.getSize(), tessellationCache.getMaxSize()); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 273 | log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(), |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 274 | dropShadowCache.getMaxSize()); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 275 | log.appendFormat(" PatchCache %8d / %8d\n", |
| 276 | patchCache.getSize(), patchCache.getMaxSize()); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 277 | for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 278 | const uint32_t sizeA8 = fontRenderer->getFontRendererSize(i, GL_ALPHA); |
| 279 | const uint32_t sizeRGBA = fontRenderer->getFontRendererSize(i, GL_RGBA); |
| 280 | log.appendFormat(" FontRenderer %d A8 %8d / %8d\n", i, sizeA8, sizeA8); |
| 281 | log.appendFormat(" FontRenderer %d RGBA %8d / %8d\n", i, sizeRGBA, sizeRGBA); |
| 282 | log.appendFormat(" FontRenderer %d total %8d / %8d\n", i, sizeA8 + sizeRGBA, |
| 283 | sizeA8 + sizeRGBA); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 284 | } |
Romain Guy | d2ba50a | 2011-05-27 10:21:07 -0700 | [diff] [blame] | 285 | log.appendFormat("Other:\n"); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 286 | log.appendFormat(" FboCache %8d / %8d\n", |
| 287 | fboCache.getSize(), fboCache.getMaxSize()); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 288 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 289 | total += textureCache.getSize(); |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 290 | total += renderBufferCache.getSize(); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 291 | total += gradientCache.getSize(); |
| 292 | total += pathCache.getSize(); |
Chris Craik | 05f3d6e | 2014-06-02 16:27:04 -0700 | [diff] [blame] | 293 | total += tessellationCache.getSize(); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 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 | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 315 | void Caches::flush(FlushMode mode) { |
| 316 | FLUSH_LOGD("Flushing caches (mode %d)", mode); |
| 317 | |
Romain Guy | b0a41ed | 2013-08-16 14:44:38 -0700 | [diff] [blame] | 318 | // We must stop tasks before clearing caches |
| 319 | if (mode > kFlushMode_Layers) { |
| 320 | tasks.stop(); |
| 321 | } |
| 322 | |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 323 | switch (mode) { |
| 324 | case kFlushMode_Full: |
| 325 | textureCache.clear(); |
| 326 | patchCache.clear(); |
| 327 | dropShadowCache.clear(); |
| 328 | gradientCache.clear(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 329 | fontRenderer->clear(); |
Romain Guy | b746371 | 2013-08-16 13:55:29 -0700 | [diff] [blame] | 330 | fboCache.clear(); |
Romain Guy | 211efea | 2012-07-31 21:16:07 -0700 | [diff] [blame] | 331 | dither.clear(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 332 | // fall through |
| 333 | case kFlushMode_Moderate: |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 334 | fontRenderer->flush(); |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 335 | textureCache.flush(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 336 | pathCache.clear(); |
Chris Craik | 05f3d6e | 2014-06-02 16:27:04 -0700 | [diff] [blame] | 337 | tessellationCache.clear(); |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 338 | // fall through |
| 339 | case kFlushMode_Layers: |
| 340 | layerCache.clear(); |
Romain Guy | 8d4aeb7 | 2013-02-12 16:08:55 -0800 | [diff] [blame] | 341 | renderBufferCache.clear(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 342 | break; |
| 343 | } |
Chet Haase | 6a2d17f | 2012-09-30 12:14:13 -0700 | [diff] [blame] | 344 | |
| 345 | clearGarbage(); |
John Reck | 4ced262 | 2014-09-19 10:10:19 -0700 | [diff] [blame] | 346 | glFinish(); |
Romain Guy | bdf7609 | 2011-07-18 15:00:43 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Romain Guy | fe48f65 | 2010-11-11 15:36:56 -0800 | [diff] [blame] | 349 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 350 | // Tiling |
| 351 | /////////////////////////////////////////////////////////////////////////////// |
| 352 | |
Romain Guy | f735c8e | 2013-01-31 17:45:55 -0800 | [diff] [blame] | 353 | 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] | 354 | if (mExtensions.hasTiledRendering() && !debugOverdraw) { |
Romain Guy | f735c8e | 2013-01-31 17:45:55 -0800 | [diff] [blame] | 355 | 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] | 356 | } |
| 357 | } |
| 358 | |
| 359 | void Caches::endTiling() { |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 360 | if (mExtensions.hasTiledRendering() && !debugOverdraw) { |
Romain Guy | 2b7028e | 2012-09-19 17:25:38 -0700 | [diff] [blame] | 361 | glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM); |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
Romain Guy | 54c1a64 | 2012-09-27 17:55:46 -0700 | [diff] [blame] | 365 | bool Caches::hasRegisteredFunctors() { |
| 366 | return mFunctorsCount > 0; |
| 367 | } |
| 368 | |
| 369 | void Caches::registerFunctors(uint32_t functorCount) { |
| 370 | mFunctorsCount += functorCount; |
| 371 | } |
| 372 | |
| 373 | void Caches::unregisterFunctors(uint32_t functorCount) { |
| 374 | if (functorCount > mFunctorsCount) { |
| 375 | mFunctorsCount = 0; |
| 376 | } else { |
| 377 | mFunctorsCount -= functorCount; |
| 378 | } |
| 379 | } |
| 380 | |
Romain Guy | 85ef80d | 2012-09-13 20:26:50 -0700 | [diff] [blame] | 381 | /////////////////////////////////////////////////////////////////////////////// |
| 382 | // Regions |
| 383 | /////////////////////////////////////////////////////////////////////////////// |
| 384 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 385 | TextureVertex* Caches::getRegionMesh() { |
| 386 | // Create the mesh, 2 triangles and 4 vertices per rectangle in the region |
| 387 | if (!mRegionMesh) { |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 388 | mRegionMesh.reset(new TextureVertex[kMaxNumberOfQuads * 4]); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 391 | return mRegionMesh.get(); |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 394 | /////////////////////////////////////////////////////////////////////////////// |
| 395 | // Temporary Properties |
| 396 | /////////////////////////////////////////////////////////////////////////////// |
| 397 | |
| 398 | void Caches::initTempProperties() { |
ztenghui | 62aa44c | 2015-02-20 10:53:22 -0800 | [diff] [blame] | 399 | propertyLightRadius = -1.0f; |
Chris Craik | f5be3ca | 2014-04-30 18:20:03 -0700 | [diff] [blame] | 400 | propertyLightPosY = -1.0f; |
| 401 | propertyLightPosZ = -1.0f; |
| 402 | propertyAmbientRatio = -1.0f; |
ztenghui | 14a4e35 | 2014-08-13 10:44:39 -0700 | [diff] [blame] | 403 | propertyAmbientShadowStrength = -1; |
| 404 | propertySpotShadowStrength = -1; |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void Caches::setTempProperty(const char* name, const char* value) { |
| 408 | ALOGD("setting property %s to %s", name, value); |
Chris Craik | a736cd9 | 2014-08-04 13:18:38 -0700 | [diff] [blame] | 409 | if (!strcmp(name, "ambientRatio")) { |
Chris Craik | f5be3ca | 2014-04-30 18:20:03 -0700 | [diff] [blame] | 410 | propertyAmbientRatio = fmin(fmax(atof(value), 0.0), 10.0); |
| 411 | ALOGD("ambientRatio = %.2f", propertyAmbientRatio); |
ztenghui | cc3c256 | 2014-01-17 10:34:10 -0800 | [diff] [blame] | 412 | return; |
ztenghui | 62aa44c | 2015-02-20 10:53:22 -0800 | [diff] [blame] | 413 | } else if (!strcmp(name, "lightRadius")) { |
| 414 | propertyLightRadius = fmin(fmax(atof(value), 0.0), 3000.0); |
| 415 | ALOGD("lightRadius = %.2f", propertyLightRadius); |
ztenghui | cc3c256 | 2014-01-17 10:34:10 -0800 | [diff] [blame] | 416 | return; |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 417 | } else if (!strcmp(name, "lightPosY")) { |
Chris Craik | f5be3ca | 2014-04-30 18:20:03 -0700 | [diff] [blame] | 418 | propertyLightPosY = fmin(fmax(atof(value), 0.0), 3000.0); |
| 419 | ALOGD("lightPos Y = %.2f", propertyLightPosY); |
| 420 | return; |
Chris Craik | 59744b7 | 2014-07-01 17:56:52 -0700 | [diff] [blame] | 421 | } else if (!strcmp(name, "lightPosZ")) { |
Chris Craik | f5be3ca | 2014-04-30 18:20:03 -0700 | [diff] [blame] | 422 | propertyLightPosZ = fmin(fmax(atof(value), 0.0), 3000.0); |
| 423 | ALOGD("lightPos Z = %.2f", propertyLightPosZ); |
ztenghui | cc3c256 | 2014-01-17 10:34:10 -0800 | [diff] [blame] | 424 | return; |
ztenghui | 14a4e35 | 2014-08-13 10:44:39 -0700 | [diff] [blame] | 425 | } else if (!strcmp(name, "ambientShadowStrength")) { |
| 426 | propertyAmbientShadowStrength = atoi(value); |
| 427 | ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength); |
| 428 | return; |
| 429 | } else if (!strcmp(name, "spotShadowStrength")) { |
| 430 | propertySpotShadowStrength = atoi(value); |
| 431 | ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength); |
| 432 | return; |
Chris Craik | ba9b613 | 2013-12-15 17:10:19 -0800 | [diff] [blame] | 433 | } |
| 434 | ALOGD(" failed"); |
| 435 | } |
| 436 | |
Chet Haase | dd78cca | 2010-10-22 18:59:26 -0700 | [diff] [blame] | 437 | }; // namespace uirenderer |
| 438 | }; // namespace android |