From 1edec35288c7f2cb133d2f9f76d490155ec2a3be Mon Sep 17 00:00:00 2001 From: Chris Fries Date: Sun, 21 Feb 2021 03:49:09 +0000 Subject: [PATCH] Revert "Simplify calling loopers" This reverts commit 07c0b7c0d13369a4d20ed833c8fb8e2e52cd216e. Reason for revert: http://b/180818875 systemui crashloops in libhwui Change-Id: Id62860d43d7fac572bd94ebc4fe5cc1ff7cc6820 --- .../pipeline/skia/SkiaRecordingCanvas.cpp | 31 ++++++++++++++++--- libs/hwui/pipeline/skia/SkiaRecordingCanvas.h | 13 -------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp index 04e3a1cb887ec..b2884023a83d6 100644 --- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp +++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp @@ -194,6 +194,25 @@ SkiaCanvas::PaintCoW&& SkiaRecordingCanvas::filterBitmap(PaintCoW&& paint) { return filterPaint(std::move(paint)); } +static BlurDrawLooper* get_looper(const Paint* paint) { + return paint ? paint->getLooper() : nullptr; +} + +template +void applyLooper(BlurDrawLooper* looper, const SkPaint* paint, Proc proc) { + if (looper) { + SkPaint p; + if (paint) { + p = *paint; + } + looper->apply(p, [&](SkPoint offset, const SkPaint& modifiedPaint) { + proc(offset.fX, offset.fY, &modifiedPaint); + }); + } else { + proc(0, 0, paint); + } +} + static SkFilterMode Paint_to_filter(const SkPaint* paint) { return paint && paint->getFilterQuality() != kNone_SkFilterQuality ? SkFilterMode::kLinear : SkFilterMode::kNearest; @@ -207,7 +226,8 @@ static SkSamplingOptions Paint_to_sampling(const SkPaint* paint) { void SkiaRecordingCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const Paint* paint) { sk_sp image = bitmap.makeImage(); - applyLooper(paint, [&](SkScalar x, SkScalar y, const SkPaint* p) { + applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y, + const SkPaint* p) { mRecorder.drawImage(image, left + x, top + y, Paint_to_sampling(p), p, bitmap.palette()); }); @@ -225,7 +245,8 @@ void SkiaRecordingCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, con sk_sp image = bitmap.makeImage(); - applyLooper(paint, [&](SkScalar x, SkScalar y, const SkPaint* p) { + applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y, + const SkPaint* p) { mRecorder.drawImage(image, x, y, Paint_to_sampling(p), p, bitmap.palette()); }); @@ -242,7 +263,8 @@ void SkiaRecordingCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop sk_sp image = bitmap.makeImage(); - applyLooper(paint, [&](SkScalar x, SkScalar y, const SkPaint* p) { + applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y, + const SkPaint* p) { mRecorder.drawImageRect(image, srcRect, dstRect.makeOffset(x, y), Paint_to_sampling(p), p, SkCanvas::kFast_SrcRectConstraint, bitmap.palette()); }); @@ -281,7 +303,8 @@ void SkiaRecordingCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& ch // HWUI always draws 9-patches with linear filtering, regardless of the Paint. const SkFilterMode filter = SkFilterMode::kLinear; - applyLooper(paint, [&](SkScalar x, SkScalar y, const SkPaint* p) { + applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y, + const SkPaint* p) { mRecorder.drawImageLattice(image, lattice, dst.makeOffset(x, y), filter, p, bitmap.palette()); }); diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h index deeae6a030d3a..8d7a21a732dd1 100644 --- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h +++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h @@ -87,19 +87,6 @@ private: std::unique_ptr mDisplayList; StartReorderBarrierDrawable* mCurrentBarrier; - template - void applyLooper(const Paint* paint, Proc proc) { - const SkPaint* sk_paint = filterBitmap(paint); - const BlurDrawLooper* looper = paint ? paint->getLooper() : nullptr; - if (looper) { - looper->apply(*sk_paint, [&](SkPoint offset, const SkPaint& modifiedPaint) { - proc(offset.fX, offset.fY, &modifiedPaint); - }); - } else { - proc(0, 0, sk_paint); - } - } - /** * A new SkiaDisplayList is created or recycled if available. *