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