blob: 1f5324440477b059f197d50ecd5c2fe70d110391 [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"
Chris Craik2507c342015-05-04 14:36:49 -070021
John Reck6b507802015-11-03 10:09:59 -080022#include <algorithm>
23#include <cstdlib>
Chris Craik2507c342015-05-04 14:36:49 -070024
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070025#include <cutils/compiler.h>
26#include <cutils/properties.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070027#include <log/log.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070028
Chris Craik2507c342015-05-04 14:36:49 -070029namespace android {
30namespace uirenderer {
31
Chris Craik2507c342015-05-04 14:36:49 -070032bool Properties::debugLayersUpdates = false;
33bool Properties::debugOverdraw = false;
34bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070035bool Properties::skipEmptyFrames = true;
John Reck149173d2015-08-10 09:52:29 -070036bool Properties::useBufferAge = true;
37bool Properties::enablePartialUpdates = true;
Chris Craik2507c342015-05-04 14:36:49 -070038
39DebugLevel Properties::debugLevel = kDebugDisabled;
40OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
Chris Craik2507c342015-05-04 14:36:49 -070041
42float Properties::overrideLightRadius = -1.0f;
43float Properties::overrideLightPosY = -1.0f;
44float Properties::overrideLightPosZ = -1.0f;
45float Properties::overrideAmbientRatio = -1.0f;
46int Properties::overrideAmbientShadowStrength = -1;
47int Properties::overrideSpotShadowStrength = -1;
48
49ProfileType Properties::sProfileType = ProfileType::None;
50bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040051RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070052bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070053
John Reck682573c2015-10-30 10:37:35 -070054bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070055bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070056
John Reckc7cd9cf2016-03-28 10:38:19 -070057bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070058bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040059bool Properties::skpCaptureEnabled = false;
John Reck9ce2bf72018-07-02 18:33:32 -070060bool Properties::forceDarkMode = false;
John Reck57119112018-10-25 15:25:51 -070061bool Properties::enableForceDarkSupport = true;
John Reck9f516442017-09-25 10:27:21 -070062bool Properties::enableRTAnimations = true;
John Reckc7cd9cf2016-03-28 10:38:19 -070063
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080064bool Properties::runningInEmulator = false;
John Reck6afa0092018-03-01 17:28:35 -080065bool Properties::debuggingEnabled = false;
John Reck56428472018-03-16 17:27:17 -070066bool Properties::isolatedProcess = false;
Lingfeng Yang3a9f2232018-01-24 10:40:18 -080067
Jorim Jaggi767e25e2018-04-04 23:07:35 +020068int Properties::contextPriority = 0;
69
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 Reck9ce2bf72018-07-02 18:33:32 -0700127 forceDarkMode = property_get_bool(PROPERTY_FORCE_DARK, false);
128
John Reck57119112018-10-25 15:25:51 -0700129 enableForceDarkSupport = property_get_bool(PROPERTY_ENABLE_FORCE_DARK, true);
John Reckbb3a3582018-09-26 11:21:08 -0700130
Derek Sollenbergerfd1c8792018-12-04 16:22:58 -0500131 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
Chris Craik2507c342015-05-04 14:36:49 -0700132}
133
134void Properties::overrideProperty(const char* name, const char* value) {
135 if (!strcmp(name, "disableProfileBars")) {
136 sDisableProfileBars = !strcmp(value, "true");
137 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
138 return;
139 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700140 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700141 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
142 return;
143 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700144 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700145 ALOGD("lightRadius = %.2f", overrideLightRadius);
146 return;
147 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700148 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700149 ALOGD("lightPos Y = %.2f", overrideLightPosY);
150 return;
151 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700152 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700153 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
154 return;
155 } else if (!strcmp(name, "ambientShadowStrength")) {
156 overrideAmbientShadowStrength = atoi(value);
157 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
158 return;
159 } else if (!strcmp(name, "spotShadowStrength")) {
160 overrideSpotShadowStrength = atoi(value);
161 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
162 return;
163 }
164 ALOGD("failed overriding property %s to %s", name, value);
165}
166
167ProfileType Properties::getProfileType() {
168 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
169 return ProfileType::None;
170 return sProfileType;
171}
172
Stan Iliev03de0742016-07-07 12:35:54 -0400173RenderPipelineType Properties::getRenderPipelineType() {
John Reck113ddd92017-11-09 16:21:21 -0800174 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400175 return sRenderPipelineType;
176 }
177 char prop[PROPERTY_VALUE_MAX];
Derek Sollenberger04f1f012017-07-24 14:21:16 -0400178 property_get(PROPERTY_RENDERER, prop, "skiagl");
John Reck18f442e2018-04-09 16:56:34 -0700179 if (!strcmp(prop, "skiavk")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800180 ALOGD("Skia Vulkan Pipeline");
Stan Iliev8a33e402016-07-08 09:57:49 -0400181 sRenderPipelineType = RenderPipelineType::SkiaVulkan;
John Reck18f442e2018-04-09 16:56:34 -0700182 } else { //"skiagl"
183 ALOGD("Skia GL Pipeline");
184 sRenderPipelineType = RenderPipelineType::SkiaGL;
Stan Iliev03de0742016-07-07 12:35:54 -0400185 }
186 return sRenderPipelineType;
187}
188
Greg Daniel98c78da2017-01-04 14:45:56 -0500189void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800190#if !defined(HWUI_GLES_WRAP_ENABLED)
191 // If we're doing actual rendering then we can't change the renderer after it's been set.
192 // Unit tests can freely change this as often as it wants, though, as there's no actual
193 // GL rendering happening
194 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
195 return;
196 }
197#endif
Greg Daniel98c78da2017-01-04 14:45:56 -0500198 sRenderPipelineType = type;
199}
Greg Daniel98c78da2017-01-04 14:45:56 -0500200
John Reck1bcacfd2017-11-03 10:12:19 -0700201}; // namespace uirenderer
202}; // namespace android