blob: 7b143224f72823caf229e2fc11153fe4a3d8962e [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;
John Reckec100972018-04-05 16:41:41 -070039bool Properties::usePresentTime = true;
Chris Craik2507c342015-05-04 14:36:49 -070040
41DebugLevel Properties::debugLevel = kDebugDisabled;
42OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
43StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
44
45float Properties::overrideLightRadius = -1.0f;
46float Properties::overrideLightPosY = -1.0f;
47float Properties::overrideLightPosZ = -1.0f;
48float Properties::overrideAmbientRatio = -1.0f;
49int Properties::overrideAmbientShadowStrength = -1;
50int Properties::overrideSpotShadowStrength = -1;
51
52ProfileType Properties::sProfileType = ProfileType::None;
53bool Properties::sDisableProfileBars = false;
Stan Iliev03de0742016-07-07 12:35:54 -040054RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized;
John Reck938e8842017-08-24 13:41:59 -070055bool Properties::enableHighContrastText = false;
Chris Craik2507c342015-05-04 14:36:49 -070056
John Reck682573c2015-10-30 10:37:35 -070057bool Properties::waitForGpuCompletion = false;
John Reckf1480762016-07-03 18:28:25 -070058bool Properties::forceDrawFrame = false;
John Reck682573c2015-10-30 10:37:35 -070059
John Reckc7cd9cf2016-03-28 10:38:19 -070060bool Properties::filterOutTestOverhead = false;
John Recka8963062017-06-14 10:47:50 -070061bool Properties::disableVsync = false;
Stan Ilieve9d00122017-09-19 12:07:10 -040062bool Properties::skpCaptureEnabled = false;
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;
86 StencilClipDebug prevDebugStencilClip = debugStencilClip;
87
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
100 // See Properties.h for valid values
101 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
102 INIT_LOGD(" Stencil clip debug enabled: %s", property);
103 if (!strcmp(property, "hide")) {
104 debugStencilClip = StencilClipDebug::Hide;
105 } else if (!strcmp(property, "highlight")) {
106 debugStencilClip = StencilClipDebug::ShowHighlight;
107 } else if (!strcmp(property, "region")) {
108 debugStencilClip = StencilClipDebug::ShowRegion;
109 }
110 } else {
111 debugStencilClip = StencilClipDebug::Hide;
112 }
113
114 sProfileType = ProfileType::None;
115 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
116 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
117 sProfileType = ProfileType::Bars;
118 } else if (!strcmp(property, "true")) {
119 sProfileType = ProfileType::Console;
120 }
121 }
122
123 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
124 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
125
126 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
127 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
128
129 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
130 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
131
132 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
133
John Reck1bcacfd2017-11-03 10:12:19 -0700134 debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700135
John Reckd04794a2015-05-08 10:04:36 -0700136 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700137 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
138 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckec100972018-04-05 16:41:41 -0700139 usePresentTime = property_get_bool(PROPERTY_USE_PRESENT_TIME, true);
John Reckd04794a2015-05-08 10:04:36 -0700140
John Reckc7cd9cf2016-03-28 10:38:19 -0700141 filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false);
142
John Reck6afa0092018-03-01 17:28:35 -0800143 skpCaptureEnabled = debuggingEnabled && property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false);
Stan Ilieve9d00122017-09-19 12:07:10 -0400144
Lingfeng Yang3a9f2232018-01-24 10:40:18 -0800145 runningInEmulator = property_get_bool(PROPERTY_QEMU_KERNEL, false);
146
John Reck1bcacfd2017-11-03 10:12:19 -0700147 return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw) ||
148 (prevDebugStencilClip != debugStencilClip);
Chris Craik2507c342015-05-04 14:36:49 -0700149}
150
151void Properties::overrideProperty(const char* name, const char* value) {
152 if (!strcmp(name, "disableProfileBars")) {
153 sDisableProfileBars = !strcmp(value, "true");
154 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
155 return;
156 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700157 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700158 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
159 return;
160 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700161 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700162 ALOGD("lightRadius = %.2f", overrideLightRadius);
163 return;
164 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700165 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700166 ALOGD("lightPos Y = %.2f", overrideLightPosY);
167 return;
168 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700169 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700170 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
171 return;
172 } else if (!strcmp(name, "ambientShadowStrength")) {
173 overrideAmbientShadowStrength = atoi(value);
174 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
175 return;
176 } else if (!strcmp(name, "spotShadowStrength")) {
177 overrideSpotShadowStrength = atoi(value);
178 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
179 return;
180 }
181 ALOGD("failed overriding property %s to %s", name, value);
182}
183
184ProfileType Properties::getProfileType() {
185 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
186 return ProfileType::None;
187 return sProfileType;
188}
189
Stan Iliev03de0742016-07-07 12:35:54 -0400190RenderPipelineType Properties::getRenderPipelineType() {
John Reck113ddd92017-11-09 16:21:21 -0800191 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
Stan Iliev03de0742016-07-07 12:35:54 -0400192 return sRenderPipelineType;
193 }
194 char prop[PROPERTY_VALUE_MAX];
Derek Sollenberger04f1f012017-07-24 14:21:16 -0400195 property_get(PROPERTY_RENDERER, prop, "skiagl");
John Reck1bcacfd2017-11-03 10:12:19 -0700196 if (!strcmp(prop, "skiagl")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800197 ALOGD("Skia GL Pipeline");
Stan Iliev03de0742016-07-07 12:35:54 -0400198 sRenderPipelineType = RenderPipelineType::SkiaGL;
John Reck1bcacfd2017-11-03 10:12:19 -0700199 } else if (!strcmp(prop, "skiavk")) {
Chris Craik6e66b392017-02-21 12:41:49 -0800200 ALOGD("Skia Vulkan Pipeline");
Stan Iliev8a33e402016-07-08 09:57:49 -0400201 sRenderPipelineType = RenderPipelineType::SkiaVulkan;
John Reck1bcacfd2017-11-03 10:12:19 -0700202 } else { //"opengl"
Chris Craik6e66b392017-02-21 12:41:49 -0800203 ALOGD("HWUI GL Pipeline");
Stan Iliev03de0742016-07-07 12:35:54 -0400204 sRenderPipelineType = RenderPipelineType::OpenGL;
205 }
206 return sRenderPipelineType;
207}
208
Greg Daniel98c78da2017-01-04 14:45:56 -0500209void Properties::overrideRenderPipelineType(RenderPipelineType type) {
John Reck113ddd92017-11-09 16:21:21 -0800210#if !defined(HWUI_GLES_WRAP_ENABLED)
211 // If we're doing actual rendering then we can't change the renderer after it's been set.
212 // Unit tests can freely change this as often as it wants, though, as there's no actual
213 // GL rendering happening
214 if (sRenderPipelineType != RenderPipelineType::NotInitialized) {
215 return;
216 }
217#endif
Greg Daniel98c78da2017-01-04 14:45:56 -0500218 sRenderPipelineType = type;
219}
Greg Daniel98c78da2017-01-04 14:45:56 -0500220
Derek Sollenberger0df62092016-09-27 16:04:42 -0400221bool Properties::isSkiaEnabled() {
222 auto renderType = getRenderPipelineType();
John Reck1bcacfd2017-11-03 10:12:19 -0700223 return RenderPipelineType::SkiaGL == renderType || RenderPipelineType::SkiaVulkan == renderType;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400224}
225
John Reck1bcacfd2017-11-03 10:12:19 -0700226}; // namespace uirenderer
227}; // namespace android