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" |
John Reck | 8dc02f9 | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 19 | #include "DeviceInfo.h" |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 20 | |
John Reck | 6b50780 | 2015-11-03 10:09:59 -0800 | [diff] [blame] | 21 | #include <algorithm> |
| 22 | #include <cstdlib> |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 23 | |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 24 | #include <cutils/compiler.h> |
| 25 | #include <cutils/properties.h> |
Mark Salyzyn | 96bf598 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 26 | #include <log/log.h> |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 27 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
| 31 | bool Properties::drawDeferDisabled = false; |
| 32 | bool Properties::drawReorderDisabled = false; |
| 33 | bool Properties::debugLayersUpdates = false; |
| 34 | bool Properties::debugOverdraw = false; |
| 35 | bool Properties::showDirtyRegions = false; |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 36 | bool Properties::skipEmptyFrames = true; |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 37 | bool Properties::useBufferAge = true; |
| 38 | bool Properties::enablePartialUpdates = true; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 39 | |
| 40 | DebugLevel Properties::debugLevel = kDebugDisabled; |
| 41 | OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default; |
| 42 | StencilClipDebug Properties::debugStencilClip = StencilClipDebug::Hide; |
| 43 | |
| 44 | float Properties::overrideLightRadius = -1.0f; |
| 45 | float Properties::overrideLightPosY = -1.0f; |
| 46 | float Properties::overrideLightPosZ = -1.0f; |
| 47 | float Properties::overrideAmbientRatio = -1.0f; |
| 48 | int Properties::overrideAmbientShadowStrength = -1; |
| 49 | int Properties::overrideSpotShadowStrength = -1; |
| 50 | |
| 51 | ProfileType Properties::sProfileType = ProfileType::None; |
| 52 | bool Properties::sDisableProfileBars = false; |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 53 | RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized; |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 54 | bool Properties::enableHighContrastText = false; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 55 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 56 | bool Properties::waitForGpuCompletion = false; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 57 | bool Properties::forceDrawFrame = false; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 58 | |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 59 | bool Properties::filterOutTestOverhead = false; |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 60 | bool Properties::disableVsync = false; |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 61 | bool Properties::skpCaptureEnabled = false; |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 62 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 63 | static int property_get_int(const char* key, int defaultValue) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 64 | char buf[PROPERTY_VALUE_MAX] = { |
| 65 | '\0', |
| 66 | }; |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 67 | |
| 68 | if (property_get(key, buf, "") > 0) { |
| 69 | return atoi(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 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 80 | debugOverdraw = false; |
| 81 | if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) { |
| 82 | INIT_LOGD(" Overdraw debug enabled: %s", property); |
| 83 | if (!strcmp(property, "show")) { |
| 84 | debugOverdraw = true; |
| 85 | overdrawColorSet = OverdrawColorSet::Default; |
| 86 | } else if (!strcmp(property, "show_deuteranomaly")) { |
| 87 | debugOverdraw = true; |
| 88 | overdrawColorSet = OverdrawColorSet::Deuteranomaly; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // See Properties.h for valid values |
| 93 | if (property_get(PROPERTY_DEBUG_STENCIL_CLIP, property, nullptr) > 0) { |
| 94 | INIT_LOGD(" Stencil clip debug enabled: %s", property); |
| 95 | if (!strcmp(property, "hide")) { |
| 96 | debugStencilClip = StencilClipDebug::Hide; |
| 97 | } else if (!strcmp(property, "highlight")) { |
| 98 | debugStencilClip = StencilClipDebug::ShowHighlight; |
| 99 | } else if (!strcmp(property, "region")) { |
| 100 | debugStencilClip = StencilClipDebug::ShowRegion; |
| 101 | } |
| 102 | } else { |
| 103 | debugStencilClip = StencilClipDebug::Hide; |
| 104 | } |
| 105 | |
| 106 | sProfileType = ProfileType::None; |
| 107 | if (property_get(PROPERTY_PROFILE, property, "") > 0) { |
| 108 | if (!strcmp(property, PROPERTY_PROFILE_VISUALIZE_BARS)) { |
| 109 | sProfileType = ProfileType::Bars; |
| 110 | } else if (!strcmp(property, "true")) { |
| 111 | sProfileType = ProfileType::Console; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | debugLayersUpdates = property_get_bool(PROPERTY_DEBUG_LAYERS_UPDATES, false); |
| 116 | INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates); |
| 117 | |
| 118 | drawDeferDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_DEFER, false); |
| 119 | INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled"); |
| 120 | |
| 121 | drawReorderDisabled = property_get_bool(PROPERTY_DISABLE_DRAW_REORDER, false); |
| 122 | INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled"); |
| 123 | |
| 124 | showDirtyRegions = property_get_bool(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false); |
| 125 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 126 | debugLevel = (DebugLevel)property_get_int(PROPERTY_DEBUG, kDebugDisabled); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 127 | |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 128 | skipEmptyFrames = property_get_bool(PROPERTY_SKIP_EMPTY_DAMAGE, true); |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 129 | useBufferAge = property_get_bool(PROPERTY_USE_BUFFER_AGE, true); |
| 130 | enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true); |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 131 | |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 132 | filterOutTestOverhead = property_get_bool(PROPERTY_FILTER_TEST_OVERHEAD, false); |
| 133 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 134 | skpCaptureEnabled = property_get_bool("ro.debuggable", false) && |
| 135 | property_get_bool(PROPERTY_CAPTURE_SKP_ENABLED, false); |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 136 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 137 | return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw) || |
| 138 | (prevDebugStencilClip != debugStencilClip); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 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 | |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 180 | RenderPipelineType Properties::getRenderPipelineType() { |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 181 | if (sRenderPipelineType != RenderPipelineType::NotInitialized) { |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 182 | return sRenderPipelineType; |
| 183 | } |
| 184 | char prop[PROPERTY_VALUE_MAX]; |
Derek Sollenberger | 04f1f01 | 2017-07-24 14:21:16 -0400 | [diff] [blame] | 185 | property_get(PROPERTY_RENDERER, prop, "skiagl"); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 186 | if (!strcmp(prop, "skiagl")) { |
Chris Craik | 6e66b39 | 2017-02-21 12:41:49 -0800 | [diff] [blame] | 187 | ALOGD("Skia GL Pipeline"); |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 188 | sRenderPipelineType = RenderPipelineType::SkiaGL; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 189 | } else if (!strcmp(prop, "skiavk")) { |
Chris Craik | 6e66b39 | 2017-02-21 12:41:49 -0800 | [diff] [blame] | 190 | ALOGD("Skia Vulkan Pipeline"); |
Stan Iliev | 8a33e40 | 2016-07-08 09:57:49 -0400 | [diff] [blame] | 191 | sRenderPipelineType = RenderPipelineType::SkiaVulkan; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 192 | } else { //"opengl" |
Chris Craik | 6e66b39 | 2017-02-21 12:41:49 -0800 | [diff] [blame] | 193 | ALOGD("HWUI GL Pipeline"); |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 194 | sRenderPipelineType = RenderPipelineType::OpenGL; |
| 195 | } |
| 196 | return sRenderPipelineType; |
| 197 | } |
| 198 | |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 199 | void Properties::overrideRenderPipelineType(RenderPipelineType type) { |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 200 | #if !defined(HWUI_GLES_WRAP_ENABLED) |
| 201 | // If we're doing actual rendering then we can't change the renderer after it's been set. |
| 202 | // Unit tests can freely change this as often as it wants, though, as there's no actual |
| 203 | // GL rendering happening |
| 204 | if (sRenderPipelineType != RenderPipelineType::NotInitialized) { |
| 205 | return; |
| 206 | } |
| 207 | #endif |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 208 | sRenderPipelineType = type; |
| 209 | } |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 210 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 211 | bool Properties::isSkiaEnabled() { |
| 212 | auto renderType = getRenderPipelineType(); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 213 | return RenderPipelineType::SkiaGL == renderType || RenderPipelineType::SkiaVulkan == renderType; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 214 | } |
| 215 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 216 | }; // namespace uirenderer |
| 217 | }; // namespace android |