Caches.cpp revision ef94c6f88fbb1deb095b1494378befcdb9722839
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 <utils/Log.h>
20#include <utils/String8.h>
21
22#include "Caches.h"
23#include "DisplayListRenderer.h"
24#include "Properties.h"
25#include "LayerRenderer.h"
26
27namespace android {
28
29#ifdef USE_OPENGL_RENDERER
30using namespace uirenderer;
31ANDROID_SINGLETON_STATIC_INSTANCE(Caches);
32#endif
33
34namespace uirenderer {
35
36///////////////////////////////////////////////////////////////////////////////
37// Macros
38///////////////////////////////////////////////////////////////////////////////
39
40#if DEBUG_CACHE_FLUSH
41    #define FLUSH_LOGD(...) ALOGD(__VA_ARGS__)
42#else
43    #define FLUSH_LOGD(...)
44#endif
45
46///////////////////////////////////////////////////////////////////////////////
47// Constructors/destructor
48///////////////////////////////////////////////////////////////////////////////
49
50Caches::Caches(): Singleton<Caches>(),
51        mExtensions(Extensions::getInstance()), mInitialized(false) {
52    init();
53    initFont();
54    initConstraints();
55    initProperties();
56    initStaticProperties();
57    initExtensions();
58    initTempProperties();
59
60    mDebugLevel = readDebugLevel();
61    ALOGD("Enabling debug mode %d", mDebugLevel);
62}
63
64bool Caches::init() {
65    if (mInitialized) return false;
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;
72    mCurrentIndicesBuffer = 0;
73    mCurrentPositionPointer = this;
74    mCurrentPositionStride = 0;
75    mCurrentTexCoordsPointer = this;
76    mCurrentPixelBuffer = 0;
77
78    mTexCoordsArrayEnabled = false;
79
80    glDisable(GL_SCISSOR_TEST);
81    scissorEnabled = false;
82    mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
83
84    glActiveTexture(gTextureUnits[0]);
85    mTextureUnit = 0;
86
87    mRegionMesh = NULL;
88    mMeshIndices = 0;
89
90    blend = false;
91    lastSrcMode = GL_ZERO;
92    lastDstMode = GL_ZERO;
93    currentProgram = NULL;
94
95    mFunctorsCount = 0;
96
97    debugLayersUpdates = false;
98    debugOverdraw = false;
99    debugStencilClip = kStencilHide;
100
101    patchCache.init(*this);
102
103    mInitialized = true;
104
105    resetBoundTextures();
106
107    return true;
108}
109
110void Caches::initFont() {
111    fontRenderer = GammaFontRenderer::createRenderer();
112}
113
114void Caches::initExtensions() {
115    if (mExtensions.hasDebugMarker()) {
116        eventMark = glInsertEventMarkerEXT;
117
118        startMark = glPushGroupMarkerEXT;
119        endMark = glPopGroupMarkerEXT;
120    } else {
121        eventMark = eventMarkNull;
122        startMark = startMarkNull;
123        endMark = endMarkNull;
124    }
125
126    if (mExtensions.hasDebugLabel() && (drawDeferDisabled || drawReorderDisabled)) {
127        setLabel = glLabelObjectEXT;
128        getLabel = glGetObjectLabelEXT;
129    } else {
130        setLabel = setLabelNull;
131        getLabel = getLabelNull;
132    }
133}
134
135void 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
145void Caches::initStaticProperties() {
146    gpuPixelBuffersEnabled = false;
147
148    // OpenGL ES 3.0+ specific features
149    if (mExtensions.hasPixelBufferObjects()) {
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
157bool Caches::initProperties() {
158    bool prevDebugLayersUpdates = debugLayersUpdates;
159    bool prevDebugOverdraw = debugOverdraw;
160    StencilClipDebug prevDebugStencilClip = debugStencilClip;
161
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    }
169
170    debugOverdraw = false;
171    if (property_get(PROPERTY_DEBUG_OVERDRAW, property, NULL) > 0) {
172        INIT_LOGD("  Overdraw debug enabled: %s", property);
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        }
180    }
181
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
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
210    return (prevDebugLayersUpdates != debugLayersUpdates) ||
211            (prevDebugOverdraw != debugOverdraw) ||
212            (prevDebugStencilClip != debugStencilClip);
213}
214
215void Caches::terminate() {
216    if (!mInitialized) return;
217
218    glDeleteBuffers(1, &meshBuffer);
219    mCurrentBuffer = 0;
220
221    glDeleteBuffers(1, &mMeshIndices);
222    delete[] mRegionMesh;
223    mMeshIndices = 0;
224    mRegionMesh = NULL;
225
226    fboCache.clear();
227
228    programCache.clear();
229    currentProgram = NULL;
230
231    assetAtlas.terminate();
232
233    patchCache.clear();
234
235    clearGarbage();
236
237    mInitialized = false;
238}
239
240///////////////////////////////////////////////////////////////////////////////
241// Debug
242///////////////////////////////////////////////////////////////////////////////
243
244uint32_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
254void Caches::dumpMemoryUsage() {
255    String8 stringLog;
256    dumpMemoryUsage(stringLog);
257    ALOGD("%s", stringLog.string());
258}
259
260void 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());
266    log.appendFormat("  RenderBufferCache    %8d / %8d\n",
267            renderBufferCache.getSize(), renderBufferCache.getMaxSize());
268    log.appendFormat("  GradientCache        %8d / %8d\n",
269            gradientCache.getSize(), gradientCache.getMaxSize());
270    log.appendFormat("  PathCache            %8d / %8d\n",
271            pathCache.getSize(), pathCache.getMaxSize());
272    log.appendFormat("  TextDropShadowCache  %8d / %8d\n", dropShadowCache.getSize(),
273            dropShadowCache.getMaxSize());
274    log.appendFormat("  PatchCache           %8d / %8d\n",
275            patchCache.getSize(), patchCache.getMaxSize());
276    for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
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);
283    }
284    log.appendFormat("Other:\n");
285    log.appendFormat("  FboCache             %8d / %8d\n",
286            fboCache.getSize(), fboCache.getMaxSize());
287
288    uint32_t total = 0;
289    total += textureCache.getSize();
290    total += layerCache.getSize();
291    total += renderBufferCache.getSize();
292    total += gradientCache.getSize();
293    total += pathCache.getSize();
294    total += dropShadowCache.getSize();
295    total += patchCache.getSize();
296    for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) {
297        total += fontRenderer->getFontRendererSize(i, GL_ALPHA);
298        total += fontRenderer->getFontRendererSize(i, GL_RGBA);
299    }
300
301    log.appendFormat("Total memory usage:\n");
302    log.appendFormat("  %d bytes, %.2f MB\n", total, total / 1024.0f / 1024.0f);
303}
304
305///////////////////////////////////////////////////////////////////////////////
306// Memory management
307///////////////////////////////////////////////////////////////////////////////
308
309void Caches::clearGarbage() {
310    textureCache.clearGarbage();
311    pathCache.clearGarbage();
312    patchCache.clearGarbage();
313
314    Vector<DisplayList*> displayLists;
315    Vector<Layer*> layers;
316
317    { // scope for the lock
318        Mutex::Autolock _l(mGarbageLock);
319        displayLists = mDisplayListGarbage;
320        layers = mLayerGarbage;
321        mDisplayListGarbage.clear();
322        mLayerGarbage.clear();
323    }
324
325    size_t count = displayLists.size();
326    for (size_t i = 0; i < count; i++) {
327        DisplayList* displayList = displayLists.itemAt(i);
328        delete displayList;
329    }
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();
337}
338
339void Caches::deleteLayerDeferred(Layer* layer) {
340    Mutex::Autolock _l(mGarbageLock);
341    mLayerGarbage.push(layer);
342}
343
344void Caches::deleteDisplayListDeferred(DisplayList* displayList) {
345    Mutex::Autolock _l(mGarbageLock);
346    mDisplayListGarbage.push(displayList);
347}
348
349void Caches::flush(FlushMode mode) {
350    FLUSH_LOGD("Flushing caches (mode %d)", mode);
351
352    // We must stop tasks before clearing caches
353    if (mode > kFlushMode_Layers) {
354        tasks.stop();
355    }
356
357    switch (mode) {
358        case kFlushMode_Full:
359            textureCache.clear();
360            patchCache.clear();
361            dropShadowCache.clear();
362            gradientCache.clear();
363            fontRenderer->clear();
364            fboCache.clear();
365            dither.clear();
366            // fall through
367        case kFlushMode_Moderate:
368            fontRenderer->flush();
369            textureCache.flush();
370            pathCache.clear();
371            // fall through
372        case kFlushMode_Layers:
373            layerCache.clear();
374            renderBufferCache.clear();
375            break;
376    }
377
378    clearGarbage();
379}
380
381///////////////////////////////////////////////////////////////////////////////
382// VBO
383///////////////////////////////////////////////////////////////////////////////
384
385bool Caches::bindMeshBuffer() {
386    return bindMeshBuffer(meshBuffer);
387}
388
389bool Caches::bindMeshBuffer(const GLuint buffer) {
390    if (mCurrentBuffer != buffer) {
391        glBindBuffer(GL_ARRAY_BUFFER, buffer);
392        mCurrentBuffer = buffer;
393        return true;
394    }
395    return false;
396}
397
398bool Caches::unbindMeshBuffer() {
399    if (mCurrentBuffer) {
400        glBindBuffer(GL_ARRAY_BUFFER, 0);
401        mCurrentBuffer = 0;
402        return true;
403    }
404    return false;
405}
406
407bool 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
416bool Caches::bindIndicesBuffer() {
417    if (!mMeshIndices) {
418        uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6];
419        for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) {
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);
432        glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t),
433                regionIndices, GL_STATIC_DRAW);
434
435        delete[] regionIndices;
436        return force;
437    }
438
439    return bindIndicesBuffer(mMeshIndices);
440}
441
442bool Caches::unbindIndicesBuffer() {
443    if (mCurrentIndicesBuffer) {
444        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
445        mCurrentIndicesBuffer = 0;
446        return true;
447    }
448    return false;
449}
450
451///////////////////////////////////////////////////////////////////////////////
452// PBO
453///////////////////////////////////////////////////////////////////////////////
454
455bool 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
464bool 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///////////////////////////////////////////////////////////////////////////////
474// Meshes and textures
475///////////////////////////////////////////////////////////////////////////////
476
477void Caches::bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) {
478    if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) {
479        GLuint slot = currentProgram->position;
480        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
481        mCurrentPositionPointer = vertices;
482        mCurrentPositionStride = stride;
483    }
484}
485
486void Caches::bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) {
487    if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) {
488        GLuint slot = currentProgram->texCoords;
489        glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices);
490        mCurrentTexCoordsPointer = vertices;
491        mCurrentTexCoordsStride = stride;
492    }
493}
494
495void Caches::resetVertexPointers() {
496    mCurrentPositionPointer = this;
497    mCurrentTexCoordsPointer = this;
498}
499
500void Caches::resetTexCoordsVertexPointer() {
501    mCurrentTexCoordsPointer = this;
502}
503
504void Caches::enableTexCoordsVertexArray() {
505    if (!mTexCoordsArrayEnabled) {
506        glEnableVertexAttribArray(Program::kBindingTexCoords);
507        mCurrentTexCoordsPointer = this;
508        mTexCoordsArrayEnabled = true;
509    }
510}
511
512void Caches::disableTexCoordsVertexArray() {
513    if (mTexCoordsArrayEnabled) {
514        glDisableVertexAttribArray(Program::kBindingTexCoords);
515        mTexCoordsArrayEnabled = false;
516    }
517}
518
519void Caches::activeTexture(GLuint textureUnit) {
520    if (mTextureUnit != textureUnit) {
521        glActiveTexture(gTextureUnits[textureUnit]);
522        mTextureUnit = textureUnit;
523    }
524}
525
526void Caches::resetActiveTexture() {
527    mTextureUnit = -1;
528}
529
530void Caches::bindTexture(GLuint texture) {
531    if (mBoundTextures[mTextureUnit] != texture) {
532        glBindTexture(GL_TEXTURE_2D, texture);
533        mBoundTextures[mTextureUnit] = texture;
534    }
535}
536
537void Caches::bindTexture(GLenum target, GLuint texture) {
538    if (mBoundTextures[mTextureUnit] != texture) {
539        glBindTexture(target, texture);
540        mBoundTextures[mTextureUnit] = texture;
541    }
542}
543
544void 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
566void Caches::resetBoundTextures() {
567    memset(mBoundTextures, 0, REQUIRED_TEXTURE_UNITS_COUNT * sizeof(GLuint));
568}
569
570///////////////////////////////////////////////////////////////////////////////
571// Scissor
572///////////////////////////////////////////////////////////////////////////////
573
574bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) {
575    if (scissorEnabled && (x != mScissorX || y != mScissorY ||
576            width != mScissorWidth || height != mScissorHeight)) {
577
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        }
592        glScissor(x, y, width, height);
593
594        mScissorX = x;
595        mScissorY = y;
596        mScissorWidth = width;
597        mScissorHeight = height;
598
599        return true;
600    }
601    return false;
602}
603
604bool Caches::enableScissor() {
605    if (!scissorEnabled) {
606        glEnable(GL_SCISSOR_TEST);
607        scissorEnabled = true;
608        resetScissor();
609        return true;
610    }
611    return false;
612}
613
614bool Caches::disableScissor() {
615    if (scissorEnabled) {
616        glDisable(GL_SCISSOR_TEST);
617        scissorEnabled = false;
618        return true;
619    }
620    return false;
621}
622
623void 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
631void Caches::resetScissor() {
632    mScissorX = mScissorY = mScissorWidth = mScissorHeight = 0;
633}
634
635///////////////////////////////////////////////////////////////////////////////
636// Tiling
637///////////////////////////////////////////////////////////////////////////////
638
639void Caches::startTiling(GLuint x, GLuint y, GLuint width, GLuint height, bool discard) {
640    if (mExtensions.hasTiledRendering() && !debugOverdraw) {
641        glStartTilingQCOM(x, y, width, height, (discard ? GL_NONE : GL_COLOR_BUFFER_BIT0_QCOM));
642    }
643}
644
645void Caches::endTiling() {
646    if (mExtensions.hasTiledRendering() && !debugOverdraw) {
647        glEndTilingQCOM(GL_COLOR_BUFFER_BIT0_QCOM);
648    }
649}
650
651bool Caches::hasRegisteredFunctors() {
652    return mFunctorsCount > 0;
653}
654
655void Caches::registerFunctors(uint32_t functorCount) {
656    mFunctorsCount += functorCount;
657}
658
659void Caches::unregisterFunctors(uint32_t functorCount) {
660    if (functorCount > mFunctorsCount) {
661        mFunctorsCount = 0;
662    } else {
663        mFunctorsCount -= functorCount;
664    }
665}
666
667///////////////////////////////////////////////////////////////////////////////
668// Regions
669///////////////////////////////////////////////////////////////////////////////
670
671TextureVertex* Caches::getRegionMesh() {
672    // Create the mesh, 2 triangles and 4 vertices per rectangle in the region
673    if (!mRegionMesh) {
674        mRegionMesh = new TextureVertex[gMaxNumberOfQuads * 4];
675    }
676
677    return mRegionMesh;
678}
679
680///////////////////////////////////////////////////////////////////////////////
681// Temporary Properties
682///////////////////////////////////////////////////////////////////////////////
683
684void Caches::initTempProperties() {
685    propertyDirtyViewport = false;
686    propertyEnable3d = false;
687    propertyCameraDistance = 1.0f;
688    propertyAmbientShadowStrength = 0x3f;
689    propertySpotShadowStrength = 0x3f;
690
691    propertyLightPosXScale = 0.5f;
692    propertyLightPosYScale = 0.0f;
693    propertyLightPosZScale = 1.0f;
694}
695
696void Caches::setTempProperty(const char* name, const char* value) {
697    ALOGD("setting property %s to %s", name, value);
698    if (!strcmp(name, "enable3d")) {
699        propertyEnable3d = !strcmp(value, "true");
700        propertyDirtyViewport = true;
701        ALOGD("enable3d = %d", propertyEnable3d);
702        return;
703    } else if (!strcmp(name, "cameraDistance")) {
704        propertyCameraDistance = fmin(fmax(atof(value), 0.001), 10);
705        propertyDirtyViewport = true;
706        ALOGD("camera dist multiplier = %.2f", propertyCameraDistance);
707        return;
708    } else if (!strcmp(name, "ambientShadowStrength")) {
709        propertyAmbientShadowStrength = atoi(value);
710        ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength);
711        return;
712    } else if (!strcmp(name, "spotShadowStrength")) {
713        propertySpotShadowStrength = atoi(value);
714        ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength);
715        return;
716    } else if (!strcmp(name, "lightPosXScale")) {
717        propertyLightPosXScale = fmin(fmax(atof(value), 0.0), 1.0);
718        propertyDirtyViewport = true;
719        ALOGD("lightPos X Scale = %.2f", propertyLightPosXScale);
720        return;
721    }  else if (!strcmp(name, "lightPosYScale")) {
722        propertyLightPosYScale = fmin(fmax(atof(value), 0.0), 1.0);
723        propertyDirtyViewport = true;
724        ALOGD("lightPos Y Scale = %.2f", propertyLightPosXScale);
725        return;
726    }  else if (!strcmp(name, "lightPosZScale")) {
727        propertyLightPosZScale = fmin(fmax(atof(value), 0.0), 1.0);
728        propertyDirtyViewport = true;
729        ALOGD("lightPos Z Scale = %.2f", propertyLightPosXScale);
730        return;
731    }
732    ALOGD("    failed");
733}
734
735}; // namespace uirenderer
736}; // namespace android
737