blob: 446e81e65bb800eb029d4bfb1c20ca6ca19588fb [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"
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010019#ifdef __ANDROID__
Stan Ilievb8811aa52018-11-08 16:25:54 -050020#include "HWUIProperties.sysprop.h"
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010021#endif
John Reck0fa0cbc2019-04-05 16:57:46 -070022#include "SkTraceEventCommon.h"
Chris Craik2507c342015-05-04 14:36:49 -070023
John Reck6b507802015-11-03 10:09:59 -080024#include <algorithm>
25#include <cstdlib>
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010026#include <optional>
Chris Craik2507c342015-05-04 14:36:49 -070027
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010028#include <android-base/properties.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070029#include <cutils/compiler.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070030#include <log/log.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070031
Chris Craik2507c342015-05-04 14:36:49 -070032namespace android {
33namespace uirenderer {
34
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010035#ifndef __ANDROID__ // Layoutlib does not compile HWUIProperties.sysprop as it depends on cutils properties
36std::optional<bool> use_vulkan() {
37 return base::GetBoolProperty("ro.hwui.use_vulkan", false);
38}
39
40std::optional<std::int32_t> render_ahead() {
41 return base::GetIntProperty("ro.hwui.render_ahead", 0);
42}
43#endif
44
Chris Craik2507c342015-05-04 14:36:49 -070045bool Properties::debugLayersUpdates = false;
46bool Properties::debugOverdraw = false;
47bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070048bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070049bool Properties::useBufferAge = true;
50bool Properties::enablePartialUpdates = true;
Chris Craik2507c342015-05-04 14:36:49 -070051
52DebugLevel Properties::debugLevel = kDebugDisabled;
53OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070054
55float Properties::overrideLightRadius = -1.0f;
56float Properties::overrideLightPosY = -1.0f;
57float Properties::overrideLightPosZ = -1.0f;
58float Properties::overrideAmbientRatio = -1.0f;
59int Properties::overrideAmbientShadowStrength = -1;
60int Properties::overrideSpotShadowStrength = -1;
61
62ProfileType Properties::sProfileType = ProfileType::None;
63bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040064RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070065bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070066
John Reck682573c2015-10-30 10:37:35 -070067bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070068bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070069
John Reckc7cd9cf2016-03-28 10:38:19 -070070bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070071bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040072bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070073bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070074
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080075bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080076bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070077bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080078
Jorim Jaggi767e25e2018-04-04 23:07:35 +020079int Properties::contextPriority = 0;
John Reckcf185f52019-04-11 16:11:24 -070080int Properties::defaultRenderAhead = -1;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020081
Chris Craik2507c342015-05-04 14:36:49 -070082bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -070083 bool prevDebugLayersUpdates = debugLayersUpdates;
84 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -070085
Chris Craik2507c342015-05-04 14:36:49 -070086 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010087 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
88 if (debugOverdrawProperty != "") {
89 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty);
90 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -070091 debugOverdraw = true;
92 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +010093 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -070094 debugOverdraw = true;
95 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
96 }
97 }
98
Chris Craik2507c342015-05-04 14:36:49 -070099 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100100 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
101 if (profileProperty != "") {
102 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700103 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100104 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700105 sProfileType = ProfileType::Console;
106 }
107 }
108
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100109 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700110 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
111
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100112 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700113
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100114 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700115
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100116 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);
John Reckd04794a2015-05-08 10:04:36 -0700119
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100120 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700121
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100122 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400123
Stan Iliev02daab62018-06-29 15:16:11 -0400124 SkAndroidFrameworkTraceUtil::setEnableTracing(
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100125 base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false));
Stan Iliev02daab62018-06-29 15:16:11 -0400126
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100127 runningInEmulator = base::GetBoolProperty(PROPERTY_QEMU_KERNEL, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800128
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100129 defaultRenderAhead = std::max(-1, std::min(2, base::GetIntProperty(PROPERTY_RENDERAHEAD,
John Reckcf185f52019-04-11 16:11:24 -0700130 render_ahead().value_or(0))));
John Reck4d527222019-03-13 16:25:20 -0700131
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500132 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700133}
134
135void 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")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700141 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700142 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
143 return;
144 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700145 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700146 ALOGD("lightRadius = %.2f", overrideLightRadius);
147 return;
148 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700149 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700150 ALOGD("lightPos Y = %.2f", overrideLightPosY);
151 return;
152 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700153 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700154 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
168ProfileType Properties::getProfileType() {
169 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
170 return ProfileType::None;
171 return sProfileType;
172}
173
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700174RenderPipelineType Properties::peekRenderPipelineType() {
175 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800176 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400177 return sRenderPipelineType;
178 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500179 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100180 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
181 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700182 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400183 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700184 return RenderPipelineType::SkiaGL;
185}
186
187RenderPipelineType Properties::getRenderPipelineType() {
188 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400189 return sRenderPipelineType;
190}
191
Greg Daniel98c78dad2017-01-04 14:45:56 -0500192void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800193 // 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) {
John Reck23462d82019-05-29 16:55:06 -0700197 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != type,
198 "Trying to change pipeline but it's already set");
John Reck113ddd92017-11-09 16:21:21 -0800199 return;
200 }
Greg Daniel98c78dad2017-01-04 14:45:56 -0500201 sRenderPipelineType = type;
202}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500203
Chris Blume7b8a8082018-11-30 15:51:58 -0800204} // namespace uirenderer
205} // namespace android