blob: a609f2d2b33e523f61f4272b0b270f6b2006f6f0 [file] [log] [blame]
John Reck67b1e2b2020-08-26 13:17:24 -07001/*
2 * Copyright 2020 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 */
16
John Reck67b1e2b2020-08-26 13:17:24 -070017#undef LOG_TAG
18#define LOG_TAG "RenderEngine"
19#define ATRACE_TAG ATRACE_TAG_GRAPHICS
20
rnleec6a73642021-06-04 14:16:42 -070021#include "SkiaRenderEngine.h"
22
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070023#include <GrBackendSemaphore.h>
24#include <GrContextOptions.h>
Kevin Lubick4011eb92023-09-12 14:18:19 +000025#include <GrTypes.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070026#include <SkBlendMode.h>
27#include <SkCanvas.h>
28#include <SkColor.h>
29#include <SkColorFilter.h>
30#include <SkColorMatrix.h>
31#include <SkColorSpace.h>
32#include <SkData.h>
33#include <SkGraphics.h>
34#include <SkImage.h>
35#include <SkImageFilters.h>
36#include <SkImageInfo.h>
37#include <SkM44.h>
38#include <SkMatrix.h>
39#include <SkPaint.h>
40#include <SkPath.h>
41#include <SkPoint.h>
42#include <SkPoint3.h>
Alec Mouri0e7d8fd2023-05-03 23:58:43 +000043#include <SkRRect.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070044#include <SkRect.h>
45#include <SkRefCnt.h>
46#include <SkRegion.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070047#include <SkRuntimeEffect.h>
48#include <SkSamplingOptions.h>
49#include <SkScalar.h>
50#include <SkShader.h>
51#include <SkShadowUtils.h>
52#include <SkString.h>
53#include <SkSurface.h>
54#include <SkTileMode.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070055#include <android-base/stringprintf.h>
Leon Scroggins IIIdf8166e2024-01-25 15:50:56 -050056#include <common/FlagManager.h>
Alec Mouri0e7d8fd2023-05-03 23:58:43 +000057#include <gui/FenceMonitor.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070058#include <gui/TraceUtils.h>
Sally Qif6918d42023-08-07 15:28:30 -070059#include <include/gpu/ganesh/SkSurfaceGanesh.h>
Alec Mouri0e7d8fd2023-05-03 23:58:43 +000060#include <pthread.h>
61#include <src/core/SkTraceEventCommon.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070062#include <sync/sync.h>
63#include <ui/BlurRegion.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070064#include <ui/DebugUtils.h>
65#include <ui/GraphicBuffer.h>
Sally Qif6918d42023-08-07 15:28:30 -070066#include <ui/HdrRenderTypeUtils.h>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070067#include <utils/Trace.h>
68
69#include <cmath>
70#include <cstdint>
Alec Mouri0e7d8fd2023-05-03 23:58:43 +000071#include <deque>
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070072#include <memory>
73#include <numeric>
74
75#include "Cache.h"
76#include "ColorSpaces.h"
Nolan Scobiefc125ec2024-03-11 20:08:27 -040077#include "compat/SkiaGpuContext.h"
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070078#include "filters/BlurFilter.h"
79#include "filters/GaussianBlurFilter.h"
80#include "filters/KawaseBlurFilter.h"
81#include "filters/LinearEffect.h"
Alec Mourif2ea10c2024-05-24 19:13:21 +000082#include "filters/MouriMap.h"
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070083#include "log/log_main.h"
Nolan Scobieca050282024-03-15 13:27:06 -040084#include "skia/compat/SkiaBackendTexture.h"
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070085#include "skia/debug/SkiaCapture.h"
86#include "skia/debug/SkiaMemoryReporter.h"
87#include "skia/filters/StretchShaderFactory.h"
88#include "system/graphics-base-v1.0.h"
89
90namespace {
91
92// Debugging settings
93static const bool kPrintLayerSettings = false;
Nolan Scobie1e06f2d2024-03-21 14:56:38 -040094static const bool kGaneshFlushAfterEveryLayer = kPrintLayerSettings;
Lingfeng Yang00c1ff62022-06-02 09:19:28 -070095
96} // namespace
97
98// Utility functions related to SkRect
99
100namespace {
101
102static inline SkRect getSkRect(const android::FloatRect& rect) {
103 return SkRect::MakeLTRB(rect.left, rect.top, rect.right, rect.bottom);
104}
105
106static inline SkRect getSkRect(const android::Rect& rect) {
107 return SkRect::MakeLTRB(rect.left, rect.top, rect.right, rect.bottom);
108}
109
110/**
111 * Verifies that common, simple bounds + clip combinations can be converted into
112 * a single RRect draw call returning true if possible. If true the radii parameter
113 * will be filled with the correct radii values that combined with bounds param will
114 * produce the insected roundRect. If false, the returned state of the radii param is undefined.
115 */
116static bool intersectionIsRoundRect(const SkRect& bounds, const SkRect& crop,
117 const SkRect& insetCrop, const android::vec2& cornerRadius,
118 SkVector radii[4]) {
119 const bool leftEqual = bounds.fLeft == crop.fLeft;
120 const bool topEqual = bounds.fTop == crop.fTop;
121 const bool rightEqual = bounds.fRight == crop.fRight;
122 const bool bottomEqual = bounds.fBottom == crop.fBottom;
123
124 // In the event that the corners of the bounds only partially align with the crop we
125 // need to ensure that the resulting shape can still be represented as a round rect.
126 // In particular the round rect implementation will scale the value of all corner radii
127 // if the sum of the radius along any edge is greater than the length of that edge.
128 // See https://www.w3.org/TR/css-backgrounds-3/#corner-overlap
129 const bool requiredWidth = bounds.width() > (cornerRadius.x * 2);
130 const bool requiredHeight = bounds.height() > (cornerRadius.y * 2);
131 if (!requiredWidth || !requiredHeight) {
132 return false;
133 }
134
135 // Check each cropped corner to ensure that it exactly matches the crop or its corner is
136 // contained within the cropped shape and does not need rounded.
137 // compute the UpperLeft corner radius
138 if (leftEqual && topEqual) {
139 radii[0].set(cornerRadius.x, cornerRadius.y);
140 } else if ((leftEqual && bounds.fTop >= insetCrop.fTop) ||
141 (topEqual && bounds.fLeft >= insetCrop.fLeft)) {
142 radii[0].set(0, 0);
143 } else {
144 return false;
145 }
146 // compute the UpperRight corner radius
147 if (rightEqual && topEqual) {
148 radii[1].set(cornerRadius.x, cornerRadius.y);
149 } else if ((rightEqual && bounds.fTop >= insetCrop.fTop) ||
150 (topEqual && bounds.fRight <= insetCrop.fRight)) {
151 radii[1].set(0, 0);
152 } else {
153 return false;
154 }
155 // compute the BottomRight corner radius
156 if (rightEqual && bottomEqual) {
157 radii[2].set(cornerRadius.x, cornerRadius.y);
158 } else if ((rightEqual && bounds.fBottom <= insetCrop.fBottom) ||
159 (bottomEqual && bounds.fRight <= insetCrop.fRight)) {
160 radii[2].set(0, 0);
161 } else {
162 return false;
163 }
164 // compute the BottomLeft corner radius
165 if (leftEqual && bottomEqual) {
166 radii[3].set(cornerRadius.x, cornerRadius.y);
167 } else if ((leftEqual && bounds.fBottom <= insetCrop.fBottom) ||
168 (bottomEqual && bounds.fLeft >= insetCrop.fLeft)) {
169 radii[3].set(0, 0);
170 } else {
171 return false;
172 }
173
174 return true;
175}
176
177static inline std::pair<SkRRect, SkRRect> getBoundsAndClip(const android::FloatRect& boundsRect,
178 const android::FloatRect& cropRect,
179 const android::vec2& cornerRadius) {
180 const SkRect bounds = getSkRect(boundsRect);
181 const SkRect crop = getSkRect(cropRect);
182
183 SkRRect clip;
184 if (cornerRadius.x > 0 && cornerRadius.y > 0) {
185 // it the crop and the bounds are equivalent or there is no crop then we don't need a clip
186 if (bounds == crop || crop.isEmpty()) {
187 return {SkRRect::MakeRectXY(bounds, cornerRadius.x, cornerRadius.y), clip};
188 }
189
190 // This makes an effort to speed up common, simple bounds + clip combinations by
191 // converting them to a single RRect draw. It is possible there are other cases
192 // that can be converted.
193 if (crop.contains(bounds)) {
194 const auto insetCrop = crop.makeInset(cornerRadius.x, cornerRadius.y);
195 if (insetCrop.contains(bounds)) {
196 return {SkRRect::MakeRect(bounds), clip}; // clip is empty - no rounding required
197 }
198
199 SkVector radii[4];
200 if (intersectionIsRoundRect(bounds, crop, insetCrop, cornerRadius, radii)) {
201 SkRRect intersectionBounds;
202 intersectionBounds.setRectRadii(bounds, radii);
203 return {intersectionBounds, clip};
204 }
205 }
206
207 // we didn't hit any of our fast paths so set the clip to the cropRect
208 clip.setRectXY(crop, cornerRadius.x, cornerRadius.y);
209 }
210
211 // if we hit this point then we either don't have rounded corners or we are going to rely
212 // on the clip to round the corners for us
213 return {SkRRect::MakeRect(bounds), clip};
214}
215
216static inline bool layerHasBlur(const android::renderengine::LayerSettings& layer,
217 bool colorTransformModifiesAlpha) {
218 if (layer.backgroundBlurRadius > 0 || layer.blurRegions.size()) {
219 // return false if the content is opaque and would therefore occlude the blur
220 const bool opaqueContent = !layer.source.buffer.buffer || layer.source.buffer.isOpaque;
221 const bool opaqueAlpha = layer.alpha == 1.0f && !colorTransformModifiesAlpha;
222 return layer.skipContentDraw || !(opaqueContent && opaqueAlpha);
223 }
224 return false;
225}
226
227static inline SkColor getSkColor(const android::vec4& color) {
228 return SkColorSetARGB(color.a * 255, color.r * 255, color.g * 255, color.b * 255);
229}
230
231static inline SkM44 getSkM44(const android::mat4& matrix) {
232 return SkM44(matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0],
233 matrix[0][1], matrix[1][1], matrix[2][1], matrix[3][1],
234 matrix[0][2], matrix[1][2], matrix[2][2], matrix[3][2],
235 matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]);
236}
237
238static inline SkPoint3 getSkPoint3(const android::vec3& vector) {
239 return SkPoint3::Make(vector.x, vector.y, vector.z);
240}
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700241} // namespace
rnleec6a73642021-06-04 14:16:42 -0700242
John Reck67b1e2b2020-08-26 13:17:24 -0700243namespace android {
244namespace renderengine {
rnleec6a73642021-06-04 14:16:42 -0700245namespace skia {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700246
247using base::StringAppendF;
248
Russell Myers3348c742024-04-29 20:22:42 +0000249std::future<void> SkiaRenderEngine::primeCache(PrimeCacheConfig config) {
250 Cache::primeShaderCache(this, config);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700251 return {};
252}
253
254sk_sp<SkData> SkiaRenderEngine::SkSLCacheMonitor::load(const SkData& key) {
255 // This "cache" does not actually cache anything. It just allows us to
256 // monitor Skia's internal cache. So this method always returns null.
257 return nullptr;
258}
259
260void SkiaRenderEngine::SkSLCacheMonitor::store(const SkData& key, const SkData& data,
261 const SkString& description) {
262 mShadersCachedSinceLastCall++;
263 mTotalShadersCompiled++;
264 ATRACE_FORMAT("SF cache: %i shaders", mTotalShadersCompiled);
265}
266
267int SkiaRenderEngine::reportShadersCompiled() {
268 return mSkSLCacheMonitor.totalShadersCompiled();
269}
Leon Scroggins IIIa37ca992022-02-02 18:08:20 -0500270
271void SkiaRenderEngine::setEnableTracing(bool tracingEnabled) {
272 SkAndroidFrameworkTraceUtil::setEnableTracing(tracingEnabled);
rnleec6a73642021-06-04 14:16:42 -0700273}
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700274
Leon Scroggins III696bf932024-01-24 15:21:05 -0500275SkiaRenderEngine::SkiaRenderEngine(Threaded threaded, PixelFormat pixelFormat,
Robin Lee7338bd92024-04-04 14:05:07 +0000276 BlurAlgorithm blurAlgorithm)
Leon Scroggins III696bf932024-01-24 15:21:05 -0500277 : RenderEngine(threaded), mDefaultPixelFormat(pixelFormat) {
Robin Lee7338bd92024-04-04 14:05:07 +0000278 switch (blurAlgorithm) {
279 case BlurAlgorithm::GAUSSIAN: {
280 ALOGD("Background Blurs Enabled (Gaussian algorithm)");
281 mBlurFilter = new GaussianBlurFilter();
282 break;
283 }
284 case BlurAlgorithm::KAWASE: {
285 ALOGD("Background Blurs Enabled (Kawase algorithm)");
286 mBlurFilter = new KawaseBlurFilter();
287 break;
288 }
289 default: {
290 mBlurFilter = nullptr;
291 break;
292 }
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700293 }
Robin Lee7338bd92024-04-04 14:05:07 +0000294
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700295 mCapture = std::make_unique<SkiaCapture>();
296}
297
298SkiaRenderEngine::~SkiaRenderEngine() { }
299
Nolan Scobie2526b2f2024-04-16 15:12:22 -0400300// To be called from backend dtors. Used to clean up Skia objects before GPU API contexts are
301// destroyed by subclasses.
302void SkiaRenderEngine::finishRenderingAndAbandonContexts() {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700303 std::lock_guard<std::mutex> lock(mRenderingMutex);
304
305 if (mBlurFilter) {
306 delete mBlurFilter;
307 }
308
Nolan Scobie2526b2f2024-04-16 15:12:22 -0400309 // Leftover textures may hold refs to backend-specific Skia contexts, which must be released
310 // before ~SkiaGpuContext is called.
311 mTextureCleanupMgr.setDeferredStatus(false);
312 mTextureCleanupMgr.cleanup();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700313
Nolan Scobie2526b2f2024-04-16 15:12:22 -0400314 // ~SkiaGpuContext must be called before GPU API contexts are torn down.
315 mContext.reset();
316 mProtectedContext.reset();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700317}
318
319void SkiaRenderEngine::useProtectedContext(bool useProtectedContext) {
320 if (useProtectedContext == mInProtectedContext ||
321 (useProtectedContext && !supportsProtectedContent())) {
322 return;
323 }
324
325 // release any scratch resources before switching into a new mode
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400326 if (getActiveContext()) {
327 getActiveContext()->purgeUnlockedScratchResources();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700328 }
329
330 // Backend-specific way to switch to protected context
331 if (useProtectedContextImpl(
332 useProtectedContext ? GrProtected::kYes : GrProtected::kNo)) {
333 mInProtectedContext = useProtectedContext;
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400334 // given that we are sharing the same thread between two contexts we need to
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700335 // make sure that the thread state is reset when switching between the two.
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400336 if (getActiveContext()) {
337 getActiveContext()->resetContextIfApplicable();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700338 }
339 }
340}
341
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400342SkiaGpuContext* SkiaRenderEngine::getActiveContext() {
343 return mInProtectedContext ? mProtectedContext.get() : mContext.get();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700344}
345
346static float toDegrees(uint32_t transform) {
347 switch (transform) {
348 case ui::Transform::ROT_90:
349 return 90.0;
350 case ui::Transform::ROT_180:
351 return 180.0;
352 case ui::Transform::ROT_270:
353 return 270.0;
354 default:
355 return 0.0;
356 }
357}
358
359static SkColorMatrix toSkColorMatrix(const android::mat4& matrix) {
360 return SkColorMatrix(matrix[0][0], matrix[1][0], matrix[2][0], matrix[3][0], 0, matrix[0][1],
361 matrix[1][1], matrix[2][1], matrix[3][1], 0, matrix[0][2], matrix[1][2],
362 matrix[2][2], matrix[3][2], 0, matrix[0][3], matrix[1][3], matrix[2][3],
363 matrix[3][3], 0);
364}
365
366static bool needsToneMapping(ui::Dataspace sourceDataspace, ui::Dataspace destinationDataspace) {
367 int64_t sourceTransfer = sourceDataspace & HAL_DATASPACE_TRANSFER_MASK;
368 int64_t destTransfer = destinationDataspace & HAL_DATASPACE_TRANSFER_MASK;
369
370 // Treat unsupported dataspaces as srgb
371 if (destTransfer != HAL_DATASPACE_TRANSFER_LINEAR &&
372 destTransfer != HAL_DATASPACE_TRANSFER_HLG &&
373 destTransfer != HAL_DATASPACE_TRANSFER_ST2084) {
374 destTransfer = HAL_DATASPACE_TRANSFER_SRGB;
375 }
376
377 if (sourceTransfer != HAL_DATASPACE_TRANSFER_LINEAR &&
378 sourceTransfer != HAL_DATASPACE_TRANSFER_HLG &&
379 sourceTransfer != HAL_DATASPACE_TRANSFER_ST2084) {
380 sourceTransfer = HAL_DATASPACE_TRANSFER_SRGB;
381 }
382
383 const bool isSourceLinear = sourceTransfer == HAL_DATASPACE_TRANSFER_LINEAR;
384 const bool isSourceSRGB = sourceTransfer == HAL_DATASPACE_TRANSFER_SRGB;
385 const bool isDestLinear = destTransfer == HAL_DATASPACE_TRANSFER_LINEAR;
386 const bool isDestSRGB = destTransfer == HAL_DATASPACE_TRANSFER_SRGB;
387
388 return !(isSourceLinear && isDestSRGB) && !(isSourceSRGB && isDestLinear) &&
389 sourceTransfer != destTransfer;
390}
391
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400392void SkiaRenderEngine::ensureContextsCreated() {
393 if (mContext) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700394 return;
395 }
396
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400397 std::tie(mContext, mProtectedContext) = createContexts();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700398}
399
400void SkiaRenderEngine::mapExternalTextureBuffer(const sp<GraphicBuffer>& buffer,
401 bool isRenderable) {
Ian Elliott1f0911e2022-09-09 16:31:47 -0600402 // Only run this if RE is running on its own thread. This
Leon Scroggins III696bf932024-01-24 15:21:05 -0500403 // way the access to GL/VK operations is guaranteed to be happening on the
Ian Elliott1f0911e2022-09-09 16:31:47 -0600404 // same thread.
Leon Scroggins III696bf932024-01-24 15:21:05 -0500405 if (!isThreaded()) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700406 return;
407 }
Ian Elliott8506e362023-03-08 12:12:09 -0700408 // We don't attempt to map a buffer if the buffer contains protected content. In GL this is
409 // important because GPU resources for protected buffers are much more limited. (In Vk we
Robert Phillips59f71732023-08-23 15:18:27 -0400410 // simply match the existing behavior for protected buffers.) We also never cache any
411 // buffers while in a protected context.
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700412 const bool isProtectedBuffer = buffer->getUsage() & GRALLOC_USAGE_PROTECTED;
Alec Mouri07196db2023-09-12 23:33:49 +0000413 // Don't attempt to map buffers if we're not gpu sampleable. Callers shouldn't send a buffer
414 // over to RenderEngine.
415 const bool isGpuSampleable = buffer->getUsage() & GRALLOC_USAGE_HW_TEXTURE;
416 if (isProtectedBuffer || isProtected() || !isGpuSampleable) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700417 return;
418 }
419 ATRACE_CALL();
420
421 // If we were to support caching protected buffers then we will need to switch the
422 // currently bound context if we are not already using the protected context (and subsequently
Leon Scroggins IIIea458282023-09-05 16:17:04 -0400423 // switch back after the buffer is cached).
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400424 auto context = getActiveContext();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700425 auto& cache = mTextureCache;
426
427 std::lock_guard<std::mutex> lock(mRenderingMutex);
428 mGraphicBufferExternalRefs[buffer->getId()]++;
429
430 if (const auto& iter = cache.find(buffer->getId()); iter == cache.end()) {
Leon Scroggins IIIdf8166e2024-01-25 15:50:56 -0500431 if (FlagManager::getInstance().renderable_buffer_usage()) {
432 isRenderable = buffer->getUsage() & GRALLOC_USAGE_HW_RENDER;
433 }
Nolan Scobieca050282024-03-15 13:27:06 -0400434 std::unique_ptr<SkiaBackendTexture> backendTexture =
435 context->makeBackendTexture(buffer->toAHardwareBuffer(), isRenderable);
436 auto imageTextureRef =
437 std::make_shared<AutoBackendTexture::LocalRef>(std::move(backendTexture),
438 mTextureCleanupMgr);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700439 cache.insert({buffer->getId(), imageTextureRef});
440 }
441}
442
Alec Mouri92f89fa2023-02-24 00:05:06 +0000443void SkiaRenderEngine::unmapExternalTextureBuffer(sp<GraphicBuffer>&& buffer) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700444 ATRACE_CALL();
445 std::lock_guard<std::mutex> lock(mRenderingMutex);
446 if (const auto& iter = mGraphicBufferExternalRefs.find(buffer->getId());
447 iter != mGraphicBufferExternalRefs.end()) {
448 if (iter->second == 0) {
449 ALOGW("Attempted to unmap GraphicBuffer <id: %" PRId64
450 "> from RenderEngine texture, but the "
451 "ref count was already zero!",
452 buffer->getId());
453 mGraphicBufferExternalRefs.erase(buffer->getId());
454 return;
455 }
456
457 iter->second--;
458
459 // Swap contexts if needed prior to deleting this buffer
460 // See Issue 1 of
461 // https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_protected_content.txt: even
462 // when a protected context and an unprotected context are part of the same share group,
463 // protected surfaces may not be accessed by an unprotected context, implying that protected
464 // surfaces may only be freed when a protected context is active.
465 const bool inProtected = mInProtectedContext;
466 useProtectedContext(buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
467
468 if (iter->second == 0) {
469 mTextureCache.erase(buffer->getId());
470 mGraphicBufferExternalRefs.erase(buffer->getId());
471 }
472
473 // Swap back to the previous context so that cached values of isProtected in SurfaceFlinger
474 // are up-to-date.
475 if (inProtected != mInProtectedContext) {
476 useProtectedContext(inProtected);
477 }
478 }
479}
480
Ian Elliott8506e362023-03-08 12:12:09 -0700481std::shared_ptr<AutoBackendTexture::LocalRef> SkiaRenderEngine::getOrCreateBackendTexture(
482 const sp<GraphicBuffer>& buffer, bool isOutputBuffer) {
Robert Phillips59f71732023-08-23 15:18:27 -0400483 // Do not lookup the buffer in the cache for protected contexts
484 if (!isProtected()) {
Ian Elliott8506e362023-03-08 12:12:09 -0700485 if (const auto& it = mTextureCache.find(buffer->getId()); it != mTextureCache.end()) {
486 return it->second;
487 }
488 }
Nolan Scobieca050282024-03-15 13:27:06 -0400489 std::unique_ptr<SkiaBackendTexture> backendTexture =
490 getActiveContext()->makeBackendTexture(buffer->toAHardwareBuffer(), isOutputBuffer);
491 return std::make_shared<AutoBackendTexture::LocalRef>(std::move(backendTexture),
492 mTextureCleanupMgr);
Ian Elliott8506e362023-03-08 12:12:09 -0700493}
494
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700495bool SkiaRenderEngine::canSkipPostRenderCleanup() const {
496 std::lock_guard<std::mutex> lock(mRenderingMutex);
497 return mTextureCleanupMgr.isEmpty();
498}
499
500void SkiaRenderEngine::cleanupPostRender() {
501 ATRACE_CALL();
502 std::lock_guard<std::mutex> lock(mRenderingMutex);
503 mTextureCleanupMgr.cleanup();
504}
505
506sk_sp<SkShader> SkiaRenderEngine::createRuntimeEffectShader(
507 const RuntimeEffectShaderParameters& parameters) {
508 // The given surface will be stretched by HWUI via matrix transformation
509 // which gets similar results for most surfaces
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000510 // Determine later on if we need to leverage the stretch shader within
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700511 // surface flinger
512 const auto& stretchEffect = parameters.layer.stretchEffect;
Alec Mourif2ea10c2024-05-24 19:13:21 +0000513 const auto& targetBuffer = parameters.layer.source.buffer.buffer;
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000514 const auto graphicBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr;
515
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700516 auto shader = parameters.shader;
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000517 if (graphicBuffer && parameters.shader) {
518 if (stretchEffect.hasEffect()) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700519 shader = mStretchShaderFactory.createSkShader(shader, stretchEffect);
520 }
Marzia Favarodcc9d9b2024-01-10 10:17:00 +0000521 // The given surface requires to be filled outside of its buffer bounds if the edge
522 // extension is required
523 const auto& edgeExtensionEffect = parameters.layer.edgeExtensionEffect;
524 if (edgeExtensionEffect.hasEffect()) {
525 shader = mEdgeExtensionShaderFactory.createSkShader(shader, parameters.layer,
526 parameters.imageBounds);
527 }
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700528 }
529
530 if (parameters.requiresLinearEffect) {
Alec Mourif2ea10c2024-05-24 19:13:21 +0000531 const auto format = targetBuffer != nullptr
532 ? std::optional<ui::PixelFormat>(
533 static_cast<ui::PixelFormat>(targetBuffer->getPixelFormat()))
534 : std::nullopt;
535
Alec Mouria32eade2024-06-25 23:20:51 +0000536 const auto hdrType = getHdrRenderType(parameters.layer.sourceDataspace, format,
537 parameters.layerDimmingRatio);
Alec Mouri77c511c2024-06-24 21:55:46 +0000538
539 const auto usingLocalTonemap =
540 parameters.display.tonemapStrategy == DisplaySettings::TonemapStrategy::Local &&
541 hdrType != HdrRenderType::SDR &&
542 shader->isAImage((SkMatrix*)nullptr, (SkTileMode*)nullptr);
543
544 if (usingLocalTonemap) {
545 static MouriMap kMapper;
546 const float ratio =
547 hdrType == HdrRenderType::GENERIC_HDR ? 1.0f : parameters.layerDimmingRatio;
548 shader = kMapper.mouriMap(getActiveContext(), shader, ratio);
Alec Mouria7e752e2024-05-24 18:21:21 +0000549 }
550
Alec Mouri77c511c2024-06-24 21:55:46 +0000551 // disable tonemapping if we already locally tonemapped
552 auto inputDataspace =
553 usingLocalTonemap ? parameters.outputDataSpace : parameters.layer.sourceDataspace;
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700554 auto effect =
Alec Mouri77c511c2024-06-24 21:55:46 +0000555 shaders::LinearEffect{.inputDataspace = inputDataspace,
Sally Qi628ef6e2023-03-30 14:49:03 -0700556 .outputDataspace = parameters.outputDataSpace,
Alec Mourie0bb6f42023-08-02 22:41:52 +0000557 .undoPremultipliedAlpha = parameters.undoPremultipliedAlpha,
558 .fakeOutputDataspace = parameters.fakeOutputDataspace};
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700559
560 auto effectIter = mRuntimeEffects.find(effect);
561 sk_sp<SkRuntimeEffect> runtimeEffect = nullptr;
562 if (effectIter == mRuntimeEffects.end()) {
563 runtimeEffect = buildRuntimeEffect(effect);
564 mRuntimeEffects.insert({effect, runtimeEffect});
565 } else {
566 runtimeEffect = effectIter->second;
567 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000568
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700569 mat4 colorTransform = parameters.layer.colorTransform;
570
Alec Mouri77c511c2024-06-24 21:55:46 +0000571 if (!usingLocalTonemap) {
572 colorTransform *=
573 mat4::scale(vec4(parameters.layerDimmingRatio, parameters.layerDimmingRatio,
574 parameters.layerDimmingRatio, 1.f));
575 }
Alec Mouri3e5965f2023-04-07 18:00:58 +0000576
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700577 const auto hardwareBuffer = graphicBuffer ? graphicBuffer->toAHardwareBuffer() : nullptr;
Alec Mouri77c511c2024-06-24 21:55:46 +0000578 return createLinearEffectShader(shader, effect, runtimeEffect, std::move(colorTransform),
579 parameters.display.maxLuminance,
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700580 parameters.display.currentLuminanceNits,
581 parameters.layer.source.buffer.maxLuminanceNits,
582 hardwareBuffer, parameters.display.renderIntent);
583 }
Alec Mouri77c511c2024-06-24 21:55:46 +0000584 return shader;
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700585}
586
587void SkiaRenderEngine::initCanvas(SkCanvas* canvas, const DisplaySettings& display) {
588 if (CC_UNLIKELY(mCapture->isCaptureRunning())) {
589 // Record display settings when capture is running.
590 std::stringstream displaySettings;
591 PrintTo(display, &displaySettings);
592 // Store the DisplaySettings in additional information.
593 canvas->drawAnnotation(SkRect::MakeEmpty(), "DisplaySettings",
594 SkData::MakeWithCString(displaySettings.str().c_str()));
595 }
596
597 // Before doing any drawing, let's make sure that we'll start at the origin of the display.
598 // Some displays don't start at 0,0 for example when we're mirroring the screen. Also, virtual
599 // displays might have different scaling when compared to the physical screen.
600
601 canvas->clipRect(getSkRect(display.physicalDisplay));
602 canvas->translate(display.physicalDisplay.left, display.physicalDisplay.top);
603
604 const auto clipWidth = display.clip.width();
605 const auto clipHeight = display.clip.height();
606 auto rotatedClipWidth = clipWidth;
607 auto rotatedClipHeight = clipHeight;
608 // Scale is contingent on the rotation result.
609 if (display.orientation & ui::Transform::ROT_90) {
610 std::swap(rotatedClipWidth, rotatedClipHeight);
611 }
612 const auto scaleX = static_cast<SkScalar>(display.physicalDisplay.width()) /
613 static_cast<SkScalar>(rotatedClipWidth);
614 const auto scaleY = static_cast<SkScalar>(display.physicalDisplay.height()) /
615 static_cast<SkScalar>(rotatedClipHeight);
616 canvas->scale(scaleX, scaleY);
617
618 // Canvas rotation is done by centering the clip window at the origin, rotating, translating
619 // back so that the top left corner of the clip is at (0, 0).
620 canvas->translate(rotatedClipWidth / 2, rotatedClipHeight / 2);
621 canvas->rotate(toDegrees(display.orientation));
622 canvas->translate(-clipWidth / 2, -clipHeight / 2);
623 canvas->translate(-display.clip.left, -display.clip.top);
624}
625
626class AutoSaveRestore {
627public:
628 AutoSaveRestore(SkCanvas* canvas) : mCanvas(canvas) { mSaveCount = canvas->save(); }
629 ~AutoSaveRestore() { restore(); }
630 void replace(SkCanvas* canvas) {
631 mCanvas = canvas;
632 mSaveCount = canvas->save();
633 }
634 void restore() {
635 if (mCanvas) {
636 mCanvas->restoreToCount(mSaveCount);
637 mCanvas = nullptr;
638 }
639 }
640
641private:
642 SkCanvas* mCanvas;
643 int mSaveCount;
644};
645
646static SkRRect getBlurRRect(const BlurRegion& region) {
647 const auto rect = SkRect::MakeLTRB(region.left, region.top, region.right, region.bottom);
648 const SkVector radii[4] = {SkVector::Make(region.cornerRadiusTL, region.cornerRadiusTL),
649 SkVector::Make(region.cornerRadiusTR, region.cornerRadiusTR),
650 SkVector::Make(region.cornerRadiusBR, region.cornerRadiusBR),
651 SkVector::Make(region.cornerRadiusBL, region.cornerRadiusBL)};
652 SkRRect roundedRect;
653 roundedRect.setRectRadii(rect, radii);
654 return roundedRect;
655}
656
657// Arbitrary default margin which should be close enough to zero.
658constexpr float kDefaultMargin = 0.0001f;
659static bool equalsWithinMargin(float expected, float value, float margin = kDefaultMargin) {
660 LOG_ALWAYS_FATAL_IF(margin < 0.f, "Margin is negative!");
661 return std::abs(expected - value) < margin;
662}
663
664namespace {
665template <typename T>
666void logSettings(const T& t) {
667 std::stringstream stream;
668 PrintTo(t, &stream);
669 auto string = stream.str();
670 size_t pos = 0;
671 // Perfetto ignores \n, so split up manually into separate ALOGD statements.
672 const size_t size = string.size();
673 while (pos < size) {
674 const size_t end = std::min(string.find("\n", pos), size);
675 ALOGD("%s", string.substr(pos, end - pos).c_str());
676 pos = end + 1;
677 }
678}
679} // namespace
680
681// Helper class intended to be used on the stack to ensure that texture cleanup
682// is deferred until after this class goes out of scope.
683class DeferTextureCleanup final {
684public:
685 DeferTextureCleanup(AutoBackendTexture::CleanupManager& mgr) : mMgr(mgr) {
686 mMgr.setDeferredStatus(true);
687 }
688 ~DeferTextureCleanup() { mMgr.setDeferredStatus(false); }
689
690private:
691 DISALLOW_COPY_AND_ASSIGN(DeferTextureCleanup);
692 AutoBackendTexture::CleanupManager& mMgr;
693};
694
695void SkiaRenderEngine::drawLayersInternal(
Patrick Williams2e9748f2022-08-09 22:48:18 +0000696 const std::shared_ptr<std::promise<FenceResult>>&& resultPromise,
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700697 const DisplaySettings& display, const std::vector<LayerSettings>& layers,
Alec Mourif29700f2023-08-17 21:53:31 +0000698 const std::shared_ptr<ExternalTexture>& buffer, base::unique_fd&& bufferFence) {
Leon Scroggins III5a655b82022-09-07 13:17:09 -0400699 ATRACE_FORMAT("%s for %s", __func__, display.namePlusId.c_str());
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700700
701 std::lock_guard<std::mutex> lock(mRenderingMutex);
702
703 if (buffer == nullptr) {
704 ALOGE("No output buffer provided. Aborting GPU composition.");
Patrick Williams2e9748f2022-08-09 22:48:18 +0000705 resultPromise->set_value(base::unexpected(BAD_VALUE));
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700706 return;
707 }
708
709 validateOutputBufferUsage(buffer->getBuffer());
710
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400711 auto context = getActiveContext();
Nolan Scobie17ffe902024-03-25 11:07:30 -0400712 LOG_ALWAYS_FATAL_IF(context->isAbandonedOrDeviceLost(),
713 "Context is abandoned/device lost at start of %s", __func__);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700714
715 // any AutoBackendTexture deletions will now be deferred until cleanupPostRender is called
716 DeferTextureCleanup dtc(mTextureCleanupMgr);
717
Ian Elliott8506e362023-03-08 12:12:09 -0700718 auto surfaceTextureRef = getOrCreateBackendTexture(buffer->getBuffer(), true);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700719
720 // wait on the buffer to be ready to use prior to using it
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400721 waitFence(context, bufferFence);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700722
Nolan Scobie17e25512024-03-13 18:02:48 -0400723 sk_sp<SkSurface> dstSurface = surfaceTextureRef->getOrCreateSurface(display.outputDataspace);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700724
725 SkCanvas* dstCanvas = mCapture->tryCapture(dstSurface.get());
726 if (dstCanvas == nullptr) {
727 ALOGE("Cannot acquire canvas from Skia.");
Patrick Williams2e9748f2022-08-09 22:48:18 +0000728 resultPromise->set_value(base::unexpected(BAD_VALUE));
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700729 return;
730 }
731
732 // setup color filter if necessary
733 sk_sp<SkColorFilter> displayColorTransform;
734 if (display.colorTransform != mat4() && !display.deviceHandlesColorTransform) {
735 displayColorTransform = SkColorFilters::Matrix(toSkColorMatrix(display.colorTransform));
736 }
737 const bool ctModifiesAlpha =
738 displayColorTransform && !displayColorTransform->isAlphaUnchanged();
739
740 // Find the max layer white point to determine the max luminance of the scene...
741 const float maxLayerWhitePoint = std::transform_reduce(
742 layers.cbegin(), layers.cend(), 0.f,
743 [](float left, float right) { return std::max(left, right); },
744 [&](const auto& l) { return l.whitePointNits; });
745
746 // ...and compute the dimming ratio if dimming is requested
Alec Mouri5697ad62024-05-24 20:00:52 +0000747 const float displayDimmingRatio = display.targetLuminanceNits > 0.f && maxLayerWhitePoint > 0.f
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700748 ? maxLayerWhitePoint / display.targetLuminanceNits
749 : 1.f;
750
751 // Find if any layers have requested blur, we'll use that info to decide when to render to an
752 // offscreen buffer and when to render to the native buffer.
753 sk_sp<SkSurface> activeSurface(dstSurface);
754 SkCanvas* canvas = dstCanvas;
755 SkiaCapture::OffscreenState offscreenCaptureState;
756 const LayerSettings* blurCompositionLayer = nullptr;
Leon Scroggins IIIf31b4bc2023-08-25 10:40:27 -0400757 if (mBlurFilter) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700758 bool requiresCompositionLayer = false;
759 for (const auto& layer : layers) {
760 // if the layer doesn't have blur or it is not visible then continue
761 if (!layerHasBlur(layer, ctModifiesAlpha)) {
762 continue;
763 }
764 if (layer.backgroundBlurRadius > 0 &&
765 layer.backgroundBlurRadius < mBlurFilter->getMaxCrossFadeRadius()) {
766 requiresCompositionLayer = true;
767 }
768 for (auto region : layer.blurRegions) {
769 if (region.blurRadius < mBlurFilter->getMaxCrossFadeRadius()) {
770 requiresCompositionLayer = true;
771 }
772 }
773 if (requiresCompositionLayer) {
774 activeSurface = dstSurface->makeSurface(dstSurface->imageInfo());
775 canvas = mCapture->tryOffscreenCapture(activeSurface.get(), &offscreenCaptureState);
776 blurCompositionLayer = &layer;
777 break;
778 }
779 }
780 }
781
782 AutoSaveRestore surfaceAutoSaveRestore(canvas);
783 // Clear the entire canvas with a transparent black to prevent ghost images.
784 canvas->clear(SK_ColorTRANSPARENT);
785 initCanvas(canvas, display);
786
787 if (kPrintLayerSettings) {
788 logSettings(display);
789 }
790 for (const auto& layer : layers) {
791 ATRACE_FORMAT("DrawLayer: %s", layer.name.c_str());
792
793 if (kPrintLayerSettings) {
794 logSettings(layer);
795 }
796
797 sk_sp<SkImage> blurInput;
798 if (blurCompositionLayer == &layer) {
799 LOG_ALWAYS_FATAL_IF(activeSurface == dstSurface);
800 LOG_ALWAYS_FATAL_IF(canvas == dstCanvas);
801
802 // save a snapshot of the activeSurface to use as input to the blur shaders
803 blurInput = activeSurface->makeImageSnapshot();
804
Leon Scroggins III48a60cc2024-01-31 12:41:33 -0500805 // blit the offscreen framebuffer into the destination AHB. This ensures that
806 // even if the blurred image does not cover the screen (for example, during
807 // a rotation animation, or if blur regions are used), the entire screen is
808 // initialized.
809 if (layer.blurRegions.size() || FlagManager::getInstance().restore_blur_step()) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700810 SkPaint paint;
811 paint.setBlendMode(SkBlendMode::kSrc);
812 if (CC_UNLIKELY(mCapture->isCaptureRunning())) {
813 uint64_t id = mCapture->endOffscreenCapture(&offscreenCaptureState);
814 dstCanvas->drawAnnotation(SkRect::Make(dstCanvas->imageInfo().dimensions()),
815 String8::format("SurfaceID|%" PRId64, id).c_str(),
816 nullptr);
817 dstCanvas->drawImage(blurInput, 0, 0, SkSamplingOptions(), &paint);
818 } else {
819 activeSurface->draw(dstCanvas, 0, 0, SkSamplingOptions(), &paint);
820 }
821 }
822
823 // assign dstCanvas to canvas and ensure that the canvas state is up to date
824 canvas = dstCanvas;
825 surfaceAutoSaveRestore.replace(canvas);
826 initCanvas(canvas, display);
827
828 LOG_ALWAYS_FATAL_IF(activeSurface->getCanvas()->getSaveCount() !=
829 dstSurface->getCanvas()->getSaveCount());
830 LOG_ALWAYS_FATAL_IF(activeSurface->getCanvas()->getTotalMatrix() !=
831 dstSurface->getCanvas()->getTotalMatrix());
832
833 // assign dstSurface to activeSurface
834 activeSurface = dstSurface;
835 }
836
837 SkAutoCanvasRestore layerAutoSaveRestore(canvas, true);
838 if (CC_UNLIKELY(mCapture->isCaptureRunning())) {
839 // Record the name of the layer if the capture is running.
840 std::stringstream layerSettings;
841 PrintTo(layer, &layerSettings);
842 // Store the LayerSettings in additional information.
843 canvas->drawAnnotation(SkRect::MakeEmpty(), layer.name.c_str(),
844 SkData::MakeWithCString(layerSettings.str().c_str()));
845 }
846 // Layers have a local transform that should be applied to them
847 canvas->concat(getSkM44(layer.geometry.positionTransform).asM33());
848
849 const auto [bounds, roundRectClip] =
850 getBoundsAndClip(layer.geometry.boundaries, layer.geometry.roundedCornersCrop,
851 layer.geometry.roundedCornersRadius);
Leon Scroggins IIIf31b4bc2023-08-25 10:40:27 -0400852 if (mBlurFilter && layerHasBlur(layer, ctModifiesAlpha)) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700853 std::unordered_map<uint32_t, sk_sp<SkImage>> cachedBlurs;
854
855 // if multiple layers have blur, then we need to take a snapshot now because
856 // only the lowest layer will have blurImage populated earlier
857 if (!blurInput) {
858 blurInput = activeSurface->makeImageSnapshot();
859 }
Leon Scroggins IIIa09cddc2023-07-25 09:34:11 -0400860
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700861 // rect to be blurred in the coordinate space of blurInput
Leon Scroggins IIIa09cddc2023-07-25 09:34:11 -0400862 SkRect blurRect = canvas->getTotalMatrix().mapRect(bounds.rect());
863
864 // Some layers may be much bigger than the screen. If we used
865 // `blurRect` directly, this would allocate a large buffer with no
866 // benefit. Apply the clip, which already takes the display size
867 // into account. The clipped size will then be used to calculate the
868 // size of the buffer we will create for blurring.
869 if (!blurRect.intersect(SkRect::Make(canvas->getDeviceClipBounds()))) {
870 // This should not happen, but if it did, we would use the full
871 // sized layer, which should still be fine.
872 ALOGW("blur bounds does not intersect display clip!");
873 }
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700874
875 // if the clip needs to be applied then apply it now and make sure
876 // it is restored before we attempt to draw any shadows.
877 SkAutoCanvasRestore acr(canvas, true);
878 if (!roundRectClip.isEmpty()) {
879 canvas->clipRRect(roundRectClip, true);
880 }
881
882 // TODO(b/182216890): Filter out empty layers earlier
883 if (blurRect.width() > 0 && blurRect.height() > 0) {
884 if (layer.backgroundBlurRadius > 0) {
885 ATRACE_NAME("BackgroundBlur");
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400886 auto blurredImage = mBlurFilter->generate(context, layer.backgroundBlurRadius,
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700887 blurInput, blurRect);
888
889 cachedBlurs[layer.backgroundBlurRadius] = blurredImage;
890
891 mBlurFilter->drawBlurRegion(canvas, bounds, layer.backgroundBlurRadius, 1.0f,
892 blurRect, blurredImage, blurInput);
893 }
894
895 canvas->concat(getSkM44(layer.blurRegionTransform).asM33());
896 for (auto region : layer.blurRegions) {
897 if (cachedBlurs[region.blurRadius] == nullptr) {
898 ATRACE_NAME("BlurRegion");
899 cachedBlurs[region.blurRadius] =
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400900 mBlurFilter->generate(context, region.blurRadius, blurInput,
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700901 blurRect);
902 }
903
904 mBlurFilter->drawBlurRegion(canvas, getBlurRRect(region), region.blurRadius,
905 region.alpha, blurRect,
906 cachedBlurs[region.blurRadius], blurInput);
907 }
908 }
909 }
910
911 if (layer.shadow.length > 0) {
912 // This would require a new parameter/flag to SkShadowUtils::DrawShadow
913 LOG_ALWAYS_FATAL_IF(layer.disableBlending, "Cannot disableBlending with a shadow");
914
915 SkRRect shadowBounds, shadowClip;
916 if (layer.geometry.boundaries == layer.shadow.boundaries) {
917 shadowBounds = bounds;
918 shadowClip = roundRectClip;
919 } else {
920 std::tie(shadowBounds, shadowClip) =
921 getBoundsAndClip(layer.shadow.boundaries, layer.geometry.roundedCornersCrop,
922 layer.geometry.roundedCornersRadius);
923 }
924
925 // Technically, if bounds is a rect and roundRectClip is not empty,
926 // it means that the bounds and roundedCornersCrop were different
927 // enough that we should intersect them to find the proper shadow.
928 // In practice, this often happens when the two rectangles appear to
929 // not match due to rounding errors. Draw the rounded version, which
930 // looks more like the intent.
931 const auto& rrect =
932 shadowBounds.isRect() && !shadowClip.isEmpty() ? shadowClip : shadowBounds;
933 drawShadow(canvas, rrect, layer.shadow);
934 }
935
936 const float layerDimmingRatio = layer.whitePointNits <= 0.f
937 ? displayDimmingRatio
938 : (layer.whitePointNits / maxLayerWhitePoint) * displayDimmingRatio;
939
940 const bool dimInLinearSpace = display.dimmingStage !=
941 aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF;
942
Sally Qi628ef6e2023-03-30 14:49:03 -0700943 const bool isExtendedHdr = (layer.sourceDataspace & ui::Dataspace::RANGE_MASK) ==
944 static_cast<int32_t>(ui::Dataspace::RANGE_EXTENDED) &&
945 (display.outputDataspace & ui::Dataspace::TRANSFER_MASK) ==
946 static_cast<int32_t>(ui::Dataspace::TRANSFER_SRGB);
947
Alec Mourie0bb6f42023-08-02 22:41:52 +0000948 const bool useFakeOutputDataspaceForRuntimeEffect = !dimInLinearSpace && isExtendedHdr;
949
950 const ui::Dataspace fakeDataspace = useFakeOutputDataspaceForRuntimeEffect
Sally Qi628ef6e2023-03-30 14:49:03 -0700951 ? static_cast<ui::Dataspace>(
952 (display.outputDataspace & ui::Dataspace::STANDARD_MASK) |
953 ui::Dataspace::TRANSFER_GAMMA2_2 |
954 (display.outputDataspace & ui::Dataspace::RANGE_MASK))
Alec Mourie0bb6f42023-08-02 22:41:52 +0000955 : ui::Dataspace::UNKNOWN;
Sally Qi628ef6e2023-03-30 14:49:03 -0700956
957 // If the input dataspace is range extended, the output dataspace transfer is sRGB
958 // and dimmingStage is GAMMA_OETF, dim in linear space instead, and
959 // set the output dataspace's transfer to be GAMMA2_2.
960 // This allows DPU side to use oetf_gamma_2p2 for extended HDR layer
961 // to avoid tone shift.
962 // The reason of tone shift here is because HDR layers manage white point
963 // luminance in linear space, which color pipelines request GAMMA_OETF break
964 // without a gamma 2.2 fixup.
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700965 const bool requiresLinearEffect = layer.colorTransform != mat4() ||
Alec Mouri47bcb072023-08-15 02:02:49 +0000966 (needsToneMapping(layer.sourceDataspace, display.outputDataspace)) ||
Sally Qi628ef6e2023-03-30 14:49:03 -0700967 (dimInLinearSpace && !equalsWithinMargin(1.f, layerDimmingRatio)) ||
968 (!dimInLinearSpace && isExtendedHdr);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700969
970 // quick abort from drawing the remaining portion of the layer
971 if (layer.skipContentDraw ||
972 (layer.alpha == 0 && !requiresLinearEffect && !layer.disableBlending &&
973 (!displayColorTransform || displayColorTransform->isAlphaUnchanged()))) {
974 continue;
975 }
976
Alec Mouri47bcb072023-08-15 02:02:49 +0000977 const ui::Dataspace layerDataspace = layer.sourceDataspace;
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700978
979 SkPaint paint;
980 if (layer.source.buffer.buffer) {
981 ATRACE_NAME("DrawImage");
982 validateInputBufferUsage(layer.source.buffer.buffer->getBuffer());
983 const auto& item = layer.source.buffer;
Ian Elliott8506e362023-03-08 12:12:09 -0700984 auto imageTextureRef = getOrCreateBackendTexture(item.buffer->getBuffer(), false);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700985
986 // if the layer's buffer has a fence, then we must must respect the fence prior to using
987 // the buffer.
988 if (layer.source.buffer.fence != nullptr) {
Nolan Scobiefc125ec2024-03-11 20:08:27 -0400989 waitFence(context, layer.source.buffer.fence->get());
Lingfeng Yang00c1ff62022-06-02 09:19:28 -0700990 }
991
992 // isOpaque means we need to ignore the alpha in the image,
993 // replacing it with the alpha specified by the LayerSettings. See
994 // https://developer.android.com/reference/android/view/SurfaceControl.Builder#setOpaque(boolean)
995 // The proper way to do this is to use an SkColorType that ignores
996 // alpha, like kRGB_888x_SkColorType, and that is used if the
997 // incoming image is kRGBA_8888_SkColorType. However, the incoming
998 // image may be kRGBA_F16_SkColorType, for which there is no RGBX
999 // SkColorType, or kRGBA_1010102_SkColorType, for which we have
1000 // kRGB_101010x_SkColorType, but it is not yet supported as a source
1001 // on the GPU. (Adding both is tracked in skbug.com/12048.) In the
1002 // meantime, we'll use a workaround that works unless we need to do
1003 // any color conversion. The workaround requires that we pretend the
1004 // image is already premultiplied, so that we do not premultiply it
1005 // before applying SkBlendMode::kPlus.
1006 const bool useIsOpaqueWorkaround = item.isOpaque &&
1007 (imageTextureRef->colorType() == kRGBA_1010102_SkColorType ||
1008 imageTextureRef->colorType() == kRGBA_F16_SkColorType);
1009 const auto alphaType = useIsOpaqueWorkaround ? kPremul_SkAlphaType
1010 : item.isOpaque ? kOpaque_SkAlphaType
1011 : item.usePremultipliedAlpha ? kPremul_SkAlphaType
1012 : kUnpremul_SkAlphaType;
Nolan Scobie17e25512024-03-13 18:02:48 -04001013 sk_sp<SkImage> image = imageTextureRef->makeImage(layerDataspace, alphaType);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001014
1015 auto texMatrix = getSkM44(item.textureTransform).asM33();
1016 // textureTansform was intended to be passed directly into a shader, so when
1017 // building the total matrix with the textureTransform we need to first
1018 // normalize it, then apply the textureTransform, then scale back up.
1019 texMatrix.preScale(1.0f / bounds.width(), 1.0f / bounds.height());
1020 texMatrix.postScale(image->width(), image->height());
1021
1022 SkMatrix matrix;
1023 if (!texMatrix.invert(&matrix)) {
1024 matrix = texMatrix;
1025 }
1026 // The shader does not respect the translation, so we add it to the texture
1027 // transform for the SkImage. This will make sure that the correct layer contents
1028 // are drawn in the correct part of the screen.
1029 matrix.postTranslate(bounds.rect().fLeft, bounds.rect().fTop);
1030
1031 sk_sp<SkShader> shader;
1032
1033 if (layer.source.buffer.useTextureFiltering) {
1034 shader = image->makeShader(SkTileMode::kClamp, SkTileMode::kClamp,
1035 SkSamplingOptions(
1036 {SkFilterMode::kLinear, SkMipmapMode::kNone}),
1037 &matrix);
1038 } else {
1039 shader = image->makeShader(SkSamplingOptions(), matrix);
1040 }
1041
1042 if (useIsOpaqueWorkaround) {
1043 shader = SkShaders::Blend(SkBlendMode::kPlus, shader,
1044 SkShaders::Color(SkColors::kBlack,
1045 toSkColorSpace(layerDataspace)));
1046 }
1047
Marzia Favarodcc9d9b2024-01-10 10:17:00 +00001048 SkRect imageBounds;
1049 matrix.mapRect(&imageBounds, SkRect::Make(image->bounds()));
1050
1051 paint.setShader(createRuntimeEffectShader(RuntimeEffectShaderParameters{
1052 .shader = shader,
1053 .layer = layer,
1054 .display = display,
1055 .undoPremultipliedAlpha = !item.isOpaque && item.usePremultipliedAlpha,
1056 .requiresLinearEffect = requiresLinearEffect,
1057 .layerDimmingRatio = dimInLinearSpace ? layerDimmingRatio : 1.f,
1058 .outputDataSpace = display.outputDataspace,
1059 .fakeOutputDataspace = fakeDataspace,
1060 .imageBounds = imageBounds,
1061 }));
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001062
1063 // Turn on dithering when dimming beyond this (arbitrary) threshold...
linkai296566e2024-01-22 20:58:15 +08001064 static constexpr float kDimmingThreshold = 0.9f;
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001065 // ...or we're rendering an HDR layer down to an 8-bit target
1066 // Most HDR standards require at least 10-bits of color depth for source content, so we
1067 // can just extract the transfer function rather than dig into precise gralloc layout.
1068 // Furthermore, we can assume that the only 8-bit target we support is RGBA8888.
Sally Qif6918d42023-08-07 15:28:30 -07001069 const bool requiresDownsample =
1070 getHdrRenderType(layer.sourceDataspace,
1071 std::optional<ui::PixelFormat>(static_cast<ui::PixelFormat>(
1072 buffer->getPixelFormat()))) != HdrRenderType::SDR &&
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001073 buffer->getPixelFormat() == PIXEL_FORMAT_RGBA_8888;
1074 if (layerDimmingRatio <= kDimmingThreshold || requiresDownsample) {
1075 paint.setDither(true);
1076 }
1077 paint.setAlphaf(layer.alpha);
1078
1079 if (imageTextureRef->colorType() == kAlpha_8_SkColorType) {
1080 LOG_ALWAYS_FATAL_IF(layer.disableBlending, "Cannot disableBlending with A8");
1081
1082 // SysUI creates the alpha layer as a coverage layer, which is
1083 // appropriate for the DPU. Use a color matrix to convert it to
1084 // a mask.
1085 // TODO (b/219525258): Handle input as a mask.
1086 //
1087 // The color matrix will convert A8 pixels with no alpha to
1088 // black, as described by this vector. If the display handles
1089 // the color transform, we need to invert it to find the color
1090 // that will result in black after the DPU applies the transform.
1091 SkV4 black{0.0f, 0.0f, 0.0f, 1.0f}; // r, g, b, a
1092 if (display.colorTransform != mat4() && display.deviceHandlesColorTransform) {
1093 SkM44 colorSpaceMatrix = getSkM44(display.colorTransform);
1094 if (colorSpaceMatrix.invert(&colorSpaceMatrix)) {
1095 black = colorSpaceMatrix * black;
1096 } else {
1097 // We'll just have to use 0,0,0 as black, which should
1098 // be close to correct.
1099 ALOGI("Could not invert colorTransform!");
1100 }
1101 }
1102 SkColorMatrix colorMatrix(0, 0, 0, 0, black[0],
1103 0, 0, 0, 0, black[1],
1104 0, 0, 0, 0, black[2],
1105 0, 0, 0, -1, 1);
1106 if (display.colorTransform != mat4() && !display.deviceHandlesColorTransform) {
1107 // On the other hand, if the device doesn't handle it, we
1108 // have to apply it ourselves.
1109 colorMatrix.postConcat(toSkColorMatrix(display.colorTransform));
1110 }
1111 paint.setColorFilter(SkColorFilters::Matrix(colorMatrix));
1112 }
1113 } else {
1114 ATRACE_NAME("DrawColor");
1115 const auto color = layer.source.solidColor;
1116 sk_sp<SkShader> shader = SkShaders::Color(SkColor4f{.fR = color.r,
1117 .fG = color.g,
1118 .fB = color.b,
1119 .fA = layer.alpha},
1120 toSkColorSpace(layerDataspace));
1121 paint.setShader(createRuntimeEffectShader(
1122 RuntimeEffectShaderParameters{.shader = shader,
1123 .layer = layer,
1124 .display = display,
1125 .undoPremultipliedAlpha = false,
1126 .requiresLinearEffect = requiresLinearEffect,
Sally Qi628ef6e2023-03-30 14:49:03 -07001127 .layerDimmingRatio = layerDimmingRatio,
Alec Mourie0bb6f42023-08-02 22:41:52 +00001128 .outputDataSpace = display.outputDataspace,
Marzia Favarodcc9d9b2024-01-10 10:17:00 +00001129 .fakeOutputDataspace = fakeDataspace,
1130 .imageBounds = SkRect::MakeEmpty()}));
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001131 }
1132
1133 if (layer.disableBlending) {
1134 paint.setBlendMode(SkBlendMode::kSrc);
1135 }
1136
1137 // An A8 buffer will already have the proper color filter attached to
1138 // its paint, including the displayColorTransform as needed.
1139 if (!paint.getColorFilter()) {
1140 if (!dimInLinearSpace && !equalsWithinMargin(1.0, layerDimmingRatio)) {
1141 // If we don't dim in linear space, then when we gamma correct the dimming ratio we
1142 // can assume a gamma 2.2 transfer function.
1143 static constexpr float kInverseGamma22 = 1.f / 2.2f;
1144 const auto gammaCorrectedDimmingRatio =
1145 std::pow(layerDimmingRatio, kInverseGamma22);
1146 auto dimmingMatrix =
1147 mat4::scale(vec4(gammaCorrectedDimmingRatio, gammaCorrectedDimmingRatio,
1148 gammaCorrectedDimmingRatio, 1.f));
1149
1150 const auto colorFilter =
1151 SkColorFilters::Matrix(toSkColorMatrix(std::move(dimmingMatrix)));
1152 paint.setColorFilter(displayColorTransform
1153 ? displayColorTransform->makeComposed(colorFilter)
1154 : colorFilter);
1155 } else {
1156 paint.setColorFilter(displayColorTransform);
1157 }
1158 }
1159
1160 if (!roundRectClip.isEmpty()) {
1161 canvas->clipRRect(roundRectClip, true);
1162 }
1163
1164 if (!bounds.isRect()) {
1165 paint.setAntiAlias(true);
1166 canvas->drawRRect(bounds, paint);
1167 } else {
1168 canvas->drawRect(bounds.rect(), paint);
1169 }
Nolan Scobie1e06f2d2024-03-21 14:56:38 -04001170 if (kGaneshFlushAfterEveryLayer) {
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001171 ATRACE_NAME("flush surface");
Nolan Scobie1e06f2d2024-03-21 14:56:38 -04001172 // No-op in Graphite. If "flushing" Skia's drawing commands after each layer is desired
1173 // in Graphite, then a graphite::Recording would need to be snapped and tracked for each
1174 // layer, which is likely possible but adds non-trivial complexity (in both bookkeeping
1175 // and refactoring).
Kevin Lubick208e11a2023-05-31 19:34:46 +00001176 skgpu::ganesh::Flush(activeSurface);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001177 }
1178 }
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001179
1180 surfaceAutoSaveRestore.restore();
1181 mCapture->endCapture();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001182
Nolan Scobie1e06f2d2024-03-21 14:56:38 -04001183 LOG_ALWAYS_FATAL_IF(activeSurface != dstSurface);
1184 auto drawFence = sp<Fence>::make(flushAndSubmit(context, dstSurface));
Alec Mouri0e7d8fd2023-05-03 23:58:43 +00001185
1186 if (ATRACE_ENABLED()) {
1187 static gui::FenceMonitor sMonitor("RE Completion");
1188 sMonitor.queueFence(drawFence);
1189 }
1190 resultPromise->set_value(std::move(drawFence));
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001191}
1192
1193size_t SkiaRenderEngine::getMaxTextureSize() const {
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001194 return mContext->getMaxTextureSize();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001195}
1196
1197size_t SkiaRenderEngine::getMaxViewportDims() const {
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001198 return mContext->getMaxRenderTargetSize();
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001199}
1200
1201void SkiaRenderEngine::drawShadow(SkCanvas* canvas,
1202 const SkRRect& casterRRect,
1203 const ShadowSettings& settings) {
1204 ATRACE_CALL();
1205 const float casterZ = settings.length / 2.0f;
1206 const auto flags =
1207 settings.casterIsTranslucent ? kTransparentOccluder_ShadowFlag : kNone_ShadowFlag;
1208
1209 SkShadowUtils::DrawShadow(canvas, SkPath::RRect(casterRRect), SkPoint3::Make(0, 0, casterZ),
1210 getSkPoint3(settings.lightPos), settings.lightRadius,
1211 getSkColor(settings.ambientColor), getSkColor(settings.spotColor),
1212 flags);
1213}
1214
1215void SkiaRenderEngine::onActiveDisplaySizeChanged(ui::Size size) {
1216 // This cache multiplier was selected based on review of cache sizes relative
1217 // to the screen resolution. Looking at the worst case memory needed by blur (~1.5x),
1218 // shadows (~1x), and general data structures (e.g. vertex buffers) we selected this as a
1219 // conservative default based on that analysis.
1220 const float SURFACE_SIZE_MULTIPLIER = 3.5f * bytesPerPixel(mDefaultPixelFormat);
1221 const int maxResourceBytes = size.width * size.height * SURFACE_SIZE_MULTIPLIER;
1222
1223 // start by resizing the current context
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001224 getActiveContext()->setResourceCacheLimit(maxResourceBytes);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001225
1226 // if it is possible to switch contexts then we will resize the other context
1227 const bool originalProtectedState = mInProtectedContext;
1228 useProtectedContext(!mInProtectedContext);
1229 if (mInProtectedContext != originalProtectedState) {
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001230 getActiveContext()->setResourceCacheLimit(maxResourceBytes);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001231 // reset back to the initial context that was active when this method was called
1232 useProtectedContext(originalProtectedState);
1233 }
1234}
1235
1236void SkiaRenderEngine::dump(std::string& result) {
1237 // Dump for the specific backend (GLES or Vk)
1238 appendBackendSpecificInfoToDump(result);
1239
1240 // Info about protected content
1241 StringAppendF(&result, "RenderEngine supports protected context: %d\n",
1242 supportsProtectedContent());
1243 StringAppendF(&result, "RenderEngine is in protected context: %d\n", mInProtectedContext);
1244 StringAppendF(&result, "RenderEngine shaders cached since last dump/primeCache: %d\n",
1245 mSkSLCacheMonitor.shadersCachedSinceLastCall());
1246
1247 std::vector<ResourcePair> cpuResourceMap = {
1248 {"skia/sk_resource_cache/bitmap_", "Bitmaps"},
1249 {"skia/sk_resource_cache/rrect-blur_", "Masks"},
1250 {"skia/sk_resource_cache/rects-blur_", "Masks"},
1251 {"skia/sk_resource_cache/tessellated", "Shadows"},
1252 {"skia", "Other"},
1253 };
1254 SkiaMemoryReporter cpuReporter(cpuResourceMap, false);
1255 SkGraphics::DumpMemoryStatistics(&cpuReporter);
1256 StringAppendF(&result, "Skia CPU Caches: ");
1257 cpuReporter.logTotals(result);
1258 cpuReporter.logOutput(result);
1259
1260 {
1261 std::lock_guard<std::mutex> lock(mRenderingMutex);
1262
1263 std::vector<ResourcePair> gpuResourceMap = {
1264 {"texture_renderbuffer", "Texture/RenderBuffer"},
1265 {"texture", "Texture"},
1266 {"gr_text_blob_cache", "Text"},
1267 {"skia", "Other"},
1268 };
1269 SkiaMemoryReporter gpuReporter(gpuResourceMap, true);
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001270 mContext->dumpMemoryStatistics(&gpuReporter);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001271 StringAppendF(&result, "Skia's GPU Caches: ");
1272 gpuReporter.logTotals(result);
1273 gpuReporter.logOutput(result);
1274 StringAppendF(&result, "Skia's Wrapped Objects:\n");
1275 gpuReporter.logOutput(result, true);
1276
1277 StringAppendF(&result, "RenderEngine tracked buffers: %zu\n",
1278 mGraphicBufferExternalRefs.size());
1279 StringAppendF(&result, "Dumping buffer ids...\n");
1280 for (const auto& [id, refCounts] : mGraphicBufferExternalRefs) {
1281 StringAppendF(&result, "- 0x%" PRIx64 " - %d refs \n", id, refCounts);
1282 }
1283 StringAppendF(&result, "RenderEngine AHB/BackendTexture cache size: %zu\n",
1284 mTextureCache.size());
1285 StringAppendF(&result, "Dumping buffer ids...\n");
1286 // TODO(178539829): It would be nice to know which layer these are coming from and what
1287 // the texture sizes are.
1288 for (const auto& [id, unused] : mTextureCache) {
1289 StringAppendF(&result, "- 0x%" PRIx64 "\n", id);
1290 }
1291 StringAppendF(&result, "\n");
1292
1293 SkiaMemoryReporter gpuProtectedReporter(gpuResourceMap, true);
Nolan Scobiefc125ec2024-03-11 20:08:27 -04001294 if (mProtectedContext) {
1295 mProtectedContext->dumpMemoryStatistics(&gpuProtectedReporter);
Lingfeng Yang00c1ff62022-06-02 09:19:28 -07001296 }
1297 StringAppendF(&result, "Skia's GPU Protected Caches: ");
1298 gpuProtectedReporter.logTotals(result);
1299 gpuProtectedReporter.logOutput(result);
1300 StringAppendF(&result, "Skia's Protected Wrapped Objects:\n");
1301 gpuProtectedReporter.logOutput(result, true);
1302
1303 StringAppendF(&result, "\n");
1304 StringAppendF(&result, "RenderEngine runtime effects: %zu\n", mRuntimeEffects.size());
1305 for (const auto& [linearEffect, unused] : mRuntimeEffects) {
1306 StringAppendF(&result, "- inputDataspace: %s\n",
1307 dataspaceDetails(
1308 static_cast<android_dataspace>(linearEffect.inputDataspace))
1309 .c_str());
1310 StringAppendF(&result, "- outputDataspace: %s\n",
1311 dataspaceDetails(
1312 static_cast<android_dataspace>(linearEffect.outputDataspace))
1313 .c_str());
1314 StringAppendF(&result, "undoPremultipliedAlpha: %s\n",
1315 linearEffect.undoPremultipliedAlpha ? "true" : "false");
1316 }
1317 }
1318 StringAppendF(&result, "\n");
1319}
1320
rnleec6a73642021-06-04 14:16:42 -07001321} // namespace skia
John Reck67b1e2b2020-08-26 13:17:24 -07001322} // namespace renderengine
rnleec6a73642021-06-04 14:16:42 -07001323} // namespace android