blob: af1b1cdd09e83f39a8af6e8cbe5248b115e87e62 [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)
51 : patchCache(renderState)
Chris Craik44eb2c02015-01-29 09:45:09 -080052 , dither(*this)
Chris Craik96a5c4c2015-01-27 15:46:35 -080053 , mRenderState(&renderState)
54 , mExtensions(Extensions::getInstance())
55 , mInitialized(false) {
56 INIT_LOGD("Creating OpenGL renderer caches");
Romain Guy8ff6b9e2011-11-09 20:10:18 -080057 init();
Romain Guyb1d0a4e2012-07-13 18:25:35 -070058 initFont();
Romain Guydfa10462012-05-12 16:18:58 -070059 initConstraints();
Romain Guy4ff0cf42012-08-06 14:51:10 -070060 initProperties();
Romain Guyf9f00162013-05-09 11:50:12 -070061 initStaticProperties();
Romain Guy0f667532013-03-01 14:31:04 -080062 initExtensions();
Chris Craikba9b6132013-12-15 17:10:19 -080063 initTempProperties();
Romain Guye190aa62010-11-10 19:01:29 -080064
65 mDebugLevel = readDebugLevel();
Chris Craik96a5c4c2015-01-27 15:46:35 -080066 ALOGD_IF(mDebugLevel != kDebugDisabled,
67 "Enabling debug mode %d", mDebugLevel);
Chet Haasedd78cca2010-10-22 18:59:26 -070068}
69
Romain Guy3b748a42013-04-17 18:54:38 -070070bool Caches::init() {
71 if (mInitialized) return false;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080072
John Reckfbc8df02014-11-14 16:18:41 -080073 ATRACE_NAME("Caches::init");
74
Chris Craikd41c4d82015-01-05 15:51:13 -080075 mRegionMesh = nullptr;
Chris Craik6c15ffa2015-02-02 13:50:55 -080076 mProgram = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080077
Romain Guy54c1a642012-09-27 17:55:46 -070078 mFunctorsCount = 0;
79
Romain Guyc2a97212013-02-06 15:29:46 -080080 debugLayersUpdates = false;
81 debugOverdraw = false;
Romain Guy3ff0bfd2013-02-25 14:15:37 -080082 debugStencilClip = kStencilHide;
Romain Guyc2a97212013-02-06 15:29:46 -080083
Chris Craik96a5c4c2015-01-27 15:46:35 -080084 patchCache.init();
Romain Guy3b748a42013-04-17 18:54:38 -070085
Romain Guy8ff6b9e2011-11-09 20:10:18 -080086 mInitialized = true;
Romain Guy3b748a42013-04-17 18:54:38 -070087
Chris Craik44eb2c02015-01-29 09:45:09 -080088 mPixelBufferState = new PixelBufferState();
89 mTextureState = new TextureState();
Romain Guy8aa195d2013-06-04 18:00:09 -070090
Romain Guy3b748a42013-04-17 18:54:38 -070091 return true;
Romain Guy8ff6b9e2011-11-09 20:10:18 -080092}
93
Romain Guyb1d0a4e2012-07-13 18:25:35 -070094void Caches::initFont() {
95 fontRenderer = GammaFontRenderer::createRenderer();
96}
97
Romain Guydfa10462012-05-12 16:18:58 -070098void Caches::initExtensions() {
Romain Guy3bbacf22013-02-06 16:51:04 -080099 if (mExtensions.hasDebugMarker()) {
Romain Guydfa10462012-05-12 16:18:58 -0700100 eventMark = glInsertEventMarkerEXT;
Romain Guy0f667532013-03-01 14:31:04 -0800101
Chris Craikff785832013-03-08 13:12:16 -0800102 startMark = glPushGroupMarkerEXT;
103 endMark = glPopGroupMarkerEXT;
Romain Guydfa10462012-05-12 16:18:58 -0700104 } else {
105 eventMark = eventMarkNull;
106 startMark = startMarkNull;
107 endMark = endMarkNull;
108 }
109
Romain Guy0f667532013-03-01 14:31:04 -0800110 if (mExtensions.hasDebugLabel() && (drawDeferDisabled || drawReorderDisabled)) {
Romain Guydfa10462012-05-12 16:18:58 -0700111 setLabel = glLabelObjectEXT;
112 getLabel = glGetObjectLabelEXT;
113 } else {
114 setLabel = setLabelNull;
115 getLabel = getLabelNull;
116 }
117}
118
119void Caches::initConstraints() {
Romain Guydfa10462012-05-12 16:18:58 -0700120 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
121}
122
Romain Guyf9f00162013-05-09 11:50:12 -0700123void Caches::initStaticProperties() {
124 gpuPixelBuffersEnabled = false;
125
126 // OpenGL ES 3.0+ specific features
Romain Guy7f430762013-06-13 14:29:40 -0700127 if (mExtensions.hasPixelBufferObjects()) {
Romain Guyf9f00162013-05-09 11:50:12 -0700128 char property[PROPERTY_VALUE_MAX];
129 if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) {
130 gpuPixelBuffersEnabled = !strcmp(property, "true");
131 }
132 }
133}
134
Romain Guy5bb3c732012-11-29 17:52:58 -0800135bool Caches::initProperties() {
136 bool prevDebugLayersUpdates = debugLayersUpdates;
137 bool prevDebugOverdraw = debugOverdraw;
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800138 StencilClipDebug prevDebugStencilClip = debugStencilClip;
Romain Guy5bb3c732012-11-29 17:52:58 -0800139
Romain Guy4ff0cf42012-08-06 14:51:10 -0700140 char property[PROPERTY_VALUE_MAX];
Chris Craikd41c4d82015-01-05 15:51:13 -0800141 if (property_get(PROPERTY_DEBUG_LAYERS_UPDATES, property, nullptr) > 0) {
Romain Guy4ff0cf42012-08-06 14:51:10 -0700142 INIT_LOGD(" Layers updates debug enabled: %s", property);
143 debugLayersUpdates = !strcmp(property, "true");
144 } else {
145 debugLayersUpdates = false;
146 }
Romain Guy7c450aa2012-09-21 19:15:00 -0700147
Romain Guy627c6fd2013-08-21 11:53:18 -0700148 debugOverdraw = false;
Chris Craikd41c4d82015-01-05 15:51:13 -0800149 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
Romain Guy7c450aa2012-09-21 19:15:00 -0700150 INIT_LOGD(" Overdraw debug enabled: %s", property);
Romain Guy627c6fd2013-08-21 11:53:18 -0700151 if (!strcmp(property, "show")) {
152 debugOverdraw = true;
153 mOverdrawDebugColorSet = kColorSet_Default;
154 } else if (!strcmp(property, "show_deuteranomaly")) {
155 debugOverdraw = true;
156 mOverdrawDebugColorSet = kColorSet_Deuteranomaly;
157 }
Romain Guy7c450aa2012-09-21 19:15:00 -0700158 }
Romain Guy5bb3c732012-11-29 17:52:58 -0800159
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800160 // See Properties.h for valid values
Chris Craikd41c4d82015-01-05 15:51:13 -0800161 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800162 INIT_LOGD(" Stencil clip debug enabled: %s", property);
163 if (!strcmp(property, "hide")) {
164 debugStencilClip = kStencilHide;
165 } else if (!strcmp(property, "highlight")) {
166 debugStencilClip = kStencilShowHighlight;
167 } else if (!strcmp(property, "region")) {
168 debugStencilClip = kStencilShowRegion;
169 }
170 } else {
171 debugStencilClip = kStencilHide;
172 }
173
Romain Guy0f667532013-03-01 14:31:04 -0800174 if (property_get(PROPERTY_DISABLE_DRAW_DEFER, property, "false")) {
175 drawDeferDisabled = !strcasecmp(property, "true");
176 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
177 } else {
Chris Craik58ddced2014-07-16 19:11:46 -0700178 drawDeferDisabled = false;
Romain Guy0f667532013-03-01 14:31:04 -0800179 INIT_LOGD(" Draw defer enabled");
180 }
181
182 if (property_get(PROPERTY_DISABLE_DRAW_REORDER, property, "false")) {
183 drawReorderDisabled = !strcasecmp(property, "true");
184 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
185 } else {
Chris Craik58ddced2014-07-16 19:11:46 -0700186 drawReorderDisabled = false;
Romain Guy0f667532013-03-01 14:31:04 -0800187 INIT_LOGD(" Draw reorder enabled");
188 }
189
Romain Guy5bb3c732012-11-29 17:52:58 -0800190 return (prevDebugLayersUpdates != debugLayersUpdates) ||
Romain Guy3ff0bfd2013-02-25 14:15:37 -0800191 (prevDebugOverdraw != debugOverdraw) ||
192 (prevDebugStencilClip != debugStencilClip);
Romain Guy4ff0cf42012-08-06 14:51:10 -0700193}
194
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800195void Caches::terminate() {
196 if (!mInitialized) return;
Chris Craik51d6a3d2014-12-22 17:16:56 -0800197 mRegionMesh.release();
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800198
199 fboCache.clear();
200
201 programCache.clear();
Chris Craik34725682015-02-05 09:06:30 -0800202 mProgram = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800203
Romain Guy3b748a42013-04-17 18:54:38 -0700204 patchCache.clear();
205
Romain Guy46bfc482013-08-16 18:38:29 -0700206 clearGarbage();
207
Chris Craik44eb2c02015-01-29 09:45:09 -0800208 delete mPixelBufferState;
209 mPixelBufferState = nullptr;
210 delete mTextureState;
211 mTextureState = nullptr;
Romain Guy8ff6b9e2011-11-09 20:10:18 -0800212 mInitialized = false;
Romain Guy5b3b3522010-10-27 18:57:51 -0700213}
214
Chris Craik6c15ffa2015-02-02 13:50:55 -0800215void Caches::setProgram(const ProgramDescription& description) {
216 setProgram(programCache.get(description));
217}
218
219void Caches::setProgram(Program* program) {
220 if (!program || !program->isInUse()) {
221 if (mProgram) {
222 mProgram->remove();
223 }
224 if (program) {
225 program->use();
226 }
227 mProgram = program;
228 }
229}
230
Romain Guy5b3b3522010-10-27 18:57:51 -0700231///////////////////////////////////////////////////////////////////////////////
Romain Guyc15008e2010-11-10 11:59:15 -0800232// Debug
233///////////////////////////////////////////////////////////////////////////////
234
Romain Guy627c6fd2013-08-21 11:53:18 -0700235uint32_t Caches::getOverdrawColor(uint32_t amount) const {
236 static uint32_t sOverdrawColors[2][4] = {
237 { 0x2f0000ff, 0x2f00ff00, 0x3fff0000, 0x7fff0000 },
238 { 0x2f0000ff, 0x4fffff00, 0x5fff8ad8, 0x7fff0000 }
239 };
240 if (amount < 1) amount = 1;
241 if (amount > 4) amount = 4;
242 return sOverdrawColors[mOverdrawDebugColorSet][amount - 1];
243}
244
Romain Guyc15008e2010-11-10 11:59:15 -0800245void Caches::dumpMemoryUsage() {
Chet Haase9c1e23b2011-03-24 10:51:31 -0700246 String8 stringLog;
247 dumpMemoryUsage(stringLog);
Steve Block5baa3a62011-12-20 16:23:08 +0000248 ALOGD("%s", stringLog.string());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700249}
250
251void Caches::dumpMemoryUsage(String8 &log) {
John Reck0e89e2b2014-10-31 14:49:06 -0700252 uint32_t total = 0;
Chet Haase9c1e23b2011-03-24 10:51:31 -0700253 log.appendFormat("Current memory usage / total memory usage (bytes):\n");
254 log.appendFormat(" TextureCache %8d / %8d\n",
255 textureCache.getSize(), textureCache.getMaxSize());
John Reck17035b02014-09-03 07:39:53 -0700256 log.appendFormat(" LayerCache %8d / %8d (numLayers = %zu)\n",
257 layerCache.getSize(), layerCache.getMaxSize(), layerCache.getCount());
John Reck0e89e2b2014-10-31 14:49:06 -0700258 if (mRenderState) {
259 int memused = 0;
John Reck57998012015-01-29 10:17:57 -0800260 for (std::set<Layer*>::iterator it = mRenderState->mActiveLayers.begin();
John Reck0e89e2b2014-10-31 14:49:06 -0700261 it != mRenderState->mActiveLayers.end(); it++) {
262 const Layer* layer = *it;
263 log.appendFormat(" Layer size %dx%d; isTextureLayer()=%d; texid=%u fbo=%u; refs=%d\n",
264 layer->getWidth(), layer->getHeight(),
265 layer->isTextureLayer(), layer->getTexture(),
266 layer->getFbo(), layer->getStrongCount());
John Reck88f5fc72014-11-03 10:32:24 -0800267 memused += layer->getWidth() * layer->getHeight() * 4;
John Reck0e89e2b2014-10-31 14:49:06 -0700268 }
269 log.appendFormat(" Layers total %8d (numLayers = %zu)\n",
270 memused, mRenderState->mActiveLayers.size());
271 total += memused;
272 }
Romain Guy8d4aeb72013-02-12 16:08:55 -0800273 log.appendFormat(" RenderBufferCache %8d / %8d\n",
274 renderBufferCache.getSize(), renderBufferCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700275 log.appendFormat(" GradientCache %8d / %8d\n",
276 gradientCache.getSize(), gradientCache.getMaxSize());
277 log.appendFormat(" PathCache %8d / %8d\n",
278 pathCache.getSize(), pathCache.getMaxSize());
Chris Craik05f3d6e2014-06-02 16:27:04 -0700279 log.appendFormat(" TessellationCache %8d / %8d\n",
280 tessellationCache.getSize(), tessellationCache.getMaxSize());
Chet Haase9c1e23b2011-03-24 10:51:31 -0700281 log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(),
Romain Guyc15008e2010-11-10 11:59:15 -0800282 dropShadowCache.getMaxSize());
Romain Guy3b748a42013-04-17 18:54:38 -0700283 log.appendFormat(" PatchCache %8d / %8d\n",
284 patchCache.getSize(), patchCache.getMaxSize());
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700285 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
Victoria Lease1e546812013-06-25 14:25:17 -0700286 const uint32_t sizeA8 = fontRenderer->getFontRendererSize(i, GL_ALPHA);
287 const uint32_t sizeRGBA = fontRenderer->getFontRendererSize(i, GL_RGBA);
288 log.appendFormat(" FontRenderer %d A8 %8d / %8d\n", i, sizeA8, sizeA8);
289 log.appendFormat(" FontRenderer %d RGBA %8d / %8d\n", i, sizeRGBA, sizeRGBA);
290 log.appendFormat(" FontRenderer %d total %8d / %8d\n", i, sizeA8 + sizeRGBA,
291 sizeA8 + sizeRGBA);
Romain Guyc15008e2010-11-10 11:59:15 -0800292 }
Romain Guyd2ba50a2011-05-27 10:21:07 -0700293 log.appendFormat("Other:\n");
Chet Haase9c1e23b2011-03-24 10:51:31 -0700294 log.appendFormat(" FboCache %8d / %8d\n",
295 fboCache.getSize(), fboCache.getMaxSize());
Romain Guyc15008e2010-11-10 11:59:15 -0800296
Romain Guyc15008e2010-11-10 11:59:15 -0800297 total += textureCache.getSize();
Romain Guy8d4aeb72013-02-12 16:08:55 -0800298 total += renderBufferCache.getSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800299 total += gradientCache.getSize();
300 total += pathCache.getSize();
Chris Craik05f3d6e2014-06-02 16:27:04 -0700301 total += tessellationCache.getSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800302 total += dropShadowCache.getSize();
Romain Guy3b748a42013-04-17 18:54:38 -0700303 total += patchCache.getSize();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700304 for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
Victoria Lease1e546812013-06-25 14:25:17 -0700305 total += fontRenderer->getFontRendererSize(i, GL_ALPHA);
306 total += fontRenderer->getFontRendererSize(i, GL_RGBA);
Romain Guyc15008e2010-11-10 11:59:15 -0800307 }
308
Chet Haase9c1e23b2011-03-24 10:51:31 -0700309 log.appendFormat("Total memory usage:\n");
310 log.appendFormat(" %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
Romain Guyc15008e2010-11-10 11:59:15 -0800311}
312
313///////////////////////////////////////////////////////////////////////////////
Romain Guyfe48f652010-11-11 15:36:56 -0800314// Memory management
315///////////////////////////////////////////////////////////////////////////////
316
317void Caches::clearGarbage() {
318 textureCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800319 pathCache.clearGarbage();
Romain Guye3b0a012013-06-26 15:45:41 -0700320 patchCache.clearGarbage();
Romain Guyfe48f652010-11-11 15:36:56 -0800321}
322
Romain Guybdf76092011-07-18 15:00:43 -0700323void Caches::flush(FlushMode mode) {
324 FLUSH_LOGD("Flushing caches (mode %d)", mode);
325
Romain Guyb0a41ed2013-08-16 14:44:38 -0700326 // We must stop tasks before clearing caches
327 if (mode > kFlushMode_Layers) {
328 tasks.stop();
329 }
330
Romain Guybdf76092011-07-18 15:00:43 -0700331 switch (mode) {
332 case kFlushMode_Full:
333 textureCache.clear();
334 patchCache.clear();
335 dropShadowCache.clear();
336 gradientCache.clear();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700337 fontRenderer->clear();
Romain Guyb7463712013-08-16 13:55:29 -0700338 fboCache.clear();
Romain Guy211efea2012-07-31 21:16:07 -0700339 dither.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700340 // fall through
341 case kFlushMode_Moderate:
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700342 fontRenderer->flush();
Romain Guyeca0ca22011-11-04 15:12:29 -0700343 textureCache.flush();
Romain Guybdf76092011-07-18 15:00:43 -0700344 pathCache.clear();
Chris Craik05f3d6e2014-06-02 16:27:04 -0700345 tessellationCache.clear();
Romain Guy6d7475d2011-07-27 16:28:21 -0700346 // fall through
347 case kFlushMode_Layers:
348 layerCache.clear();
Romain Guy8d4aeb72013-02-12 16:08:55 -0800349 renderBufferCache.clear();
Romain Guybdf76092011-07-18 15:00:43 -0700350 break;
351 }
Chet Haase6a2d17f2012-09-30 12:14:13 -0700352
353 clearGarbage();
John Reck4ced2622014-09-19 10:10:19 -0700354 glFinish();
Romain Guybdf76092011-07-18 15:00:43 -0700355}
356
Romain Guyfe48f652010-11-11 15:36:56 -0800357///////////////////////////////////////////////////////////////////////////////
Romain Guy85ef80d2012-09-13 20:26:50 -0700358// Tiling
359///////////////////////////////////////////////////////////////////////////////
360
Romain Guyf735c8e2013-01-31 17:45:55 -0800361void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard) {
Romain Guy3bbacf22013-02-06 16:51:04 -0800362 if (mExtensions.hasTiledRendering() && !debugOverdraw) {
Romain Guyf735c8e2013-01-31 17:45:55 -0800363 glStartTilingQCOM(x, y, width, height, (discard ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
Romain Guy85ef80d2012-09-13 20:26:50 -0700364 }
365}
366
367void Caches::endTiling() {
Romain Guy3bbacf22013-02-06 16:51:04 -0800368 if (mExtensions.hasTiledRendering() && !debugOverdraw) {
Romain Guy2b7028e2012-09-19 17:25:38 -0700369 glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
Romain Guy85ef80d2012-09-13 20:26:50 -0700370 }
371}
372
Romain Guy54c1a642012-09-27 17:55:46 -0700373bool Caches::hasRegisteredFunctors() {
374 return mFunctorsCount > 0;
375}
376
377void Caches::registerFunctors(uint32_t functorCount) {
378 mFunctorsCount += functorCount;
379}
380
381void Caches::unregisterFunctors(uint32_t functorCount) {
382 if (functorCount > mFunctorsCount) {
383 mFunctorsCount = 0;
384 } else {
385 mFunctorsCount -= functorCount;
386 }
387}
388
Romain Guy85ef80d2012-09-13 20:26:50 -0700389///////////////////////////////////////////////////////////////////////////////
390// Regions
391///////////////////////////////////////////////////////////////////////////////
392
Romain Guy5b3b3522010-10-27 18:57:51 -0700393TextureVertex* Caches::getRegionMesh() {
394 // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
395 if (!mRegionMesh) {
Chris Craik96a5c4c2015-01-27 15:46:35 -0800396 mRegionMesh.reset(new TextureVertex[kMaxNumberOfQuads * 4]);
Romain Guy5b3b3522010-10-27 18:57:51 -0700397 }
398
Chris Craik51d6a3d2014-12-22 17:16:56 -0800399 return mRegionMesh.get();
Romain Guy5b3b3522010-10-27 18:57:51 -0700400}
401
Chris Craikba9b6132013-12-15 17:10:19 -0800402///////////////////////////////////////////////////////////////////////////////
403// Temporary Properties
404///////////////////////////////////////////////////////////////////////////////
405
406void Caches::initTempProperties() {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700407 propertyLightDiameter = -1.0f;
408 propertyLightPosY = -1.0f;
409 propertyLightPosZ = -1.0f;
410 propertyAmbientRatio = -1.0f;
ztenghui14a4e352014-08-13 10:44:39 -0700411 propertyAmbientShadowStrength = -1;
412 propertySpotShadowStrength = -1;
Chris Craikba9b6132013-12-15 17:10:19 -0800413}
414
415void Caches::setTempProperty(const char* name, const char* value) {
416 ALOGD("setting property %s to %s", name, value);
Chris Craika736cd92014-08-04 13:18:38 -0700417 if (!strcmp(name, "ambientRatio")) {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700418 propertyAmbientRatio = fmin(fmax(atof(value), 0.0), 10.0);
419 ALOGD("ambientRatio = %.2f", propertyAmbientRatio);
ztenghuicc3c2562014-01-17 10:34:10 -0800420 return;
Chris Craikf5be3ca2014-04-30 18:20:03 -0700421 } else if (!strcmp(name, "lightDiameter")) {
422 propertyLightDiameter = fmin(fmax(atof(value), 0.0), 3000.0);
423 ALOGD("lightDiameter = %.2f", propertyLightDiameter);
ztenghuicc3c2562014-01-17 10:34:10 -0800424 return;
Chris Craik59744b72014-07-01 17:56:52 -0700425 } else if (!strcmp(name, "lightPosY")) {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700426 propertyLightPosY = fmin(fmax(atof(value), 0.0), 3000.0);
427 ALOGD("lightPos Y = %.2f", propertyLightPosY);
428 return;
Chris Craik59744b72014-07-01 17:56:52 -0700429 } else if (!strcmp(name, "lightPosZ")) {
Chris Craikf5be3ca2014-04-30 18:20:03 -0700430 propertyLightPosZ = fmin(fmax(atof(value), 0.0), 3000.0);
431 ALOGD("lightPos Z = %.2f", propertyLightPosZ);
ztenghuicc3c2562014-01-17 10:34:10 -0800432 return;
ztenghui14a4e352014-08-13 10:44:39 -0700433 } else if (!strcmp(name, "ambientShadowStrength")) {
434 propertyAmbientShadowStrength = atoi(value);
435 ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength);
436 return;
437 } else if (!strcmp(name, "spotShadowStrength")) {
438 propertySpotShadowStrength = atoi(value);
439 ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength);
440 return;
Chris Craikba9b6132013-12-15 17:10:19 -0800441 }
442 ALOGD(" failed");
443}
444
Chet Haasedd78cca2010-10-22 18:59:26 -0700445}; // namespace uirenderer
446}; // namespace android