blob: 505f965565882f5784c7383e4f5b8f884a134e53 [file] [log] [blame]
fmalita65cdb572015-03-26 07:24:48 -07001/*
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"
fmalitabad23dc2016-01-11 13:58:29 -080012#include "SkTLazy.h"
fmalita65cdb572015-03-26 07:24:48 -070013
14/** \class SkPaintFilterCanvas
15
fmalitabad23dc2016-01-11 13:58:29 -080016 A utility proxy base class for implementing draw/paint filters.
fmalita65cdb572015-03-26 07:24:48 -070017*/
18class SK_API SkPaintFilterCanvas : public SkNWayCanvas {
19public:
fmalitaf433bb22015-08-17 08:05:13 -070020 /**
21 * DEPRECATED: use the variant below.
22 */
fmalita65cdb572015-03-26 07:24:48 -070023 SkPaintFilterCanvas(int width, int height);
24
fmalitaf433bb22015-08-17 08:05:13 -070025 /**
26 * The new SkPaintFilterCanvas is configured for forwarding to the
27 * specified canvas. Also copies the target canvas matrix and clip bounds.
28 */
29 SkPaintFilterCanvas(SkCanvas* canvas);
30
fmalita65cdb572015-03-26 07:24:48 -070031 enum Type {
32 kPaint_Type,
33 kPoint_Type,
34 kBitmap_Type,
35 kRect_Type,
36 kRRect_Type,
37 kDRRect_Type,
38 kOval_Type,
39 kPath_Type,
40 kPicture_Type,
41 kText_Type,
42 kTextBlob_Type,
43 kVertices_Type,
44 kPatch_Type,
45
46 kTypeCount
47 };
48
49protected:
50 /**
51 * Called with the paint that will be used to draw the specified type.
fmalita65cdb572015-03-26 07:24:48 -070052 *
fmalitabad23dc2016-01-11 13:58:29 -080053 * Upon return, if filteredPaint is initialized it will replace the original paint
54 * for the current draw. Note that that implementation is responsible for
55 * initializing *filteredPaint (e.g. via set(*paint)).
56 *
57 * The result bool is used to determine whether the draw op is to be
58 * executed (true) or skipped (false). When the draw is skipped, filteredPaint is
59 * ignored.
60 *
61 * Note: The base implementation calls onFilter() for top-level/explicit paints only.
fmalita65cdb572015-03-26 07:24:48 -070062 * To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to
63 * override the relevant methods (i.e. drawPicture, drawTextBlob).
64 */
fmalitabad23dc2016-01-11 13:58:29 -080065 virtual bool onFilter(const SkPaint* paint, Type type, SkTLazy<SkPaint>* filteredPaint) const {
66 if (paint) {
67 this->onFilterPaint(filteredPaint->set(*paint), type);
68 }
69 return true;
70 }
71
72 // DEPRECATED - do not use
73 virtual void onFilterPaint(SkPaint*, Type) const { }
fmalita65cdb572015-03-26 07:24:48 -070074
75 void onDrawPaint(const SkPaint&) override;
76 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
77 void onDrawRect(const SkRect&, const SkPaint&) override;
78 void onDrawRRect(const SkRRect&, const SkPaint&) override;
79 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
80 void onDrawOval(const SkRect&, const SkPaint&) override;
81 void onDrawPath(const SkPath&, const SkPaint&) override;
82 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
83 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
reed562fe472015-07-28 07:35:14 -070084 SrcRectConstraint) override;
fmalitabad23dc2016-01-11 13:58:29 -080085 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
86 const SkPaint*) override;
fmalita65cdb572015-03-26 07:24:48 -070087 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
88 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -070089 const SkPaint*, SrcRectConstraint) override;
fmalitabad23dc2016-01-11 13:58:29 -080090 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
91 const SkPaint*) override;
fmalita65cdb572015-03-26 07:24:48 -070092 void onDrawVertices(VertexMode vmode, int vertexCount,
93 const SkPoint vertices[], const SkPoint texs[],
94 const SkColor colors[], SkXfermode* xmode,
95 const uint16_t indices[], int indexCount,
96 const SkPaint&) override;
97 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
98 const SkPoint texCoords[4], SkXfermode* xmode,
99 const SkPaint& paint) override;
100 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
101
102 void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
103 const SkPaint&) override;
104 void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
105 const SkPaint&) override;
106 void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
107 SkScalar constY, const SkPaint&) override;
108 void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
109 const SkMatrix* matrix, const SkPaint&) override;
110 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
111 const SkPaint& paint) override;
112
113private:
114 class AutoPaintFilter;
115
116 typedef SkNWayCanvas INHERITED;
117};
118
119#endif