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" |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 19 | #ifdef __ANDROID__ |
Stan Iliev | b8811aa5 | 2018-11-08 16:25:54 -0500 | [diff] [blame] | 20 | #include "HWUIProperties.sysprop.h" |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 21 | #endif |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 22 | #include "SkTraceEventCommon.h" |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 23 | |
John Reck | 6b50780 | 2015-11-03 10:09:59 -0800 | [diff] [blame] | 24 | #include <algorithm> |
| 25 | #include <cstdlib> |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 26 | #include <optional> |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 27 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 28 | #include <android-base/properties.h> |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 29 | #include <cutils/compiler.h> |
Mark Salyzyn | 96bf598 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 30 | #include <log/log.h> |
Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 31 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace uirenderer { |
| 34 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 35 | #ifndef __ANDROID__ // Layoutlib does not compile HWUIProperties.sysprop as it depends on cutils properties |
| 36 | std::optional<bool> use_vulkan() { |
| 37 | return base::GetBoolProperty("ro.hwui.use_vulkan", false); |
| 38 | } |
| 39 | |
| 40 | std::optional<std::int32_t> render_ahead() { |
| 41 | return base::GetIntProperty("ro.hwui.render_ahead", 0); |
| 42 | } |
| 43 | #endif |
| 44 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 45 | bool Properties::debugLayersUpdates = false; |
| 46 | bool Properties::debugOverdraw = false; |
| 47 | bool Properties::showDirtyRegions = false; |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 48 | bool Properties::skipEmptyFrames = true; |
John Reck | 149173d | 2015-08-10 09:52:29 -0700 | [diff] [blame] | 49 | bool Properties::useBufferAge = true; |
| 50 | bool Properties::enablePartialUpdates = true; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 51 | |
| 52 | DebugLevel Properties::debugLevel = kDebugDisabled; |
| 53 | OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 54 | |
| 55 | float Properties::overrideLightRadius = -1.0f; |
| 56 | float Properties::overrideLightPosY = -1.0f; |
| 57 | float Properties::overrideLightPosZ = -1.0f; |
| 58 | float Properties::overrideAmbientRatio = -1.0f; |
| 59 | int Properties::overrideAmbientShadowStrength = -1; |
| 60 | int Properties::overrideSpotShadowStrength = -1; |
| 61 | |
| 62 | ProfileType Properties::sProfileType = ProfileType::None; |
| 63 | bool Properties::sDisableProfileBars = false; |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 64 | RenderPipelineType Properties::sRenderPipelineType = RenderPipelineType::NotInitialized; |
John Reck | 938e884 | 2017-08-24 13:41:59 -0700 | [diff] [blame] | 65 | bool Properties::enableHighContrastText = false; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 66 | |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 67 | bool Properties::waitForGpuCompletion = false; |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 68 | bool Properties::forceDrawFrame = false; |
John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 69 | |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 70 | bool Properties::filterOutTestOverhead = false; |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 71 | bool Properties::disableVsync = false; |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 72 | bool Properties::skpCaptureEnabled = false; |
John Reck | 9f51644 | 2017-09-25 10:27:21 -0700 | [diff] [blame] | 73 | bool Properties::enableRTAnimations = true; |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 74 | |
Lingfeng Yang | 3a9f223 | 2018-01-24 10:40:18 -0800 | [diff] [blame] | 75 | bool Properties::runningInEmulator = false; |
John Reck | 6afa009 | 2018-03-01 17:28:35 -0800 | [diff] [blame] | 76 | bool Properties::debuggingEnabled = false; |
John Reck | 5642847 | 2018-03-16 17:27:17 -0700 | [diff] [blame] | 77 | bool Properties::isolatedProcess = false; |
Lingfeng Yang | 3a9f223 | 2018-01-24 10:40:18 -0800 | [diff] [blame] | 78 | |
Jorim Jaggi | 767e25e | 2018-04-04 23:07:35 +0200 | [diff] [blame] | 79 | int Properties::contextPriority = 0; |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 80 | int Properties::defaultRenderAhead = -1; |
Jorim Jaggi | 767e25e | 2018-04-04 23:07:35 +0200 | [diff] [blame] | 81 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 82 | bool Properties::load() { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 83 | bool prevDebugLayersUpdates = debugLayersUpdates; |
| 84 | bool prevDebugOverdraw = debugOverdraw; |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 85 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 86 | debugOverdraw = false; |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 87 | std::string debugOverdrawProperty = base::GetProperty(PROPERTY_DEBUG_OVERDRAW, ""); |
| 88 | if (debugOverdrawProperty != "") { |
| 89 | INIT_LOGD(" Overdraw debug enabled: %s", debugOverdrawProperty); |
| 90 | if (debugOverdrawProperty == "show") { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 91 | debugOverdraw = true; |
| 92 | overdrawColorSet = OverdrawColorSet::Default; |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 93 | } else if (debugOverdrawProperty == "show_deuteranomaly") { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 94 | debugOverdraw = true; |
| 95 | overdrawColorSet = OverdrawColorSet::Deuteranomaly; |
| 96 | } |
| 97 | } |
| 98 | |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 99 | sProfileType = ProfileType::None; |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 100 | std::string profileProperty = base::GetProperty(PROPERTY_PROFILE, ""); |
| 101 | if (profileProperty != "") { |
| 102 | if (profileProperty == PROPERTY_PROFILE_VISUALIZE_BARS) { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 103 | sProfileType = ProfileType::Bars; |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 104 | } else if (profileProperty == "true") { |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 105 | sProfileType = ProfileType::Console; |
| 106 | } |
| 107 | } |
| 108 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 109 | debugLayersUpdates = base::GetBoolProperty(PROPERTY_DEBUG_LAYERS_UPDATES, false); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 110 | INIT_LOGD(" Layers updates debug enabled: %d", debugLayersUpdates); |
| 111 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 112 | showDirtyRegions = base::GetBoolProperty(PROPERTY_DEBUG_SHOW_DIRTY_REGIONS, false); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 113 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 114 | debugLevel = (DebugLevel)base::GetIntProperty(PROPERTY_DEBUG, (int)kDebugDisabled); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 115 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 116 | skipEmptyFrames = base::GetBoolProperty(PROPERTY_SKIP_EMPTY_DAMAGE, true); |
| 117 | useBufferAge = base::GetBoolProperty(PROPERTY_USE_BUFFER_AGE, true); |
| 118 | enablePartialUpdates = base::GetBoolProperty(PROPERTY_ENABLE_PARTIAL_UPDATES, true); |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 119 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 120 | filterOutTestOverhead = base::GetBoolProperty(PROPERTY_FILTER_TEST_OVERHEAD, false); |
John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 121 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 122 | skpCaptureEnabled = debuggingEnabled && base::GetBoolProperty(PROPERTY_CAPTURE_SKP_ENABLED, false); |
Stan Iliev | e9d0012 | 2017-09-19 12:07:10 -0400 | [diff] [blame] | 123 | |
Stan Iliev | 02daab6 | 2018-06-29 15:16:11 -0400 | [diff] [blame] | 124 | SkAndroidFrameworkTraceUtil::setEnableTracing( |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 125 | base::GetBoolProperty(PROPERTY_SKIA_ATRACE_ENABLED, false)); |
Stan Iliev | 02daab6 | 2018-06-29 15:16:11 -0400 | [diff] [blame] | 126 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 127 | runningInEmulator = base::GetBoolProperty(PROPERTY_QEMU_KERNEL, false); |
Lingfeng Yang | 3a9f223 | 2018-01-24 10:40:18 -0800 | [diff] [blame] | 128 | |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 129 | defaultRenderAhead = std::max(-1, std::min(2, base::GetIntProperty(PROPERTY_RENDERAHEAD, |
John Reck | cf185f5 | 2019-04-11 16:11:24 -0700 | [diff] [blame] | 130 | render_ahead().value_or(0)))); |
John Reck | 4d52722 | 2019-03-13 16:25:20 -0700 | [diff] [blame] | 131 | |
Derek Sollenberger | fd1c879 | 2018-12-04 16:22:58 -0500 | [diff] [blame] | 132 | return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | void Properties::overrideProperty(const char* name, const char* value) { |
| 136 | if (!strcmp(name, "disableProfileBars")) { |
| 137 | sDisableProfileBars = !strcmp(value, "true"); |
| 138 | ALOGD("profile bars %s", sDisableProfileBars ? "disabled" : "enabled"); |
| 139 | return; |
| 140 | } else if (!strcmp(name, "ambientRatio")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 141 | overrideAmbientRatio = std::min(std::max(atof(value), 0.0), 10.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 142 | ALOGD("ambientRatio = %.2f", overrideAmbientRatio); |
| 143 | return; |
| 144 | } else if (!strcmp(name, "lightRadius")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 145 | overrideLightRadius = std::min(std::max(atof(value), 0.0), 3000.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 146 | ALOGD("lightRadius = %.2f", overrideLightRadius); |
| 147 | return; |
| 148 | } else if (!strcmp(name, "lightPosY")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 149 | overrideLightPosY = std::min(std::max(atof(value), 0.0), 3000.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 150 | ALOGD("lightPos Y = %.2f", overrideLightPosY); |
| 151 | return; |
| 152 | } else if (!strcmp(name, "lightPosZ")) { |
Chris Craik | e6a15ee | 2015-07-07 18:42:17 -0700 | [diff] [blame] | 153 | overrideLightPosZ = std::min(std::max(atof(value), 0.0), 3000.0); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 154 | ALOGD("lightPos Z = %.2f", overrideLightPosZ); |
| 155 | return; |
| 156 | } else if (!strcmp(name, "ambientShadowStrength")) { |
| 157 | overrideAmbientShadowStrength = atoi(value); |
| 158 | ALOGD("ambient shadow strength = 0x%x out of 0xff", overrideAmbientShadowStrength); |
| 159 | return; |
| 160 | } else if (!strcmp(name, "spotShadowStrength")) { |
| 161 | overrideSpotShadowStrength = atoi(value); |
| 162 | ALOGD("spot shadow strength = 0x%x out of 0xff", overrideSpotShadowStrength); |
| 163 | return; |
| 164 | } |
| 165 | ALOGD("failed overriding property %s to %s", name, value); |
| 166 | } |
| 167 | |
| 168 | ProfileType Properties::getProfileType() { |
| 169 | if (CC_UNLIKELY(sDisableProfileBars && sProfileType == ProfileType::Bars)) |
| 170 | return ProfileType::None; |
| 171 | return sProfileType; |
| 172 | } |
| 173 | |
Yiwei Zhang | 4bf3d9e | 2019-04-15 16:24:32 -0700 | [diff] [blame] | 174 | RenderPipelineType Properties::peekRenderPipelineType() { |
| 175 | // If sRenderPipelineType has been locked, just return the locked type immediately. |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 176 | if (sRenderPipelineType != RenderPipelineType::NotInitialized) { |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 177 | return sRenderPipelineType; |
| 178 | } |
Stan Iliev | b8811aa5 | 2018-11-08 16:25:54 -0500 | [diff] [blame] | 179 | bool useVulkan = use_vulkan().value_or(false); |
Jerome Gaillard | a02a12d | 2019-05-28 18:07:56 +0100 | [diff] [blame] | 180 | std::string rendererProperty = base::GetProperty(PROPERTY_RENDERER, useVulkan ? "skiavk" : "skiagl"); |
| 181 | if (rendererProperty == "skiavk") { |
Yiwei Zhang | 4bf3d9e | 2019-04-15 16:24:32 -0700 | [diff] [blame] | 182 | return RenderPipelineType::SkiaVulkan; |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 183 | } |
Yiwei Zhang | 4bf3d9e | 2019-04-15 16:24:32 -0700 | [diff] [blame] | 184 | return RenderPipelineType::SkiaGL; |
| 185 | } |
| 186 | |
| 187 | RenderPipelineType Properties::getRenderPipelineType() { |
| 188 | sRenderPipelineType = peekRenderPipelineType(); |
Stan Iliev | 03de074 | 2016-07-07 12:35:54 -0400 | [diff] [blame] | 189 | return sRenderPipelineType; |
| 190 | } |
| 191 | |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 192 | void Properties::overrideRenderPipelineType(RenderPipelineType type) { |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 193 | // If we're doing actual rendering then we can't change the renderer after it's been set. |
| 194 | // Unit tests can freely change this as often as it wants, though, as there's no actual |
| 195 | // GL rendering happening |
| 196 | if (sRenderPipelineType != RenderPipelineType::NotInitialized) { |
John Reck | 23462d8 | 2019-05-29 16:55:06 -0700 | [diff] [blame] | 197 | LOG_ALWAYS_FATAL_IF(sRenderPipelineType != type, |
| 198 | "Trying to change pipeline but it's already set"); |
John Reck | 113ddd9 | 2017-11-09 16:21:21 -0800 | [diff] [blame] | 199 | return; |
| 200 | } |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 201 | sRenderPipelineType = type; |
| 202 | } |
Greg Daniel | 98c78dad | 2017-01-04 14:45:56 -0500 | [diff] [blame] | 203 | |
Chris Blume | 7b8a808 | 2018-11-30 15:51:58 -0800 | [diff] [blame] | 204 | } // namespace uirenderer |
| 205 | } // namespace android |