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 | */ |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 16 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 17 | #include "Properties.h" |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 18 | #include "Debug.h" |
| 19 | |
John Reck | 6b50780 | 2015-11-03 10:09:59 -0800 | [diff] [blame] | 20 | #include <algorithm> |
| 21 | #include <cstdlib> |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 22 | |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 23 | #include <cutils/compiler.h> |
| 24 | #include <cutils/properties.h> |
Mark Salyzyn | 96bf598 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 25 | #include <log/log.h> |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 26 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 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 | 48a8f43 | 2016-02-05 15:59:29 -0800 | [diff] [blame] | 40 | |
| 41 | int Properties::fboCacheSize = DEFAULT_FBO_CACHE_SIZE; |
| 42 | int Properties::gradientCacheSize = MB(DEFAULT_GRADIENT_CACHE_SIZE); |
| 43 | int Properties::layerPoolSize = MB(DEFAULT_LAYER_CACHE_SIZE); |
| 44 | int Properties::patchCacheSize = KB(DEFAULT_PATCH_CACHE_SIZE); |
| 45 | int Properties::pathCacheSize = MB(DEFAULT_PATH_CACHE_SIZE); |
| 46 | int Properties::renderBufferCacheSize = MB(DEFAULT_RENDER_BUFFER_CACHE_SIZE); |
| 47 | int Properties::tessellationCacheSize = MB(DEFAULT_VERTEX_CACHE_SIZE); |
| 48 | int Properties::textDropShadowCacheSize = MB(DEFAULT_DROP_SHADOW_CACHE_SIZE); |
| 49 | int Properties::textureCacheSize = MB(DEFAULT_TEXTURE_CACHE_SIZE); |
| 50 | |
| 51 | float Properties::textureCacheFlushRate = DEFAULT_TEXTURE_CACHE_FLUSH_RATE; |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 52 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 53 | DebugLevel Properties::debugLevel = kDebugDisabled; |
| 54 | OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default; |
| 55 | StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide; |
| 56 | |
| 57 | float Properties::overrideLightRadius = -1.0f; |
| 58 | float Properties::overrideLightPosY = -1.0f; |
| 59 | float Properties::overrideLightPosZ = -1.0f; |
| 60 | float Properties::overrideAmbientRatio = -1.0f; |
| 61 | int Properties::overrideAmbientShadowStrength = -1; |
| 62 | int Properties::overrideSpotShadowStrength = -1; |
| 63 | |
| 64 | ProfileType Properties::sProfileType = ProfileType::None; |
| 65 | bool Properties::sDisableProfileBars = false; |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 66 | RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 67 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 68 | bool Properties::waitForGpuCompletion = false; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 69 | bool Properties::forceDrawFrame = false; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 70 | |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 71 | bool Properties::filterOutTestOverhead = false; |
| 72 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 73 | static int property_get_int(const char* key, int defaultValue) { |
| 74 | char buf[PROPERTY_VALUE_MAX] = {'\0',}; |
| 75 | |
| 76 | if (property_get(key, buf, "") > 0) { |
| 77 | return atoi(buf); |
| 78 | } |
| 79 | return defaultValue; |
| 80 | } |
| 81 | |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 82 | static float property_get_float(const char* key, float defaultValue) { |
| 83 | char buf[PROPERTY_VALUE_MAX] = {'\0',}; |
| 84 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 85 | if (property_get(key, buf, "") > 0) { |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 86 | return atof(buf); |
| 87 | } |
| 88 | return defaultValue; |
| 89 | } |
| 90 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 91 | bool Properties::load() { |
| 92 | char property[PROPERTY_VALUE_MAX]; |
| 93 | bool prevDebugLayersUpdates = debugLayersUpdates; |
| 94 | bool prevDebugOverdraw = debugOverdraw; |
| 95 | StencilClipDebug prevDebugStencilClip = debugStencilClip; |
| 96 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 97 | debugOverdraw = false; |
| 98 | if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) { |
| 99 | INIT_LOGD(" Overdraw debug enabled: %s", property); |
| 100 | if (!strcmp(property, "show")) { |
| 101 | debugOverdraw = true; |
| 102 | overdrawColorSet = OverdrawColorSet::Default; |
| 103 | } else if (!strcmp(property, "show_deuteranomaly")) { |
| 104 | debugOverdraw = true; |
| 105 | overdrawColorSet = OverdrawColorSet::Deuteranomaly; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // See Properties.h for valid values |
| 110 | if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) { |
| 111 | INIT_LOGD(" Stencil clip debug enabled: %s", property); |
| 112 | if (!strcmp(property, "hide")) { |
| 113 | debugStencilClip = StencilClipDebug::Hide; |
| 114 | } else if (!strcmp(property, "highlight")) { |
| 115 | debugStencilClip = StencilClipDebug::ShowHighlight; |
| 116 | } else if (!strcmp(property, "region")) { |
| 117 | debugStencilClip = StencilClipDebug::ShowRegion; |
| 118 | } |
| 119 | } else { |
| 120 | debugStencilClip = StencilClipDebug::Hide; |
| 121 | } |
| 122 | |
| 123 | sProfileType = ProfileType::None; |
| 124 | if (property_get(PROPERTY_PROFILE, property, "") > 0) { |
| 125 | if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) { |
| 126 | sProfileType = ProfileType::Bars; |
| 127 | } else if (!strcmp(property, "true")) { |
| 128 | sProfileType = ProfileType::Console; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false); |
| 133 | INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates); |
| 134 | |
| 135 | drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false); |
| 136 | INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled"); |
| 137 | |
| 138 | drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false); |
| 139 | INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled"); |
| 140 | |
| 141 | showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false); |
| 142 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 143 | debugLevel = (DebugLevel) property_get_int(PROPERTY_DEBUG, kDebugDisabled); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 144 | |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 145 | skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 146 | useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true); |
| 147 | enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true); |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 148 | |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 149 | textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA); |
Chris Craik | 48a8f43 | 2016-02-05 15:59:29 -0800 | [diff] [blame] | 150 | |
| 151 | fboCacheSize = property_get_int(PROPERTY_FBO_CACHE_SIZE, DEFAULT_FBO_CACHE_SIZE); |
| 152 | gradientCacheSize = MB(property_get_float(PROPERTY_GRADIENT_CACHE_SIZE, DEFAULT_GRADIENT_CACHE_SIZE)); |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 153 | layerPoolSize = MB(property_get_float(PROPERTY_LAYER_CACHE_SIZE, DEFAULT_LAYER_CACHE_SIZE)); |
Chris Craik | 48a8f43 | 2016-02-05 15:59:29 -0800 | [diff] [blame] | 154 | patchCacheSize = KB(property_get_float(PROPERTY_PATCH_CACHE_SIZE, DEFAULT_PATCH_CACHE_SIZE)); |
| 155 | pathCacheSize = MB(property_get_float(PROPERTY_PATH_CACHE_SIZE, DEFAULT_PATH_CACHE_SIZE)); |
| 156 | renderBufferCacheSize = MB(property_get_float(PROPERTY_RENDER_BUFFER_CACHE_SIZE, DEFAULT_RENDER_BUFFER_CACHE_SIZE)); |
| 157 | tessellationCacheSize = MB(property_get_float(PROPERTY_VERTEX_CACHE_SIZE, DEFAULT_VERTEX_CACHE_SIZE)); |
| 158 | textDropShadowCacheSize = MB(property_get_float(PROPERTY_DROP_SHADOW_CACHE_SIZE, DEFAULT_DROP_SHADOW_CACHE_SIZE)); |
| 159 | textureCacheSize = MB(property_get_float(PROPERTY_TEXTURE_CACHE_SIZE, DEFAULT_TEXTURE_CACHE_SIZE)); |
| 160 | textureCacheFlushRate = std::max(0.0f, std::min(1.0f, |
| 161 | property_get_float(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, DEFAULT_TEXTURE_CACHE_FLUSH_RATE))); |
Chris Craik | c08820f | 2015-09-22 14:22:29 -0700 | [diff] [blame] | 162 | |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 163 | filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false); |
| 164 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 165 | return (prevDebugLayersUpdates != debugLayersUpdates) |
| 166 | || (prevDebugOverdraw != debugOverdraw) |
| 167 | || (prevDebugStencilClip != debugStencilClip); |
| 168 | } |
| 169 | |
| 170 | void Properties::overrideProperty(const char* name, const char* value) { |
| 171 | if (!strcmp(name, "disableProfileBars")) { |
| 172 | sDisableProfileBars = !strcmp(value, "true"); |
| 173 | ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled"); |
| 174 | return; |
| 175 | } else if (!strcmp(name, "ambientRatio")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 176 | overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 177 | ALOGD("ambientRatio = %.2f", overrideAmbientRatio); |
| 178 | return; |
| 179 | } else if (!strcmp(name, "lightRadius")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 180 | overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 181 | ALOGD("lightRadius = %.2f", overrideLightRadius); |
| 182 | return; |
| 183 | } else if (!strcmp(name, "lightPosY")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 184 | overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 185 | ALOGD("lightPos Y = %.2f", overrideLightPosY); |
| 186 | return; |
| 187 | } else if (!strcmp(name, "lightPosZ")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 188 | overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 189 | ALOGD("lightPos Z = %.2f", overrideLightPosZ); |
| 190 | return; |
| 191 | } else if (!strcmp(name, "ambientShadowStrength")) { |
| 192 | overrideAmbientShadowStrength = atoi(value); |
| 193 | ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength); |
| 194 | return; |
| 195 | } else if (!strcmp(name, "spotShadowStrength")) { |
| 196 | overrideSpotShadowStrength = atoi(value); |
| 197 | ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength); |
| 198 | return; |
| 199 | } |
| 200 | ALOGD("failed overriding property %s to %s", name, value); |
| 201 | } |
| 202 | |
| 203 | ProfileType Properties::getProfileType() { |
| 204 | if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars)) |
| 205 | return ProfileType::None; |
| 206 | return sProfileType; |
| 207 | } |
| 208 | |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 209 | RenderPipelineType Properties::getRenderPipelineType() { |
| 210 | if (RenderPipelineType::NotInitialized != sRenderPipelineType) { |
| 211 | return sRenderPipelineType; |
| 212 | } |
| 213 | char prop[PROPERTY_VALUE_MAX]; |
Derek Sollenberger | 4badfe6 | 2017-02-14 11:38:06 -0500 | [diff] [blame] | 214 | property_get(PROPERTY_RENDERER, prop, "opengl"); |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 215 | if (!strcmp(prop, "skiagl") ) { |
Chris Craik | 6e66b39 | 2017-02-21 12:41:49 -0800 | [diff] [blame^] | 216 | ALOGD("Skia GL Pipeline"); |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 217 | sRenderPipelineType = RenderPipelineType::SkiaGL; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 218 | } else if (!strcmp(prop, "skiavk") ) { |
Chris Craik | 6e66b39 | 2017-02-21 12:41:49 -0800 | [diff] [blame^] | 219 | ALOGD("Skia Vulkan Pipeline"); |
Stan Iliev | 8a33e40 | 2016-07-08 09:57:49 -0400 | [diff] [blame] | 220 | sRenderPipelineType = RenderPipelineType::SkiaVulkan; |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 221 | } else { //"opengl" |
Chris Craik | 6e66b39 | 2017-02-21 12:41:49 -0800 | [diff] [blame^] | 222 | ALOGD("HWUI GL Pipeline"); |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 223 | sRenderPipelineType = RenderPipelineType::OpenGL; |
| 224 | } |
| 225 | return sRenderPipelineType; |
| 226 | } |
| 227 | |
Greg Daniel | 98c78da | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 228 | #ifdef HWUI_GLES_WRAP_ENABLED |
| 229 | void Properties::overrideRenderPipelineType(RenderPipelineType type) { |
| 230 | sRenderPipelineType = type; |
| 231 | } |
| 232 | #endif |
| 233 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 234 | bool Properties::isSkiaEnabled() { |
| 235 | auto renderType = getRenderPipelineType(); |
| 236 | return RenderPipelineType::SkiaGL == renderType |
| 237 | || RenderPipelineType::SkiaVulkan == renderType; |
| 238 | } |
| 239 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 240 | }; // namespace uirenderer |
| 241 | }; // namespace android |