blob: 0669596b21ca6b5abb7477dcf8f1d83dd6e42b08 [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 */
16#include "Properties.h"
17
18#include "Debug.h"
19
John Reck6b507802015-11-03 10:09:59 -080020#include <cutils/compiler.h>
Chris Craik2507c342015-05-04 14:36:49 -070021#include <cutils/log.h>
John Reck6b507802015-11-03 10:09:59 -080022#include <cutils/properties.h>
23
24#include <algorithm>
25#include <cstdlib>
Chris Craik2507c342015-05-04 14:36:49 -070026
27namespace android {
28namespace uirenderer {
29
30bool Properties::drawDeferDisabled = false;
31bool Properties::drawReorderDisabled = false;
32bool 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
Chris Craikc08820f2015-09-22 14:22:29 -070039float Properties::textGamma = DEFAULT_TEXT_GAMMA;
Chris Craik9fded232015-11-11 16:42:34 -080040int Properties::layerPoolSize = DEFAULT_LAYER_CACHE_SIZE;
Chris Craikc08820f2015-09-22 14:22:29 -070041
Chris Craik2507c342015-05-04 14:36:49 -070042DebugLevel Properties::debugLevel = kDebugDisabled;
43OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
44StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
45
46float Properties::overrideLightRadius = -1.0f;
47float Properties::overrideLightPosY = -1.0f;
48float Properties::overrideLightPosZ = -1.0f;
49float Properties::overrideAmbientRatio = -1.0f;
50int Properties::overrideAmbientShadowStrength = -1;
51int Properties::overrideSpotShadowStrength = -1;
52
53ProfileType Properties::sProfileType = ProfileType::None;
54bool Properties::sDisableProfileBars = false;
55
Chris Craik9fded232015-11-11 16:42:34 -080056static int property_get_int(const char* key, int defaultValue) {
57 char buf[PROPERTY_VALUE_MAX] = {'\0',};
58
59 if (property_get(key, buf, "") > 0) {
60 return atoi(buf);
61 }
62 return defaultValue;
63}
64
Chris Craikc08820f2015-09-22 14:22:29 -070065static float property_get_float(const char* key, float defaultValue) {
66 char buf[PROPERTY_VALUE_MAX] = {'\0',};
67
Chris Craik9fded232015-11-11 16:42:34 -080068 if (property_get(key, buf, "") > 0) {
Chris Craikc08820f2015-09-22 14:22:29 -070069 return atof(buf);
70 }
71 return defaultValue;
72}
73
Chris Craik2507c342015-05-04 14:36:49 -070074bool Properties::load() {
75 char property[PROPERTY_VALUE_MAX];
76 bool prevDebugLayersUpdates = debugLayersUpdates;
77 bool prevDebugOverdraw = debugOverdraw;
78 StencilClipDebug prevDebugStencilClip = debugStencilClip;
79
80
81 debugOverdraw = false;
82 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
83 INIT_LOGD(" Overdraw debug enabled: %s", property);
84 if (!strcmp(property, "show")) {
85 debugOverdraw = true;
86 overdrawColorSet = OverdrawColorSet::Default;
87 } else if (!strcmp(property, "show_deuteranomaly")) {
88 debugOverdraw = true;
89 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
90 }
91 }
92
93 // See Properties.h for valid values
94 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
95 INIT_LOGD(" Stencil clip debug enabled: %s", property);
96 if (!strcmp(property, "hide")) {
97 debugStencilClip = StencilClipDebug::Hide;
98 } else if (!strcmp(property, "highlight")) {
99 debugStencilClip = StencilClipDebug::ShowHighlight;
100 } else if (!strcmp(property, "region")) {
101 debugStencilClip = StencilClipDebug::ShowRegion;
102 }
103 } else {
104 debugStencilClip = StencilClipDebug::Hide;
105 }
106
107 sProfileType = ProfileType::None;
108 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
109 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
110 sProfileType = ProfileType::Bars;
111 } else if (!strcmp(property, "true")) {
112 sProfileType = ProfileType::Console;
113 }
114 }
115
116 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
117 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
118
119 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
120 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
121
122 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
123 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
124
125 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
126
Chris Craik9fded232015-11-11 16:42:34 -0800127 debugLevel = (DebugLevel) property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700128
John Reckd04794a2015-05-08 10:04:36 -0700129 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700130 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
131 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700132
Chris Craikc08820f2015-09-22 14:22:29 -0700133 textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
Chris Craik9fded232015-11-11 16:42:34 -0800134 layerPoolSize = MB(property_get_float(PROPERTY_LAYER_CACHE_SIZE, DEFAULT_LAYER_CACHE_SIZE));
Chris Craikc08820f2015-09-22 14:22:29 -0700135
Chris Craik2507c342015-05-04 14:36:49 -0700136 return (prevDebugLayersUpdates != debugLayersUpdates)
137 || (prevDebugOverdraw != debugOverdraw)
138 || (prevDebugStencilClip != debugStencilClip);
139}
140
141void Properties::overrideProperty(const char* name, const char* value) {
142 if (!strcmp(name, "disableProfileBars")) {
143 sDisableProfileBars = !strcmp(value, "true");
144 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
145 return;
146 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700147 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700148 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
149 return;
150 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700151 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700152 ALOGD("lightRadius = %.2f", overrideLightRadius);
153 return;
154 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700155 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700156 ALOGD("lightPos Y = %.2f", overrideLightPosY);
157 return;
158 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700159 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700160 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
161 return;
162 } else if (!strcmp(name, "ambientShadowStrength")) {
163 overrideAmbientShadowStrength = atoi(value);
164 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
165 return;
166 } else if (!strcmp(name, "spotShadowStrength")) {
167 overrideSpotShadowStrength = atoi(value);
168 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
169 return;
170 }
171 ALOGD("failed overriding property %s to %s", name, value);
172}
173
174ProfileType Properties::getProfileType() {
175 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
176 return ProfileType::None;
177 return sProfileType;
178}
179
180}; // namespace uirenderer
181}; // namespace android