aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-01-11 13:58:29 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-11 13:58:30 -0800
commitbad23dc9ed2e00f2a066db01ab88e4c4adcecfc6 (patch)
tree70e23d68615f8fc1070c7f0a4256c56d803c54c3 /include
parentce894007eb51c4dc34b2b6eb19ff6c772a1fb590 (diff)
SkPaintFilterCanvas skip-draw support
At the time SkPaintFilterCanvas was introduced as a SkDrawFilter replacement, no clients were relying on the draw veto logic. Now Chromium does. To facilitate migrating off SkDrawFilter, let's augment SkPaintFilterCanvas with skip-draw semantics. A side effect of the CL is that now we call the filter virtual even for null paints. BUG=skia:4782 R=reed@google.com,robertphillips@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1577933002 Review URL: https://codereview.chromium.org/1577933002
Diffstat (limited to 'include')
-rw-r--r--include/utils/SkPaintFilterCanvas.h30
1 files changed, 24 insertions, 6 deletions
diff --git a/include/utils/SkPaintFilterCanvas.h b/include/utils/SkPaintFilterCanvas.h
index 0ad7e251b6..505f965565 100644
--- a/include/utils/SkPaintFilterCanvas.h
+++ b/include/utils/SkPaintFilterCanvas.h
@@ -9,10 +9,11 @@
#define SkPaintFilterCanvas_DEFINED
#include "SkNWayCanvas.h"
+#include "SkTLazy.h"
/** \class SkPaintFilterCanvas
- A utility proxy base class for implementing paint filters.
+ A utility proxy base class for implementing draw/paint filters.
*/
class SK_API SkPaintFilterCanvas : public SkNWayCanvas {
public:
@@ -48,13 +49,28 @@ public:
protected:
/**
* Called with the paint that will be used to draw the specified type.
- * The implementation may modify the paint as they wish.
*
- * Note: The base implementation calls onFilterPaint() for top-level/explicit paints only.
+ * Upon return, if filteredPaint is initialized it will replace the original paint
+ * for the current draw. Note that that implementation is responsible for
+ * initializing *filteredPaint (e.g. via set(*paint)).
+ *
+ * The result bool is used to determine whether the draw op is to be
+ * executed (true) or skipped (false). When the draw is skipped, filteredPaint is
+ * ignored.
+ *
+ * Note: The base implementation calls onFilter() for top-level/explicit paints only.
* To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to
* override the relevant methods (i.e. drawPicture, drawTextBlob).
*/
- virtual void onFilterPaint(SkPaint* paint, Type type) const = 0;
+ virtual bool onFilter(const SkPaint* paint, Type type, SkTLazy<SkPaint>* filteredPaint) const {
+ if (paint) {
+ this->onFilterPaint(filteredPaint->set(*paint), type);
+ }
+ return true;
+ }
+
+ // DEPRECATED - do not use
+ virtual void onFilterPaint(SkPaint*, Type) const { }
void onDrawPaint(const SkPaint&) override;
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
@@ -66,11 +82,13 @@ protected:
void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
SrcRectConstraint) override;
+ void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
+ const SkPaint*) override;
void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
const SkPaint*, SrcRectConstraint) override;
- void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
- const SkPaint*) override;
+ void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
+ const SkPaint*) override;
void onDrawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
const SkColor colors[], SkXfermode* xmode,