diff options
author | Ben Wagner <bungeman@google.com> | 2018-06-28 17:08:16 -0400 |
---|---|---|
committer | Ben Wagner <bungeman@google.com> | 2018-07-11 12:07:22 -0400 |
commit | 0ed10bedbb8d0821ff02d0209806614a585f68b4 (patch) | |
tree | 3d6d677a74a98b2347dce286083ea53f2c8e54d5 /libs/hwui/SkiaCanvas.h | |
parent | 9fb99abd78a9f7e0c7995ca68ff2226f1e7ba6ed (diff) |
Replace SkDrawFilter with PaintFilter.
Skia is removing SkDrawFilter.
Test: refactoring CL. Existing unit tests still pass.
Change-Id: If81c1a2feabf7d377ae1d7bcb3e8cf0f599ad3ce
Diffstat (limited to 'libs/hwui/SkiaCanvas.h')
-rw-r--r-- | libs/hwui/SkiaCanvas.h | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h index 3efc22a03cdf..24b7ec6d5c7b 100644 --- a/libs/hwui/SkiaCanvas.h +++ b/libs/hwui/SkiaCanvas.h @@ -22,7 +22,9 @@ #include "hwui/Canvas.h" #include <SkCanvas.h> -#include <SkTLazy.h> + +#include <cassert> +#include <optional> namespace android { @@ -87,8 +89,8 @@ public: virtual bool clipRect(float left, float top, float right, float bottom, SkClipOp op) override; virtual bool clipPath(const SkPath* path, SkClipOp op) override; - virtual SkDrawFilter* getDrawFilter() override; - virtual void setDrawFilter(SkDrawFilter* drawFilter) override; + virtual PaintFilter* getPaintFilter() override; + virtual void setPaintFilter(sk_sp<PaintFilter> paintFilter) override; virtual SkCanvasState* captureCanvasState() const override; @@ -158,6 +160,46 @@ protected: const SkPaint& paint, const SkPath& path, size_t start, size_t end) override; + /** This class acts as a copy on write SkPaint. + * + * Initially this will be the SkPaint passed to the contructor. + * The first time writable() is called this will become a copy of the + * initial SkPaint (or a default SkPaint if nullptr). + */ + struct PaintCoW { + PaintCoW(const SkPaint& that) : mPtr(&that) {} + PaintCoW(const SkPaint* ptr) : mPtr(ptr) {} + PaintCoW(const PaintCoW&) = delete; + PaintCoW(PaintCoW&&) = delete; + PaintCoW& operator=(const PaintCoW&) = delete; + PaintCoW& operator=(PaintCoW&&) = delete; + SkPaint& writeable() { + if (!mStorage) { + if (!mPtr) { + mStorage.emplace(); + } else { + mStorage.emplace(*mPtr); + } + mPtr = &*mStorage; + } + return *mStorage; + } + operator const SkPaint*() const { return mPtr; } + const SkPaint* operator->() const { assert(mPtr); return mPtr; } + const SkPaint& operator*() const { assert(mPtr); return *mPtr; } + explicit operator bool() { return mPtr != nullptr; } + private: + const SkPaint* mPtr; + std::optional<SkPaint> mStorage; + }; + + /** Filters the paint using the current paint filter. + * + * @param paint the paint to filter. Will be initialized with the default + * SkPaint before filtering if filtering is required. + */ + PaintCoW&& filterPaint(PaintCoW&& paint) const; + private: struct SaveRec { int saveCount; @@ -174,8 +216,15 @@ private: void drawPoints(const float* points, int count, const SkPaint& paint, SkCanvas::PointMode mode); - const SkPaint* addFilter(const SkPaint* origPaint, SkPaint* tmpPaint, - sk_sp<SkColorFilter> colorSpaceFilter); + /** Filters the paint for bitmap drawing. + * + * After filtering the paint for bitmap drawing, + * also calls filterPaint on the paint. + * + * @param paint the paint to filter. Will be initialized with the default + * SkPaint before filtering if filtering is required. + */ + PaintCoW&& filterBitmap(PaintCoW&& paint, sk_sp<SkColorFilter> colorSpaceFilter) const; class Clip; @@ -185,6 +234,7 @@ private: // unless it is the same as mCanvasOwned.get() std::unique_ptr<SkDeque> mSaveStack; // lazily allocated, tracks partial saves. std::vector<Clip> mClipStack; // tracks persistent clips. + sk_sp<PaintFilter> mPaintFilter; }; } // namespace android |