blob: 064cac2a6fc6bf4a15ba5679c86d7091cd2eec2c [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}
Tom Murphy102ba1282024-07-25 12:50:46 +000045
46constexpr bool skip_eglmanager_telemetry() {
47 return false;
48}
49
Alec Mouri7dcb7d22024-07-26 13:41:04 +000050constexpr bool resample_gainmap_regions() {
51 return false;
52}
Juston Li9a9e06c2024-08-13 20:45:14 +000053
54constexpr bool query_global_priority() {
55 return false;
56}
John Reck1b152e72023-10-24 20:43:22 -040057} // namespace hwui_flags
58#endif
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070059
Chris Craik2507c342015-05-04 14:36:49 -070060namespace android {
61namespace uirenderer {
62
Chris Craik2507c342015-05-04 14:36:49 -070063bool Properties::debugLayersUpdates = false;
64bool Properties::debugOverdraw = false;
Nolan Scobie1083707b2024-01-11 16:45:36 -050065bool Properties::debugTraceGpuResourceCategories = false;
Chris Craik2507c342015-05-04 14:36:49 -070066bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070067bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070068bool Properties::useBufferAge = true;
69bool Properties::enablePartialUpdates = true;
Nader Jawad086645d2021-09-24 13:42:47 -070070// Default true unless otherwise specified in RenderThread Configuration
71bool Properties::enableRenderEffectCache = true;
Chris Craik2507c342015-05-04 14:36:49 -070072
73DebugLevel Properties::debugLevel = kDebugDisabled;
74OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070075
76float Properties::overrideLightRadius = -1.0f;
77float Properties::overrideLightPosY = -1.0f;
78float Properties::overrideLightPosZ = -1.0f;
79float Properties::overrideAmbientRatio = -1.0f;
80int Properties::overrideAmbientShadowStrength = -1;
81int Properties::overrideSpotShadowStrength = -1;
82
83ProfileType Properties::sProfileType = ProfileType::None;
84bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040085RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070086bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070087
John Reck682573c2015-10-30 10:37:35 -070088bool Properties::waitForGpuCompletion = false;
89
John Reckc7cd9cf2016-03-28 10:38:19 -070090bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070091bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040092bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070093bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070094
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080095bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080096bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070097bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080098
Jorim Jaggi767e25e2018-04-04 23:07:35 +020099int Properties::contextPriority = 0;
John Reckf42ff762020-08-06 13:53:22 -0700100float Properties::defaultSdrWhitePoint = 200.f;
Jorim Jaggi767e25e2018-04-04 23:07:35 +0200101
Matt Buckley49602f52022-12-06 22:03:30 +0000102bool Properties::useHintManager = false;
Bo Liu027b2182021-03-18 16:50:38 -0400103int Properties::targetCpuTimePercentage = 70;
104
Huihong Luo35b1dde2021-08-13 10:28:10 -0700105bool Properties::enableWebViewOverlays = true;
Huihong Luoeb931072021-06-30 10:12:17 -0700106
John Reck5f66fb82022-09-23 17:49:23 -0400107bool Properties::isHighEndGfx = true;
108bool Properties::isLowRam = false;
109bool Properties::isSystemOrPersistent = false;
110
John Reck342f6212023-03-14 21:58:26 -0400111float Properties::maxHdrHeadroomOn8bit = 5.f; // TODO: Refine this number
112
John Reck1b152e72023-10-24 20:43:22 -0400113bool Properties::clipSurfaceViews = false;
Alec Mouri22ab7f32023-09-06 02:11:56 +0000114bool Properties::hdr10bitPlus = false;
Tom Murphy102ba1282024-07-25 12:50:46 +0000115bool Properties::skipTelemetry = false;
Juston Li9a9e06c2024-08-13 20:45:14 +0000116bool Properties::queryGlobalPriority = false;
John Reck1b152e72023-10-24 20:43:22 -0400117
Jason Macnakc355c232024-07-29 11:10:34 -0700118int Properties::timeoutMultiplier = 1;
119
Nader Jawad9272f212021-05-10 13:27:52 -0700120StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
John Reck8ed00dc2021-05-10 13:09:27 -0400121
Brett Chabot074ba592021-07-16 14:38:11 -0700122DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
Brett Chabot856db9e2021-05-21 08:41:58 -0700123
Chris Craik2507c342015-05-04 14:36:49 -0700124bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -0700125 bool prevDebugLayersUpdates = debugLayersUpdates;
126 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -0700127
Chris Craik2507c342015-05-04 14:36:49 -0700128 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100129 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
130 if (debugOverdrawProperty != "") {
tangcheng70ee5642023-03-17 11:27:59 +0800131 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty.c_str());
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100132 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -0700133 debugOverdraw = true;
134 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100135 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -0700136 debugOverdraw = true;
137 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
138 }
139 }
140
Chris Craik2507c342015-05-04 14:36:49 -0700141 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100142 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
143 if (profileProperty != "") {
144 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700145 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100146 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700147 sProfileType = ProfileType::Console;
148 }
149 }
150
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100151 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700152 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
153
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100154 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700155
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100156 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700157
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100158 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
159 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
160 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700161
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100162 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700163
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100164 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400165
Nolan Scobie1083707b2024-01-11 16:45:36 -0500166 bool skiaBroadTracing = base::GetBoolProperty(PROPERTY_SKIA_TRACING_ENABLED, false);
167 SkAndroidFrameworkTraceUtil::setEnableTracing(skiaBroadTracing);
Nolan Scobie799b5742022-12-05 21:12:16 -0500168 SkAndroidFrameworkTraceUtil::setUsePerfettoTrackEvents(
169 base::GetBoolProperty(PROPERTY_SKIA_USE_PERFETTO_TRACK_EVENTS, false));
Nolan Scobie1083707b2024-01-11 16:45:36 -0500170 debugTraceGpuResourceCategories =
171 base::GetBoolProperty(PROPERTY_TRACE_GPU_RESOURCES, skiaBroadTracing);
Stan Iliev02daab62018-06-29 15:16:11 -0400172
Roman Kiryanovd6a9f4252021-03-10 16:57:41 -0800173 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800174
Matt Buckley49602f52022-12-06 22:03:30 +0000175 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, false);
Bo Liu027b2182021-03-18 16:50:38 -0400176 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
177 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
178
Huihong Luo35b1dde2021-08-13 10:28:10 -0700179 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, true);
Huihong Luoeb931072021-06-30 10:12:17 -0700180
John Reck342f6212023-03-14 21:58:26 -0400181 auto hdrHeadroom = (float)atof(base::GetProperty(PROPERTY_8BIT_HDR_HEADROOM, "").c_str());
182 if (hdrHeadroom >= 1.f) {
183 maxHdrHeadroomOn8bit = std::min(hdrHeadroom, 100.f);
184 }
185
Brett Chabot074ba592021-07-16 14:38:11 -0700186 // call isDrawingEnabled to force loading of the property
187 isDrawingEnabled();
Brett Chabot856db9e2021-05-21 08:41:58 -0700188
John Reck1b152e72023-10-24 20:43:22 -0400189 clipSurfaceViews =
190 base::GetBoolProperty("debug.hwui.clip_surfaceviews", hwui_flags::clip_surfaceviews());
Alec Mouri22ab7f32023-09-06 02:11:56 +0000191 hdr10bitPlus = hwui_flags::hdr_10bit_plus();
Juston Li9a9e06c2024-08-13 20:45:14 +0000192 queryGlobalPriority = hwui_flags::query_global_priority();
John Reck1b152e72023-10-24 20:43:22 -0400193
Jason Macnakc355c232024-07-29 11:10:34 -0700194 timeoutMultiplier = android::base::GetIntProperty("ro.hw_timeout_multiplier", 1);
Tom Murphy102ba1282024-07-25 12:50:46 +0000195 skipTelemetry = base::GetBoolProperty(PROPERTY_SKIP_EGLMANAGER_TELEMETRY,
196 hwui_flags::skip_eglmanager_telemetry());
Jason Macnakc355c232024-07-29 11:10:34 -0700197
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500198 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700199}
200
201void Properties::overrideProperty(const char* name, const char* value) {
202 if (!strcmp(name, "disableProfileBars")) {
203 sDisableProfileBars = !strcmp(value, "true");
204 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
205 return;
206 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700207 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700208 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
209 return;
210 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700211 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700212 ALOGD("lightRadius = %.2f", overrideLightRadius);
213 return;
214 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700215 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700216 ALOGD("lightPos Y = %.2f", overrideLightPosY);
217 return;
218 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700219 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700220 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
221 return;
222 } else if (!strcmp(name, "ambientShadowStrength")) {
223 overrideAmbientShadowStrength = atoi(value);
224 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
225 return;
226 } else if (!strcmp(name, "spotShadowStrength")) {
227 overrideSpotShadowStrength = atoi(value);
228 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
229 return;
230 }
231 ALOGD("failed overriding property %s to %s", name, value);
232}
233
234ProfileType Properties::getProfileType() {
235 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
236 return ProfileType::None;
237 return sProfileType;
238}
239
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700240RenderPipelineType Properties::peekRenderPipelineType() {
241 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800242 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400243 return sRenderPipelineType;
244 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500245 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100246 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
247 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700248 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400249 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700250 return RenderPipelineType::SkiaGL;
251}
252
253RenderPipelineType Properties::getRenderPipelineType() {
254 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400255 return sRenderPipelineType;
256}
257
Alec Mouri219997a2023-05-23 17:25:19 +0000258void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800259 // 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 +0000260 // Unit tests can freely change this as often as it wants, though, as there's no actual
261 // GL rendering happening
262 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
263 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != type,
264 "Trying to change pipeline but it's already set");
265 return;
266 }
Greg Daniel98c78dad2017-01-04 14:45:56 -0500267 sRenderPipelineType = type;
268}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500269
Brett Chabot856db9e2021-05-21 08:41:58 -0700270void Properties::setDrawingEnabled(bool newDrawingEnabled) {
Brett Chabot074ba592021-07-16 14:38:11 -0700271 drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
Brett Chabot856db9e2021-05-21 08:41:58 -0700272 enableRTAnimations = newDrawingEnabled;
273}
274
275bool Properties::isDrawingEnabled() {
Brett Chabot074ba592021-07-16 14:38:11 -0700276 if (drawingEnabled == DrawingEnabled::NotInitialized) {
277 bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
278 drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
279 enableRTAnimations = drawingEnabledProp;
Brett Chabot856db9e2021-05-21 08:41:58 -0700280 }
Brett Chabot074ba592021-07-16 14:38:11 -0700281 return drawingEnabled == DrawingEnabled::On;
Brett Chabot856db9e2021-05-21 08:41:58 -0700282}
283
Leon Scroggins IIIbac87062024-05-31 16:40:17 -0400284bool Properties::initializeGlAlways() {
285 return base::GetBoolProperty(PROPERTY_INITIALIZE_GL_ALWAYS, hwui_flags::initialize_gl_always());
286}
287
Alec Mouriedc27ee2024-11-09 02:06:07 +0000288bool Properties::resampleGainmapRegions() {
289 static bool sResampleGainmapRegions = base::GetBoolProperty(
290 "debug.hwui.resample_gainmap_regions", hwui_flags::resample_gainmap_regions());
291 return sResampleGainmapRegions;
292}
293
Chris Blume7b8a8082018-11-30 15:51:58 -0800294} // namespace uirenderer
295} // namespace android