blob: b6476c9d466fd2cb07a758e1cde63a01dfba6931 [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}
John Reck1b152e72023-10-24 20:43:22 -040053} // namespace hwui_flags
54#endif
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070055
Chris Craik2507c342015-05-04 14:36:49 -070056namespace android {
57namespace uirenderer {
58
Chris Craik2507c342015-05-04 14:36:49 -070059bool Properties::debugLayersUpdates = false;
60bool Properties::debugOverdraw = false;
Nolan Scobie1083707b2024-01-11 16:45:36 -050061bool Properties::debugTraceGpuResourceCategories = false;
Chris Craik2507c342015-05-04 14:36:49 -070062bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070063bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070064bool Properties::useBufferAge = true;
65bool Properties::enablePartialUpdates = true;
Nader Jawad086645d2021-09-24 13:42:47 -070066// Default true unless otherwise specified in RenderThread Configuration
67bool Properties::enableRenderEffectCache = true;
Chris Craik2507c342015-05-04 14:36:49 -070068
69DebugLevel Properties::debugLevel = kDebugDisabled;
70OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070071
72float Properties::overrideLightRadius = -1.0f;
73float Properties::overrideLightPosY = -1.0f;
74float Properties::overrideLightPosZ = -1.0f;
75float Properties::overrideAmbientRatio = -1.0f;
76int Properties::overrideAmbientShadowStrength = -1;
77int Properties::overrideSpotShadowStrength = -1;
78
79ProfileType Properties::sProfileType = ProfileType::None;
80bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040081RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070082bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070083
John Reck682573c2015-10-30 10:37:35 -070084bool Properties::waitForGpuCompletion = false;
85
John Reckc7cd9cf2016-03-28 10:38:19 -070086bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070087bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040088bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070089bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070090
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080091bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080092bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070093bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080094
Jorim Jaggi767e25e2018-04-04 23:07:35 +020095int Properties::contextPriority = 0;
John Reckf42ff762020-08-06 13:53:22 -070096float Properties::defaultSdrWhitePoint = 200.f;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020097
Matt Buckley49602f52022-12-06 22:03:30 +000098bool Properties::useHintManager = false;
Bo Liu027b2182021-03-18 16:50:38 -040099int Properties::targetCpuTimePercentage = 70;
100
Huihong Luo35b1dde2021-08-13 10:28:10 -0700101bool Properties::enableWebViewOverlays = true;
Huihong Luoeb931072021-06-30 10:12:17 -0700102
John Reck5f66fb82022-09-23 17:49:23 -0400103bool Properties::isHighEndGfx = true;
104bool Properties::isLowRam = false;
105bool Properties::isSystemOrPersistent = false;
106
John Reck342f6212023-03-14 21:58:26 -0400107float Properties::maxHdrHeadroomOn8bit = 5.f; // TODO: Refine this number
108
John Reck1b152e72023-10-24 20:43:22 -0400109bool Properties::clipSurfaceViews = false;
Alec Mouri22ab7f32023-09-06 02:11:56 +0000110bool Properties::hdr10bitPlus = false;
Tom Murphy102ba1282024-07-25 12:50:46 +0000111bool Properties::skipTelemetry = false;
Alec Mouri7dcb7d22024-07-26 13:41:04 +0000112bool Properties::resampleGainmapRegions = false;
John Reck1b152e72023-10-24 20:43:22 -0400113
Jason Macnakc355c232024-07-29 11:10:34 -0700114int Properties::timeoutMultiplier = 1;
115
Nader Jawad9272f212021-05-10 13:27:52 -0700116StretchEffectBehavior Properties::stretchEffectBehavior = StretchEffectBehavior::ShaderHWUI;
John Reck8ed00dc2021-05-10 13:09:27 -0400117
Brett Chabot074ba592021-07-16 14:38:11 -0700118DrawingEnabled Properties::drawingEnabled = DrawingEnabled::NotInitialized;
Brett Chabot856db9e2021-05-21 08:41:58 -0700119
Chris Craik2507c342015-05-04 14:36:49 -0700120bool Properties::load() {
Chris Craik2507c342015-05-04 14:36:49 -0700121 bool prevDebugLayersUpdates = debugLayersUpdates;
122 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -0700123
Chris Craik2507c342015-05-04 14:36:49 -0700124 debugOverdraw = false;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100125 std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, "");
126 if (debugOverdrawProperty != "") {
tangcheng70ee5642023-03-17 11:27:59 +0800127 INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty.c_str());
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100128 if (debugOverdrawProperty == "show") {
Chris Craik2507c342015-05-04 14:36:49 -0700129 debugOverdraw = true;
130 overdrawColorSet = OverdrawColorSet::Default;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100131 } else if (debugOverdrawProperty == "show_deuteranomaly") {
Chris Craik2507c342015-05-04 14:36:49 -0700132 debugOverdraw = true;
133 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
134 }
135 }
136
Chris Craik2507c342015-05-04 14:36:49 -0700137 sProfileType = ProfileType::None;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100138 std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, "");
139 if (profileProperty != "") {
140 if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) {
Chris Craik2507c342015-05-04 14:36:49 -0700141 sProfileType = ProfileType::Bars;
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100142 } else if (profileProperty == "true") {
Chris Craik2507c342015-05-04 14:36:49 -0700143 sProfileType = ProfileType::Console;
144 }
145 }
146
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100147 debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false);
Chris Craik2507c342015-05-04 14:36:49 -0700148 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
149
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100150 showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
Chris Craik2507c342015-05-04 14:36:49 -0700151
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100152 debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700153
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100154 skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true);
155 useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true);
156 enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700157
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100158 filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false);
John Reckc7cd9cf2016-03-28 10:38:19 -0700159
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100160 skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400161
Nolan Scobie1083707b2024-01-11 16:45:36 -0500162 bool skiaBroadTracing = base::GetBoolProperty(PROPERTY_SKIA_TRACING_ENABLED, false);
163 SkAndroidFrameworkTraceUtil::setEnableTracing(skiaBroadTracing);
Nolan Scobie799b5742022-12-05 21:12:16 -0500164 SkAndroidFrameworkTraceUtil::setUsePerfettoTrackEvents(
165 base::GetBoolProperty(PROPERTY_SKIA_USE_PERFETTO_TRACK_EVENTS, false));
Nolan Scobie1083707b2024-01-11 16:45:36 -0500166 debugTraceGpuResourceCategories =
167 base::GetBoolProperty(PROPERTY_TRACE_GPU_RESOURCES, skiaBroadTracing);
Stan Iliev02daab62018-06-29 15:16:11 -0400168
Roman Kiryanovd6a9f4252021-03-10 16:57:41 -0800169 runningInEmulator = base::GetBoolProperty(PROPERTY_IS_EMULATOR, false);
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800170
Matt Buckley49602f52022-12-06 22:03:30 +0000171 useHintManager = base::GetBoolProperty(PROPERTY_USE_HINT_MANAGER, false);
Bo Liu027b2182021-03-18 16:50:38 -0400172 targetCpuTimePercentage = base::GetIntProperty(PROPERTY_TARGET_CPU_TIME_PERCENTAGE, 70);
173 if (targetCpuTimePercentage <= 0 || targetCpuTimePercentage > 100) targetCpuTimePercentage = 70;
174
Huihong Luo35b1dde2021-08-13 10:28:10 -0700175 enableWebViewOverlays = base::GetBoolProperty(PROPERTY_WEBVIEW_OVERLAYS_ENABLED, true);
Huihong Luoeb931072021-06-30 10:12:17 -0700176
John Reck342f6212023-03-14 21:58:26 -0400177 auto hdrHeadroom = (float)atof(base::GetProperty(PROPERTY_8BIT_HDR_HEADROOM, "").c_str());
178 if (hdrHeadroom >= 1.f) {
179 maxHdrHeadroomOn8bit = std::min(hdrHeadroom, 100.f);
180 }
181
Brett Chabot074ba592021-07-16 14:38:11 -0700182 // call isDrawingEnabled to force loading of the property
183 isDrawingEnabled();
Brett Chabot856db9e2021-05-21 08:41:58 -0700184
John Reck1b152e72023-10-24 20:43:22 -0400185 clipSurfaceViews =
186 base::GetBoolProperty("debug.hwui.clip_surfaceviews", hwui_flags::clip_surfaceviews());
Alec Mouri22ab7f32023-09-06 02:11:56 +0000187 hdr10bitPlus = hwui_flags::hdr_10bit_plus();
Alec Mouri7dcb7d22024-07-26 13:41:04 +0000188 resampleGainmapRegions = base::GetBoolProperty("debug.hwui.resample_gainmap_regions",
189 hwui_flags::resample_gainmap_regions());
John Reck1b152e72023-10-24 20:43:22 -0400190
Jason Macnakc355c232024-07-29 11:10:34 -0700191 timeoutMultiplier = android::base::GetIntProperty("ro.hw_timeout_multiplier", 1);
Tom Murphy102ba1282024-07-25 12:50:46 +0000192 skipTelemetry = base::GetBoolProperty(PROPERTY_SKIP_EGLMANAGER_TELEMETRY,
193 hwui_flags::skip_eglmanager_telemetry());
Jason Macnakc355c232024-07-29 11:10:34 -0700194
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500195 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700196}
197
198void Properties::overrideProperty(const char* name, const char* value) {
199 if (!strcmp(name, "disableProfileBars")) {
200 sDisableProfileBars = !strcmp(value, "true");
201 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
202 return;
203 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700204 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700205 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
206 return;
207 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700208 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700209 ALOGD("lightRadius = %.2f", overrideLightRadius);
210 return;
211 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700212 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700213 ALOGD("lightPos Y = %.2f", overrideLightPosY);
214 return;
215 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700216 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700217 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
218 return;
219 } else if (!strcmp(name, "ambientShadowStrength")) {
220 overrideAmbientShadowStrength = atoi(value);
221 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
222 return;
223 } else if (!strcmp(name, "spotShadowStrength")) {
224 overrideSpotShadowStrength = atoi(value);
225 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
226 return;
227 }
228 ALOGD("failed overriding property %s to %s", name, value);
229}
230
231ProfileType Properties::getProfileType() {
232 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
233 return ProfileType::None;
234 return sProfileType;
235}
236
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700237RenderPipelineType Properties::peekRenderPipelineType() {
238 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800239 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400240 return sRenderPipelineType;
241 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500242 bool useVulkan = use_vulkan().value_or(false);
Jerome Gaillarda02a12d2019-05-28 18:07:56 +0100243 std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl");
244 if (rendererProperty == "skiavk") {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700245 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400246 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700247 return RenderPipelineType::SkiaGL;
248}
249
250RenderPipelineType Properties::getRenderPipelineType() {
251 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400252 return sRenderPipelineType;
253}
254
Alec Mouri219997a2023-05-23 17:25:19 +0000255void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800256 // 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 +0000257 // Unit tests can freely change this as often as it wants, though, as there's no actual
258 // GL rendering happening
259 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
260 LOG_ALWAYS_FATAL_IF(sRenderPipelineType != type,
261 "Trying to change pipeline but it's already set");
262 return;
263 }
Greg Daniel98c78dad2017-01-04 14:45:56 -0500264 sRenderPipelineType = type;
265}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500266
Brett Chabot856db9e2021-05-21 08:41:58 -0700267void Properties::setDrawingEnabled(bool newDrawingEnabled) {
Brett Chabot074ba592021-07-16 14:38:11 -0700268 drawingEnabled = newDrawingEnabled ? DrawingEnabled::On : DrawingEnabled::Off;
Brett Chabot856db9e2021-05-21 08:41:58 -0700269 enableRTAnimations = newDrawingEnabled;
270}
271
272bool Properties::isDrawingEnabled() {
Brett Chabot074ba592021-07-16 14:38:11 -0700273 if (drawingEnabled == DrawingEnabled::NotInitialized) {
274 bool drawingEnabledProp = base::GetBoolProperty(PROPERTY_DRAWING_ENABLED, true);
275 drawingEnabled = drawingEnabledProp ? DrawingEnabled::On : DrawingEnabled::Off;
276 enableRTAnimations = drawingEnabledProp;
Brett Chabot856db9e2021-05-21 08:41:58 -0700277 }
Brett Chabot074ba592021-07-16 14:38:11 -0700278 return drawingEnabled == DrawingEnabled::On;
Brett Chabot856db9e2021-05-21 08:41:58 -0700279}
280
Leon Scroggins IIIbac87062024-05-31 16:40:17 -0400281bool Properties::initializeGlAlways() {
282 return base::GetBoolProperty(PROPERTY_INITIALIZE_GL_ALWAYS, hwui_flags::initialize_gl_always());
283}
284
Chris Blume7b8a8082018-11-30 15:51:58 -0800285} // namespace uirenderer
286} // namespace android