blob: bcfe9c3ecab4bb85f6fa8cdd29b63f9fbc92992d [file] [log] [blame]
Chris Craik2507c342015-05-04 14:36:49 -07001/*
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 */
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070016
Chris Craik2507c342015-05-04 14:36:49 -070017#include "Properties.h"
Alec Mouriaa3e4982020-12-14 14:47:57 -080018
Chris Craik2507c342015-05-04 14:36:49 -070019#include "Debug.h"
Alec Mouriaa3e4982020-12-14 14:47:57 -080020#include "log/log_main.h"
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010021#ifdef __ANDROID__
Stan Ilievb8811aa52018-11-08 16:25:54 -050022#include "HWUIProperties.sysprop.h"
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010023#endif
John Reck0fa0cbc2019-04-05 16:57:46 -070024#include "SkTraceEventCommon.h"
Chris Craik2507c342015-05-04 14:36:49 -070025
John Reck6b507802015-11-03 10:09:59 -080026#include <algorithm>
27#include <cstdlib>
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010028#include <optional>
Chris Craik2507c342015-05-04 14:36:49 -070029
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010030#include <android-base/properties.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070031#include <cutils/compiler.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070032#include <log/log.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070033
Chris Craik2507c342015-05-04 14:36:49 -070034namespace android {
35namespace uirenderer {
36
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010037#ifndef __ANDROID__ // Layoutlib does not compile HWUIProperties.sysprop as it depends on cutils properties
38std::optional<bool> use_vulkan() {
39 return base::GetBoolProperty("ro.hwui.use_vulkan", false);
40}
41
42std::optional<std::int32_t> render_ahead() {
43 return base::GetIntProperty("ro.hwui.render_ahead", 0);
44}
45#endif
46
Chris Craik2507c342015-05-04 14:36:49 -070047bool Properties::debugLayersUpdates = false;
48bool Properties::debugOverdraw = false;
49bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070050bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070051bool Properties::useBufferAge = true;
52bool Properties::enablePartialUpdates = true;
Nader Jawad086645d2021-09-24 13:42:47 -070053// Default true unless otherwise specified in RenderThread Configuration
54bool Properties::enableRenderEffectCache = true;
Chris Craik2507c342015-05-04 14:36:49 -070055
56DebugLevel Properties::debugLevel = kDebugDisabled;
57OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070058
59float Properties::overrideLightRadius = -1.0f;
60float Properties::overrideLightPosY = -1.0f;
61float Properties::overrideLightPosZ = -1.0f;
62float Properties::overrideAmbientRatio = -1.0f;
63int Properties::overrideAmbientShadowStrength = -1;
64int Properties::overrideSpotShadowStrength = -1;
65
66ProfileType Properties::sProfileType = ProfileType::None;
67bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040068RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070069bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070070
John Reck682573c2015-10-30 10:37:35 -070071bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070072bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070073
John Reckc7cd9cf2016-03-28 10:38:19 -070074bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070075bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040076bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070077bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070078
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080079bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080080bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070081bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080082
Jorim Jaggi767e25e2018-04-04 23:07:35 +020083int Properties::contextPriority = 0;
John Reckf42ff762020-08-06 13:53:22 -070084float Properties::defaultSdrWhitePoint = 200.f;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020085
Bo Liu027b2182021-03-18 16:50:38 -040086bool Properties::useHintManager = true;
87int Properties::targetCpuTimePercentage = 70;
88
Huihong Luo35b1dde2021-08-13 10:28:10 -070089bool Properties::enableWebViewOverlays = true;
Huihong Luoeb931072021-06-30 10:12:17 -070090
Nader Jawad9272f212021-05-10 13:27:52 -070091StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
John Reck8ed00dc2021-05-10 13:09:27 -040092
Brett Chabot074ba592021-07-16 14:38:11 -070093DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
Brett Chabot856db9e2021-05-21 08:41:58 -070094
Chris Craik2507c342015-05-04 14:36:49 -070095bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -070096 bool prevDebugLayersUpdates = debugLayersUpdates;
97 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -070098
Chris Craik2507c342015-05-04 14:36:49 -070099 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100100 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
101 if (debugOverdrawProperty != "") {
102 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
103 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -0700104 debugOverdraw = true;
105 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100106 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -0700107 debugOverdraw = true;
108 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
109 }
110 }
111
Chris Craik2507c342015-05-04 14:36:49 -0700112 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100113 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
114 if (profileProperty != "") {
115 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700116 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100117 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700118 sProfileType = ProfileType::Console;
119 }
120 }
121
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100122 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700123 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
124
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100125 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700126
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100127 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700128
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100129 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
130 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
131 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700132
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100133 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700134
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100135 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400136
Stan Iliev02daab62018-06-29 15:16:11 -0400137 SkAndroidFrameworkTraceUtil::setEnableTracing(
Leon Scroggins3c815c92022-05-05 21:13:02 +0000138 base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
Stan Iliev02daab62018-06-29 15:16:11 -0400139
Roman Kiryanovd6a9f4252021-03-10 16:57:41 -0800140 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800141
Bo Liu027b2182021-03-18 16:50:38 -0400142 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, true);
143 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
144 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
145
Huihong Luo35b1dde2021-08-13 10:28:10 -0700146 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, true);
Huihong Luoeb931072021-06-30 10:12:17 -0700147
Brett Chabot074ba592021-07-16 14:38:11 -0700148 // call isDrawingEnabled to force loading of the property
149 isDrawingEnabled();
Brett Chabot856db9e2021-05-21 08:41:58 -0700150
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500151 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700152}
153
154void Properties::overrideProperty(const char* name, const char* value) {
155 if (!strcmp(name, "disableProfileBars")) {
156 sDisableProfileBars = !strcmp(value, "true");
157 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
158 return;
159 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700160 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700161 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
162 return;
163 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700164 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700165 ALOGD("lightRadius = %.2f", overrideLightRadius);
166 return;
167 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700168 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700169 ALOGD("lightPos Y = %.2f", overrideLightPosY);
170 return;
171 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700172 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700173 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
174 return;
175 } else if (!strcmp(name, "ambientShadowStrength")) {
176 overrideAmbientShadowStrength = atoi(value);
177 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
178 return;
179 } else if (!strcmp(name, "spotShadowStrength")) {
180 overrideSpotShadowStrength = atoi(value);
181 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
182 return;
183 }
184 ALOGD("failed overriding property %s to %s", name, value);
185}
186
187ProfileType Properties::getProfileType() {
188 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
189 return ProfileType::None;
190 return sProfileType;
191}
192
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700193RenderPipelineType Properties::peekRenderPipelineType() {
194 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800195 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400196 return sRenderPipelineType;
197 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500198 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100199 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
200 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700201 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400202 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700203 return RenderPipelineType::SkiaGL;
204}
205
206RenderPipelineType Properties::getRenderPipelineType() {
207 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400208 return sRenderPipelineType;
209}
210
Alec Mouriaa3e4982020-12-14 14:47:57 -0800211void Properties::overrideRenderPipelineType(RenderPipelineType type, bool inUnitTest) {
John Reck113ddd92017-11-09 16:21:21 -0800212 // If we're doing actual rendering then we can't change the renderer after it's been set.
Alec Mouriaa3e4982020-12-14 14:47:57 -0800213 // Unit tests can freely change this as often as it wants.
214 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != RenderPipelineType::NotInitialized &&
215 sRenderPipelineType != type && !inUnitTest,
216 "Trying to change pipeline but it's already set.");
Greg Daniel98c78dad2017-01-04 14:45:56 -0500217 sRenderPipelineType = type;
218}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500219
Brett Chabot856db9e2021-05-21 08:41:58 -0700220void Properties::setDrawingEnabled(bool newDrawingEnabled) {
Brett Chabot074ba592021-07-16 14:38:11 -0700221 drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
Brett Chabot856db9e2021-05-21 08:41:58 -0700222 enableRTAnimations = newDrawingEnabled;
223}
224
225bool Properties::isDrawingEnabled() {
Brett Chabot074ba592021-07-16 14:38:11 -0700226 if (drawingEnabled == DrawingEnabled::NotInitialized) {
227 bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
228 drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
229 enableRTAnimations = drawingEnabledProp;
Brett Chabot856db9e2021-05-21 08:41:58 -0700230 }
Brett Chabot074ba592021-07-16 14:38:11 -0700231 return drawingEnabled == DrawingEnabled::On;
Brett Chabot856db9e2021-05-21 08:41:58 -0700232}
233
Chris Blume7b8a8082018-11-30 15:51:58 -0800234} // namespace uirenderer
235} // namespace android