Properties.cpp revision 6b50780363d3bb8db600c770183fa07677509ae8
1/*
2 * Copyright (C) 2015 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#include "Properties.h"
17
18#include "Debug.h"
19
20#include <cutils/compiler.h>
21#include <cutils/log.h>
22#include <cutils/properties.h>
23
24#include <algorithm>
25#include <cstdlib>
26
27namespace android {
28namespace uirenderer {
29
30bool Properties::drawDeferDisabled = false;
31bool Properties::drawReorderDisabled = false;
32bool Properties::debugLayersUpdates = false;
33bool Properties::debugOverdraw = false;
34bool Properties::showDirtyRegions = false;
35bool Properties::skipEmptyFrames = true;
36bool Properties::useBufferAge = true;
37bool Properties::enablePartialUpdates = true;
38
39float Properties::textGamma = DEFAULT_TEXT_GAMMA;
40
41DebugLevel Properties::debugLevel = kDebugDisabled;
42OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
43StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
44
45float Properties::overrideLightRadius = -1.0f;
46float Properties::overrideLightPosY = -1.0f;
47float Properties::overrideLightPosZ = -1.0f;
48float Properties::overrideAmbientRatio = -1.0f;
49int Properties::overrideAmbientShadowStrength = -1;
50int Properties::overrideSpotShadowStrength = -1;
51
52ProfileType Properties::sProfileType = ProfileType::None;
53bool Properties::sDisableProfileBars = false;
54
55static float property_get_float(const char* key, float defaultValue) {
56    char buf[PROPERTY_VALUE_MAX] = {'\0',};
57
58    if (property_get(PROPERTY_PROFILE, buf, "") > 0) {
59        return atof(buf);
60    }
61    return defaultValue;
62}
63
64bool Properties::load() {
65    char property[PROPERTY_VALUE_MAX];
66    bool prevDebugLayersUpdates = debugLayersUpdates;
67    bool prevDebugOverdraw = debugOverdraw;
68    StencilClipDebug prevDebugStencilClip = debugStencilClip;
69
70
71    debugOverdraw = false;
72    if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
73        INIT_LOGD("  Overdraw debug enabled: %s", property);
74        if (!strcmp(property, "show")) {
75            debugOverdraw = true;
76            overdrawColorSet = OverdrawColorSet::Default;
77        } else if (!strcmp(property, "show_deuteranomaly")) {
78            debugOverdraw = true;
79            overdrawColorSet = OverdrawColorSet::Deuteranomaly;
80        }
81    }
82
83    // See Properties.h for valid values
84    if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
85        INIT_LOGD("  Stencil clip debug enabled: %s", property);
86        if (!strcmp(property, "hide")) {
87            debugStencilClip = StencilClipDebug::Hide;
88        } else if (!strcmp(property, "highlight")) {
89            debugStencilClip = StencilClipDebug::ShowHighlight;
90        } else if (!strcmp(property, "region")) {
91            debugStencilClip = StencilClipDebug::ShowRegion;
92        }
93    } else {
94        debugStencilClip = StencilClipDebug::Hide;
95    }
96
97    sProfileType = ProfileType::None;
98    if (property_get(PROPERTY_PROFILE, property, "") > 0) {
99        if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
100            sProfileType = ProfileType::Bars;
101        } else if (!strcmp(property, "true")) {
102            sProfileType = ProfileType::Console;
103        }
104    }
105
106    debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
107    INIT_LOGD("  Layers updates debug enabled: %d", debugLayersUpdates);
108
109    drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
110    INIT_LOGD("  Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
111
112    drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
113    INIT_LOGD("  Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
114
115    showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
116
117    debugLevel = kDebugDisabled;
118    if (property_get(PROPERTY_DEBUG, property, nullptr) > 0) {
119        debugLevel = (DebugLevel) atoi(property);
120    }
121
122    skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
123    useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
124    enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
125
126    textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
127
128    return (prevDebugLayersUpdates != debugLayersUpdates)
129            || (prevDebugOverdraw != debugOverdraw)
130            || (prevDebugStencilClip != debugStencilClip);
131}
132
133void Properties::overrideProperty(const char* name, const char* value) {
134    if (!strcmp(name, "disableProfileBars")) {
135        sDisableProfileBars = !strcmp(value, "true");
136        ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
137        return;
138    } else if (!strcmp(name, "ambientRatio")) {
139        overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
140        ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
141        return;
142    } else if (!strcmp(name, "lightRadius")) {
143        overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
144        ALOGD("lightRadius = %.2f", overrideLightRadius);
145        return;
146    } else if (!strcmp(name, "lightPosY")) {
147        overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
148        ALOGD("lightPos Y = %.2f", overrideLightPosY);
149        return;
150    } else if (!strcmp(name, "lightPosZ")) {
151        overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
152        ALOGD("lightPos Z = %.2f", overrideLightPosZ);
153        return;
154    } else if (!strcmp(name, "ambientShadowStrength")) {
155        overrideAmbientShadowStrength = atoi(value);
156        ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
157        return;
158    } else if (!strcmp(name, "spotShadowStrength")) {
159        overrideSpotShadowStrength = atoi(value);
160        ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
161        return;
162    }
163    ALOGD("failed overriding property %s to %s", name, value);
164}
165
166ProfileType Properties::getProfileType() {
167    if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
168        return ProfileType::None;
169    return sProfileType;
170}
171
172}; // namespace uirenderer
173}; // namespace android
174