blob: 9b1f25986d56501a1085d190bf996eb830a20c58 [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 Iliev02daab62018-06-29 15:16:11 -040020#include "SkTraceEventCommon.h"
Stan Ilievb8811aa52018-11-08 16:25:54 -050021#include "HWUIProperties.sysprop.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 Reck9ce2bf72018-07-02 18:33:32 -070061bool Properties::forceDarkMode = false;
John Reck57119112018-10-25 15:25:51 -070062bool Properties::enableForceDarkSupport = true;
John Reck9f516442017-09-25 10:27:21 -070063bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070064
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080065bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080066bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070067bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080068
Jorim Jaggi767e25e2018-04-04 23:07:35 +020069int Properties::contextPriority = 0;
John Reck859f98d2019-03-13 16:25:20 -070070int Properties::defaultRenderAhead = 0;
Jorim Jaggi767e25e2018-04-04 23:07:35 +020071
Chris Craik9fded232015-11-11 16:42:34 -080072static int property_get_int(const char* key, int defaultValue) {
John Reck1bcacfd2017-11-03 10:12:19 -070073 char buf[PROPERTY_VALUE_MAX] = {
74 '\0',
75 };
Chris Craik9fded232015-11-11 16:42:34 -080076
77 if (property_get(key, buf, "") > 0) {
78 return atoi(buf);
79 }
80 return defaultValue;
81}
82
Chris Craik2507c342015-05-04 14:36:49 -070083bool Properties::load() {
84 char property[PROPERTY_VALUE_MAX];
85 bool prevDebugLayersUpdates = debugLayersUpdates;
86 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -070087
Chris Craik2507c342015-05-04 14:36:49 -070088 debugOverdraw = false;
89 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
90 INIT_LOGD(" Overdraw debug enabled: %s", property);
91 if (!strcmp(property, "show")) {
92 debugOverdraw = true;
93 overdrawColorSet = OverdrawColorSet::Default;
94 } else if (!strcmp(property, "show_deuteranomaly")) {
95 debugOverdraw = true;
96 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
97 }
98 }
99
Chris Craik2507c342015-05-04 14:36:49 -0700100 sProfileType = ProfileType::None;
101 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
102 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
103 sProfileType = ProfileType::Bars;
104 } else if (!strcmp(property, "true")) {
105 sProfileType = ProfileType::Console;
106 }
107 }
108
109 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
110 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
111
Chris Craik2507c342015-05-04 14:36:49 -0700112 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
113
John Reck1bcacfd2017-11-03 10:12:19 -0700114 debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700115
John Reckd04794a2015-05-08 10:04:36 -0700116 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700117 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
118 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700119
John Reckc7cd9cf2016-03-28 10:38:19 -0700120 filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
121
John Reck6afa0092018-03-01 17:28:35 -0800122 skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400123
Stan Iliev02daab62018-06-29 15:16:11 -0400124 SkAndroidFrameworkTraceUtil::setEnableTracing(
125 property_get_bool(PROPERTY_SKIA_ATRACE_ENABLED, false));
126
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800127 runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
128
John Reck9ce2bf72018-07-02 18:33:32 -0700129 forceDarkMode = property_get_bool(PROPERTY_FORCE_DARK, false);
130
John Reck57119112018-10-25 15:25:51 -0700131 enableForceDarkSupport = property_get_bool(PROPERTY_ENABLE_FORCE_DARK, true);
John Reckbb3a3582018-09-26 11:21:08 -0700132
John Reck859f98d2019-03-13 16:25:20 -0700133 defaultRenderAhead = std::max(0, std::min(2, property_get_int(PROPERTY_RENDERAHEAD,
134 render_ahead().value_or(0))));
135
136 if (defaultRenderAhead && sRenderPipelineType == RenderPipelineType::SkiaVulkan) {
137 ALOGW("hwui.render_ahead of %d ignored because pipeline is skiavk", defaultRenderAhead);
138 }
139
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500140 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700141}
142
143void Properties::overrideProperty(const char* name, const char* value) {
144 if (!strcmp(name, "disableProfileBars")) {
145 sDisableProfileBars = !strcmp(value, "true");
146 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
147 return;
148 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700149 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700150 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
151 return;
152 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700153 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700154 ALOGD("lightRadius = %.2f", overrideLightRadius);
155 return;
156 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700157 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700158 ALOGD("lightPos Y = %.2f", overrideLightPosY);
159 return;
160 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700161 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700162 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
163 return;
164 } else if (!strcmp(name, "ambientShadowStrength")) {
165 overrideAmbientShadowStrength = atoi(value);
166 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
167 return;
168 } else if (!strcmp(name, "spotShadowStrength")) {
169 overrideSpotShadowStrength = atoi(value);
170 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
171 return;
172 }
173 ALOGD("failed overriding property %s to %s", name, value);
174}
175
176ProfileType Properties::getProfileType() {
177 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
178 return ProfileType::None;
179 return sProfileType;
180}
181
Stan Iliev03de0742016-07-07 12:35:54 -0400182RenderPipelineType Properties::getRenderPipelineType() {
John Reck113ddd92017-11-09 16:21:21 -0800183 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400184 return sRenderPipelineType;
185 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500186 bool useVulkan = use_vulkan().value_or(false);
Stan Iliev03de0742016-07-07 12:35:54 -0400187 char prop[PROPERTY_VALUE_MAX];
Stan Ilievb8811aa52018-11-08 16:25:54 -0500188 if (useVulkan) {
189 property_get(PROPERTY_RENDERER, prop, "skiavk");
190 } else {
191 property_get(PROPERTY_RENDERER, prop, "skiagl");
192 }
John Reck18f442e2018-04-09 16:56:34 -0700193 if (!strcmp(prop, "skiavk")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800194 ALOGD("Skia Vulkan Pipeline");
Stan Iliev8a33e402016-07-08 09:57:49 -0400195 sRenderPipelineType = RenderPipelineType::SkiaVulkan;
John Reck18f442e2018-04-09 16:56:34 -0700196 } else { //"skiagl"
197 ALOGD("Skia GL Pipeline");
198 sRenderPipelineType = RenderPipelineType::SkiaGL;
Stan Iliev03de0742016-07-07 12:35:54 -0400199 }
200 return sRenderPipelineType;
201}
202
Greg Daniel98c78da2017-01-04 14:45:56 -0500203void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800204#if !defined(HWUI_GLES_WRAP_ENABLED)
205 // If we're doing actual rendering then we can't change the renderer after it's been set.
206 // Unit tests can freely change this as often as it wants, though, as there's no actual
207 // GL rendering happening
208 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
209 return;
210 }
211#endif
Greg Daniel98c78da2017-01-04 14:45:56 -0500212 sRenderPipelineType = type;
213}
Greg Daniel98c78da2017-01-04 14:45:56 -0500214
Chris Blume7b8a8082018-11-30 15:51:58 -0800215} // namespace uirenderer
216} // namespace android