blob: b8f8585e5af67ec5881f2f6cedae9b16e9667042 [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
36DebugLevel Properties::debugLevel = kDebugDisabled;
37OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
38StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide;
39
40float Properties::overrideLightRadius = -1.0f;
41float Properties::overrideLightPosY = -1.0f;
42float Properties::overrideLightPosZ = -1.0f;
43float Properties::overrideAmbientRatio = -1.0f;
44int Properties::overrideAmbientShadowStrength = -1;
45int Properties::overrideSpotShadowStrength = -1;
46
47ProfileType Properties::sProfileType = ProfileType::None;
48bool Properties::sDisableProfileBars = false;
49
50bool Properties::load() {
51 char property[PROPERTY_VALUE_MAX];
52 bool prevDebugLayersUpdates = debugLayersUpdates;
53 bool prevDebugOverdraw = debugOverdraw;
54 StencilClipDebug prevDebugStencilClip = debugStencilClip;
55
56
57 debugOverdraw = false;
58 if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
59 INIT_LOGD(" Overdraw debug enabled: %s", property);
60 if (!strcmp(property, "show")) {
61 debugOverdraw = true;
62 overdrawColorSet = OverdrawColorSet::Default;
63 } else if (!strcmp(property, "show_deuteranomaly")) {
64 debugOverdraw = true;
65 overdrawColorSet = OverdrawColorSet::Deuteranomaly;
66 }
67 }
68
69 // See Properties.h for valid values
70 if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) {
71 INIT_LOGD(" Stencil clip debug enabled: %s", property);
72 if (!strcmp(property, "hide")) {
73 debugStencilClip = StencilClipDebug::Hide;
74 } else if (!strcmp(property, "highlight")) {
75 debugStencilClip = StencilClipDebug::ShowHighlight;
76 } else if (!strcmp(property, "region")) {
77 debugStencilClip = StencilClipDebug::ShowRegion;
78 }
79 } else {
80 debugStencilClip = StencilClipDebug::Hide;
81 }
82
83 sProfileType = ProfileType::None;
84 if (property_get(PROPERTY_PROFILE, property, "") > 0) {
85 if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) {
86 sProfileType = ProfileType::Bars;
87 } else if (!strcmp(property, "true")) {
88 sProfileType = ProfileType::Console;
89 }
90 }
91
92 debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false);
93 INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates);
94
95 drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false);
96 INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled");
97
98 drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false);
99 INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled");
100
101 showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false);
102
103 debugLevel = kDebugDisabled;
104 if (property_get(PROPERTY_DEBUG, property, nullptr) > 0) {
105 debugLevel = (DebugLevel) atoi(property);
106 }
107
John Reckd04794a2015-05-08 10:04:36 -0700108 skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true);
John Reck4cd44f82015-05-27 10:26:10 -0700109 swapBuffersWithDamage = property_get_bool(PROPERTY_SWAP_WITH_DAMAGE, true);
John Reck149173d2015-08-10 09:52:29 -0700110 useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true);
111 enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
John Reckd04794a2015-05-08 10:04:36 -0700112
Chris Craik2507c342015-05-04 14:36:49 -0700113 return (prevDebugLayersUpdates != debugLayersUpdates)
114 || (prevDebugOverdraw != debugOverdraw)
115 || (prevDebugStencilClip != debugStencilClip);
116}
117
118void Properties::overrideProperty(const char* name, const char* value) {
119 if (!strcmp(name, "disableProfileBars")) {
120 sDisableProfileBars = !strcmp(value, "true");
121 ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled");
122 return;
123 } else if (!strcmp(name, "ambientRatio")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700124 overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0);
Chris Craik2507c342015-05-04 14:36:49 -0700125 ALOGD("ambientRatio = %.2f", overrideAmbientRatio);
126 return;
127 } else if (!strcmp(name, "lightRadius")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700128 overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700129 ALOGD("lightRadius = %.2f", overrideLightRadius);
130 return;
131 } else if (!strcmp(name, "lightPosY")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700132 overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700133 ALOGD("lightPos Y = %.2f", overrideLightPosY);
134 return;
135 } else if (!strcmp(name, "lightPosZ")) {
Chris Craike6a15ee2015-07-07 18:42:17 -0700136 overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0);
Chris Craik2507c342015-05-04 14:36:49 -0700137 ALOGD("lightPos Z = %.2f", overrideLightPosZ);
138 return;
139 } else if (!strcmp(name, "ambientShadowStrength")) {
140 overrideAmbientShadowStrength = atoi(value);
141 ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength);
142 return;
143 } else if (!strcmp(name, "spotShadowStrength")) {
144 overrideSpotShadowStrength = atoi(value);
145 ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength);
146 return;
147 }
148 ALOGD("failed overriding property %s to %s", name, value);
149}
150
151ProfileType Properties::getProfileType() {
152 if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars))
153 return ProfileType::None;
154 return sProfileType;
155}
156
157}; // namespace uirenderer
158}; // namespace android