blob: 083aeb7ed5858192453de0f6bb42511e63ee70f9 [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
John Reck682573c2015-10-30 10:37:35 -070056bool Properties::waitForGpuCompletion = false;
57
Chris Craik9fded232015-11-11 16:42:34 -080058static int property_get_int(const char* key, int defaultValue) {
59 char buf[PROPERTY_VALUE_MAX] = {'\0',};
60
61 if (property_get(key, buf, "") > 0) {
62 return atoi(buf);
63 }
64 return defaultValue;
65}
66
Chris Craikc08820f2015-09-22 14:22:29 -070067static float property_get_float(const char* key, float defaultValue) {
68 char buf[PROPERTY_VALUE_MAX] = {'\0',};
69
Chris Craik9fded232015-11-11 16:42:34 -080070 if (property_get(key, buf, "") > 0) {
Chris Craikc08820f2015-09-22 14:22:29 -070071 return atof(buf);
72 }
73 return defaultValue;
74}
75
Chris Craik2507c342015-05-04 14:36:49 -070076bool Properties::load() {
77 char property[PROPERTY_VALUE_MAX];
78 bool prevDebugLayersUpdates = debugLayersUpdates;
79 bool prevDebugOverdraw = debugOverdraw;
80 StencilClipDebug prevDebugStencilClip = debugStencilClip;
81
82
83 debugOverdraw = false;
84 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
85 INIT_LOGD(" Overdraw debug enabled: %s", property);
86 if (!strcmp(property, "show")) {
87 debugOverdraw = true;
88 overdrawColorSet = OverdrawColorSet::Default;
89 } else if (!strcmp(property, "show_deuteranomaly")) {
90 debugOverdraw = true;
91 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
92 }
93 }
94
95 // See Properties.h for valid values
96 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
97 INIT_LOGD(" Stencil clip debug enabled: %s", property);
98 if (!strcmp(property, "hide")) {
99 debugStencilClip = StencilClipDebug::Hide;
100 } else if (!strcmp(property, "highlight")) {
101 debugStencilClip = StencilClipDebug::ShowHighlight;
102 } else if (!strcmp(property, "region")) {
103 debugStencilClip = StencilClipDebug::ShowRegion;
104 }
105 } else {
106 debugStencilClip = StencilClipDebug::Hide;
107 }
108
109 sProfileType = ProfileType::None;
110 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
111 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
112 sProfileType = ProfileType::Bars;
113 } else if (!strcmp(property, "true")) {
114 sProfileType = ProfileType::Console;
115 }
116 }
117
118 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
119 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
120
121 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
122 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
123
124 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
125 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
126
127 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
128
Chris Craik9fded232015-11-11 16:42:34 -0800129 debugLevel = (DebugLevel) property_get_int(PROPERTY_DEBUG, kDebugDisabled);
Chris Craik2507c342015-05-04 14:36:49 -0700130
John Reckd04794a2015-05-08 10:04:36 -0700131 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700132 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
133 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700134
Chris Craikc08820f2015-09-22 14:22:29 -0700135 textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
Chris Craik9fded232015-11-11 16:42:34 -0800136 layerPoolSize = MB(property_get_float(PROPERTY_LAYER_CACHE_SIZE, DEFAULT_LAYER_CACHE_SIZE));
Chris Craikc08820f2015-09-22 14:22:29 -0700137
Chris Craik2507c342015-05-04 14:36:49 -0700138 return (prevDebugLayersUpdates != debugLayersUpdates)
139 || (prevDebugOverdraw != debugOverdraw)
140 || (prevDebugStencilClip != debugStencilClip);
141}
142
143void Properties::overrideProperty(const char* name, const char* value) {
144 if (!strcmp(name, "disableProfileBars")) {
145 sDisableProfileBars = !strcmp(value, "true");
146 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
147 return;
148 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700149 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700150 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
151 return;
152 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700153 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700154 ALOGD("lightRadius = %.2f", overrideLightRadius);
155 return;
156 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700157 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700158 ALOGD("lightPos Y = %.2f", overrideLightPosY);
159 return;
160 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700161 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700162 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
163 return;
164 } else if (!strcmp(name, "ambientShadowStrength")) {
165 overrideAmbientShadowStrength = atoi(value);
166 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
167 return;
168 } else if (!strcmp(name, "spotShadowStrength")) {
169 overrideSpotShadowStrength = atoi(value);
170 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
171 return;
172 }
173 ALOGD("failed overriding property %s to %s", name, value);
174}
175
176ProfileType Properties::getProfileType() {
177 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
178 return ProfileType::None;
179 return sProfileType;
180}
181
182}; // namespace uirenderer
183}; // namespace android