blob: 36a8dac9d0c1fd74ec36a32797bd4a9c5724b467 [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
Chris Craike6a15ee2015-07-07 18:42:17 -070020#include <algorithm>
Chris Craik2507c342015-05-04 14:36:49 -070021#include <cutils/log.h>
22
23namespace android {
24namespace uirenderer {
25
26bool Properties::drawDeferDisabled = false;
27bool Properties::drawReorderDisabled = false;
28bool Properties::debugLayersUpdates = false;
29bool Properties::debugOverdraw = false;
30bool Properties::showDirtyRegions = false;
John Reckd04794a2015-05-08 10:04:36 -070031bool Properties::skipEmptyFrames = true;
John Reck4cd44f82015-05-27 10:26:10 -070032bool Properties::swapBuffersWithDamage = true;
John Reck149173d2015-08-10 09:52:29 -070033bool Properties::useBufferAge = true;
34bool Properties::enablePartialUpdates = true;
Chris Craik2507c342015-05-04 14:36:49 -070035
Chris Craikc08820f2015-09-22 14:22:29 -070036float Properties::textGamma = DEFAULT_TEXT_GAMMA;
37
Chris Craik2507c342015-05-04 14:36:49 -070038DebugLevel Properties::debugLevel = kDebugDisabled;
39OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
40StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
41
42float Properties::overrideLightRadius = -1.0f;
43float Properties::overrideLightPosY = -1.0f;
44float Properties::overrideLightPosZ = -1.0f;
45float Properties::overrideAmbientRatio = -1.0f;
46int Properties::overrideAmbientShadowStrength = -1;
47int Properties::overrideSpotShadowStrength = -1;
48
49ProfileType Properties::sProfileType = ProfileType::None;
50bool Properties::sDisableProfileBars = false;
51
Chris Craikc08820f2015-09-22 14:22:29 -070052static float property_get_float(const char* key, float defaultValue) {
53 char buf[PROPERTY_VALUE_MAX] = {'\0',};
54
55 if (property_get(PROPERTY_PROFILE, buf, "") > 0) {
56 return atof(buf);
57 }
58 return defaultValue;
59}
60
Chris Craik2507c342015-05-04 14:36:49 -070061bool Properties::load() {
62 char property[PROPERTY_VALUE_MAX];
63 bool prevDebugLayersUpdates = debugLayersUpdates;
64 bool prevDebugOverdraw = debugOverdraw;
65 StencilClipDebug prevDebugStencilClip = debugStencilClip;
66
67
68 debugOverdraw = false;
69 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
70 INIT_LOGD(" Overdraw debug enabled: %s", property);
71 if (!strcmp(property, "show")) {
72 debugOverdraw = true;
73 overdrawColorSet = OverdrawColorSet::Default;
74 } else if (!strcmp(property, "show_deuteranomaly")) {
75 debugOverdraw = true;
76 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
77 }
78 }
79
80 // See Properties.h for valid values
81 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
82 INIT_LOGD(" Stencil clip debug enabled: %s", property);
83 if (!strcmp(property, "hide")) {
84 debugStencilClip = StencilClipDebug::Hide;
85 } else if (!strcmp(property, "highlight")) {
86 debugStencilClip = StencilClipDebug::ShowHighlight;
87 } else if (!strcmp(property, "region")) {
88 debugStencilClip = StencilClipDebug::ShowRegion;
89 }
90 } else {
91 debugStencilClip = StencilClipDebug::Hide;
92 }
93
94 sProfileType = ProfileType::None;
95 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
96 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
97 sProfileType = ProfileType::Bars;
98 } else if (!strcmp(property, "true")) {
99 sProfileType = ProfileType::Console;
100 }
101 }
102
103 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
104 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
105
106 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
107 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
108
109 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
110 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
111
112 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
113
114 debugLevel = kDebugDisabled;
115 if (property_get(PROPERTY_DEBUG, property, nullptr) > 0) {
116 debugLevel = (DebugLevel) atoi(property);
117 }
118
John Reckd04794a2015-05-08 10:04:36 -0700119 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck4cd44f82015-05-27 10:26:10 -0700120 swapBuffersWithDamage = property_get_bool(PROPERTY_SWAP_WITH_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700121 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
122 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700123
Chris Craikc08820f2015-09-22 14:22:29 -0700124 textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
125
Chris Craik2507c342015-05-04 14:36:49 -0700126 return (prevDebugLayersUpdates != debugLayersUpdates)
127 || (prevDebugOverdraw != debugOverdraw)
128 || (prevDebugStencilClip != debugStencilClip);
129}
130
131void Properties::overrideProperty(const char* name, const char* value) {
132 if (!strcmp(name, "disableProfileBars")) {
133 sDisableProfileBars = !strcmp(value, "true");
134 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
135 return;
136 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700137 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700138 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
139 return;
140 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700141 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700142 ALOGD("lightRadius = %.2f", overrideLightRadius);
143 return;
144 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700145 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700146 ALOGD("lightPos Y = %.2f", overrideLightPosY);
147 return;
148 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700149 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700150 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
151 return;
152 } else if (!strcmp(name, "ambientShadowStrength")) {
153 overrideAmbientShadowStrength = atoi(value);
154 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
155 return;
156 } else if (!strcmp(name, "spotShadowStrength")) {
157 overrideSpotShadowStrength = atoi(value);
158 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
159 return;
160 }
161 ALOGD("failed overriding property %s to %s", name, value);
162}
163
164ProfileType Properties::getProfileType() {
165 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
166 return ProfileType::None;
167 return sProfileType;
168}
169
170}; // namespace uirenderer
171}; // namespace android