blob: 4e7df88b8095985dd14d19e74283f5f43fc8f868 [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"
Chris Craik2507c342015-05-04 14:36:49 -070018#include "Debug.h"
John Reck8dc02f92017-07-17 09:55:02 -070019#include "DeviceInfo.h"
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010020#ifdef __ANDROID__
Stan Ilievb8811aa52018-11-08 16:25:54 -050021#include "HWUIProperties.sysprop.h"
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010022#endif
John Reck0fa0cbc2019-04-05 16:57:46 -070023#include "SkTraceEventCommon.h"
Chris Craik2507c342015-05-04 14:36:49 -070024
John Reck6b507802015-11-03 10:09:59 -080025#include <algorithm>
26#include <cstdlib>
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010027#include <optional>
Chris Craik2507c342015-05-04 14:36:49 -070028
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010029#include <android-base/properties.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070030#include <cutils/compiler.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070031#include <log/log.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070032
Chris Craik2507c342015-05-04 14:36:49 -070033namespace android {
34namespace uirenderer {
35
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010036#ifndef __ANDROID__ // Layoutlib does not compile HWUIProperties.sysprop as it depends on cutils properties
37std::optional<bool> use_vulkan() {
38 return base::GetBoolProperty("ro.hwui.use_vulkan", false);
39}
40
41std::optional<std::int32_t> render_ahead() {
42 return base::GetIntProperty("ro.hwui.render_ahead", 0);
43}
44#endif
45
Chris Craik2507c342015-05-04 14:36:49 -070046bool Properties::debugLayersUpdates = false;
47bool Properties::debugOverdraw = false;
48bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070049bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070050bool Properties::useBufferAge = true;
51bool Properties::enablePartialUpdates = true;
Chris Craik2507c342015-05-04 14:36:49 -070052
53DebugLevel Properties::debugLevel = kDebugDisabled;
54OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070055
56float Properties::overrideLightRadius = -1.0f;
57float Properties::overrideLightPosY = -1.0f;
58float Properties::overrideLightPosZ = -1.0f;
59float Properties::overrideAmbientRatio = -1.0f;
60int Properties::overrideAmbientShadowStrength = -1;
61int Properties::overrideSpotShadowStrength = -1;
62
63ProfileType Properties::sProfileType = ProfileType::None;
64bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040065RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070066bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070067
John Reck682573c2015-10-30 10:37:35 -070068bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070069bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070070
John Reckc7cd9cf2016-03-28 10:38:19 -070071bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070072bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040073bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070074bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070075
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080076bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080077bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070078bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080079
Jorim Jaggi767e25e2018-04-04 23:07:35 +020080int Properties::contextPriority = 0;
John Reckcf185f52019-04-11 16:11:24 -070081int Properties::defaultRenderAhead = -1;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020082
Chris Craik2507c342015-05-04 14:36:49 -070083bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -070084 bool prevDebugLayersUpdates = debugLayersUpdates;
85 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -070086
Chris Craik2507c342015-05-04 14:36:49 -070087 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010088 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
89 if (debugOverdrawProperty != "") {
90 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
91 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -070092 debugOverdraw = true;
93 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010094 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -070095 debugOverdraw = true;
96 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
97 }
98 }
99
Chris Craik2507c342015-05-04 14:36:49 -0700100 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100101 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
102 if (profileProperty != "") {
103 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700104 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100105 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700106 sProfileType = ProfileType::Console;
107 }
108 }
109
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100110 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700111 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
112
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100113 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700114
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100115 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700116
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100117 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
118 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
119 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700120
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100121 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700122
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100123 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400124
Stan Iliev02daab62018-06-29 15:16:11 -0400125 SkAndroidFrameworkTraceUtil::setEnableTracing(
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100126 base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
Stan Iliev02daab62018-06-29 15:16:11 -0400127
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100128 runningInEmulator = base::GetBoolProperty(PROPERTY_QEMU_KERNEL, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800129
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100130 defaultRenderAhead = std::max(-1, std::min(2, base::GetIntProperty(PROPERTY_RENDERAHEAD,
John Reckcf185f52019-04-11 16:11:24 -0700131 render_ahead().value_or(0))));
John Reck4d527222019-03-13 16:25:20 -0700132
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500133 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700134}
135
136void Properties::overrideProperty(const char* name, const char* value) {
137 if (!strcmp(name, "disableProfileBars")) {
138 sDisableProfileBars = !strcmp(value, "true");
139 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
140 return;
141 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700142 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700143 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
144 return;
145 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700146 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700147 ALOGD("lightRadius = %.2f", overrideLightRadius);
148 return;
149 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700150 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700151 ALOGD("lightPos Y = %.2f", overrideLightPosY);
152 return;
153 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700154 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700155 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
156 return;
157 } else if (!strcmp(name, "ambientShadowStrength")) {
158 overrideAmbientShadowStrength = atoi(value);
159 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
160 return;
161 } else if (!strcmp(name, "spotShadowStrength")) {
162 overrideSpotShadowStrength = atoi(value);
163 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
164 return;
165 }
166 ALOGD("failed overriding property %s to %s", name, value);
167}
168
169ProfileType Properties::getProfileType() {
170 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
171 return ProfileType::None;
172 return sProfileType;
173}
174
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700175RenderPipelineType Properties::peekRenderPipelineType() {
176 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800177 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400178 return sRenderPipelineType;
179 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500180 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100181 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
182 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700183 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400184 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700185 return RenderPipelineType::SkiaGL;
186}
187
188RenderPipelineType Properties::getRenderPipelineType() {
189 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400190 return sRenderPipelineType;
191}
192
Greg Daniel98c78da2017-01-04 14:45:56 -0500193void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800194 // If we're doing actual rendering then we can't change the renderer after it's been set.
195 // Unit tests can freely change this as often as it wants, though, as there's no actual
196 // GL rendering happening
197 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
John Reck23462d82019-05-29 16:55:06 -0700198 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != type,
199 "Trying to change pipeline but it's already set");
John Reck113ddd92017-11-09 16:21:21 -0800200 return;
201 }
Greg Daniel98c78da2017-01-04 14:45:56 -0500202 sRenderPipelineType = type;
203}
Greg Daniel98c78da2017-01-04 14:45:56 -0500204
Chris Blume7b8a8082018-11-30 15:51:58 -0800205} // namespace uirenderer
206} // namespace android