blob: bbd8c7226ab2250e3a68951917324c04bcf607ab [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 Craik48a8f432016-02-05 15:59:29 -080040
41int Properties::fboCacheSize = DEFAULT_FBO_CACHE_SIZE;
42int Properties::gradientCacheSize = MB(DEFAULT_GRADIENT_CACHE_SIZE);
43int Properties::layerPoolSize = MB(DEFAULT_LAYER_CACHE_SIZE);
44int Properties::patchCacheSize = KB(DEFAULT_PATCH_CACHE_SIZE);
45int Properties::pathCacheSize = MB(DEFAULT_PATH_CACHE_SIZE);
46int Properties::renderBufferCacheSize = MB(DEFAULT_RENDER_BUFFER_CACHE_SIZE);
47int Properties::tessellationCacheSize = MB(DEFAULT_VERTEX_CACHE_SIZE);
48int Properties::textDropShadowCacheSize = MB(DEFAULT_DROP_SHADOW_CACHE_SIZE);
49int Properties::textureCacheSize = MB(DEFAULT_TEXTURE_CACHE_SIZE);
50
51float Properties::textureCacheFlushRate = DEFAULT_TEXTURE_CACHE_FLUSH_RATE;
Chris Craikc08820f2015-09-22 14:22:29 -070052
Chris Craik2507c342015-05-04 14:36:49 -070053DebugLevel Properties::debugLevel = kDebugDisabled;
54OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
55StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
56
57float Properties::overrideLightRadius = -1.0f;
58float Properties::overrideLightPosY = -1.0f;
59float Properties::overrideLightPosZ = -1.0f;
60float Properties::overrideAmbientRatio = -1.0f;
61int Properties::overrideAmbientShadowStrength = -1;
62int Properties::overrideSpotShadowStrength = -1;
63
64ProfileType Properties::sProfileType = ProfileType::None;
65bool Properties::sDisableProfileBars = false;
66
John Reck682573c2015-10-30 10:37:35 -070067bool Properties::waitForGpuCompletion = false;
68
Chris Craik9fded232015-11-11 16:42:34 -080069static int property_get_int(const char* key, int defaultValue) {
70 char buf[PROPERTY_VALUE_MAX] = {'\0',};
71
72 if (property_get(key, buf, "") > 0) {
73 return atoi(buf);
74 }
75 return defaultValue;
76}
77
Chris Craikc08820f2015-09-22 14:22:29 -070078static float property_get_float(const char* key, float defaultValue) {
79 char buf[PROPERTY_VALUE_MAX] = {'\0',};
80
Chris Craik9fded232015-11-11 16:42:34 -080081 if (property_get(key, buf, "") > 0) {
Chris Craikc08820f2015-09-22 14:22:29 -070082 return atof(buf);
83 }
84 return defaultValue;
85}
86
Chris Craik2507c342015-05-04 14:36:49 -070087bool Properties::load() {
88 char property[PROPERTY_VALUE_MAX];
89 bool prevDebugLayersUpdates = debugLayersUpdates;
90 bool prevDebugOverdraw = debugOverdraw;
91 StencilClipDebug prevDebugStencilClip = debugStencilClip;
92
Chris Craik2507c342015-05-04 14:36:49 -070093 debugOverdraw = false;
94 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
95 INIT_LOGD(" Overdraw debug enabled: %s", property);
96 if (!strcmp(property, "show")) {
97 debugOverdraw = true;
98 overdrawColorSet = OverdrawColorSet::Default;
99 } else if (!strcmp(property, "show_deuteranomaly")) {
100 debugOverdraw = true;
101 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
102 }
103 }
104
105 // See Properties.h for valid values
106 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
107 INIT_LOGD(" Stencil clip debug enabled: %s", property);
108 if (!strcmp(property, "hide")) {
109 debugStencilClip = StencilClipDebug::Hide;
110 } else if (!strcmp(property, "highlight")) {
111 debugStencilClip = StencilClipDebug::ShowHighlight;
112 } else if (!strcmp(property, "region")) {
113 debugStencilClip = StencilClipDebug::ShowRegion;
114 }
115 } else {
116 debugStencilClip = StencilClipDebug::Hide;
117 }
118
119 sProfileType = ProfileType::None;
120 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
121 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
122 sProfileType = ProfileType::Bars;
123 } else if (!strcmp(property, "true")) {
124 sProfileType = ProfileType::Console;
125 }
126 }
127
128 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
129 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
130
131 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
132 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
133
134 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
135 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
136
137 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
138
Chris Craik9fded232015-11-11 16:42:34 -0800139 debugLevel = (DebugLevel) property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700140
John Reckd04794a2015-05-08 10:04:36 -0700141 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700142 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
143 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700144
Chris Craikc08820f2015-09-22 14:22:29 -0700145 textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
Chris Craik48a8f432016-02-05 15:59:29 -0800146
147 fboCacheSize = property_get_int(PROPERTY_FBO_CACHE_SIZE, DEFAULT_FBO_CACHE_SIZE);
148 gradientCacheSize = MB(property_get_float(PROPERTY_GRADIENT_CACHE_SIZE, DEFAULT_GRADIENT_CACHE_SIZE));
Chris Craik9fded232015-11-11 16:42:34 -0800149 layerPoolSize = MB(property_get_float(PROPERTY_LAYER_CACHE_SIZE, DEFAULT_LAYER_CACHE_SIZE));
Chris Craik48a8f432016-02-05 15:59:29 -0800150 patchCacheSize = KB(property_get_float(PROPERTY_PATCH_CACHE_SIZE, DEFAULT_PATCH_CACHE_SIZE));
151 pathCacheSize = MB(property_get_float(PROPERTY_PATH_CACHE_SIZE, DEFAULT_PATH_CACHE_SIZE));
152 renderBufferCacheSize = MB(property_get_float(PROPERTY_RENDER_BUFFER_CACHE_SIZE, DEFAULT_RENDER_BUFFER_CACHE_SIZE));
153 tessellationCacheSize = MB(property_get_float(PROPERTY_VERTEX_CACHE_SIZE, DEFAULT_VERTEX_CACHE_SIZE));
154 textDropShadowCacheSize = MB(property_get_float(PROPERTY_DROP_SHADOW_CACHE_SIZE, DEFAULT_DROP_SHADOW_CACHE_SIZE));
155 textureCacheSize = MB(property_get_float(PROPERTY_TEXTURE_CACHE_SIZE, DEFAULT_TEXTURE_CACHE_SIZE));
156 textureCacheFlushRate = std::max(0.0f, std::min(1.0f,
157 property_get_float(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, DEFAULT_TEXTURE_CACHE_FLUSH_RATE)));
Chris Craikc08820f2015-09-22 14:22:29 -0700158
Chris Craik2507c342015-05-04 14:36:49 -0700159 return (prevDebugLayersUpdates != debugLayersUpdates)
160 || (prevDebugOverdraw != debugOverdraw)
161 || (prevDebugStencilClip != debugStencilClip);
162}
163
164void Properties::overrideProperty(const char* name, const char* value) {
165 if (!strcmp(name, "disableProfileBars")) {
166 sDisableProfileBars = !strcmp(value, "true");
167 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
168 return;
169 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700170 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700171 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
172 return;
173 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700174 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700175 ALOGD("lightRadius = %.2f", overrideLightRadius);
176 return;
177 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700178 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700179 ALOGD("lightPos Y = %.2f", overrideLightPosY);
180 return;
181 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700182 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700183 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
184 return;
185 } else if (!strcmp(name, "ambientShadowStrength")) {
186 overrideAmbientShadowStrength = atoi(value);
187 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
188 return;
189 } else if (!strcmp(name, "spotShadowStrength")) {
190 overrideSpotShadowStrength = atoi(value);
191 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
192 return;
193 }
194 ALOGD("failed overriding property %s to %s", name, value);
195}
196
197ProfileType Properties::getProfileType() {
198 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
199 return ProfileType::None;
200 return sProfileType;
201}
202
203}; // namespace uirenderer
204}; // namespace android