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