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 bool Properties::enableRenderEffectCache = false;
54
55 DebugLevel Properties::debugLevel = kDebugDisabled;
56 OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
57
58 float Properties::overrideLightRadius = -1.0f;
59 float Properties::overrideLightPosY = -1.0f;
60 float Properties::overrideLightPosZ = -1.0f;
61 float Properties::overrideAmbientRatio = -1.0f;
62 int Properties::overrideAmbientShadowStrength = -1;
63 int Properties::overrideSpotShadowStrength = -1;
64
65 ProfileType Properties::sProfileType = ProfileType::None;
66 bool Properties::sDisableProfileBars = false;
67 RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
68 bool Properties::enableHighContrastText = false;
69
70 bool Properties::waitForGpuCompletion = false;
71 bool Properties::forceDrawFrame = 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 = false;
89
90 StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
91
load()92 bool Properties::load() {
93 bool prevDebugLayersUpdates = debugLayersUpdates;
94 bool prevDebugOverdraw = debugOverdraw;
95
96 debugOverdraw = false;
97 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
98 if (debugOverdrawProperty != "") {
99 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
100 if (debugOverdrawProperty == "show") {
101 debugOverdraw = true;
102 overdrawColorSet = OverdrawColorSet::Default;
103 } else if (debugOverdrawProperty == "show_deuteranomaly") {
104 debugOverdraw = true;
105 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
106 }
107 }
108
109 sProfileType = ProfileType::None;
110 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
111 if (profileProperty != "") {
112 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
113 sProfileType = ProfileType::Bars;
114 } else if (profileProperty == "true") {
115 sProfileType = ProfileType::Console;
116 }
117 }
118
119 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
120 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
121
122 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
123
124 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
125
126 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
127 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
128 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
129
130 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
131
132 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
133
134 SkAndroidFrameworkTraceUtil::setEnableTracing(
135 base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
136
137 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
138
139 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, true);
140 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
141 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
142
143 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, false);
144
145 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
146 }
147
overrideProperty(const char * name,const char * value)148 void Properties::overrideProperty(const char* name, const char* value) {
149 if (!strcmp(name, "disableProfileBars")) {
150 sDisableProfileBars = !strcmp(value, "true");
151 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
152 return;
153 } else if (!strcmp(name, "ambientRatio")) {
154 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
155 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
156 return;
157 } else if (!strcmp(name, "lightRadius")) {
158 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
159 ALOGD("lightRadius = %.2f", overrideLightRadius);
160 return;
161 } else if (!strcmp(name, "lightPosY")) {
162 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
163 ALOGD("lightPos Y = %.2f", overrideLightPosY);
164 return;
165 } else if (!strcmp(name, "lightPosZ")) {
166 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
167 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
168 return;
169 } else if (!strcmp(name, "ambientShadowStrength")) {
170 overrideAmbientShadowStrength = atoi(value);
171 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
172 return;
173 } else if (!strcmp(name, "spotShadowStrength")) {
174 overrideSpotShadowStrength = atoi(value);
175 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
176 return;
177 }
178 ALOGD("failed overriding property %s to %s", name, value);
179 }
180
getProfileType()181 ProfileType Properties::getProfileType() {
182 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
183 return ProfileType::None;
184 return sProfileType;
185 }
186
peekRenderPipelineType()187 RenderPipelineType Properties::peekRenderPipelineType() {
188 // If sRenderPipelineType has been locked, just return the locked type immediately.
189 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
190 return sRenderPipelineType;
191 }
192 bool useVulkan = use_vulkan().value_or(false);
193 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
194 if (rendererProperty == "skiavk") {
195 return RenderPipelineType::SkiaVulkan;
196 }
197 return RenderPipelineType::SkiaGL;
198 }
199
getRenderPipelineType()200 RenderPipelineType Properties::getRenderPipelineType() {
201 sRenderPipelineType = peekRenderPipelineType();
202 return sRenderPipelineType;
203 }
204
overrideRenderPipelineType(RenderPipelineType type,bool inUnitTest)205 void Properties::overrideRenderPipelineType(RenderPipelineType type, bool inUnitTest) {
206 // If we're doing actual rendering then we can't change the renderer after it's been set.
207 // Unit tests can freely change this as often as it wants.
208 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != RenderPipelineType::NotInitialized &&
209 sRenderPipelineType != type && !inUnitTest,
210 "Trying to change pipeline but it's already set.");
211 sRenderPipelineType = type;
212 }
213
214 } // namespace uirenderer
215 } // namespace android
216