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