blob: f4fc06840bee58f47e817c780e954f7f5b446166 [file] [log] [blame]
Chet Haasedd78cca2010-10-22 18:59:26 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include "Caches.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080020
Romain Guybb0acdf2012-03-05 13:44:35 -080021#include "DisplayListRenderer.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040022#include "GammaFontRenderer.h"
Romain Guy09b7c912011-02-02 20:28:09 -080023#include "LayerRenderer.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080024#include "Properties.h"
25#include "renderstate/RenderState.h"
ztenghui63d41ab2014-02-14 13:13:41 -080026#include "ShadowTessellator.h"
Chris Craik65fe5ee2015-01-26 18:06:29 -080027
28#include <utils/Log.h>
29#include <utils/String8.h>
Chet Haasedd78cca2010-10-22 18:59:26 -070030
31namespace android {
Chet Haasedd78cca2010-10-22 18:59:26 -070032namespace uirenderer {
33
Chris Craik96a5c4c2015-01-27 15:46:35 -080034Caches* Caches::sInstance = nullptr;
35
Chet Haasedd78cca2010-10-22 18:59:26 -070036///////////////////////////////////////////////////////////////////////////////
Romain Guybdf76092011-07-18 15:00:43 -070037// Macros
38///////////////////////////////////////////////////////////////////////////////
39
40#if DEBUG_CACHE_FLUSH
Steve Block5baa3a62011-12-20 16:23:08 +000041 #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guybdf76092011-07-18 15:00:43 -070042#else
43 #define FLUSH_LOGD(...)
44#endif
45
46///////////////////////////////////////////////////////////////////////////////
Chet Haasedd78cca2010-10-22 18:59:26 -070047// Constructors/destructor
48///////////////////////////////////////////////////////////////////////////////
49
Chris Craik96a5c4c2015-01-27 15:46:35 -080050Caches::Caches(RenderState& renderState)
Chris Craik117bdbc2015-02-05 10:12:38 -080051 : gradientCache(mExtensions)
52 , patchCache(renderState)
53 , programCache(mExtensions)
Chris Craik44eb2c02015-01-29 09:45:09 -080054 , dither(*this)
Chris Craik96a5c4c2015-01-27 15:46:35 -080055 , mRenderState(&renderState)
Chris Craik96a5c4c2015-01-27 15:46:35 -080056 , mInitialized(false) {
57 INIT_LOGD("Creating OpenGL renderer caches");
Romain Guy8ff6b9e2011-11-09 20:10:18 -080058 init();
Romain Guyb1d0a4e2012-07-13 18:25:35 -070059 initFont();
Romain Guydfa10462012-05-12 16:18:58 -070060 initConstraints();
Romain Guy4ff0cf42012-08-06 14:51:10 -070061 initProperties();
Romain Guyf9f00162013-05-09 11:50:12 -070062 initStaticProperties();
Romain Guy0f667532013-03-01 14:31:04 -080063 initExtensions();
Chris Craikba9b6132013-12-15 17:10:19 -080064 initTempProperties();
Romain Guye190aa62010-11-10 19:01:29 -080065
66 mDebugLevel = readDebugLevel();
Chris Craik96a5c4c2015-01-27 15:46:35 -080067 ALOGD_IF(mDebugLevel != kDebugDisabled,
68 "Enabling debug mode %d", mDebugLevel);
Chet Haasedd78cca2010-10-22 18:59:26 -070069}
70
Romain Guy3b748a42013-04-17 18:54:38 -070071bool Caches::init() {
72 if (mInitialized) return false;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080073
John Reckfbc8df02014-11-14 16:18:41 -080074 ATRACE_NAME("Caches::init");
75
Chris Craikd41c4d82015-01-05 15:51:13 -080076 mRegionMesh = nullptr;
Chris Craik6c15ffa2015-02-02 13:50:55 -080077 mProgram = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080078
Romain Guy54c1a642012-09-27 17:55:46 -070079 mFunctorsCount = 0;
80
Romain Guyc2a97212013-02-06 15:29:46 -080081 debugLayersUpdates = false;
82 debugOverdraw = false;
Romain Guy3ff0bfd2013-02-25 14:15:37 -080083 debugStencilClip = kStencilHide;
Romain Guyc2a97212013-02-06 15:29:46 -080084
Chris Craik96a5c4c2015-01-27 15:46:35 -080085 patchCache.init();
Romain Guy3b748a42013-04-17 18:54:38 -070086
Romain Guy8ff6b9e2011-11-09 20:10:18 -080087 mInitialized = true;
Romain Guy3b748a42013-04-17 18:54:38 -070088
Chris Craik44eb2c02015-01-29 09:45:09 -080089 mPixelBufferState = new PixelBufferState();
90 mTextureState = new TextureState();
Romain Guy8aa195d2013-06-04 18:00:09 -070091
Romain Guy3b748a42013-04-17 18:54:38 -070092 return true;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080093}
94
Romain Guyb1d0a4e2012-07-13 18:25:35 -070095void Caches::initFont() {
96 fontRenderer = GammaFontRenderer::createRenderer();
97}
98
Romain Guydfa10462012-05-12 16:18:58 -070099void Caches::initExtensions() {
Romain Guy3bbacf22013-02-06 16:51:04 -0800100 if (mExtensions.hasDebugMarker()) {
Romain Guydfa10462012-05-12 16:18:58 -0700101 eventMark = glInsertEventMarkerEXT;
Romain Guy0f667532013-03-01 14:31:04 -0800102
Chris Craikff785832013-03-08 13:12:16 -0800103 startMark = glPushGroupMarkerEXT;
104 endMark = glPopGroupMarkerEXT;
Romain Guydfa10462012-05-12 16:18:58 -0700105 } else {
106 eventMark = eventMarkNull;
107 startMark = startMarkNull;
108 endMark = endMarkNull;
109 }
110
Romain Guy0f667532013-03-01 14:31:04 -0800111 if (mExtensions.hasDebugLabel() && (drawDeferDisabled || drawReorderDisabled)) {
Romain Guydfa10462012-05-12 16:18:58 -0700112 setLabel = glLabelObjectEXT;
113 getLabel = glGetObjectLabelEXT;
114 } else {
115 setLabel = setLabelNull;
116 getLabel = getLabelNull;
117 }
118}
119
120void Caches::initConstraints() {
Romain Guydfa10462012-05-12 16:18:58 -0700121 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
122}
123
Romain Guyf9f00162013-05-09 11:50:12 -0700124void Caches::initStaticProperties() {
125 gpuPixelBuffersEnabled = false;
126
127 // OpenGL ES 3.0+ specific features
Romain Guy7f430762013-06-13 14:29:40 -0700128 if (mExtensions.hasPixelBufferObjects()) {
Romain Guyf9f00162013-05-09 11:50:12 -0700129 char property[PROPERTY_VALUE_MAX];
130 if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) {
131 gpuPixelBuffersEnabled = !strcmp(property, "true");
132 }
133 }
134}
135
Romain Guy5bb3c732012-11-29 17:52:58 -0800136bool Caches::initProperties() {
137 bool prevDebugLayersUpdates = debugLayersUpdates;
138 bool prevDebugOverdraw = debugOverdraw;
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800139 StencilClipDebug prevDebugStencilClip = debugStencilClip;
Romain Guy5bb3c732012-11-29 17:52:58 -0800140
Romain Guy4ff0cf42012-08-06 14:51:10 -0700141 char property[PROPERTY_VALUE_MAX];
Chris Craikd41c4d82015-01-05 15:51:13 -0800142 if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, nullptr) > 0) {
Romain Guy4ff0cf42012-08-06 14:51:10 -0700143 INIT_LOGD(" Layers updates debug enabled: %s", property);
144 debugLayersUpdates = !strcmp(property, "true");
145 } else {
146 debugLayersUpdates = false;
147 }
Romain Guy7c450aa2012-09-21 19:15:00 -0700148
Romain Guy627c6fd2013-08-21 11:53:18 -0700149 debugOverdraw = false;
Chris Craikd41c4d82015-01-05 15:51:13 -0800150 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
Romain Guy7c450aa2012-09-21 19:15:00 -0700151 INIT_LOGD(" Overdraw debug enabled: %s", property);
Romain Guy627c6fd2013-08-21 11:53:18 -0700152 if (!strcmp(property, "show")) {
153 debugOverdraw = true;
154 mOverdrawDebugColorSet = kColorSet_Default;
155 } else if (!strcmp(property, "show_deuteranomaly")) {
156 debugOverdraw = true;
157 mOverdrawDebugColorSet = kColorSet_Deuteranomaly;
158 }
Romain Guy7c450aa2012-09-21 19:15:00 -0700159 }
Romain Guy5bb3c732012-11-29 17:52:58 -0800160
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800161 // See Properties.h for valid values
Chris Craikd41c4d82015-01-05 15:51:13 -0800162 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800163 INIT_LOGD(" Stencil clip debug enabled: %s", property);
164 if (!strcmp(property, "hide")) {
165 debugStencilClip = kStencilHide;
166 } else if (!strcmp(property, "highlight")) {
167 debugStencilClip = kStencilShowHighlight;
168 } else if (!strcmp(property, "region")) {
169 debugStencilClip = kStencilShowRegion;
170 }
171 } else {
172 debugStencilClip = kStencilHide;
173 }
174
Romain Guy0f667532013-03-01 14:31:04 -0800175 if (property_get(PROPERTY_DISABLE_DRAW_DEFER, property, "false")) {
176 drawDeferDisabled = !strcasecmp(property, "true");
177 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
178 } else {
Chris Craik58ddced2014-07-16 19:11:46 -0700179 drawDeferDisabled = false;
Romain Guy0f667532013-03-01 14:31:04 -0800180 INIT_LOGD(" Draw defer enabled");
181 }
182
183 if (property_get(PROPERTY_DISABLE_DRAW_REORDER, property, "false")) {
184 drawReorderDisabled = !strcasecmp(property, "true");
185 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
186 } else {
Chris Craik58ddced2014-07-16 19:11:46 -0700187 drawReorderDisabled = false;
Romain Guy0f667532013-03-01 14:31:04 -0800188 INIT_LOGD(" Draw reorder enabled");
189 }
190
Chris Craik117bdbc2015-02-05 10:12:38 -0800191 return (prevDebugLayersUpdates != debugLayersUpdates)
192 || (prevDebugOverdraw != debugOverdraw)
193 || (prevDebugStencilClip != debugStencilClip);
Romain Guy4ff0cf42012-08-06 14:51:10 -0700194}
195
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800196void Caches::terminate() {
197 if (!mInitialized) return;
Chris Craik51d6a3d2014-12-22 17:16:56 -0800198 mRegionMesh.release();
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800199
200 fboCache.clear();
201
202 programCache.clear();
Chris Craik34725682015-02-05 09:06:30 -0800203 mProgram = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800204
Romain Guy3b748a42013-04-17 18:54:38 -0700205 patchCache.clear();
206
Romain Guy46bfc482013-08-16 18:38:29 -0700207 clearGarbage();
208
Chris Craik44eb2c02015-01-29 09:45:09 -0800209 delete mPixelBufferState;
210 mPixelBufferState = nullptr;
211 delete mTextureState;
212 mTextureState = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800213 mInitialized = false;
Romain Guy5b3b3522010-10-27 18:57:51 -0700214}
215
Chris Craik6c15ffa2015-02-02 13:50:55 -0800216void Caches::setProgram(const ProgramDescription& description) {
217 setProgram(programCache.get(description));
218}
219
220void Caches::setProgram(Program* program) {
221 if (!program || !program->isInUse()) {
222 if (mProgram) {
223 mProgram->remove();
224 }
225 if (program) {
226 program->use();
227 }
228 mProgram = program;
229 }
230}
231
Romain Guy5b3b3522010-10-27 18:57:51 -0700232///////////////////////////////////////////////////////////////////////////////
Romain Guyc15008e2010-11-10 11:59:15 -0800233// Debug
234///////////////////////////////////////////////////////////////////////////////
235
Romain Guy627c6fd2013-08-21 11:53:18 -0700236uint32_t Caches::getOverdrawColor(uint32_t amount) const {
237 static uint32_t sOverdrawColors[2][4] = {
238 { 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000 },
239 { 0x2f0000ff, 0x4fffff00, 0x5fff8ad8, 0x7fff0000 }
240 };
241 if (amount < 1) amount = 1;
242 if (amount > 4) amount = 4;
243 return sOverdrawColors[mOverdrawDebugColorSet][amount - 1];
244}
245
Romain Guyc15008e2010-11-10 11:59:15 -0800246void Caches::dumpMemoryUsage() {
Chet Haase9c1e23b2011-03-24 10:51:31 -0700247 String8 stringLog;
248 dumpMemoryUsage(stringLog);
Steve Block5baa3a62011-12-20 16:23:08 +0000249 ALOGD("%s", stringLog.string());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700250}
251
252void Caches::dumpMemoryUsage(String8 &log) {
John Reck0e89e2b2014-10-31 14:49:06 -0700253 uint32_t total = 0;
Chet Haase9c1e23b2011-03-24 10:51:31 -0700254 log.appendFormat("Current memory usage / total memory usage (bytes):\n");
255 log.appendFormat(" TextureCache %8d / %8d\n",
256 textureCache.getSize(), textureCache.getMaxSize());
John Reck17035b02014-09-03 07:39:53 -0700257 log.appendFormat(" LayerCache %8d / %8d (numLayers = %zu)\n",
258 layerCache.getSize(), layerCache.getMaxSize(), layerCache.getCount());
John Reck0e89e2b2014-10-31 14:49:06 -0700259 if (mRenderState) {
260 int memused = 0;
John Reck57998012015-01-29 10:17:57 -0800261 for (std::set<Layer*>::iterator it = mRenderState->mActiveLayers.begin();
John Reck0e89e2b2014-10-31 14:49:06 -0700262 it != mRenderState->mActiveLayers.end(); it++) {
263 const Layer* layer = *it;
264 log.appendFormat(" Layer size %dx%d; isTextureLayer()=%d; texid=%u fbo=%u; refs=%d\n",
265 layer->getWidth(), layer->getHeight(),
266 layer->isTextureLayer(), layer->getTexture(),
267 layer->getFbo(), layer->getStrongCount());
John Reck88f5fc72014-11-03 10:32:24 -0800268 memused += layer->getWidth() * layer->getHeight() * 4;
John Reck0e89e2b2014-10-31 14:49:06 -0700269 }
270 log.appendFormat(" Layers total %8d (numLayers = %zu)\n",
271 memused, mRenderState->mActiveLayers.size());
272 total += memused;
273 }
Romain Guy8d4aeb72013-02-12 16:08:55 -0800274 log.appendFormat(" RenderBufferCache %8d / %8d\n",
275 renderBufferCache.getSize(), renderBufferCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700276 log.appendFormat(" GradientCache %8d / %8d\n",
277 gradientCache.getSize(), gradientCache.getMaxSize());
278 log.appendFormat(" PathCache %8d / %8d\n",
279 pathCache.getSize(), pathCache.getMaxSize());
Chris Craik05f3d6e2014-06-02 16:27:04 -0700280 log.appendFormat(" TessellationCache %8d / %8d\n",
281 tessellationCache.getSize(), tessellationCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700282 log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(),
Romain Guyc15008e2010-11-10 11:59:15 -0800283 dropShadowCache.getMaxSize());
Romain Guy3b748a42013-04-17 18:54:38 -0700284 log.appendFormat(" PatchCache %8d / %8d\n",
285 patchCache.getSize(), patchCache.getMaxSize());
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700286 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
Victoria Lease1e546812013-06-25 14:25:17 -0700287 const uint32_t sizeA8 = fontRenderer->getFontRendererSize(i, GL_ALPHA);
288 const uint32_t sizeRGBA = fontRenderer->getFontRendererSize(i, GL_RGBA);
289 log.appendFormat(" FontRenderer %d A8 %8d / %8d\n", i, sizeA8, sizeA8);
290 log.appendFormat(" FontRenderer %d RGBA %8d / %8d\n", i, sizeRGBA, sizeRGBA);
291 log.appendFormat(" FontRenderer %d total %8d / %8d\n", i, sizeA8 + sizeRGBA,
292 sizeA8 + sizeRGBA);
Romain Guyc15008e2010-11-10 11:59:15 -0800293 }
Romain Guyd2ba50a2011-05-27 10:21:07 -0700294 log.appendFormat("Other:\n");
Chet Haase9c1e23b2011-03-24 10:51:31 -0700295 log.appendFormat(" FboCache %8d / %8d\n",
296 fboCache.getSize(), fboCache.getMaxSize());
Romain Guyc15008e2010-11-10 11:59:15 -0800297
Romain Guyc15008e2010-11-10 11:59:15 -0800298 total += textureCache.getSize();
Romain Guy8d4aeb72013-02-12 16:08:55 -0800299 total += renderBufferCache.getSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800300 total += gradientCache.getSize();
301 total += pathCache.getSize();
Chris Craik05f3d6e2014-06-02 16:27:04 -0700302 total += tessellationCache.getSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800303 total += dropShadowCache.getSize();
Romain Guy3b748a42013-04-17 18:54:38 -0700304 total += patchCache.getSize();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700305 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
Victoria Lease1e546812013-06-25 14:25:17 -0700306 total += fontRenderer->getFontRendererSize(i, GL_ALPHA);
307 total += fontRenderer->getFontRendererSize(i, GL_RGBA);
Romain Guyc15008e2010-11-10 11:59:15 -0800308 }
309
Chet Haase9c1e23b2011-03-24 10:51:31 -0700310 log.appendFormat("Total memory usage:\n");
311 log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
Romain Guyc15008e2010-11-10 11:59:15 -0800312}
313
314///////////////////////////////////////////////////////////////////////////////
Romain Guyfe48f652010-11-11 15:36:56 -0800315// Memory management
316///////////////////////////////////////////////////////////////////////////////
317
318void Caches::clearGarbage() {
319 textureCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800320 pathCache.clearGarbage();
Romain Guye3b0a012013-06-26 15:45:41 -0700321 patchCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800322}
323
Romain Guybdf76092011-07-18 15:00:43 -0700324void Caches::flush(FlushMode mode) {
325 FLUSH_LOGD("Flushing caches (mode %d)", mode);
326
Romain Guyb0a41ed2013-08-16 14:44:38 -0700327 // We must stop tasks before clearing caches
328 if (mode > kFlushMode_Layers) {
329 tasks.stop();
330 }
331
Romain Guybdf76092011-07-18 15:00:43 -0700332 switch (mode) {
333 case kFlushMode_Full:
334 textureCache.clear();
335 patchCache.clear();
336 dropShadowCache.clear();
337 gradientCache.clear();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700338 fontRenderer->clear();
Romain Guyb7463712013-08-16 13:55:29 -0700339 fboCache.clear();
Romain Guy211efea2012-07-31 21:16:07 -0700340 dither.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700341 // fall through
342 case kFlushMode_Moderate:
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700343 fontRenderer->flush();
Romain Guyeca0ca22011-11-04 15:12:29 -0700344 textureCache.flush();
Romain Guybdf76092011-07-18 15:00:43 -0700345 pathCache.clear();
Chris Craik05f3d6e2014-06-02 16:27:04 -0700346 tessellationCache.clear();
Romain Guy6d7475d2011-07-27 16:28:21 -0700347 // fall through
348 case kFlushMode_Layers:
349 layerCache.clear();
Romain Guy8d4aeb72013-02-12 16:08:55 -0800350 renderBufferCache.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700351 break;
352 }
Chet Haase6a2d17f2012-09-30 12:14:13 -0700353
354 clearGarbage();
John Reck4ced2622014-09-19 10:10:19 -0700355 glFinish();
Romain Guybdf76092011-07-18 15:00:43 -0700356}
357
Romain Guyfe48f652010-11-11 15:36:56 -0800358///////////////////////////////////////////////////////////////////////////////
Romain Guy85ef80d2012-09-13 20:26:50 -0700359// Tiling
360///////////////////////////////////////////////////////////////////////////////
361
Romain Guyf735c8e2013-01-31 17:45:55 -0800362void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard) {
Romain Guy3bbacf22013-02-06 16:51:04 -0800363 if (mExtensions.hasTiledRendering() && !debugOverdraw) {
Romain Guyf735c8e2013-01-31 17:45:55 -0800364 glStartTilingQCOM(x, y, width, height, (discard ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
Romain Guy85ef80d2012-09-13 20:26:50 -0700365 }
366}
367
368void Caches::endTiling() {
Romain Guy3bbacf22013-02-06 16:51:04 -0800369 if (mExtensions.hasTiledRendering() && !debugOverdraw) {
Romain Guy2b7028e2012-09-19 17:25:38 -0700370 glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
Romain Guy85ef80d2012-09-13 20:26:50 -0700371 }
372}
373
Romain Guy54c1a642012-09-27 17:55:46 -0700374bool Caches::hasRegisteredFunctors() {
375 return mFunctorsCount > 0;
376}
377
378void Caches::registerFunctors(uint32_t functorCount) {
379 mFunctorsCount += functorCount;
380}
381
382void Caches::unregisterFunctors(uint32_t functorCount) {
383 if (functorCount > mFunctorsCount) {
384 mFunctorsCount = 0;
385 } else {
386 mFunctorsCount -= functorCount;
387 }
388}
389
Romain Guy85ef80d2012-09-13 20:26:50 -0700390///////////////////////////////////////////////////////////////////////////////
391// Regions
392///////////////////////////////////////////////////////////////////////////////
393
Romain Guy5b3b3522010-10-27 18:57:51 -0700394TextureVertex* Caches::getRegionMesh() {
395 // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
396 if (!mRegionMesh) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800397 mRegionMesh.reset(new TextureVertex[kMaxNumberOfQuads * 4]);
Romain Guy5b3b3522010-10-27 18:57:51 -0700398 }
399
Chris Craik51d6a3d2014-12-22 17:16:56 -0800400 return mRegionMesh.get();
Romain Guy5b3b3522010-10-27 18:57:51 -0700401}
402
Chris Craikba9b6132013-12-15 17:10:19 -0800403///////////////////////////////////////////////////////////////////////////////
404// Temporary Properties
405///////////////////////////////////////////////////////////////////////////////
406
407void Caches::initTempProperties() {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700408 propertyLightDiameter = -1.0f;
409 propertyLightPosY = -1.0f;
410 propertyLightPosZ = -1.0f;
411 propertyAmbientRatio = -1.0f;
ztenghui14a4e352014-08-13 10:44:39 -0700412 propertyAmbientShadowStrength = -1;
413 propertySpotShadowStrength = -1;
Chris Craikba9b6132013-12-15 17:10:19 -0800414}
415
416void Caches::setTempProperty(const char* name, const char* value) {
417 ALOGD("setting property %s to %s", name, value);
Chris Craika736cd92014-08-04 13:18:38 -0700418 if (!strcmp(name, "ambientRatio")) {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700419 propertyAmbientRatio = fmin(fmax(atof(value), 0.0), 10.0);
420 ALOGD("ambientRatio = %.2f", propertyAmbientRatio);
ztenghuicc3c2562014-01-17 10:34:10 -0800421 return;
Chris Craikf5be3ca2014-04-30 18:20:03 -0700422 } else if (!strcmp(name, "lightDiameter")) {
423 propertyLightDiameter = fmin(fmax(atof(value), 0.0), 3000.0);
424 ALOGD("lightDiameter = %.2f", propertyLightDiameter);
ztenghuicc3c2562014-01-17 10:34:10 -0800425 return;
Chris Craik59744b72014-07-01 17:56:52 -0700426 } else if (!strcmp(name, "lightPosY")) {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700427 propertyLightPosY = fmin(fmax(atof(value), 0.0), 3000.0);
428 ALOGD("lightPos Y = %.2f", propertyLightPosY);
429 return;
Chris Craik59744b72014-07-01 17:56:52 -0700430 } else if (!strcmp(name, "lightPosZ")) {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700431 propertyLightPosZ = fmin(fmax(atof(value), 0.0), 3000.0);
432 ALOGD("lightPos Z = %.2f", propertyLightPosZ);
ztenghuicc3c2562014-01-17 10:34:10 -0800433 return;
ztenghui14a4e352014-08-13 10:44:39 -0700434 } else if (!strcmp(name, "ambientShadowStrength")) {
435 propertyAmbientShadowStrength = atoi(value);
436 ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength);
437 return;
438 } else if (!strcmp(name, "spotShadowStrength")) {
439 propertySpotShadowStrength = atoi(value);
440 ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength);
441 return;
Chris Craikba9b6132013-12-15 17:10:19 -0800442 }
443 ALOGD(" failed");
444}
445
Chet Haasedd78cca2010-10-22 18:59:26 -0700446}; // namespace uirenderer
447}; // namespace android