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