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