blob: fd32b6f80dfa2ce03770ac25409a601b562134e5 [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
20#include <cmath>
21#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;
31
32DebugLevel Properties::debugLevel = kDebugDisabled;
33OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
34StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
35
36float Properties::overrideLightRadius = -1.0f;
37float Properties::overrideLightPosY = -1.0f;
38float Properties::overrideLightPosZ = -1.0f;
39float Properties::overrideAmbientRatio = -1.0f;
40int Properties::overrideAmbientShadowStrength = -1;
41int Properties::overrideSpotShadowStrength = -1;
42
43ProfileType Properties::sProfileType = ProfileType::None;
44bool Properties::sDisableProfileBars = false;
45
46bool Properties::load() {
47 char property[PROPERTY_VALUE_MAX];
48 bool prevDebugLayersUpdates = debugLayersUpdates;
49 bool prevDebugOverdraw = debugOverdraw;
50 StencilClipDebug prevDebugStencilClip = debugStencilClip;
51
52
53 debugOverdraw = false;
54 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
55 INIT_LOGD(" Overdraw debug enabled: %s", property);
56 if (!strcmp(property, "show")) {
57 debugOverdraw = true;
58 overdrawColorSet = OverdrawColorSet::Default;
59 } else if (!strcmp(property, "show_deuteranomaly")) {
60 debugOverdraw = true;
61 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
62 }
63 }
64
65 // See Properties.h for valid values
66 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
67 INIT_LOGD(" Stencil clip debug enabled: %s", property);
68 if (!strcmp(property, "hide")) {
69 debugStencilClip = StencilClipDebug::Hide;
70 } else if (!strcmp(property, "highlight")) {
71 debugStencilClip = StencilClipDebug::ShowHighlight;
72 } else if (!strcmp(property, "region")) {
73 debugStencilClip = StencilClipDebug::ShowRegion;
74 }
75 } else {
76 debugStencilClip = StencilClipDebug::Hide;
77 }
78
79 sProfileType = ProfileType::None;
80 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
81 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
82 sProfileType = ProfileType::Bars;
83 } else if (!strcmp(property, "true")) {
84 sProfileType = ProfileType::Console;
85 }
86 }
87
88 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
89 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
90
91 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
92 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
93
94 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
95 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
96
97 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
98
99 debugLevel = kDebugDisabled;
100 if (property_get(PROPERTY_DEBUG, property, nullptr) > 0) {
101 debugLevel = (DebugLevel) atoi(property);
102 }
103
104 return (prevDebugLayersUpdates != debugLayersUpdates)
105 || (prevDebugOverdraw != debugOverdraw)
106 || (prevDebugStencilClip != debugStencilClip);
107}
108
109void Properties::overrideProperty(const char* name, const char* value) {
110 if (!strcmp(name, "disableProfileBars")) {
111 sDisableProfileBars = !strcmp(value, "true");
112 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
113 return;
114 } else if (!strcmp(name, "ambientRatio")) {
115 overrideAmbientRatio = fmin(fmax(atof(value), 0.0), 10.0);
116 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
117 return;
118 } else if (!strcmp(name, "lightRadius")) {
119 overrideLightRadius = fmin(fmax(atof(value), 0.0), 3000.0);
120 ALOGD("lightRadius = %.2f", overrideLightRadius);
121 return;
122 } else if (!strcmp(name, "lightPosY")) {
123 overrideLightPosY = fmin(fmax(atof(value), 0.0), 3000.0);
124 ALOGD("lightPos Y = %.2f", overrideLightPosY);
125 return;
126 } else if (!strcmp(name, "lightPosZ")) {
127 overrideLightPosZ = fmin(fmax(atof(value), 0.0), 3000.0);
128 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
129 return;
130 } else if (!strcmp(name, "ambientShadowStrength")) {
131 overrideAmbientShadowStrength = atoi(value);
132 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
133 return;
134 } else if (!strcmp(name, "spotShadowStrength")) {
135 overrideSpotShadowStrength = atoi(value);
136 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
137 return;
138 }
139 ALOGD("failed overriding property %s to %s", name, value);
140}
141
142ProfileType Properties::getProfileType() {
143 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
144 return ProfileType::None;
145 return sProfileType;
146}
147
148}; // namespace uirenderer
149}; // namespace android