• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkPaintFilterCanvas_DEFINED
9 #define SkPaintFilterCanvas_DEFINED
10 
11 #include "SkNWayCanvas.h"
12 #include "SkTLazy.h"
13 
14 /** \class SkPaintFilterCanvas
15 
16     A utility proxy base class for implementing draw/paint filters.
17 */
18 class SK_API SkPaintFilterCanvas : public SkNWayCanvas {
19 public:
20     /**
21      * The new SkPaintFilterCanvas is configured for forwarding to the
22      * specified canvas.  Also copies the target canvas matrix and clip bounds.
23      */
24     SkPaintFilterCanvas(SkCanvas* canvas);
25 
26     enum Type {
27         kPaint_Type,
28         kPoint_Type,
29         kArc_Type,
30         kBitmap_Type,
31         kRect_Type,
32         kRRect_Type,
33         kDRRect_Type,
34         kOval_Type,
35         kPath_Type,
36         kPicture_Type,
37         kText_Type,
38         kTextBlob_Type,
39         kVertices_Type,
40         kPatch_Type,
41 
42         kTypeCount
43     };
44 
45 protected:
46     /**
47      *  Called with the paint that will be used to draw the specified type.
48      *  The implementation may modify the paint as they wish (using SkTCopyOnFirstWrite::writable).
49      *
50      *  The result bool is used to determine whether the draw op is to be
51      *  executed (true) or skipped (false).
52      *
53      *  Note: The base implementation calls onFilter() for top-level/explicit paints only.
54      *        To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to
55      *        override the relevant methods (i.e. drawPicture, drawTextBlob).
56      */
57     virtual bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const = 0;
58 
59     void onDrawPaint(const SkPaint&) override;
60     void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
61     void onDrawRect(const SkRect&, const SkPaint&) override;
62     void onDrawRRect(const SkRRect&, const SkPaint&) override;
63     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
64     void onDrawOval(const SkRect&, const SkPaint&) override;
65     void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
66     void onDrawPath(const SkPath&, const SkPaint&) override;
67     void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
68     void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
69                           SrcRectConstraint) override;
70     void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
71                           const SkPaint*) override;
72     void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
73     void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
74                          const SkPaint*, SrcRectConstraint) override;
75     void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
76                          const SkPaint*) override;
77     void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
78     void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
79                              const SkPoint texCoords[4], SkBlendMode,
80                              const SkPaint& paint) override;
81     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
82 
83     void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
84                     const SkPaint&) override;
85     void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
86                        const SkPaint&) override;
87     void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
88                         SkScalar constY, const SkPaint&) override;
89     void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
90                           const SkMatrix* matrix, const SkPaint&) override;
91     void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
92                            const SkRect* cull, const SkPaint& paint) override;
93     void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
94                         const SkPaint& paint) override;
95 
96 private:
97     class AutoPaintFilter;
98 
99     typedef SkNWayCanvas INHERITED;
100 };
101 
102 #endif
103