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
19 #include "Debug.h"
20 #include "log/log_main.h"
21 #ifdef __ANDROID__
22 #include "HWUIProperties.sysprop.h"
23 #endif
24 #include "SkTraceEventCommon.h"
25
26 #include <algorithm>
27 #include <cstdlib>
28 #include <optional>
29
30 #include <android-base/properties.h>
31 #include <cutils/compiler.h>
32 #include <log/log.h>
33
34 namespace android {
35 namespace uirenderer {
36
37 #ifndef __ANDROID__ // Layoutlib does not compile HWUIProperties.sysprop as it depends on cutils properties
use_vulkan()38 std::optional<bool> use_vulkan() {
39 return base::GetBoolProperty("ro.hwui.use_vulkan", false);
40 }
41
render_ahead()42 std::optional<std::int32_t> render_ahead() {
43 return base::GetIntProperty("ro.hwui.render_ahead", 0);
44 }
45 #endif
46
47 bool Properties::debugLayersUpdates = false;
48 bool Properties::debugOverdraw = false;
49 bool Properties::showDirtyRegions = false;
50 bool Properties::skipEmptyFrames = true;
51 bool Properties::useBufferAge = true;
52 bool Properties::enablePartialUpdates = true;
53 // Default true unless otherwise specified in RenderThread Configuration
54 bool Properties::enableRenderEffectCache = true;
55
56 DebugLevel Properties::debugLevel = kDebugDisabled;
57 OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
58
59 float Properties::overrideLightRadius = -1.0f;
60 float Properties::overrideLightPosY = -1.0f;
61 float Properties::overrideLightPosZ = -1.0f;
62 float Properties::overrideAmbientRatio = -1.0f;
63 int Properties::overrideAmbientShadowStrength = -1;
64 int Properties::overrideSpotShadowStrength = -1;
65
66 ProfileType Properties::sProfileType = ProfileType::None;
67 bool Properties::sDisableProfileBars = false;
68 RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
69 bool Properties::enableHighContrastText = false;
70
71 bool Properties::waitForGpuCompletion = false;
72
73 bool Properties::filterOutTestOverhead = false;
74 bool Properties::disableVsync = false;
75 bool Properties::skpCaptureEnabled = false;
76 bool Properties::enableRTAnimations = true;
77
78 bool Properties::runningInEmulator = false;
79 bool Properties::debuggingEnabled = false;
80 bool Properties::isolatedProcess = false;
81
82 int Properties::contextPriority = 0;
83 float Properties::defaultSdrWhitePoint = 200.f;
84
85 bool Properties::useHintManager = true;
86 int Properties::targetCpuTimePercentage = 70;
87
88 bool Properties::enableWebViewOverlays = true;
89
90 StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
91
92 DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
93
load()94 bool Properties::load() {
95 bool prevDebugLayersUpdates = debugLayersUpdates;
96 bool prevDebugOverdraw = debugOverdraw;
97
98 debugOverdraw = false;
99 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
100 if (debugOverdrawProperty != "") {
101 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
102 if (debugOverdrawProperty == "show") {
103 debugOverdraw = true;
104 overdrawColorSet = OverdrawColorSet::Default;
105 } else if (debugOverdrawProperty == "show_deuteranomaly") {
106 debugOverdraw = true;
107 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
108 }
109 }
110
111 sProfileType = ProfileType::None;
112 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
113 if (profileProperty != "") {
114 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
115 sProfileType = ProfileType::Bars;
116 } else if (profileProperty == "true") {
117 sProfileType = ProfileType::Console;
118 }
119 }
120
121 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
122 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
123
124 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
125
126 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
127
128 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
129 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
130 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
131
132 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
133
134 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
135
136 SkAndroidFrameworkTraceUtil::setEnableTracing(
137 base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
138
139 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
140
141 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, true);
142 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
143 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
144
145 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, true);
146
147 // call isDrawingEnabled to force loading of the property
148 isDrawingEnabled();
149
150 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
151 }
152
overrideProperty(const char * name,const char * value)153 void Properties::overrideProperty(const char* name, const char* value) {
154 if (!strcmp(name, "disableProfileBars")) {
155 sDisableProfileBars = !strcmp(value, "true");
156 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
157 return;
158 } else if (!strcmp(name, "ambientRatio")) {
159 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
160 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
161 return;
162 } else if (!strcmp(name, "lightRadius")) {
163 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
164 ALOGD("lightRadius = %.2f", overrideLightRadius);
165 return;
166 } else if (!strcmp(name, "lightPosY")) {
167 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
168 ALOGD("lightPos Y = %.2f", overrideLightPosY);
169 return;
170 } else if (!strcmp(name, "lightPosZ")) {
171 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
172 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
173 return;
174 } else if (!strcmp(name, "ambientShadowStrength")) {
175 overrideAmbientShadowStrength = atoi(value);
176 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
177 return;
178 } else if (!strcmp(name, "spotShadowStrength")) {
179 overrideSpotShadowStrength = atoi(value);
180 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
181 return;
182 }
183 ALOGD("failed overriding property %s to %s", name, value);
184 }
185
getProfileType()186 ProfileType Properties::getProfileType() {
187 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
188 return ProfileType::None;
189 return sProfileType;
190 }
191
peekRenderPipelineType()192 RenderPipelineType Properties::peekRenderPipelineType() {
193 // If sRenderPipelineType has been locked, just return the locked type immediately.
194 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
195 return sRenderPipelineType;
196 }
197 bool useVulkan = use_vulkan().value_or(false);
198 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
199 if (rendererProperty == "skiavk") {
200 return RenderPipelineType::SkiaVulkan;
201 }
202 return RenderPipelineType::SkiaGL;
203 }
204
getRenderPipelineType()205 RenderPipelineType Properties::getRenderPipelineType() {
206 sRenderPipelineType = peekRenderPipelineType();
207 return sRenderPipelineType;
208 }
209
overrideRenderPipelineType(RenderPipelineType type,bool inUnitTest)210 void Properties::overrideRenderPipelineType(RenderPipelineType type, bool inUnitTest) {
211 // If we're doing actual rendering then we can't change the renderer after it's been set.
212 // Unit tests can freely change this as often as it wants.
213 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != RenderPipelineType::NotInitialized &&
214 sRenderPipelineType != type && !inUnitTest,
215 "Trying to change pipeline but it's already set.");
216 sRenderPipelineType = type;
217 }
218
setDrawingEnabled(bool newDrawingEnabled)219 void Properties::setDrawingEnabled(bool newDrawingEnabled) {
220 drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
221 enableRTAnimations = newDrawingEnabled;
222 }
223
isDrawingEnabled()224 bool Properties::isDrawingEnabled() {
225 if (drawingEnabled == DrawingEnabled::NotInitialized) {
226 bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
227 drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
228 enableRTAnimations = drawingEnabledProp;
229 }
230 return drawingEnabled == DrawingEnabled::On;
231 }
232
233 } // namespace uirenderer
234 } // namespace android
235