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