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