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