• 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 "include/core/SkCanvasVirtualEnforcer.h"
12 #include "include/utils/SkNWayCanvas.h"
13 
14 class SkAndroidFrameworkUtils;
15 
16 /** \class SkPaintFilterCanvas
17 
18     A utility proxy base class for implementing draw/paint filters.
19 */
20 class SK_API SkPaintFilterCanvas : public SkCanvasVirtualEnforcer<SkNWayCanvas> {
21 public:
22     /**
23      * The new SkPaintFilterCanvas is configured for forwarding to the
24      * specified canvas.  Also copies the target canvas matrix and clip bounds.
25      */
26     SkPaintFilterCanvas(SkCanvas* canvas);
27 
28     enum Type {
29         kPicture_Type,
30     };
31 
32     // Forwarded to the wrapped canvas.
getBaseLayerSize()33     SkISize getBaseLayerSize() const override { return proxy()->getBaseLayerSize(); }
recordingContext()34     GrRecordingContext* recordingContext() override { return proxy()->recordingContext(); }
35 
36 protected:
37     /**
38      *  Called with the paint that will be used to draw the specified type.
39      *  The implementation may modify the paint as they wish.
40      *
41      *  The result bool is used to determine whether the draw op is to be
42      *  executed (true) or skipped (false).
43      *
44      *  Note: The base implementation calls onFilter() for top-level/explicit paints only.
45      *        To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to
46      *        override the relevant methods (i.e. drawPicture, drawTextBlob).
47      */
48     virtual bool onFilter(SkPaint& paint) const = 0;
49 
50     void onDrawPaint(const SkPaint&) override;
51     void onDrawBehind(const SkPaint&) override;
52     void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
53     void onDrawRect(const SkRect&, const SkPaint&) override;
54     void onDrawRRect(const SkRRect&, const SkPaint&) override;
55     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
56     void onDrawRegion(const SkRegion&, const SkPaint&) override;
57     void onDrawOval(const SkRect&, const SkPaint&) override;
58     void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
59     void onDrawPath(const SkPath&, const SkPaint&) override;
60 
61     void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
62                       const SkPaint*) override;
63     void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
64                           const SkPaint*, SrcRectConstraint) override;
65     void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
66                              const SkPaint*) override;
67     void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
68                      SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
69 
70     void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
71     void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
72                              const SkPoint texCoords[4], SkBlendMode,
73                              const SkPaint& paint) override;
74     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
75     void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
76 
77     void onDrawGlyphRunList(const SkGlyphRunList&, const SkPaint&) override;
78     void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
79                         const SkPaint& paint) override;
80     void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
81     void onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) override;
82 
83     void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
84                           SkBlendMode) override;
85     void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
86                                const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override;
87 
88     // Forwarded to the wrapped canvas.
89     sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
90     bool onPeekPixels(SkPixmap* pixmap) override;
91     bool onAccessTopLayerPixels(SkPixmap* pixmap) override;
92     SkImageInfo onImageInfo() const override;
93     bool onGetProps(SkSurfaceProps* props) const override;
94 
95 private:
96     class AutoPaintFilter;
97 
proxy()98     SkCanvas* proxy() const { SkASSERT(fList.count() == 1); return fList[0]; }
99 
internal_private_asPaintFilterCanvas()100     SkPaintFilterCanvas* internal_private_asPaintFilterCanvas() const override {
101         return const_cast<SkPaintFilterCanvas*>(this);
102     }
103 
104     friend class SkAndroidFrameworkUtils;
105 };
106 
107 #endif
108