blob: 046ffc4da5ea34a84be9abeca261151b15205f40 [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;
70
Chris Craik9fded232015-11-11 16:42:34 -080071static int property_get_int(const char* key, int defaultValue) {
John Reck1bcacfd2017-11-03 10:12:19 -070072 char buf[PROPERTY_VALUE_MAX] = {
73 '\0',
74 };
Chris Craik9fded232015-11-11 16:42:34 -080075
76 if (property_get(key, buf, "") > 0) {
77 return atoi(buf);
78 }
79 return defaultValue;
80}
81
Chris Craik2507c342015-05-04 14:36:49 -070082bool Properties::load() {
83 char property[PROPERTY_VALUE_MAX];
84 bool prevDebugLayersUpdates = debugLayersUpdates;
85 bool prevDebugOverdraw = debugOverdraw;
Chris Craik2507c342015-05-04 14:36:49 -070086
Chris Craik2507c342015-05-04 14:36:49 -070087 debugOverdraw = false;
88 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
89 INIT_LOGD(" Overdraw debug enabled: %s", property);
90 if (!strcmp(property, "show")) {
91 debugOverdraw = true;
92 overdrawColorSet = OverdrawColorSet::Default;
93 } else if (!strcmp(property, "show_deuteranomaly")) {
94 debugOverdraw = true;
95 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
96 }
97 }
98
Chris Craik2507c342015-05-04 14:36:49 -070099 sProfileType = ProfileType::None;
100 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
101 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
102 sProfileType = ProfileType::Bars;
103 } else if (!strcmp(property, "true")) {
104 sProfileType = ProfileType::Console;
105 }
106 }
107
108 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
109 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
110
Chris Craik2507c342015-05-04 14:36:49 -0700111 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
112
John Reck1bcacfd2017-11-03 10:12:19 -0700113 debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700114
John Reckd04794a2015-05-08 10:04:36 -0700115 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700116 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
117 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700118
John Reckc7cd9cf2016-03-28 10:38:19 -0700119 filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
120
John Reck6afa0092018-03-01 17:28:35 -0800121 skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400122
Stan Iliev02daab62018-06-29 15:16:11 -0400123 SkAndroidFrameworkTraceUtil::setEnableTracing(
124 property_get_bool(PROPERTY_SKIA_ATRACE_ENABLED, false));
125
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800126 runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
127
John Reck9ce2bf72018-07-02 18:33:32 -0700128 forceDarkMode = property_get_bool(PROPERTY_FORCE_DARK, false);
129
John Reck57119112018-10-25 15:25:51 -0700130 enableForceDarkSupport = property_get_bool(PROPERTY_ENABLE_FORCE_DARK, true);
John Reckbb3a3582018-09-26 11:21:08 -0700131
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500132 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700133}
134
135void Properties::overrideProperty(const char* name, const char* value) {
136 if (!strcmp(name, "disableProfileBars")) {
137 sDisableProfileBars = !strcmp(value, "true");
138 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
139 return;
140 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700141 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700142 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
143 return;
144 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700145 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700146 ALOGD("lightRadius = %.2f", overrideLightRadius);
147 return;
148 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700149 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700150 ALOGD("lightPos Y = %.2f", overrideLightPosY);
151 return;
152 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700153 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700154 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
155 return;
156 } else if (!strcmp(name, "ambientShadowStrength")) {
157 overrideAmbientShadowStrength = atoi(value);
158 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
159 return;
160 } else if (!strcmp(name, "spotShadowStrength")) {
161 overrideSpotShadowStrength = atoi(value);
162 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
163 return;
164 }
165 ALOGD("failed overriding property %s to %s", name, value);
166}
167
168ProfileType Properties::getProfileType() {
169 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
170 return ProfileType::None;
171 return sProfileType;
172}
173
Stan Iliev03de0742016-07-07 12:35:54 -0400174RenderPipelineType Properties::getRenderPipelineType() {
John Reck113ddd92017-11-09 16:21:21 -0800175 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400176 return sRenderPipelineType;
177 }
Stan Ilievb8811aa52018-11-08 16:25:54 -0500178 bool useVulkan = use_vulkan().value_or(false);
Stan Iliev03de0742016-07-07 12:35:54 -0400179 char prop[PROPERTY_VALUE_MAX];
Stan Ilievb8811aa52018-11-08 16:25:54 -0500180 if (useVulkan) {
181 property_get(PROPERTY_RENDERER, prop, "skiavk");
182 } else {
183 property_get(PROPERTY_RENDERER, prop, "skiagl");
184 }
John Reck18f442e2018-04-09 16:56:34 -0700185 if (!strcmp(prop, "skiavk")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800186 ALOGD("Skia Vulkan Pipeline");
Stan Iliev8a33e402016-07-08 09:57:49 -0400187 sRenderPipelineType = RenderPipelineType::SkiaVulkan;
John Reck18f442e2018-04-09 16:56:34 -0700188 } else { //"skiagl"
189 ALOGD("Skia GL Pipeline");
190 sRenderPipelineType = RenderPipelineType::SkiaGL;
Stan Iliev03de0742016-07-07 12:35:54 -0400191 }
192 return sRenderPipelineType;
193}
194
Greg Daniel98c78da2017-01-04 14:45:56 -0500195void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800196#if !defined(HWUI_GLES_WRAP_ENABLED)
197 // If we're doing actual rendering then we can't change the renderer after it's been set.
198 // Unit tests can freely change this as often as it wants, though, as there's no actual
199 // GL rendering happening
200 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
201 return;
202 }
203#endif
Greg Daniel98c78da2017-01-04 14:45:56 -0500204 sRenderPipelineType = type;
205}
Greg Daniel98c78da2017-01-04 14:45:56 -0500206
Chris Blume7b8a8082018-11-30 15:51:58 -0800207} // namespace uirenderer
208} // namespace android