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