blob: c804418e838070fa9d0ce08ecb65ac2e1f7369b1 [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;
Chris Craik2507c342015-05-04 14:36:49 -070053
54DebugLevel Properties::debugLevel = kDebugDisabled;
55OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070056
57float Properties::overrideLightRadius = -1.0f;
58float Properties::overrideLightPosY = -1.0f;
59float Properties::overrideLightPosZ = -1.0f;
60float Properties::overrideAmbientRatio = -1.0f;
61int Properties::overrideAmbientShadowStrength = -1;
62int Properties::overrideSpotShadowStrength = -1;
63
64ProfileType Properties::sProfileType = ProfileType::None;
65bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040066RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070067bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070068
John Reck682573c2015-10-30 10:37:35 -070069bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070070bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070071
John Reckc7cd9cf2016-03-28 10:38:19 -070072bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070073bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040074bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070075bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070076
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080077bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080078bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070079bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080080
Jorim Jaggi767e25e2018-04-04 23:07:35 +020081int Properties::contextPriority = 0;
John Reckf42ff762020-08-06 13:53:22 -070082float Properties::defaultSdrWhitePoint = 200.f;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020083
Bo Liu027b2182021-03-18 16:50:38 -040084bool Properties::useHintManager = true;
85int Properties::targetCpuTimePercentage = 70;
86
Huihong Luoeb931072021-06-30 10:12:17 -070087bool Properties::enableWebViewOverlays = false;
88
Nader Jawad9272f212021-05-10 13:27:52 -070089StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
John Reck8ed00dc2021-05-10 13:09:27 -040090
Brett Chabot074ba592021-07-16 14:38:11 -070091DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
Brett Chabot856db9e2021-05-21 08:41:58 -070092
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 Luoeb931072021-06-30 10:12:17 -0700144 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, false);
145
Brett Chabot074ba592021-07-16 14:38:11 -0700146 // call isDrawingEnabled to force loading of the property
147 isDrawingEnabled();
Brett Chabot856db9e2021-05-21 08:41:58 -0700148
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500149 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700150}
151
152void Properties::overrideProperty(const char* name, const char* value) {
153 if (!strcmp(name, "disableProfileBars")) {
154 sDisableProfileBars = !strcmp(value, "true");
155 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
156 return;
157 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700158 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700159 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
160 return;
161 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700162 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700163 ALOGD("lightRadius = %.2f", overrideLightRadius);
164 return;
165 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700166 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700167 ALOGD("lightPos Y = %.2f", overrideLightPosY);
168 return;
169 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700170 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700171 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
172 return;
173 } else if (!strcmp(name, "ambientShadowStrength")) {
174 overrideAmbientShadowStrength = atoi(value);
175 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
176 return;
177 } else if (!strcmp(name, "spotShadowStrength")) {
178 overrideSpotShadowStrength = atoi(value);
179 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
180 return;
181 }
182 ALOGD("failed overriding property %s to %s", name, value);
183}
184
185ProfileType Properties::getProfileType() {
186 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
187 return ProfileType::None;
188 return sProfileType;
189}
190
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700191RenderPipelineType Properties::peekRenderPipelineType() {
192 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800193 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400194 return sRenderPipelineType;
195 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500196 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100197 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
198 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700199 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400200 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700201 return RenderPipelineType::SkiaGL;
202}
203
204RenderPipelineType Properties::getRenderPipelineType() {
205 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400206 return sRenderPipelineType;
207}
208
Alec Mouriaa3e4982020-12-14 14:47:57 -0800209void Properties::overrideRenderPipelineType(RenderPipelineType type, bool inUnitTest) {
John Reck113ddd92017-11-09 16:21:21 -0800210 // 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 -0800211 // Unit tests can freely change this as often as it wants.
212 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != RenderPipelineType::NotInitialized &&
213 sRenderPipelineType != type && !inUnitTest,
214 "Trying to change pipeline but it's already set.");
Greg Daniel98c78dad2017-01-04 14:45:56 -0500215 sRenderPipelineType = type;
216}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500217
Brett Chabot856db9e2021-05-21 08:41:58 -0700218void Properties::setDrawingEnabled(bool newDrawingEnabled) {
Brett Chabot074ba592021-07-16 14:38:11 -0700219 drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
Brett Chabot856db9e2021-05-21 08:41:58 -0700220 enableRTAnimations = newDrawingEnabled;
221}
222
223bool Properties::isDrawingEnabled() {
Brett Chabot074ba592021-07-16 14:38:11 -0700224 if (drawingEnabled == DrawingEnabled::NotInitialized) {
225 bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
226 drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
227 enableRTAnimations = drawingEnabledProp;
Brett Chabot856db9e2021-05-21 08:41:58 -0700228 }
Brett Chabot074ba592021-07-16 14:38:11 -0700229 return drawingEnabled == DrawingEnabled::On;
Brett Chabot856db9e2021-05-21 08:41:58 -0700230}
231
Chris Blume7b8a8082018-11-30 15:51:58 -0800232} // namespace uirenderer
233} // namespace android