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
17 #include "Properties.h"
18 #include "Debug.h"
19 #include "DeviceInfo.h"
20
21 #include <algorithm>
22 #include <cstdlib>
23
24 #include <cutils/compiler.h>
25 #include <cutils/properties.h>
26 #include <log/log.h>
27
28 namespace android {
29 namespace uirenderer {
30
31 bool Properties::drawDeferDisabled = false;
32 bool Properties::drawReorderDisabled = false;
33 bool Properties::debugLayersUpdates = false;
34 bool Properties::debugOverdraw = false;
35 bool Properties::showDirtyRegions = false;
36 bool Properties::skipEmptyFrames = true;
37 bool Properties::useBufferAge = true;
38 bool Properties::enablePartialUpdates = true;
39
40 DebugLevel Properties::debugLevel = kDebugDisabled;
41 OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
42 StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
43
44 float Properties::overrideLightRadius = -1.0f;
45 float Properties::overrideLightPosY = -1.0f;
46 float Properties::overrideLightPosZ = -1.0f;
47 float Properties::overrideAmbientRatio = -1.0f;
48 int Properties::overrideAmbientShadowStrength = -1;
49 int Properties::overrideSpotShadowStrength = -1;
50
51 ProfileType Properties::sProfileType = ProfileType::None;
52 bool Properties::sDisableProfileBars = false;
53 RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
54 bool Properties::enableHighContrastText = false;
55
56 bool Properties::waitForGpuCompletion = false;
57 bool Properties::forceDrawFrame = false;
58
59 bool Properties::filterOutTestOverhead = false;
60 bool Properties::disableVsync = false;
61 bool Properties::skpCaptureEnabled = false;
62 bool Properties::enableRTAnimations = true;
63
64 bool Properties::runningInEmulator = false;
65 bool Properties::debuggingEnabled = false;
66 bool Properties::isolatedProcess = false;
67
68 int Properties::contextPriority = 0;
69
property_get_int(const char * key,int defaultValue)70 static int property_get_int(const char* key, int defaultValue) {
71 char buf[PROPERTY_VALUE_MAX] = {
72 '\0',
73 };
74
75 if (property_get(key, buf, "") > 0) {
76 return atoi(buf);
77 }
78 return defaultValue;
79 }
80
load()81 bool Properties::load() {
82 char property[PROPERTY_VALUE_MAX];
83 bool prevDebugLayersUpdates = debugLayersUpdates;
84 bool prevDebugOverdraw = debugOverdraw;
85 StencilClipDebug prevDebugStencilClip = debugStencilClip;
86
87 debugOverdraw = false;
88 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
89 INIT_LOGD(" Overdraw debug enabled: %s", property);
90 if (!strcmp(property, "show")) {
91 debugOverdraw = true;
92 overdrawColorSet = OverdrawColorSet::Default;
93 } else if (!strcmp(property, "show_deuteranomaly")) {
94 debugOverdraw = true;
95 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
96 }
97 }
98
99 // See Properties.h for valid values
100 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
101 INIT_LOGD(" Stencil clip debug enabled: %s", property);
102 if (!strcmp(property, "hide")) {
103 debugStencilClip = StencilClipDebug::Hide;
104 } else if (!strcmp(property, "highlight")) {
105 debugStencilClip = StencilClipDebug::ShowHighlight;
106 } else if (!strcmp(property, "region")) {
107 debugStencilClip = StencilClipDebug::ShowRegion;
108 }
109 } else {
110 debugStencilClip = StencilClipDebug::Hide;
111 }
112
113 sProfileType = ProfileType::None;
114 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
115 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
116 sProfileType = ProfileType::Bars;
117 } else if (!strcmp(property, "true")) {
118 sProfileType = ProfileType::Console;
119 }
120 }
121
122 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
123 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
124
125 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
126 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
127
128 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
129 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
130
131 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
132
133 debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
134
135 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
136 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
137 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
138
139 filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
140
141 skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
142
143 runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
144
145 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw) ||
146 (prevDebugStencilClip != debugStencilClip);
147 }
148
overrideProperty(const char * name,const char * value)149 void Properties::overrideProperty(const char* name, const char* value) {
150 if (!strcmp(name, "disableProfileBars")) {
151 sDisableProfileBars = !strcmp(value, "true");
152 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
153 return;
154 } else if (!strcmp(name, "ambientRatio")) {
155 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
156 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
157 return;
158 } else if (!strcmp(name, "lightRadius")) {
159 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
160 ALOGD("lightRadius = %.2f", overrideLightRadius);
161 return;
162 } else if (!strcmp(name, "lightPosY")) {
163 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
164 ALOGD("lightPos Y = %.2f", overrideLightPosY);
165 return;
166 } else if (!strcmp(name, "lightPosZ")) {
167 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
168 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
169 return;
170 } else if (!strcmp(name, "ambientShadowStrength")) {
171 overrideAmbientShadowStrength = atoi(value);
172 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
173 return;
174 } else if (!strcmp(name, "spotShadowStrength")) {
175 overrideSpotShadowStrength = atoi(value);
176 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
177 return;
178 }
179 ALOGD("failed overriding property %s to %s", name, value);
180 }
181
getProfileType()182 ProfileType Properties::getProfileType() {
183 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
184 return ProfileType::None;
185 return sProfileType;
186 }
187
getRenderPipelineType()188 RenderPipelineType Properties::getRenderPipelineType() {
189 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
190 return sRenderPipelineType;
191 }
192 char prop[PROPERTY_VALUE_MAX];
193 property_get(PROPERTY_RENDERER, prop, "skiagl");
194 if (!strcmp(prop, "skiagl")) {
195 ALOGD("Skia GL Pipeline");
196 sRenderPipelineType = RenderPipelineType::SkiaGL;
197 } else if (!strcmp(prop, "skiavk")) {
198 ALOGD("Skia Vulkan Pipeline");
199 sRenderPipelineType = RenderPipelineType::SkiaVulkan;
200 } else { //"opengl"
201 ALOGD("HWUI GL Pipeline");
202 sRenderPipelineType = RenderPipelineType::OpenGL;
203 }
204 return sRenderPipelineType;
205 }
206
overrideRenderPipelineType(RenderPipelineType type)207 void Properties::overrideRenderPipelineType(RenderPipelineType type) {
208 #if !defined(HWUI_GLES_WRAP_ENABLED)
209 // If we're doing actual rendering then we can't change the renderer after it's been set.
210 // Unit tests can freely change this as often as it wants, though, as there's no actual
211 // GL rendering happening
212 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
213 return;
214 }
215 #endif
216 sRenderPipelineType = type;
217 }
218
isSkiaEnabled()219 bool Properties::isSkiaEnabled() {
220 auto renderType = getRenderPipelineType();
221 return RenderPipelineType::SkiaGL == renderType || RenderPipelineType::SkiaVulkan == renderType;
222 }
223
224 }; // namespace uirenderer
225 }; // namespace android
226