blob: e81818679f3e2f86098bc7e817db68a4b6f9d268 [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;
40
Chris Craik2507c342015-05-04 14:36:49 -070041DebugLevel 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;
54
Chris Craikc08820f2015-09-22 14:22:29 -070055static float property_get_float(const char* key, float defaultValue) {
56 char buf[PROPERTY_VALUE_MAX] = {'\0',};
57
58 if (property_get(PROPERTY_PROFILE, buf, "") > 0) {
59 return atof(buf);
60 }
61 return defaultValue;
62}
63
Chris Craik2507c342015-05-04 14:36:49 -070064bool Properties::load() {
65 char property[PROPERTY_VALUE_MAX];
66 bool prevDebugLayersUpdates = debugLayersUpdates;
67 bool prevDebugOverdraw = debugOverdraw;
68 StencilClipDebug prevDebugStencilClip = debugStencilClip;
69
70
71 debugOverdraw = false;
72 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
73 INIT_LOGD(" Overdraw debug enabled: %s", property);
74 if (!strcmp(property, "show")) {
75 debugOverdraw = true;
76 overdrawColorSet = OverdrawColorSet::Default;
77 } else if (!strcmp(property, "show_deuteranomaly")) {
78 debugOverdraw = true;
79 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
80 }
81 }
82
83 // See Properties.h for valid values
84 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
85 INIT_LOGD(" Stencil clip debug enabled: %s", property);
86 if (!strcmp(property, "hide")) {
87 debugStencilClip = StencilClipDebug::Hide;
88 } else if (!strcmp(property, "highlight")) {
89 debugStencilClip = StencilClipDebug::ShowHighlight;
90 } else if (!strcmp(property, "region")) {
91 debugStencilClip = StencilClipDebug::ShowRegion;
92 }
93 } else {
94 debugStencilClip = StencilClipDebug::Hide;
95 }
96
97 sProfileType = ProfileType::None;
98 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
99 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
100 sProfileType = ProfileType::Bars;
101 } else if (!strcmp(property, "true")) {
102 sProfileType = ProfileType::Console;
103 }
104 }
105
106 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
107 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
108
109 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
110 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
111
112 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
113 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
114
115 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
116
117 debugLevel = kDebugDisabled;
118 if (property_get(PROPERTY_DEBUG, property, nullptr) > 0) {
119 debugLevel = (DebugLevel) atoi(property);
120 }
121
John Reckd04794a2015-05-08 10:04:36 -0700122 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700123 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
124 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700125
Chris Craikc08820f2015-09-22 14:22:29 -0700126 textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
127
Chris Craik2507c342015-05-04 14:36:49 -0700128 return (prevDebugLayersUpdates != debugLayersUpdates)
129 || (prevDebugOverdraw != debugOverdraw)
130 || (prevDebugStencilClip != debugStencilClip);
131}
132
133void Properties::overrideProperty(const char* name, const char* value) {
134 if (!strcmp(name, "disableProfileBars")) {
135 sDisableProfileBars = !strcmp(value, "true");
136 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
137 return;
138 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700139 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700140 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
141 return;
142 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700143 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700144 ALOGD("lightRadius = %.2f", overrideLightRadius);
145 return;
146 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700147 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700148 ALOGD("lightPos Y = %.2f", overrideLightPosY);
149 return;
150 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700151 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700152 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
153 return;
154 } else if (!strcmp(name, "ambientShadowStrength")) {
155 overrideAmbientShadowStrength = atoi(value);
156 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
157 return;
158 } else if (!strcmp(name, "spotShadowStrength")) {
159 overrideSpotShadowStrength = atoi(value);
160 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
161 return;
162 }
163 ALOGD("failed overriding property %s to %s", name, value);
164}
165
166ProfileType Properties::getProfileType() {
167 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
168 return ProfileType::None;
169 return sProfileType;
170}
171
172}; // namespace uirenderer
173}; // namespace android