Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6cb58a9 authored by Mike Reed's avatar Mike Reed
Browse files

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
parent ba0a0ac9
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include "RecordingCanvas.h"
#include <hwui/Paint.h>

#include <GrRecordingContext.h>

@@ -495,7 +496,7 @@ struct DrawVectorDrawable final : Op {

    sp<VectorDrawableRoot> mRoot;
    SkRect mBounds;
    SkPaint paint;
    Paint paint;
    BitmapPalette palette;
};

@@ -833,7 +834,8 @@ constexpr color_transform_fn colorTransformForOp() {
                // TODO: We should be const. Or not. Or just use a different map
                // Unclear, but this is the quick fix
                const T* op = reinterpret_cast<const T*>(opRaw);
                transformPaint(transform, const_cast<SkPaint*>(&(op->paint)), op->palette);
                const SkPaint* paint = &op->paint;
                transformPaint(transform, const_cast<SkPaint*>(paint), op->palette);
            };
        }
    else if
@@ -842,7 +844,8 @@ constexpr color_transform_fn colorTransformForOp() {
                // TODO: We should be const. Or not. Or just use a different map
                // Unclear, but this is the quick fix
                const T* op = reinterpret_cast<const T*>(opRaw);
                transformPaint(transform, const_cast<SkPaint*>(&(op->paint)));
                const SkPaint* paint = &op->paint;
                transformPaint(transform, const_cast<SkPaint*>(paint));
            };
        }
    else {
+15 −24
Original line number Diff line number Diff line
@@ -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);
    });
}

+11 −11
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include "VectorDrawable.h"
#include "hwui/Canvas.h"
#include "hwui/Paint.h"
#include "hwui/BlurDrawLooper.h"

#include <SkCanvas.h>
#include "pipeline/skia/AnimatedDrawables.h"
@@ -73,7 +74,7 @@ public:
    virtual int save(SaveFlags::Flags flags) override;
    virtual void restore() override;
    virtual void restoreToCount(int saveCount) override;
    virtual void restoreUnclippedLayer(int saveCount, const SkPaint& paint) override;
    virtual void restoreUnclippedLayer(int saveCount, const Paint& paint) override;

    virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint) override;
    virtual int saveLayerAlpha(float left, float top, float right, float bottom, int alpha) override;
@@ -99,7 +100,7 @@ public:
    virtual SkCanvasState* captureCanvasState() const override;

    virtual void drawColor(int color, SkBlendMode mode) override;
    virtual void drawPaint(const SkPaint& paint) override;
    virtual void drawPaint(const Paint& paint) override;

    virtual void drawPoint(float x, float y, const Paint& paint) override;
    virtual void drawPoints(const float* points, int count, const Paint& paint) override;
@@ -167,10 +168,10 @@ protected:
                                  const Paint& paint, const SkPath& path, size_t start,
                                  size_t end) override;

    void onFilterPaint(SkPaint& paint);
    void onFilterPaint(Paint& paint);

    SkPaint filterPaint(const SkPaint& src) {
        SkPaint dst(src);
    Paint filterPaint(const Paint& src) {
        Paint dst(src);
        this->onFilterPaint(dst);
        return dst;
    }
@@ -179,21 +180,20 @@ protected:
    template <typename Proc>
    void applyLooper(const Paint* paint, Proc proc, void (*preFilter)(SkPaint&) = nullptr) {
        BlurDrawLooper* looper = paint ? paint->getLooper() : nullptr;
        const SkPaint* skpPtr = paint;
        SkPaint skp = skpPtr ? *skpPtr : SkPaint();
        Paint pnt = paint ? *paint : Paint();
        if (preFilter) {
            preFilter(skp);
            preFilter(pnt);
        }
        this->onFilterPaint(skp);
        this->onFilterPaint(pnt);
        if (looper) {
            looper->apply(skp, [&](SkPoint offset, const SkPaint& modifiedPaint) {
            looper->apply(pnt, [&](SkPoint offset, const Paint& modifiedPaint) {
                mCanvas->save();
                mCanvas->translate(offset.fX, offset.fY);
                proc(modifiedPaint);
                mCanvas->restore();
            });
        } else {
            proc(skp);
            proc(pnt);
        }
    }

+4 −4
Original line number Diff line number Diff line
@@ -463,10 +463,10 @@ void Tree::drawStaging(Canvas* outCanvas) {
        mStagingCache.dirty = false;
    }

    SkPaint skp;
    Paint skp;
    getPaintFor(&skp, mStagingProperties);
    Paint paint;
    paint.setFilterQuality(skp.getFilterQuality());
    paint.setFilterBitmap(skp.isFilterBitmap());
    paint.setColorFilter(skp.refColorFilter());
    paint.setAlpha(skp.getAlpha());
    outCanvas->drawBitmap(*mStagingCache.bitmap, 0, 0, mStagingCache.bitmap->width(),
@@ -476,9 +476,9 @@ void Tree::drawStaging(Canvas* outCanvas) {
                          mStagingProperties.getBounds().bottom(), &paint);
}

void Tree::getPaintFor(SkPaint* outPaint, const TreeProperties& prop) const {
void Tree::getPaintFor(Paint* outPaint, const TreeProperties& prop) const {
    // HWUI always draws VD with bilinear filtering.
    outPaint->setFilterQuality(kLow_SkFilterQuality);
    outPaint->setFilterBitmap(true);
    if (prop.getColorFilter() != nullptr) {
        outPaint->setColorFilter(sk_ref_sp(prop.getColorFilter()));
    }
+1 −1
Original line number Diff line number Diff line
@@ -648,7 +648,7 @@ public:
     */
    void draw(SkCanvas* canvas, const SkRect& bounds, const SkPaint& paint);

    void getPaintFor(SkPaint* outPaint, const TreeProperties &props) const;
    void getPaintFor(Paint* outPaint, const TreeProperties &props) const;
    BitmapPalette computePalette();

    void setAntiAlias(bool aa) { mRootNode->setAntiAlias(aa); }
Loading