blob: 475fd700ccc9dd5dd22bfc394494b865eaecc75f [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
Chris Craik2507c342015-05-04 14:36:49 -070093bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -070094 bool prevDebugLayersUpdates = debugLayersUpdates;
95 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -070096
Chris Craik2507c342015-05-04 14:36:49 -070097 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010098 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
99 if (debugOverdrawProperty != "") {
100 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
101 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -0700102 debugOverdraw = true;
103 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100104 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -0700105 debugOverdraw = true;
106 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
107 }
108 }
109
Chris Craik2507c342015-05-04 14:36:49 -0700110 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100111 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
112 if (profileProperty != "") {
113 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700114 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100115 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700116 sProfileType = ProfileType::Console;
117 }
118 }
119
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100120 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700121 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
122
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100123 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700124
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100125 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700126
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100127 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
128 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
129 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700130
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100131 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700132
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100133 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400134
Stan Iliev02daab62018-06-29 15:16:11 -0400135 SkAndroidFrameworkTraceUtil::setEnableTracing(
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100136 base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
Stan Iliev02daab62018-06-29 15:16:11 -0400137
Roman Kiryanovd6a9f4252021-03-10 16:57:41 -0800138 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800139
Bo Liu027b2182021-03-18 16:50:38 -0400140 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, true);
141 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
142 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
143
Huihong Luo35b1dde2021-08-13 10:28:10 -0700144 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, true);
Huihong Luoeb931072021-06-30 10:12:17 -0700145
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500146 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700147}
148
149void Properties::overrideProperty(const char* name, const char* value) {
150 if (!strcmp(name, "disableProfileBars")) {
151 sDisableProfileBars = !strcmp(value, "true");
152 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
153 return;
154 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700155 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700156 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
157 return;
158 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700159 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700160 ALOGD("lightRadius = %.2f", overrideLightRadius);
161 return;
162 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700163 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700164 ALOGD("lightPos Y = %.2f", overrideLightPosY);
165 return;
166 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700167 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700168 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
169 return;
170 } else if (!strcmp(name, "ambientShadowStrength")) {
171 overrideAmbientShadowStrength = atoi(value);
172 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
173 return;
174 } else if (!strcmp(name, "spotShadowStrength")) {
175 overrideSpotShadowStrength = atoi(value);
176 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
177 return;
178 }
179 ALOGD("failed overriding property %s to %s", name, value);
180}
181
182ProfileType Properties::getProfileType() {
183 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
184 return ProfileType::None;
185 return sProfileType;
186}
187
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700188RenderPipelineType Properties::peekRenderPipelineType() {
189 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800190 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400191 return sRenderPipelineType;
192 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500193 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100194 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
195 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700196 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400197 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700198 return RenderPipelineType::SkiaGL;
199}
200
201RenderPipelineType Properties::getRenderPipelineType() {
202 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400203 return sRenderPipelineType;
204}
205
Alec Mouriaa3e4982020-12-14 14:47:57 -0800206void Properties::overrideRenderPipelineType(RenderPipelineType type, bool inUnitTest) {
John Reck113ddd92017-11-09 16:21:21 -0800207 // 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 -0800208 // Unit tests can freely change this as often as it wants.
209 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != RenderPipelineType::NotInitialized &&
210 sRenderPipelineType != type && !inUnitTest,
211 "Trying to change pipeline but it's already set.");
Greg Daniel98c78dad2017-01-04 14:45:56 -0500212 sRenderPipelineType = type;
213}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500214
Chris Blume7b8a8082018-11-30 15:51:58 -0800215} // namespace uirenderer
216} // namespace android