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