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