summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mike Reed <reed@google.com> 2021-02-21 09:27:26 -0500
committer Mike Reed <reed@google.com> 2021-02-21 17:08:01 +0000
commit07bee70eb71fd40a309613f8e54957b240e8fbdb (patch)
tree432fdf30fb54be07b41bb0b0b6f288c4b218f597
parentee9b56d9bca5b1e0a996198cea040fc74e0b1c0f (diff)
Revert "Revert "Simplify calling loopers""
This reverts commit 1edec35288c7f2cb133d2f9f76d490155ec2a3be. Previous attempt at this mistakenly used a pointer to an rvalue, which was out of scope when it was used. e.g. const SkPaint* sk_paint = filterBitmap(paint); ... // now use sk_paint <-- bad Test: make Bug: 178700363 Change-Id: I2e2913385e05257c482a5d12eaeaddadd04126e2
-rw-r--r--libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp31
-rw-r--r--libs/hwui/pipeline/skia/SkiaRecordingCanvas.h17
2 files changed, 21 insertions, 27 deletions
diff --git a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
index b2884023a83d..04e3a1cb887e 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.cpp
@@ -194,25 +194,6 @@ SkiaCanvas::PaintCoW&& SkiaRecordingCanvas::filterBitmap(PaintCoW&& paint) {
return filterPaint(std::move(paint));
}
-static BlurDrawLooper* get_looper(const Paint* paint) {
- return paint ? paint->getLooper() : nullptr;
-}
-
-template <typename Proc>
-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;
@@ -226,8 +207,7 @@ static SkSamplingOptions Paint_to_sampling(const SkPaint* paint) {
void SkiaRecordingCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const Paint* paint) {
sk_sp<SkImage> image = bitmap.makeImage();
- applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y,
- const SkPaint* p) {
+ applyLooper(paint, [&](SkScalar x, SkScalar y, const SkPaint* p) {
mRecorder.drawImage(image, left + x, top + y, Paint_to_sampling(p), p, bitmap.palette());
});
@@ -245,8 +225,7 @@ void SkiaRecordingCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, con
sk_sp<SkImage> image = bitmap.makeImage();
- applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y,
- const SkPaint* p) {
+ applyLooper(paint, [&](SkScalar x, SkScalar y, const SkPaint* p) {
mRecorder.drawImage(image, x, y, Paint_to_sampling(p), p, bitmap.palette());
});
@@ -263,8 +242,7 @@ void SkiaRecordingCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop
sk_sp<SkImage> image = bitmap.makeImage();
- applyLooper(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y,
- const SkPaint* p) {
+ applyLooper(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());
});
@@ -303,8 +281,7 @@ 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(get_looper(paint), filterBitmap(paint), [&](SkScalar x, SkScalar y,
- const SkPaint* p) {
+ applyLooper(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 8d7a21a732dd..1e404b845084 100644
--- a/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h
+++ b/libs/hwui/pipeline/skia/SkiaRecordingCanvas.h
@@ -87,6 +87,23 @@ private:
std::unique_ptr<SkiaDisplayList> mDisplayList;
StartReorderBarrierDrawable* mCurrentBarrier;
+ template <typename Proc>
+ void applyLooper(const Paint* paint, Proc proc) {
+ SkPaint skp;
+ BlurDrawLooper* looper = nullptr;
+ if (paint) {
+ skp = *filterBitmap(paint);
+ looper = paint->getLooper();
+ }
+ if (looper) {
+ looper->apply(skp, [&](SkPoint offset, const SkPaint& modifiedPaint) {
+ proc(offset.fX, offset.fY, &modifiedPaint);
+ });
+ } else {
+ proc(0, 0, &skp);
+ }
+ }
+
/**
* A new SkiaDisplayList is created or recycled if available.
*