blob: af20c4f4f20e10b47f026e2f98a372668a97325b [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"
Stan Ilievb8811aa52018-11-08 16:25:54 -050020#include "HWUIProperties.sysprop.h"
John Reck0fa0cbc2019-04-05 16:57:46 -070021#include "SkTraceEventCommon.h"
Chris Craik2507c342015-05-04 14:36:49 -070022
John Reck6b507802015-11-03 10:09:59 -080023#include <algorithm>
24#include <cstdlib>
Chris Craik2507c342015-05-04 14:36:49 -070025
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070026#include <cutils/compiler.h>
27#include <cutils/properties.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070028#include <log/log.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070029
Chris Craik2507c342015-05-04 14:36:49 -070030namespace android {
31namespace uirenderer {
32
Chris Craik2507c342015-05-04 14:36:49 -070033bool Properties::debugLayersUpdates = false;
34bool Properties::debugOverdraw = false;
35bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070036bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070037bool Properties::useBufferAge = true;
38bool Properties::enablePartialUpdates = true;
Chris Craik2507c342015-05-04 14:36:49 -070039
40DebugLevel Properties::debugLevel = kDebugDisabled;
41OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070042
43float Properties::overrideLightRadius = -1.0f;
44float Properties::overrideLightPosY = -1.0f;
45float Properties::overrideLightPosZ = -1.0f;
46float Properties::overrideAmbientRatio = -1.0f;
47int Properties::overrideAmbientShadowStrength = -1;
48int Properties::overrideSpotShadowStrength = -1;
49
50ProfileType Properties::sProfileType = ProfileType::None;
51bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040052RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070053bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070054
John Reck682573c2015-10-30 10:37:35 -070055bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070056bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070057
John Reckc7cd9cf2016-03-28 10:38:19 -070058bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070059bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040060bool Properties::skpCaptureEnabled = false;
John Reck9f516442017-09-25 10:27:21 -070061bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070062
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080063bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080064bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070065bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080066
Jorim Jaggi767e25e2018-04-04 23:07:35 +020067int Properties::contextPriority = 0;
John Reckcf185f52019-04-11 16:11:24 -070068int Properties::defaultRenderAhead = -1;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020069
Chris Craik9fded232015-11-11 16:42:34 -080070static int property_get_int(const char* key, int defaultValue) {
John Reck1bcacfd2017-11-03 10:12:19 -070071 char buf[PROPERTY_VALUE_MAX] = {
72 '\0',
73 };
Chris Craik9fded232015-11-11 16:42:34 -080074
75 if (property_get(key, buf, "") > 0) {
76 return atoi(buf);
77 }
78 return defaultValue;
79}
80
Chris Craik2507c342015-05-04 14:36:49 -070081bool Properties::load() {
82 char property[PROPERTY_VALUE_MAX];
83 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;
87 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
88 INIT_LOGD(" Overdraw debug enabled: %s", property);
89 if (!strcmp(property, "show")) {
90 debugOverdraw = true;
91 overdrawColorSet = OverdrawColorSet::Default;
92 } else if (!strcmp(property, "show_deuteranomaly")) {
93 debugOverdraw = true;
94 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
95 }
96 }
97
Chris Craik2507c342015-05-04 14:36:49 -070098 sProfileType = ProfileType::None;
99 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
100 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
101 sProfileType = ProfileType::Bars;
102 } else if (!strcmp(property, "true")) {
103 sProfileType = ProfileType::Console;
104 }
105 }
106
107 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
108 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
109
Chris Craik2507c342015-05-04 14:36:49 -0700110 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
111
John Reck1bcacfd2017-11-03 10:12:19 -0700112 debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700113
John Reckd04794a2015-05-08 10:04:36 -0700114 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700115 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
116 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700117
John Reckc7cd9cf2016-03-28 10:38:19 -0700118 filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
119
John Reck6afa0092018-03-01 17:28:35 -0800120 skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400121
Stan Iliev02daab62018-06-29 15:16:11 -0400122 SkAndroidFrameworkTraceUtil::setEnableTracing(
123 property_get_bool(PROPERTY_SKIA_ATRACE_ENABLED, false));
124
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800125 runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
126
John Reckcf185f52019-04-11 16:11:24 -0700127 defaultRenderAhead = std::max(-1, std::min(2, property_get_int(PROPERTY_RENDERAHEAD,
128 render_ahead().value_or(0))));
John Reck4d527222019-03-13 16:25:20 -0700129
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500130 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700131}
132
133void Properties::overrideProperty(const char* name, const char* value) {
134 if (!strcmp(name, "disableProfileBars")) {
135 sDisableProfileBars = !strcmp(value, "true");
136 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
137 return;
138 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700139 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700140 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
141 return;
142 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700143 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700144 ALOGD("lightRadius = %.2f", overrideLightRadius);
145 return;
146 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700147 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700148 ALOGD("lightPos Y = %.2f", overrideLightPosY);
149 return;
150 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700151 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700152 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
153 return;
154 } else if (!strcmp(name, "ambientShadowStrength")) {
155 overrideAmbientShadowStrength = atoi(value);
156 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
157 return;
158 } else if (!strcmp(name, "spotShadowStrength")) {
159 overrideSpotShadowStrength = atoi(value);
160 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
161 return;
162 }
163 ALOGD("failed overriding property %s to %s", name, value);
164}
165
166ProfileType Properties::getProfileType() {
167 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
168 return ProfileType::None;
169 return sProfileType;
170}
171
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700172RenderPipelineType Properties::peekRenderPipelineType() {
173 // If sRenderPipelineType has been locked, just return the locked type immediately.
John Reck113ddd92017-11-09 16:21:21 -0800174 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400175 return sRenderPipelineType;
176 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500177 bool useVulkan = use_vulkan().value_or(false);
Stan Iliev03de0742016-07-07 12:35:54 -0400178 char prop[PROPERTY_VALUE_MAX];
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700179 property_get(PROPERTY_RENDERER, prop, useVulkan ? "skiavk" : "skiagl");
John Reck18f442e2018-04-09 16:56:34 -0700180 if (!strcmp(prop, "skiavk")) {
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700181 return RenderPipelineType::SkiaVulkan;
Stan Iliev03de0742016-07-07 12:35:54 -0400182 }
Yiwei Zhang4bf3d9e2019-04-15 16:24:32 -0700183 return RenderPipelineType::SkiaGL;
184}
185
186RenderPipelineType Properties::getRenderPipelineType() {
187 sRenderPipelineType = peekRenderPipelineType();
Stan Iliev03de0742016-07-07 12:35:54 -0400188 return sRenderPipelineType;
189}
190
Greg Daniel98c78da2017-01-04 14:45:56 -0500191void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800192#if !defined(HWUI_GLES_WRAP_ENABLED)
193 // 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) {
197 return;
198 }
199#endif
Greg Daniel98c78da2017-01-04 14:45:56 -0500200 sRenderPipelineType = type;
201}
Greg Daniel98c78da2017-01-04 14:45:56 -0500202
Chris Blume7b8a8082018-11-30 15:51:58 -0800203} // namespace uirenderer
204} // namespace android