blob: 0a6c45beedf95311d7380e945d13e8c29fc5ecef [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"
Chris Craik2507c342015-05-04 14:36:49 -070020
John Reck6b507802015-11-03 10:09:59 -080021#include <algorithm>
22#include <cstdlib>
Chris Craik2507c342015-05-04 14:36:49 -070023
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070024#include <cutils/compiler.h>
25#include <cutils/properties.h>
Mark Salyzyn96bf5982016-09-28 16:15:30 -070026#include <log/log.h>
Mark Salyzyn52eb4e02016-09-28 16:15:30 -070027
Chris Craik2507c342015-05-04 14:36:49 -070028namespace android {
29namespace uirenderer {
30
31bool Properties::drawDeferDisabled = false;
32bool Properties::drawReorderDisabled = false;
33bool 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;
42StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
43
44float Properties::overrideLightRadius = -1.0f;
45float Properties::overrideLightPosY = -1.0f;
46float Properties::overrideLightPosZ = -1.0f;
47float Properties::overrideAmbientRatio = -1.0f;
48int Properties::overrideAmbientShadowStrength = -1;
49int Properties::overrideSpotShadowStrength = -1;
50
51ProfileType Properties::sProfileType = ProfileType::None;
52bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040053RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070054bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070055
John Reck682573c2015-10-30 10:37:35 -070056bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070057bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070058
John Reckc7cd9cf2016-03-28 10:38:19 -070059bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070060bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040061bool Properties::skpCaptureEnabled = false;
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;
85 StencilClipDebug prevDebugStencilClip = debugStencilClip;
86
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
99 // See Properties.h for valid values
100 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
101 INIT_LOGD(" Stencil clip debug enabled: %s", property);
102 if (!strcmp(property, "hide")) {
103 debugStencilClip = StencilClipDebug::Hide;
104 } else if (!strcmp(property, "highlight")) {
105 debugStencilClip = StencilClipDebug::ShowHighlight;
106 } else if (!strcmp(property, "region")) {
107 debugStencilClip = StencilClipDebug::ShowRegion;
108 }
109 } else {
110 debugStencilClip = StencilClipDebug::Hide;
111 }
112
113 sProfileType = ProfileType::None;
114 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
115 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
116 sProfileType = ProfileType::Bars;
117 } else if (!strcmp(property, "true")) {
118 sProfileType = ProfileType::Console;
119 }
120 }
121
122 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
123 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
124
125 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
126 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
127
128 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
129 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
130
131 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
132
John Reck1bcacfd2017-11-03 10:12:19 -0700133 debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700134
John Reckd04794a2015-05-08 10:04:36 -0700135 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700136 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
137 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700138
John Reckc7cd9cf2016-03-28 10:38:19 -0700139 filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
140
John Reck6afa0092018-03-01 17:28:35 -0800141 skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400142
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800143 runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
144
John Reck1bcacfd2017-11-03 10:12:19 -0700145 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw) ||
146 (prevDebugStencilClip != debugStencilClip);
Chris Craik2507c342015-05-04 14:36:49 -0700147}
148
149void Properties::overrideProperty(const char* name, const char* value) {
150 if (!strcmp(name, "disableProfileBars")) {
151 sDisableProfileBars = !strcmp(value, "true");
152 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
153 return;
154 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700155 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700156 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
157 return;
158 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700159 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700160 ALOGD("lightRadius = %.2f", overrideLightRadius);
161 return;
162 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700163 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700164 ALOGD("lightPos Y = %.2f", overrideLightPosY);
165 return;
166 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700167 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700168 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
169 return;
170 } else if (!strcmp(name, "ambientShadowStrength")) {
171 overrideAmbientShadowStrength = atoi(value);
172 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
173 return;
174 } else if (!strcmp(name, "spotShadowStrength")) {
175 overrideSpotShadowStrength = atoi(value);
176 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
177 return;
178 }
179 ALOGD("failed overriding property %s to %s", name, value);
180}
181
182ProfileType Properties::getProfileType() {
183 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
184 return ProfileType::None;
185 return sProfileType;
186}
187
Stan Iliev03de0742016-07-07 12:35:54 -0400188RenderPipelineType Properties::getRenderPipelineType() {
John Reck113ddd92017-11-09 16:21:21 -0800189 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400190 return sRenderPipelineType;
191 }
192 char prop[PROPERTY_VALUE_MAX];
Derek Sollenberger04f1f012017-07-24 14:21:16 -0400193 property_get(PROPERTY_RENDERER, prop, "skiagl");
John Reck1bcacfd2017-11-03 10:12:19 -0700194 if (!strcmp(prop, "skiagl")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800195 ALOGD("Skia GL Pipeline");
Stan Iliev03de0742016-07-07 12:35:54 -0400196 sRenderPipelineType = RenderPipelineType::SkiaGL;
John Reck1bcacfd2017-11-03 10:12:19 -0700197 } else if (!strcmp(prop, "skiavk")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800198 ALOGD("Skia Vulkan Pipeline");
Stan Iliev8a33e402016-07-08 09:57:49 -0400199 sRenderPipelineType = RenderPipelineType::SkiaVulkan;
John Reck1bcacfd2017-11-03 10:12:19 -0700200 } else { //"opengl"
Chris Craik6e66b392017-02-21 12:41:49 -0800201 ALOGD("HWUI GL Pipeline");
Stan Iliev03de0742016-07-07 12:35:54 -0400202 sRenderPipelineType = RenderPipelineType::OpenGL;
203 }
204 return sRenderPipelineType;
205}
206
Greg Daniel98c78dad2017-01-04 14:45:56 -0500207void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800208#if !defined(HWUI_GLES_WRAP_ENABLED)
209 // If we're doing actual rendering then we can't change the renderer after it's been set.
210 // Unit tests can freely change this as often as it wants, though, as there's no actual
211 // GL rendering happening
212 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
213 return;
214 }
215#endif
Greg Daniel98c78dad2017-01-04 14:45:56 -0500216 sRenderPipelineType = type;
217}
Greg Daniel98c78dad2017-01-04 14:45:56 -0500218
Derek Sollenberger0df62092016-09-27 16:04:42 -0400219bool Properties::isSkiaEnabled() {
220 auto renderType = getRenderPipelineType();
John Reck1bcacfd2017-11-03 10:12:19 -0700221 return RenderPipelineType::SkiaGL == renderType || RenderPipelineType::SkiaVulkan == renderType;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400222}
223
John Reck1bcacfd2017-11-03 10:12:19 -0700224}; // namespace uirenderer
225}; // namespace android