blob: 1217b47664ddc23f4ef98a7177b2a54680700420 [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
John Reck1b152e72023-10-24 20:43:22 -040019#include <android-base/properties.h>
20#include <cutils/compiler.h>
21#include <log/log.h>
Chris Craik2507c342015-05-04 14:36:49 -070022
John Reck6b507802015-11-03 10:09:59 -080023#include <algorithm>
24#include <cstdlib>
Jerome Gaillard21e7e2d2019-05-14 14:34:46 +010025#include <optional>
Chris Craik2507c342015-05-04 14:36:49 -070026
Jerome Gaillardea9bf2a2024-03-13 19:32:31 +000027#include "Debug.h"
28#include "HWUIProperties.sysprop.h"
John Reck1b152e72023-10-24 20:43:22 -040029#include "src/core/SkTraceEventCommon.h"
30
31#ifdef __ANDROID__
32#include <com_android_graphics_hwui_flags.h>
33namespace hwui_flags = com::android::graphics::hwui::flags;
34#else
35namespace hwui_flags {
36constexpr bool clip_surfaceviews() {
37 return false;
38}
Alec Mouri22ab7f32023-09-06 02:11:56 +000039constexpr bool hdr_10bit_plus() {
40 return false;
41}
Leon Scroggins IIIbac87062024-05-31 16:40:17 -040042constexpr bool initialize_gl_always() {
43 return false;
44}
Alec Mouri7dcb7d22024-07-26 13:41:04 +000045constexpr bool resample_gainmap_regions() {
46 return false;
47}
John Reck1b152e72023-10-24 20:43:22 -040048} // namespace hwui_flags
49#endif
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070050
Chris Craik2507c342015-05-04 14:36:49 -070051namespace android {
52namespace uirenderer {
53
Chris Craik2507c342015-05-04 14:36:49 -070054bool Properties::debugLayersUpdates = false;
55bool Properties::debugOverdraw = false;
Nolan Scobie1083707b2024-01-11 16:45:36 -050056bool Properties::debugTraceGpuResourceCategories = false;
Chris Craik2507c342015-05-04 14:36:49 -070057bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070058bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070059bool Properties::useBufferAge = true;
60bool Properties::enablePartialUpdates = true;
Nader Jawad086645d2021-09-24 13:42:47 -070061// Default true unless otherwise specified in RenderThread Configuration
62bool Properties::enableRenderEffectCache = true;
Chris Craik2507c342015-05-04 14:36:49 -070063
64DebugLevel Properties::debugLevel = kDebugDisabled;
65OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070066
67float Properties::overrideLightRadius = -1.0f;
68float Properties::overrideLightPosY = -1.0f;
69float Properties::overrideLightPosZ = -1.0f;
70float Properties::overrideAmbientRatio = -1.0f;
71int Properties::overrideAmbientShadowStrength = -1;
72int Properties::overrideSpotShadowStrength = -1;
73
74ProfileType Properties::sProfileType = ProfileType::None;
75bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040076RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070077bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070078
John Reck682573c2015-10-30 10:37:35 -070079bool Properties::waitForGpuCompletion = false;
80
John Reckc7cd9cf2016-03-28 10:38:19 -070081bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070082bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040083bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070084bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070085
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080086bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080087bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070088bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080089
Jorim Jaggi767e25e2018-04-04 23:07:35 +020090int Properties::contextPriority = 0;
John Reckf42ff762020-08-06 13:53:22 -070091float Properties::defaultSdrWhitePoint = 200.f;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020092
Matt Buckley49602f52022-12-06 22:03:30 +000093bool Properties::useHintManager = false;
Bo Liu027b2182021-03-18 16:50:38 -040094int Properties::targetCpuTimePercentage = 70;
95
Huihong Luo35b1dde2021-08-13 10:28:10 -070096bool Properties::enableWebViewOverlays = true;
Huihong Luoeb931072021-06-30 10:12:17 -070097
John Reck5f66fb82022-09-23 17:49:23 -040098bool Properties::isHighEndGfx = true;
99bool Properties::isLowRam = false;
100bool Properties::isSystemOrPersistent = false;
101
John Reck342f6212023-03-14 21:58:26 -0400102float Properties::maxHdrHeadroomOn8bit = 5.f; // TODO: Refine this number
103
John Reck1b152e72023-10-24 20:43:22 -0400104bool Properties::clipSurfaceViews = false;
Alec Mouri22ab7f32023-09-06 02:11:56 +0000105bool Properties::hdr10bitPlus = false;
Alec Mouri7dcb7d22024-07-26 13:41:04 +0000106bool Properties::resampleGainmapRegions = false;
John Reck1b152e72023-10-24 20:43:22 -0400107
Jason Macnakc355c232024-07-29 11:10:34 -0700108int Properties::timeoutMultiplier = 1;
109
Nader Jawad9272f212021-05-10 13:27:52 -0700110StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
John Reck8ed00dc2021-05-10 13:09:27 -0400111
Brett Chabot074ba592021-07-16 14:38:11 -0700112DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
Brett Chabot856db9e2021-05-21 08:41:58 -0700113
Chris Craik2507c342015-05-04 14:36:49 -0700114bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -0700115 bool prevDebugLayersUpdates = debugLayersUpdates;
116 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -0700117
Chris Craik2507c342015-05-04 14:36:49 -0700118 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100119 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
120 if (debugOverdrawProperty != "") {
tangcheng70ee5642023-03-17 11:27:59 +0800121 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty.c_str());
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100122 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -0700123 debugOverdraw = true;
124 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100125 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -0700126 debugOverdraw = true;
127 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
128 }
129 }
130
Chris Craik2507c342015-05-04 14:36:49 -0700131 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100132 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
133 if (profileProperty != "") {
134 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700135 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100136 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700137 sProfileType = ProfileType::Console;
138 }
139 }
140
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100141 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700142 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
143
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100144 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700145
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100146 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700147
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100148 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
149 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
150 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700151
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100152 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700153
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100154 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400155
Nolan Scobie1083707b2024-01-11 16:45:36 -0500156 bool skiaBroadTracing = base::GetBoolProperty(PROPERTY_SKIA_TRACING_ENABLED, false);
157 SkAndroidFrameworkTraceUtil::setEnableTracing(skiaBroadTracing);
Nolan Scobie799b5742022-12-05 21:12:16 -0500158 SkAndroidFrameworkTraceUtil::setUsePerfettoTrackEvents(
159 base::GetBoolProperty(PROPERTY_SKIA_USE_PERFETTO_TRACK_EVENTS, false));
Nolan Scobie1083707b2024-01-11 16:45:36 -0500160 debugTraceGpuResourceCategories =
161 base::GetBoolProperty(PROPERTY_TRACE_GPU_RESOURCES, skiaBroadTracing);
Stan Iliev02daab62018-06-29 15:16:11 -0400162
Roman Kiryanovd6a9f4252021-03-10 16:57:41 -0800163 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800164
Matt Buckley49602f52022-12-06 22:03:30 +0000165 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, false);
Bo Liu027b2182021-03-18 16:50:38 -0400166 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
167 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
168
Huihong Luo35b1dde2021-08-13 10:28:10 -0700169 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, true);
Huihong Luoeb931072021-06-30 10:12:17 -0700170
John Reck342f6212023-03-14 21:58:26 -0400171 auto hdrHeadroom = (float)atof(base::GetProperty(PROPERTY_8BIT_HDR_HEADROOM, "").c_str());
172 if (hdrHeadroom >= 1.f) {
173 maxHdrHeadroomOn8bit = std::min(hdrHeadroom, 100.f);
174 }
175
Brett Chabot074ba592021-07-16 14:38:11 -0700176 // call isDrawingEnabled to force loading of the property
177 isDrawingEnabled();
Brett Chabot856db9e2021-05-21 08:41:58 -0700178
John Reck1b152e72023-10-24 20:43:22 -0400179 clipSurfaceViews =
180 base::GetBoolProperty("debug.hwui.clip_surfaceviews", hwui_flags::clip_surfaceviews());
Alec Mouri22ab7f32023-09-06 02:11:56 +0000181 hdr10bitPlus = hwui_flags::hdr_10bit_plus();
Alec Mouri7dcb7d22024-07-26 13:41:04 +0000182 resampleGainmapRegions = base::GetBoolProperty("debug.hwui.resample_gainmap_regions",
183 hwui_flags::resample_gainmap_regions());
John Reck1b152e72023-10-24 20:43:22 -0400184
Jason Macnakc355c232024-07-29 11:10:34 -0700185 timeoutMultiplier = android::base::GetIntProperty("ro.hw_timeout_multiplier", 1);
186
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500187 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700188}
189
190void Properties::overrideProperty(const char* name, const char* value) {
191 if (!strcmp(name, "disableProfileBars")) {
192 sDisableProfileBars = !strcmp(value, "true");
193 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
194 return;
195 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700196 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700197 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
198 return;
199 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700200 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700201 ALOGD("lightRadius = %.2f", overrideLightRadius);
202 return;
203 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700204 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700205 ALOGD("lightPos Y = %.2f", overrideLightPosY);
206 return;
207 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700208 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700209 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
210 return;
211 } else if (!strcmp(name, "ambientShadowStrength")) {
212 overrideAmbientShadowStrength = atoi(value);
213 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
214 return;
215 } else if (!strcmp(name, "spotShadowStrength")) {
216 overrideSpotShadowStrength = atoi(value);
217 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
218 return;
219 }
220 ALOGD("failed overriding property %s to %s", name, value);
221}
222
223ProfileType Properties::getProfileType() {
224 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
225 return ProfileType::None;
226 return sProfileType;
227}
228
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700229RenderPipelineType Properties::peekRenderPipelineType() {
230 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800231 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400232 return sRenderPipelineType;
233 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500234 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100235 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
236 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700237 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400238 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700239 return RenderPipelineType::SkiaGL;
240}
241
242RenderPipelineType Properties::getRenderPipelineType() {
243 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400244 return sRenderPipelineType;
245}
246
Alec Mouri219997a2023-05-23 17:25:19 +0000247void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800248 // If we're doing actual rendering then we can't change the renderer after it's been set.
Alec Mouri219997a2023-05-23 17:25:19 +0000249 // Unit tests can freely change this as often as it wants, though, as there's no actual
250 // GL rendering happening
251 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
252 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != type,
253 "Trying to change pipeline but it's already set");
254 return;
255 }
Greg Daniel98c78dad2017-01-04 14:45:56 -0500256 sRenderPipelineType = type;
257}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500258
Brett Chabot856db9e2021-05-21 08:41:58 -0700259void Properties::setDrawingEnabled(bool newDrawingEnabled) {
Brett Chabot074ba592021-07-16 14:38:11 -0700260 drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
Brett Chabot856db9e2021-05-21 08:41:58 -0700261 enableRTAnimations = newDrawingEnabled;
262}
263
264bool Properties::isDrawingEnabled() {
Brett Chabot074ba592021-07-16 14:38:11 -0700265 if (drawingEnabled == DrawingEnabled::NotInitialized) {
266 bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
267 drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
268 enableRTAnimations = drawingEnabledProp;
Brett Chabot856db9e2021-05-21 08:41:58 -0700269 }
Brett Chabot074ba592021-07-16 14:38:11 -0700270 return drawingEnabled == DrawingEnabled::On;
Brett Chabot856db9e2021-05-21 08:41:58 -0700271}
272
Leon Scroggins IIIbac87062024-05-31 16:40:17 -0400273bool Properties::initializeGlAlways() {
274 return base::GetBoolProperty(PROPERTY_INITIALIZE_GL_ALWAYS, hwui_flags::initialize_gl_always());
275}
276
Chris Blume7b8a8082018-11-30 15:51:58 -0800277} // namespace uirenderer
278} // namespace android