diff options
author | 2021-07-10 13:31:34 -0400 | |
---|---|---|
committer | 2021-07-12 09:29:59 -0400 | |
commit | a6cb58a924c24ba5f0ca928e850129a945792089 (patch) | |
tree | 3ae1724fee85f9568bd9c77be620fb751f4b9534 /libs/hwui/SkiaCanvas.cpp | |
parent | ba0a0ac99d43a392039135c72c9985d5c86af88a (diff) |
Store filterbitmap on Paint
Update Paint and SkiaCanvas now that SkFilterQuality is no longer
part of Skia's API.
1. Store mFilterBitmap:bool directly in Paint (matching java side)
2. Change Looper construct to operate on Paint rather than SkPaint
... so it can access mFilterBitmap.
3. Update PaintFilter to take Paint instead of SkPaint
As before, when we do have to call SkCanvas, we convert Paint's
mFilterBitmap into SkSamplingOptions as needed.
Test: make
Bug: 178700363
Change-Id: I7fccf17657d4e255f2453b4bfc513215503597b2
Diffstat (limited to 'libs/hwui/SkiaCanvas.cpp')
-rw-r--r-- | libs/hwui/SkiaCanvas.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index d032e2b00649..d6b6e162757c 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -182,7 +182,7 @@ int SkiaCanvas::saveUnclippedLayer(int left, int top, int right, int bottom) { return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds); } -void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const SkPaint& paint) { +void SkiaCanvas::restoreUnclippedLayer(int restoreCount, const Paint& paint) { while (mCanvas->getSaveCount() > restoreCount + 1) { this->restore(); @@ -439,13 +439,13 @@ void SkiaCanvas::drawColor(int color, SkBlendMode mode) { mCanvas->drawColor(color, mode); } -void SkiaCanvas::onFilterPaint(SkPaint& paint) { +void SkiaCanvas::onFilterPaint(Paint& paint) { if (mPaintFilter) { - mPaintFilter->filter(&paint); + mPaintFilter->filterFullPaint(&paint); } } -void SkiaCanvas::drawPaint(const SkPaint& paint) { +void SkiaCanvas::drawPaint(const Paint& paint) { mCanvas->drawPaint(filterPaint(paint)); } @@ -552,9 +552,8 @@ void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, cons void SkiaCanvas::drawBitmap(Bitmap& bitmap, float left, float top, const Paint* paint) { auto image = bitmap.makeImage(); - applyLooper(paint, [&](const SkPaint& p) { - auto sampling = SkSamplingOptions(p.getFilterQuality()); - mCanvas->drawImage(image, left, top, sampling, &p); + applyLooper(paint, [&](const Paint& p) { + mCanvas->drawImage(image, left, top, p.sampling(), &p); }); } @@ -562,9 +561,8 @@ void SkiaCanvas::drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const Paint* auto image = bitmap.makeImage(); SkAutoCanvasRestore acr(mCanvas, true); mCanvas->concat(matrix); - applyLooper(paint, [&](const SkPaint& p) { - auto sampling = SkSamplingOptions(p.getFilterQuality()); - mCanvas->drawImage(image, 0, 0, sampling, &p); + applyLooper(paint, [&](const Paint& p) { + mCanvas->drawImage(image, 0, 0, p.sampling(), &p); }); } @@ -575,18 +573,12 @@ void SkiaCanvas::drawBitmap(Bitmap& bitmap, float srcLeft, float srcTop, float s SkRect srcRect = SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom); SkRect dstRect = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); - applyLooper(paint, [&](const SkPaint& p) { - auto sampling = SkSamplingOptions(p.getFilterQuality()); - mCanvas->drawImageRect(image, srcRect, dstRect, sampling, &p, + applyLooper(paint, [&](const Paint& p) { + mCanvas->drawImageRect(image, srcRect, dstRect, p.sampling(), &p, SkCanvas::kFast_SrcRectConstraint); }); } -static SkFilterMode paintToFilter(const Paint* paint) { - return paint && paint->isFilterBitmap() ? SkFilterMode::kLinear - : SkFilterMode::kNearest; -} - void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, const float* vertices, const int* colors, const Paint* paint) { const int ptCount = (meshWidth + 1) * (meshHeight + 1); @@ -668,13 +660,13 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& bitmap, int meshWidth, int meshHeight, if (paint) { pnt = *paint; } - SkSamplingOptions sampling(paintToFilter(&pnt)); + SkSamplingOptions sampling = pnt.sampling(); pnt.setShader(image->makeShader(sampling)); auto v = builder.detach(); - applyLooper(&pnt, [&](const SkPaint& p) { + applyLooper(&pnt, [&](const Paint& p) { SkPaint copy(p); - auto s = SkSamplingOptions(p.getFilterQuality()); + auto s = p.sampling(); if (s != sampling) { // applyLooper changed the quality? copy.setShader(image->makeShader(s)); @@ -707,9 +699,8 @@ void SkiaCanvas::drawNinePatch(Bitmap& bitmap, const Res_png_9patch& chunk, floa lattice.fBounds = nullptr; SkRect dst = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom); auto image = bitmap.makeImage(); - applyLooper(paint, [&](const SkPaint& p) { - auto filter = SkSamplingOptions(p.getFilterQuality()).filter; - mCanvas->drawImageLattice(image.get(), lattice, dst, filter, &p); + applyLooper(paint, [&](const Paint& p) { + mCanvas->drawImageLattice(image.get(), lattice, dst, p.filterMode(), &p); }); } |