Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 | */ |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 16 | #include "Cache.h" |
| 17 | #include "AutoBackendTexture.h" |
| 18 | #include "SkiaRenderEngine.h" |
| 19 | #include "android-base/unique_fd.h" |
| 20 | #include "renderengine/DisplaySettings.h" |
| 21 | #include "renderengine/LayerSettings.h" |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 22 | #include "renderengine/impl/ExternalTexture.h" |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 23 | #include "ui/GraphicBuffer.h" |
| 24 | #include "ui/GraphicTypes.h" |
| 25 | #include "ui/PixelFormat.h" |
| 26 | #include "ui/Rect.h" |
| 27 | #include "utils/Timers.h" |
| 28 | |
| 29 | namespace android::renderengine::skia { |
| 30 | |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 31 | namespace { |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 32 | |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 33 | // clang-format off |
| 34 | // Any non-identity matrix will do. |
| 35 | const auto kScaleAndTranslate = mat4(0.7f, 0.f, 0.f, 0.f, |
| 36 | 0.f, 0.7f, 0.f, 0.f, |
| 37 | 0.f, 0.f, 1.f, 0.f, |
| 38 | 67.3f, 52.2f, 0.f, 1.f); |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 39 | const auto kScaleAsymmetric = mat4(0.8f, 0.f, 0.f, 0.f, |
| 40 | 0.f, 1.1f, 0.f, 0.f, |
| 41 | 0.f, 0.f, 1.f, 0.f, |
| 42 | 0.f, 0.f, 0.f, 1.f); |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 43 | const auto kFlip = mat4(1.1f, -0.1f, 0.f, 0.f, |
| 44 | 0.1f, 1.1f, 0.f, 0.f, |
| 45 | 0.f, 0.f, 1.f, 0.f, |
| 46 | 2.f, 2.f, 0.f, 1.f); |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 47 | // clang-format on |
Nathaniel Nifong | bf6f754 | 2021-04-27 12:05:16 -0400 | [diff] [blame] | 48 | // When setting layer.sourceDataspace, whether it matches the destination or not determines whether |
| 49 | // a color correction effect is added to the shader. |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 50 | constexpr auto kDestDataSpace = ui::Dataspace::SRGB; |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 51 | constexpr auto kOtherDataSpace = ui::Dataspace::DISPLAY_P3; |
Mattias Simonsson | 458adf1 | 2023-08-16 10:49:30 +0000 | [diff] [blame] | 52 | constexpr auto kBT2020DataSpace = ui::Dataspace::BT2020_ITU_PQ; |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 53 | constexpr auto kExtendedHdrDataSpce = |
| 54 | static_cast<ui::Dataspace>(ui::Dataspace::RANGE_EXTENDED | ui::Dataspace::TRANSFER_SRGB | |
| 55 | ui::Dataspace::STANDARD_DCI_P3); |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 56 | // Dimming is needed to trigger linear effects for some dataspace pairs |
| 57 | const std::array<float, 3> kLayerWhitePoints = { |
| 58 | 1000.0f, 500.0f, |
| 59 | 100.0f, // trigger dithering by dimming below 20% |
| 60 | }; |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 61 | } // namespace |
| 62 | |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 63 | static void drawShadowLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 64 | const std::shared_ptr<ExternalTexture>& dstTexture) { |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 65 | // Somewhat arbitrary dimensions, but on screen and slightly shorter, based |
| 66 | // on actual use. |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 67 | const Rect& displayRect = display.physicalDisplay; |
| 68 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 69 | FloatRect smallerRect(20, 20, displayRect.width()-20, displayRect.height()-20); |
| 70 | |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 71 | LayerSettings layer{ |
| 72 | .geometry = |
| 73 | Geometry{ |
| 74 | .boundaries = rect, |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 75 | .roundedCornersRadius = {50.f, 50.f}, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 76 | .roundedCornersCrop = rect, |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 77 | }, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 78 | .alpha = 1, |
| 79 | // setting this is mandatory for shadows and blurs |
| 80 | .skipContentDraw = true, |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 81 | // drawShadow ignores alpha |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 82 | .shadow = |
| 83 | ShadowSettings{ |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 84 | .boundaries = rect, |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 85 | .ambientColor = vec4(0, 0, 0, 0.00935997f), |
| 86 | .spotColor = vec4(0, 0, 0, 0.0455841f), |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 87 | .lightPos = vec3(500.f, -1500.f, 1500.f), |
| 88 | .lightRadius = 2500.0f, |
| 89 | .length = 15.f, |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 90 | }, |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 91 | }; |
| 92 | LayerSettings caster{ |
| 93 | .geometry = |
| 94 | Geometry{ |
| 95 | .boundaries = smallerRect, |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 96 | .roundedCornersRadius = {50.f, 50.f}, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 97 | .roundedCornersCrop = rect, |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 98 | }, |
| 99 | .source = |
| 100 | PixelSource{ |
| 101 | .solidColor = half3(0.f, 0.f, 0.f), |
| 102 | }, |
| 103 | .alpha = 1, |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 104 | }; |
| 105 | |
Nathaniel Nifong | 49a5958 | 2021-07-26 19:49:47 -0400 | [diff] [blame] | 106 | // Four combinations of settings are used (two transforms here, and drawShadowLayers is |
| 107 | // called with two different destination data spaces) They're all rounded rect. |
| 108 | // Three of these are cache misses that generate new shaders. |
| 109 | // The first combination generates a short and simple shadow shader. |
| 110 | // The second combination, flip transform, generates two shaders. The first appears to involve |
| 111 | // gaussian_fp. The second is a long and general purpose shadow shader with a device space |
| 112 | // transformation stage. |
| 113 | // The third combination is a cache hit, nothing new. |
| 114 | // The fourth combination, flip transform with a non-SRGB destination dataspace, is new. |
| 115 | // It is unique in that nearly everything is done in the vertex shader, and that vertex shader |
| 116 | // requires color correction. This is triggered differently from every other instance of color |
| 117 | // correction. All other instances are triggered when src and dst dataspaces differ, while |
| 118 | // this one is triggered by the destination being non-srgb. Apparently since the third |
| 119 | // combination is a cache hit, this color correction is only added when the vertex shader is |
| 120 | // doing something non-trivial. |
| 121 | for (auto transform : {mat4(), kFlip}) { |
| 122 | layer.geometry.positionTransform = transform; |
| 123 | caster.geometry.positionTransform = transform; |
Leon Scroggins III | ae07fe5 | 2022-04-26 15:23:55 -0400 | [diff] [blame] | 124 | |
| 125 | auto layers = std::vector<LayerSettings>{layer, caster}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 126 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | static void drawImageLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 131 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 132 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 133 | const Rect& displayRect = display.physicalDisplay; |
| 134 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 135 | LayerSettings layer{ |
| 136 | .geometry = |
| 137 | Geometry{ |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 138 | .boundaries = rect, |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 139 | // The position transform doesn't matter when the reduced shader mode |
| 140 | // in in effect. A matrix transform stage is always included. |
| 141 | .positionTransform = mat4(), |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 142 | .roundedCornersCrop = rect, |
| 143 | }, |
| 144 | .source = PixelSource{.buffer = |
| 145 | Buffer{ |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 146 | .buffer = srcTexture, |
John Reck | ac09e45 | 2021-04-07 16:35:37 -0400 | [diff] [blame] | 147 | .maxLuminanceNits = 1000.f, |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 148 | }}, |
| 149 | }; |
| 150 | |
Nathaniel Nifong | bf6f754 | 2021-04-27 12:05:16 -0400 | [diff] [blame] | 151 | for (auto dataspace : {kDestDataSpace, kOtherDataSpace}) { |
| 152 | layer.sourceDataspace = dataspace; |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 153 | // Cache shaders for both rects and round rects. |
| 154 | // In reduced shader mode, all non-zero round rect radii get the same code path. |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 155 | for (float roundedCornersRadius : {0.0f, 50.0f}) { |
| 156 | // roundedCornersCrop is always set, but the radius triggers the behavior |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 157 | layer.geometry.roundedCornersRadius = {roundedCornersRadius, roundedCornersRadius}; |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 158 | for (bool isOpaque : {true, false}) { |
| 159 | layer.source.buffer.isOpaque = isOpaque; |
| 160 | for (auto alpha : {half(.2f), half(1.0f)}) { |
| 161 | layer.alpha = alpha; |
Leon Scroggins III | ae07fe5 | 2022-04-26 15:23:55 -0400 | [diff] [blame] | 162 | auto layers = std::vector<LayerSettings>{layer}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 163 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 170 | static void drawSolidLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 171 | const std::shared_ptr<ExternalTexture>& dstTexture) { |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 172 | const Rect& displayRect = display.physicalDisplay; |
| 173 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 174 | LayerSettings layer{ |
| 175 | .geometry = |
| 176 | Geometry{ |
| 177 | .boundaries = rect, |
| 178 | }, |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 179 | .source = |
| 180 | PixelSource{ |
| 181 | .solidColor = half3(0.1f, 0.2f, 0.3f), |
| 182 | }, |
Nathaniel Nifong | 768693f | 2021-06-08 14:33:47 -0400 | [diff] [blame] | 183 | .alpha = 0.5, |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 184 | }; |
| 185 | |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 186 | for (auto transform : {mat4(), kScaleAndTranslate}) { |
| 187 | layer.geometry.positionTransform = transform; |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 188 | for (float roundedCornersRadius : {0.0f, 50.f}) { |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 189 | layer.geometry.roundedCornersRadius = {roundedCornersRadius, roundedCornersRadius}; |
Leon Scroggins III | ae07fe5 | 2022-04-26 15:23:55 -0400 | [diff] [blame] | 190 | auto layers = std::vector<LayerSettings>{layer}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 191 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 192 | } |
| 193 | } |
Nathaniel Nifong | 4fc750d | 2021-03-19 11:37:36 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 196 | static void drawBlurLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 197 | const std::shared_ptr<ExternalTexture>& dstTexture) { |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 198 | const Rect& displayRect = display.physicalDisplay; |
| 199 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 200 | LayerSettings layer{ |
| 201 | .geometry = |
| 202 | Geometry{ |
| 203 | .boundaries = rect, |
| 204 | }, |
| 205 | .alpha = 1, |
Nathaniel Nifong | 490a947 | 2021-06-23 16:44:19 -0400 | [diff] [blame] | 206 | // setting this is mandatory for shadows and blurs |
| 207 | .skipContentDraw = true, |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 208 | }; |
| 209 | |
Nathaniel Nifong | 490a947 | 2021-06-23 16:44:19 -0400 | [diff] [blame] | 210 | // Different blur code is invoked for radii less and greater than 30 pixels |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 211 | for (int radius : {9, 60}) { |
| 212 | layer.backgroundBlurRadius = radius; |
Leon Scroggins III | ae07fe5 | 2022-04-26 15:23:55 -0400 | [diff] [blame] | 213 | auto layers = std::vector<LayerSettings>{layer}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 214 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | |
Nathaniel Nifong | 2d91c5e | 2021-05-13 17:14:00 -0400 | [diff] [blame] | 218 | // The unique feature of these layers is that the boundary is slightly smaller than the rounded |
| 219 | // rect crop, so the rounded edges intersect that boundary and require a different clipping method. |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 220 | // For buffers, this is done with a stage that computes coverage and it will differ for round and |
| 221 | // elliptical corners. |
Nathaniel Nifong | 2d91c5e | 2021-05-13 17:14:00 -0400 | [diff] [blame] | 222 | static void drawClippedLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 223 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 224 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 225 | const Rect& displayRect = display.physicalDisplay; |
Nathaniel Nifong | 2d91c5e | 2021-05-13 17:14:00 -0400 | [diff] [blame] | 226 | FloatRect rect(0, 0, displayRect.width(), displayRect.height() - 20); // boundary is smaller |
| 227 | |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 228 | PixelSource bufferSource{.buffer = Buffer{ |
| 229 | .buffer = srcTexture, |
| 230 | .isOpaque = 0, |
| 231 | .maxLuminanceNits = 1000.f, |
| 232 | }}; |
| 233 | PixelSource bufferOpaque{.buffer = Buffer{ |
| 234 | .buffer = srcTexture, |
| 235 | .isOpaque = 1, |
| 236 | .maxLuminanceNits = 1000.f, |
| 237 | }}; |
| 238 | PixelSource colorSource{.solidColor = half3(0.1f, 0.2f, 0.3f)}; |
Nathaniel Nifong | 2d91c5e | 2021-05-13 17:14:00 -0400 | [diff] [blame] | 239 | |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 240 | LayerSettings layer{ |
| 241 | .geometry = |
| 242 | Geometry{ |
| 243 | .boundaries = rect, |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 244 | .roundedCornersRadius = {27.f, 27.f}, |
Nathaniel Nifong | 2d91c5e | 2021-05-13 17:14:00 -0400 | [diff] [blame] | 245 | .roundedCornersCrop = |
| 246 | FloatRect(0, 0, displayRect.width(), displayRect.height()), |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 247 | }, |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 248 | }; |
| 249 | |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 250 | for (auto pixelSource : {bufferSource, bufferOpaque, colorSource}) { |
| 251 | layer.source = pixelSource; |
| 252 | for (auto dataspace : {kDestDataSpace, kOtherDataSpace}) { |
| 253 | layer.sourceDataspace = dataspace; |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 254 | // Produce a CircularRRect clip and an EllipticalRRect clip. |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 255 | for (auto transform : {kScaleAndTranslate, kScaleAsymmetric}) { |
| 256 | layer.geometry.positionTransform = transform; |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 257 | for (float alpha : {0.5f, 1.f}) { |
Leon Scroggins III | ae07fe5 | 2022-04-26 15:23:55 -0400 | [diff] [blame] | 258 | layer.alpha = alpha; |
| 259 | auto layers = std::vector<LayerSettings>{layer}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 260 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Nathaniel Nifong | afeac5b | 2021-05-27 10:52:30 -0400 | [diff] [blame] | 261 | } |
| 262 | } |
Nathaniel Nifong | 2d91c5e | 2021-05-13 17:14:00 -0400 | [diff] [blame] | 263 | } |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 267 | static void drawPIPImageLayer(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 268 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 269 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 270 | const Rect& displayRect = display.physicalDisplay; |
| 271 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 272 | LayerSettings layer{ |
| 273 | .geometry = |
| 274 | Geometry{ |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 275 | .boundaries = rect, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 276 | // Note that this flip matrix only makes a difference when clipping, |
| 277 | // which happens in this layer because the roundrect crop is just a bit |
| 278 | // larger than the layer bounds. |
| 279 | .positionTransform = kFlip, |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 280 | .roundedCornersRadius = {94.2551f, 94.2551f}, |
| 281 | .roundedCornersCrop = FloatRect(-93.75, 0, displayRect.width() + 93.75, |
| 282 | displayRect.height()), |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 283 | }, |
| 284 | .source = PixelSource{.buffer = |
| 285 | Buffer{ |
| 286 | .buffer = srcTexture, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 287 | .usePremultipliedAlpha = 1, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 288 | .isOpaque = 0, |
| 289 | .maxLuminanceNits = 1000.f, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 290 | }}, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 291 | .alpha = 1, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 292 | .sourceDataspace = kOtherDataSpace, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 293 | |
| 294 | }; |
| 295 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 296 | auto layers = std::vector<LayerSettings>{layer}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 297 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void drawHolePunchLayer(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 301 | const std::shared_ptr<ExternalTexture>& dstTexture) { |
| 302 | const Rect& displayRect = display.physicalDisplay; |
| 303 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 304 | FloatRect small(0, 0, displayRect.width()-20, displayRect.height()+20); |
| 305 | LayerSettings layer{ |
| 306 | .geometry = |
| 307 | Geometry{ |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 308 | // the boundaries have to be smaller than the rounded crop so that |
| 309 | // clipRRect is used instead of drawRRect |
| 310 | .boundaries = small, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 311 | .positionTransform = kScaleAndTranslate, |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 312 | .roundedCornersRadius = {50.f, 50.f}, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 313 | .roundedCornersCrop = rect, |
| 314 | }, |
Vishnu Nair | 50c0afe | 2022-07-11 15:04:07 -0700 | [diff] [blame] | 315 | .source = |
| 316 | PixelSource{ |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 317 | .solidColor = half3(0.f, 0.f, 0.f), |
| 318 | }, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 319 | .alpha = 0, |
Leon Scroggins III | 894c5f8 | 2023-08-25 14:43:54 -0400 | [diff] [blame] | 320 | .sourceDataspace = kDestDataSpace, |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 321 | .disableBlending = true, |
| 322 | |
| 323 | }; |
| 324 | |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 325 | auto layers = std::vector<LayerSettings>{layer}; |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 326 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 327 | } |
| 328 | |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 329 | static void drawImageDimmedLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 330 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 331 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 332 | const Rect& displayRect = display.physicalDisplay; |
| 333 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 334 | LayerSettings layer{ |
| 335 | .geometry = |
| 336 | Geometry{ |
| 337 | // The position transform doesn't matter when the reduced shader mode |
| 338 | // in in effect. A matrix transform stage is always included. |
| 339 | .positionTransform = mat4(), |
| 340 | .boundaries = rect, |
| 341 | .roundedCornersCrop = rect, |
| 342 | .roundedCornersRadius = {0.f, 0.f}, |
| 343 | }, |
| 344 | .source = PixelSource{.buffer = Buffer{.buffer = srcTexture, |
| 345 | .maxLuminanceNits = 1000.f, |
| 346 | .usePremultipliedAlpha = true, |
| 347 | .isOpaque = true}}, |
| 348 | .alpha = 1.f, |
| 349 | .sourceDataspace = kDestDataSpace, |
| 350 | }; |
| 351 | |
| 352 | std::vector<LayerSettings> layers; |
| 353 | |
| 354 | for (auto layerWhitePoint : kLayerWhitePoints) { |
| 355 | layer.whitePointNits = layerWhitePoint; |
| 356 | layers.push_back(layer); |
| 357 | } |
| 358 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 359 | } |
| 360 | |
| 361 | static void drawTransparentImageDimmedLayers(SkiaRenderEngine* renderengine, |
| 362 | const DisplaySettings& display, |
| 363 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 364 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 365 | const Rect& displayRect = display.physicalDisplay; |
| 366 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 367 | LayerSettings layer{ |
| 368 | .geometry = |
| 369 | Geometry{ |
| 370 | .positionTransform = mat4(), |
| 371 | .boundaries = rect, |
| 372 | .roundedCornersCrop = rect, |
| 373 | }, |
| 374 | .source = PixelSource{.buffer = |
| 375 | Buffer{ |
| 376 | .buffer = srcTexture, |
| 377 | .maxLuminanceNits = 1000.f, |
| 378 | .usePremultipliedAlpha = true, |
| 379 | .isOpaque = false, |
| 380 | }}, |
| 381 | .sourceDataspace = kDestDataSpace, |
| 382 | }; |
| 383 | |
| 384 | for (auto roundedCornerRadius : {0.f, 50.f}) { |
| 385 | layer.geometry.roundedCornersRadius = {roundedCornerRadius, roundedCornerRadius}; |
| 386 | for (auto alpha : {0.5f, 1.0f}) { |
| 387 | layer.alpha = alpha; |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 388 | for (auto isOpaque : {true, false}) { |
| 389 | if (roundedCornerRadius == 0.f && isOpaque) { |
| 390 | // already covered in drawImageDimmedLayers |
| 391 | continue; |
| 392 | } |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 393 | |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 394 | layer.source.buffer.isOpaque = isOpaque; |
| 395 | std::vector<LayerSettings> layers; |
| 396 | |
| 397 | for (auto layerWhitePoint : kLayerWhitePoints) { |
| 398 | layer.whitePointNits = layerWhitePoint; |
| 399 | layers.push_back(layer); |
| 400 | } |
| 401 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 402 | } |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | static void drawClippedDimmedImageLayers(SkiaRenderEngine* renderengine, |
| 408 | const DisplaySettings& display, |
| 409 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 410 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 411 | const Rect& displayRect = display.physicalDisplay; |
| 412 | |
| 413 | // If rect and boundary is too small compared to roundedCornersRadius, Skia will switch to |
| 414 | // blending instead of EllipticalRRect, so enlarge them a bit. |
| 415 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 416 | FloatRect boundary(0, 0, displayRect.width(), |
| 417 | displayRect.height() - 20); // boundary is smaller |
| 418 | LayerSettings layer{ |
| 419 | .geometry = |
| 420 | Geometry{ |
| 421 | .positionTransform = mat4(), |
| 422 | .boundaries = boundary, |
| 423 | .roundedCornersCrop = rect, |
| 424 | .roundedCornersRadius = {27.f, 27.f}, |
| 425 | }, |
| 426 | .source = PixelSource{.buffer = |
| 427 | Buffer{ |
| 428 | .buffer = srcTexture, |
| 429 | .maxLuminanceNits = 1000.f, |
| 430 | .usePremultipliedAlpha = true, |
| 431 | .isOpaque = false, |
| 432 | }}, |
| 433 | .alpha = 1.f, |
| 434 | .sourceDataspace = kDestDataSpace, |
| 435 | }; |
| 436 | |
| 437 | std::array<mat4, 2> transforms = {kScaleAndTranslate, kScaleAsymmetric}; |
| 438 | |
| 439 | constexpr float radius = 27.f; |
| 440 | |
| 441 | for (size_t i = 0; i < transforms.size(); i++) { |
| 442 | layer.geometry.positionTransform = transforms[i]; |
| 443 | layer.geometry.roundedCornersRadius = {radius, radius}; |
| 444 | |
| 445 | std::vector<LayerSettings> layers; |
| 446 | |
| 447 | for (auto layerWhitePoint : kLayerWhitePoints) { |
| 448 | layer.whitePointNits = layerWhitePoint; |
| 449 | layers.push_back(layer); |
| 450 | } |
| 451 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | static void drawSolidDimmedLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 456 | const std::shared_ptr<ExternalTexture>& dstTexture) { |
| 457 | const Rect& displayRect = display.physicalDisplay; |
| 458 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 459 | LayerSettings layer{ |
| 460 | .geometry = |
| 461 | Geometry{ |
| 462 | .boundaries = rect, |
| 463 | .roundedCornersCrop = rect, |
| 464 | }, |
| 465 | .source = |
| 466 | PixelSource{ |
| 467 | .solidColor = half3(0.1f, 0.2f, 0.3f), |
| 468 | }, |
| 469 | .alpha = 1.f, |
| 470 | }; |
| 471 | |
| 472 | std::vector<LayerSettings> layers; |
| 473 | |
| 474 | for (auto layerWhitePoint : kLayerWhitePoints) { |
| 475 | layer.whitePointNits = layerWhitePoint; |
| 476 | layers.push_back(layer); |
| 477 | } |
| 478 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 479 | } |
| 480 | |
Mattias Simonsson | 458adf1 | 2023-08-16 10:49:30 +0000 | [diff] [blame] | 481 | static void drawBT2020ImageLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 482 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 483 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 484 | const Rect& displayRect = display.physicalDisplay; |
| 485 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 486 | LayerSettings layer{ |
| 487 | .geometry = |
| 488 | Geometry{ |
| 489 | // The position transform doesn't matter when the reduced shader mode |
| 490 | // in in effect. A matrix transform stage is always included. |
| 491 | .positionTransform = mat4(), |
| 492 | .boundaries = rect, |
| 493 | .roundedCornersCrop = rect, |
| 494 | .roundedCornersRadius = {0.f, 0.f}, |
| 495 | }, |
| 496 | .source = PixelSource{.buffer = Buffer{.buffer = srcTexture, |
| 497 | .maxLuminanceNits = 1000.f, |
| 498 | .usePremultipliedAlpha = true, |
| 499 | .isOpaque = true}}, |
| 500 | .alpha = 1.f, |
| 501 | .sourceDataspace = kBT2020DataSpace, |
| 502 | }; |
| 503 | |
| 504 | for (auto alpha : {0.5f, 1.f}) { |
| 505 | layer.alpha = alpha; |
| 506 | std::vector<LayerSettings> layers; |
| 507 | layer.whitePointNits = -1.f; |
| 508 | layers.push_back(layer); |
| 509 | |
| 510 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 511 | } |
| 512 | } |
| 513 | static void drawBT2020ClippedImageLayers(SkiaRenderEngine* renderengine, |
| 514 | const DisplaySettings& display, |
| 515 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 516 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 517 | const Rect& displayRect = display.physicalDisplay; |
| 518 | |
| 519 | // If rect and boundary is too small compared to roundedCornersRadius, Skia will switch to |
| 520 | // blending instead of EllipticalRRect, so enlarge them a bit. |
| 521 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 522 | FloatRect boundary(0, 0, displayRect.width(), |
| 523 | displayRect.height() - 10); // boundary is smaller |
| 524 | LayerSettings layer{ |
| 525 | .geometry = |
| 526 | Geometry{ |
| 527 | .positionTransform = kScaleAsymmetric, |
| 528 | .boundaries = boundary, |
| 529 | .roundedCornersCrop = rect, |
| 530 | .roundedCornersRadius = {64.1f, 64.1f}, |
| 531 | }, |
| 532 | .source = PixelSource{.buffer = |
| 533 | Buffer{ |
| 534 | .buffer = srcTexture, |
| 535 | .maxLuminanceNits = 1000.f, |
| 536 | .usePremultipliedAlpha = true, |
| 537 | .isOpaque = true, |
| 538 | }}, |
| 539 | .alpha = 0.5f, |
| 540 | .sourceDataspace = kBT2020DataSpace, |
| 541 | }; |
| 542 | |
| 543 | std::vector<LayerSettings> layers = {layer}; |
| 544 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 545 | } |
| 546 | |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 547 | static void drawExtendedHDRImageLayers(SkiaRenderEngine* renderengine, |
| 548 | const DisplaySettings& display, |
| 549 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 550 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 551 | const Rect& displayRect = display.physicalDisplay; |
| 552 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 553 | LayerSettings layer{ |
| 554 | .geometry = |
| 555 | Geometry{ |
| 556 | // The position transform doesn't matter when the reduced shader mode |
| 557 | // in in effect. A matrix transform stage is always included. |
| 558 | .positionTransform = mat4(), |
| 559 | .boundaries = rect, |
| 560 | .roundedCornersCrop = rect, |
| 561 | .roundedCornersRadius = {50.f, 50.f}, |
| 562 | }, |
| 563 | .source = PixelSource{.buffer = Buffer{.buffer = srcTexture, |
| 564 | .maxLuminanceNits = 1000.f, |
| 565 | .usePremultipliedAlpha = true, |
| 566 | .isOpaque = true}}, |
| 567 | .alpha = 0.5f, |
| 568 | .sourceDataspace = kExtendedHdrDataSpce, |
| 569 | }; |
| 570 | |
| 571 | for (auto roundedCornerRadius : {0.f, 50.f}) { |
| 572 | layer.geometry.roundedCornersRadius = {roundedCornerRadius, roundedCornerRadius}; |
| 573 | for (auto alpha : {0.5f, 1.f}) { |
| 574 | layer.alpha = alpha; |
| 575 | std::vector<LayerSettings> layers; |
| 576 | |
| 577 | for (auto layerWhitePoint : kLayerWhitePoints) { |
| 578 | layer.whitePointNits = layerWhitePoint; |
| 579 | layers.push_back(layer); |
| 580 | } |
| 581 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | static void drawP3ImageLayers(SkiaRenderEngine* renderengine, const DisplaySettings& display, |
| 587 | const std::shared_ptr<ExternalTexture>& dstTexture, |
| 588 | const std::shared_ptr<ExternalTexture>& srcTexture) { |
| 589 | const Rect& displayRect = display.physicalDisplay; |
| 590 | FloatRect rect(0, 0, displayRect.width(), displayRect.height()); |
| 591 | LayerSettings layer{ |
| 592 | .geometry = |
| 593 | Geometry{ |
| 594 | // The position transform doesn't matter when the reduced shader mode |
| 595 | // in in effect. A matrix transform stage is always included. |
| 596 | .positionTransform = mat4(), |
| 597 | .boundaries = rect, |
| 598 | .roundedCornersCrop = rect, |
| 599 | .roundedCornersRadius = {50.f, 50.f}, |
| 600 | }, |
| 601 | .source = PixelSource{.buffer = Buffer{.buffer = srcTexture, |
| 602 | .maxLuminanceNits = 1000.f, |
| 603 | .usePremultipliedAlpha = true, |
| 604 | .isOpaque = false}}, |
| 605 | .alpha = 0.5f, |
| 606 | .sourceDataspace = kOtherDataSpace, |
| 607 | }; |
| 608 | |
| 609 | for (auto alpha : {0.5f, 1.f}) { |
| 610 | layer.alpha = alpha; |
| 611 | std::vector<LayerSettings> layers; |
| 612 | |
| 613 | for (auto layerWhitePoint : kLayerWhitePoints) { |
| 614 | layer.whitePointNits = layerWhitePoint; |
| 615 | layers.push_back(layer); |
| 616 | } |
| 617 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()); |
| 618 | } |
| 619 | } |
| 620 | |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 621 | // |
| 622 | // The collection of shaders cached here were found by using perfetto to record shader compiles |
| 623 | // during actions that involve RenderEngine, logging the layer settings, and the shader code |
| 624 | // and reproducing those settings here. |
| 625 | // |
| 626 | // It is helpful when debugging this to turn on |
| 627 | // in SkGLRenderEngine.cpp: |
| 628 | // kPrintLayerSettings = true |
| 629 | // kFlushAfterEveryLayer = true |
| 630 | // in external/skia/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp |
| 631 | // gPrintSKSL = true |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 632 | void Cache::primeShaderCache(SkiaRenderEngine* renderengine) { |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 633 | const int previousCount = renderengine->reportShadersCompiled(); |
| 634 | if (previousCount) { |
| 635 | ALOGD("%d Shaders already compiled before Cache::primeShaderCache ran\n", previousCount); |
| 636 | } |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 637 | |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 638 | // The loop is beneficial for debugging and should otherwise be optimized out by the compiler. |
| 639 | // Adding additional bounds to the loop is useful for verifying that the size of the dst buffer |
| 640 | // does not impact the shader compilation counts by triggering different behaviors in RE/Skia. |
| 641 | for (SkSize bounds : {SkSize::Make(128, 128), /*SkSize::Make(1080, 2340)*/}) { |
| 642 | const nsecs_t timeBefore = systemTime(); |
| 643 | // The dimensions should not matter, so long as we draw inside them. |
| 644 | const Rect displayRect(0, 0, bounds.fWidth, bounds.fHeight); |
| 645 | DisplaySettings display{ |
| 646 | .physicalDisplay = displayRect, |
| 647 | .clip = displayRect, |
| 648 | .maxLuminance = 500, |
| 649 | .outputDataspace = kDestDataSpace, |
| 650 | }; |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 651 | DisplaySettings p3Display{ |
| 652 | .physicalDisplay = displayRect, |
| 653 | .clip = displayRect, |
| 654 | .maxLuminance = 500, |
| 655 | .outputDataspace = kOtherDataSpace, |
| 656 | }; |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 657 | DisplaySettings p3DisplayEnhance{.physicalDisplay = displayRect, |
| 658 | .clip = displayRect, |
| 659 | .maxLuminance = 500, |
| 660 | .outputDataspace = kOtherDataSpace, |
| 661 | .dimmingStage = aidl::android::hardware::graphics:: |
| 662 | composer3::DimmingStage::GAMMA_OETF, |
| 663 | .renderIntent = aidl::android::hardware::graphics:: |
| 664 | composer3::RenderIntent::ENHANCE}; |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 665 | DisplaySettings bt2020Display{.physicalDisplay = displayRect, |
| 666 | .clip = displayRect, |
| 667 | .maxLuminance = 500, |
| 668 | .outputDataspace = ui::Dataspace::BT2020, |
| 669 | .deviceHandlesColorTransform = true, |
| 670 | .dimmingStage = aidl::android::hardware::graphics::composer3:: |
| 671 | DimmingStage::GAMMA_OETF, |
| 672 | .renderIntent = aidl::android::hardware::graphics::composer3:: |
| 673 | RenderIntent::TONE_MAP_ENHANCE}; |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 674 | |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 675 | const int64_t usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 676 | |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 677 | sp<GraphicBuffer> dstBuffer = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 678 | sp<GraphicBuffer>::make(displayRect.width(), displayRect.height(), |
| 679 | PIXEL_FORMAT_RGBA_8888, 1, usage, "primeShaderCache_dst"); |
Nathaniel Nifong | b9f27ef | 2021-04-01 16:44:12 -0400 | [diff] [blame] | 680 | |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 681 | const auto dstTexture = |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 682 | std::make_shared<impl::ExternalTexture>(dstBuffer, *renderengine, |
| 683 | impl::ExternalTexture::Usage::WRITEABLE); |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 684 | // This buffer will be the source for the call to drawImageLayers. Draw |
| 685 | // something to it as a placeholder for what an app draws. We should draw |
| 686 | // something, but the details are not important. Make use of the shadow layer drawing step |
| 687 | // to populate it. |
| 688 | sp<GraphicBuffer> srcBuffer = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 689 | sp<GraphicBuffer>::make(displayRect.width(), displayRect.height(), |
| 690 | PIXEL_FORMAT_RGBA_8888, 1, usage, "drawImageLayer_src"); |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 691 | |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 692 | const auto srcTexture = std::make_shared< |
| 693 | impl::ExternalTexture>(srcBuffer, *renderengine, |
| 694 | impl::ExternalTexture::Usage::READABLE | |
| 695 | impl::ExternalTexture::Usage::WRITEABLE); |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 696 | drawHolePunchLayer(renderengine, display, dstTexture); |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 697 | drawSolidLayers(renderengine, display, dstTexture); |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 698 | drawSolidLayers(renderengine, p3Display, dstTexture); |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 699 | drawSolidDimmedLayers(renderengine, display, dstTexture); |
Nathaniel Nifong | 49a5958 | 2021-07-26 19:49:47 -0400 | [diff] [blame] | 700 | |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 701 | drawShadowLayers(renderengine, display, srcTexture); |
Nathaniel Nifong | a6b5423 | 2021-07-02 13:24:32 -0400 | [diff] [blame] | 702 | drawShadowLayers(renderengine, p3Display, srcTexture); |
Nathaniel Nifong | cda45e9 | 2021-06-10 15:01:42 -0400 | [diff] [blame] | 703 | |
| 704 | if (renderengine->supportsBackgroundBlur()) { |
| 705 | drawBlurLayers(renderengine, display, dstTexture); |
| 706 | } |
| 707 | |
Nathaniel Nifong | 73537a3 | 2021-08-06 15:07:26 -0400 | [diff] [blame] | 708 | // The majority of skia shaders needed by RenderEngine are related to sampling images. |
| 709 | // These need to be generated with various source textures. |
| 710 | // Make a list of applicable sources. |
| 711 | // GRALLOC_USAGE_HW_TEXTURE should be the same as AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE. |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 712 | const int64_t usageExternal = GRALLOC_USAGE_HW_TEXTURE; |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 713 | sp<GraphicBuffer> externalBuffer = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 714 | sp<GraphicBuffer>::make(displayRect.width(), displayRect.height(), |
| 715 | PIXEL_FORMAT_RGBA_8888, 1, usageExternal, |
| 716 | "primeShaderCache_external"); |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 717 | const auto externalTexture = |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 718 | std::make_shared<impl::ExternalTexture>(externalBuffer, *renderengine, |
| 719 | impl::ExternalTexture::Usage::READABLE); |
Nathaniel Nifong | 73537a3 | 2021-08-06 15:07:26 -0400 | [diff] [blame] | 720 | std::vector<const std::shared_ptr<ExternalTexture>> textures = |
| 721 | {srcTexture, externalTexture}; |
Nathaniel Nifong | 21e021f | 2021-04-21 13:15:46 -0400 | [diff] [blame] | 722 | |
Nathaniel Nifong | 73537a3 | 2021-08-06 15:07:26 -0400 | [diff] [blame] | 723 | // Another external texture with a different pixel format triggers useIsOpaqueWorkaround. |
| 724 | // It doesn't have to be f16, but it can't be the usual 8888. |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 725 | sp<GraphicBuffer> f16ExternalBuffer = |
Ady Abraham | d11bade | 2022-08-01 16:18:03 -0700 | [diff] [blame] | 726 | sp<GraphicBuffer>::make(displayRect.width(), displayRect.height(), |
| 727 | PIXEL_FORMAT_RGBA_FP16, 1, usageExternal, |
| 728 | "primeShaderCache_external_f16"); |
Nathaniel Nifong | 73537a3 | 2021-08-06 15:07:26 -0400 | [diff] [blame] | 729 | // The F16 texture may not be usable on all devices, so check first that it was created. |
| 730 | status_t error = f16ExternalBuffer->initCheck(); |
| 731 | if (!error) { |
| 732 | const auto f16ExternalTexture = |
Vishnu Nair | dbbe385 | 2022-01-12 20:22:11 -0800 | [diff] [blame] | 733 | std::make_shared<impl::ExternalTexture>(f16ExternalBuffer, *renderengine, |
| 734 | impl::ExternalTexture::Usage::READABLE); |
Nathaniel Nifong | 73537a3 | 2021-08-06 15:07:26 -0400 | [diff] [blame] | 735 | textures.push_back(f16ExternalTexture); |
| 736 | } |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 737 | |
Nathaniel Nifong | 73537a3 | 2021-08-06 15:07:26 -0400 | [diff] [blame] | 738 | for (auto texture : textures) { |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 739 | drawImageLayers(renderengine, display, dstTexture, texture); |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 740 | |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 741 | drawImageDimmedLayers(renderengine, display, dstTexture, texture); |
| 742 | drawImageDimmedLayers(renderengine, p3Display, dstTexture, texture); |
| 743 | drawImageDimmedLayers(renderengine, bt2020Display, dstTexture, texture); |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 744 | |
Nathaniel Nifong | f06a45b | 2021-06-25 17:24:26 -0400 | [diff] [blame] | 745 | // Draw layers for b/185569240. |
| 746 | drawClippedLayers(renderengine, display, dstTexture, texture); |
| 747 | } |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 748 | |
Nathaniel Nifong | 1349150 | 2021-06-30 17:28:29 -0400 | [diff] [blame] | 749 | drawPIPImageLayer(renderengine, display, dstTexture, externalTexture); |
| 750 | |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 751 | drawTransparentImageDimmedLayers(renderengine, bt2020Display, dstTexture, externalTexture); |
| 752 | drawTransparentImageDimmedLayers(renderengine, display, dstTexture, externalTexture); |
| 753 | drawTransparentImageDimmedLayers(renderengine, p3Display, dstTexture, externalTexture); |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 754 | drawTransparentImageDimmedLayers(renderengine, p3DisplayEnhance, dstTexture, |
| 755 | externalTexture); |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 756 | |
| 757 | drawClippedDimmedImageLayers(renderengine, bt2020Display, dstTexture, externalTexture); |
Mattias Simonsson | 458adf1 | 2023-08-16 10:49:30 +0000 | [diff] [blame] | 758 | drawBT2020ClippedImageLayers(renderengine, bt2020Display, dstTexture, externalTexture); |
| 759 | |
| 760 | drawBT2020ImageLayers(renderengine, bt2020Display, dstTexture, externalTexture); |
| 761 | drawBT2020ImageLayers(renderengine, p3Display, dstTexture, externalTexture); |
Mattias Simonsson | 6574613 | 2023-08-15 13:26:16 +0000 | [diff] [blame] | 762 | |
Mattias Simonsson | 5860d92 | 2023-08-16 13:47:41 +0000 | [diff] [blame] | 763 | drawExtendedHDRImageLayers(renderengine, display, dstTexture, externalTexture); |
| 764 | drawExtendedHDRImageLayers(renderengine, p3Display, dstTexture, externalTexture); |
| 765 | drawExtendedHDRImageLayers(renderengine, p3DisplayEnhance, dstTexture, externalTexture); |
| 766 | |
| 767 | drawP3ImageLayers(renderengine, p3DisplayEnhance, dstTexture, externalTexture); |
| 768 | |
Nathaniel Nifong | 2d2f432 | 2021-07-22 15:17:36 -0400 | [diff] [blame] | 769 | // draw one final layer synchronously to force GL submit |
| 770 | LayerSettings layer{ |
| 771 | .source = PixelSource{.solidColor = half3(0.f, 0.f, 0.f)}, |
| 772 | }; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 773 | auto layers = std::vector<LayerSettings>{layer}; |
Sally Qi | 4cabdd0 | 2021-08-05 16:45:57 -0700 | [diff] [blame] | 774 | // call get() to make it synchronous |
Alec Mouri | f29700f | 2023-08-17 21:53:31 +0000 | [diff] [blame] | 775 | renderengine->drawLayers(display, layers, dstTexture, base::unique_fd()).get(); |
Nathaniel Nifong | 2d2f432 | 2021-07-22 15:17:36 -0400 | [diff] [blame] | 776 | |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 777 | const nsecs_t timeAfter = systemTime(); |
| 778 | const float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; |
Leon Scroggins III | 45be918 | 2022-04-27 10:37:11 -0400 | [diff] [blame] | 779 | const int shadersCompiled = renderengine->reportShadersCompiled() - previousCount; |
Derek Sollenberger | e9a5108 | 2021-05-06 14:01:38 -0400 | [diff] [blame] | 780 | ALOGD("Shader cache generated %d shaders in %f ms\n", shadersCompiled, compileTimeMs); |
| 781 | } |
Leon Scroggins III | b9216dc | 2021-03-08 17:19:01 -0500 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | } // namespace android::renderengine::skia |