OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPaintFilterCanvas.h" | 8 #include "SkPaintFilterCanvas.h" |
9 | 9 |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkTLazy.h" | 11 #include "SkTLazy.h" |
12 | 12 |
13 class SkPaintFilterCanvas::AutoPaintFilter { | 13 class SkPaintFilterCanvas::AutoPaintFilter { |
14 public: | 14 public: |
15 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint*
paint) { | 15 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint*
paint) { |
16 if (paint) { | 16 if (paint) { |
17 canvas->onFilterPaint(fLazyPaint.set(*paint), type); | 17 fLazyPaint.set(*paint); |
18 } | 18 } |
| 19 |
| 20 fShouldDraw = canvas->onFilter(fLazyPaint.getMaybeNull(), type); |
19 } | 21 } |
20 | 22 |
21 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint&
paint) { | 23 AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint&
paint) { |
22 canvas->onFilterPaint(fLazyPaint.set(paint), type); | 24 fShouldDraw = canvas->onFilter(fLazyPaint.set(paint), type); |
23 } | 25 } |
24 | 26 |
25 const SkPaint* paint() const { return fLazyPaint.getMaybeNull(); } | 27 const SkPaint* paint() const { return fLazyPaint.getMaybeNull(); } |
26 | 28 |
| 29 bool shouldDraw() const { return fShouldDraw; } |
| 30 |
27 private: | 31 private: |
28 SkTLazy<SkPaint> fLazyPaint; | 32 SkTLazy<SkPaint> fLazyPaint; |
| 33 bool fShouldDraw; |
29 }; | 34 }; |
30 | 35 |
31 SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(widt
h, height) { } | 36 SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(widt
h, height) { } |
32 | 37 |
33 SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas) | 38 SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas) |
34 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) { | 39 : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height()) { |
35 | 40 |
36 // Transfer matrix & clip state before adding the target canvas. | 41 // Transfer matrix & clip state before adding the target canvas. |
37 SkIRect devClip; | 42 SkIRect devClip; |
38 canvas->getClipDeviceBounds(&devClip); | 43 canvas->getClipDeviceBounds(&devClip); |
39 this->clipRect(SkRect::Make(devClip)); | 44 this->clipRect(SkRect::Make(devClip)); |
40 this->setMatrix(canvas->getTotalMatrix()); | 45 this->setMatrix(canvas->getTotalMatrix()); |
41 | 46 |
42 this->addCanvas(canvas); | 47 this->addCanvas(canvas); |
43 } | 48 } |
44 | 49 |
45 void SkPaintFilterCanvas::onDrawPaint(const SkPaint& paint) { | 50 void SkPaintFilterCanvas::onDrawPaint(const SkPaint& paint) { |
46 AutoPaintFilter apf(this, kPaint_Type, paint); | 51 AutoPaintFilter apf(this, kPaint_Type, paint); |
47 this->INHERITED::onDrawPaint(*apf.paint()); | 52 if (apf.shouldDraw()) { |
| 53 this->INHERITED::onDrawPaint(*apf.paint()); |
| 54 } |
48 } | 55 } |
49 | 56 |
50 void SkPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoi
nt pts[], | 57 void SkPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoi
nt pts[], |
51 const SkPaint& paint) { | 58 const SkPaint& paint) { |
52 AutoPaintFilter apf(this, kPoint_Type, paint); | 59 AutoPaintFilter apf(this, kPoint_Type, paint); |
53 this->INHERITED::onDrawPoints(mode, count, pts, *apf.paint()); | 60 if (apf.shouldDraw()) { |
| 61 this->INHERITED::onDrawPoints(mode, count, pts, *apf.paint()); |
| 62 } |
54 } | 63 } |
55 | 64 |
56 void SkPaintFilterCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { | 65 void SkPaintFilterCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { |
57 AutoPaintFilter apf(this, kRect_Type, paint); | 66 AutoPaintFilter apf(this, kRect_Type, paint); |
58 this->INHERITED::onDrawRect(rect, *apf.paint()); | 67 if (apf.shouldDraw()) { |
| 68 this->INHERITED::onDrawRect(rect, *apf.paint()); |
| 69 } |
59 } | 70 } |
60 | 71 |
61 void SkPaintFilterCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint
) { | 72 void SkPaintFilterCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint
) { |
62 AutoPaintFilter apf(this, kRRect_Type, paint); | 73 AutoPaintFilter apf(this, kRRect_Type, paint); |
63 this->INHERITED::onDrawRRect(rrect, *apf.paint()); | 74 if (apf.shouldDraw()) { |
| 75 this->INHERITED::onDrawRRect(rrect, *apf.paint()); |
| 76 } |
64 } | 77 } |
65 | 78 |
66 void SkPaintFilterCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inne
r, | 79 void SkPaintFilterCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inne
r, |
67 const SkPaint& paint) { | 80 const SkPaint& paint) { |
68 AutoPaintFilter apf(this, kDRRect_Type, paint); | 81 AutoPaintFilter apf(this, kDRRect_Type, paint); |
69 this->INHERITED::onDrawDRRect(outer, inner, *apf.paint()); | 82 if (apf.shouldDraw()) { |
| 83 this->INHERITED::onDrawDRRect(outer, inner, *apf.paint()); |
| 84 } |
70 } | 85 } |
71 | 86 |
72 void SkPaintFilterCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { | 87 void SkPaintFilterCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { |
73 AutoPaintFilter apf(this, kOval_Type, paint); | 88 AutoPaintFilter apf(this, kOval_Type, paint); |
74 this->INHERITED::onDrawOval(rect, *apf.paint()); | 89 if (apf.shouldDraw()) { |
| 90 this->INHERITED::onDrawOval(rect, *apf.paint()); |
| 91 } |
75 } | 92 } |
76 | 93 |
77 void SkPaintFilterCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { | 94 void SkPaintFilterCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { |
78 AutoPaintFilter apf(this, kPath_Type, paint); | 95 AutoPaintFilter apf(this, kPath_Type, paint); |
79 this->INHERITED::onDrawPath(path, *apf.paint()); | 96 if (apf.shouldDraw()) { |
| 97 this->INHERITED::onDrawPath(path, *apf.paint()); |
| 98 } |
80 } | 99 } |
81 | 100 |
82 void SkPaintFilterCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScal
ar top, | 101 void SkPaintFilterCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScal
ar top, |
83 const SkPaint* paint) { | 102 const SkPaint* paint) { |
84 AutoPaintFilter apf(this, kBitmap_Type, paint); | 103 AutoPaintFilter apf(this, kBitmap_Type, paint); |
85 this->INHERITED::onDrawBitmap(bm, left, top, apf.paint()); | 104 if (apf.shouldDraw()) { |
| 105 this->INHERITED::onDrawBitmap(bm, left, top, apf.paint()); |
| 106 } |
86 } | 107 } |
87 | 108 |
88 void SkPaintFilterCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src
, const SkRect& dst, | 109 void SkPaintFilterCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src
, const SkRect& dst, |
89 const SkPaint* paint, SrcRectConstrai
nt constraint) { | 110 const SkPaint* paint, SrcRectConstrai
nt constraint) { |
90 AutoPaintFilter apf(this, kBitmap_Type, paint); | 111 AutoPaintFilter apf(this, kBitmap_Type, paint); |
91 this->INHERITED::onDrawBitmapRect(bm, src, dst, apf.paint(), constraint); | 112 if (apf.shouldDraw()) { |
| 113 this->INHERITED::onDrawBitmapRect(bm, src, dst, apf.paint(), constraint)
; |
| 114 } |
92 } | 115 } |
93 | 116 |
94 void SkPaintFilterCanvas::onDrawImage(const SkImage* image, SkScalar left, SkSca
lar top, | 117 void SkPaintFilterCanvas::onDrawImage(const SkImage* image, SkScalar left, SkSca
lar top, |
95 const SkPaint* paint) { | 118 const SkPaint* paint) { |
96 AutoPaintFilter apf(this, kBitmap_Type, paint); | 119 AutoPaintFilter apf(this, kBitmap_Type, paint); |
97 this->INHERITED::onDrawImage(image, left, top, apf.paint()); | 120 if (apf.shouldDraw()) { |
| 121 this->INHERITED::onDrawImage(image, left, top, apf.paint()); |
| 122 } |
98 } | 123 } |
99 | 124 |
100 void SkPaintFilterCanvas::onDrawImageRect(const SkImage* image, const SkRect* sr
c, | 125 void SkPaintFilterCanvas::onDrawImageRect(const SkImage* image, const SkRect* sr
c, |
101 const SkRect& dst, const SkPaint* pain
t, | 126 const SkRect& dst, const SkPaint* pain
t, |
102 SrcRectConstraint constraint) { | 127 SrcRectConstraint constraint) { |
103 AutoPaintFilter apf(this, kBitmap_Type, paint); | 128 AutoPaintFilter apf(this, kBitmap_Type, paint); |
104 this->INHERITED::onDrawImageRect(image, src, dst, apf.paint(), constraint); | 129 if (apf.shouldDraw()) { |
| 130 this->INHERITED::onDrawImageRect(image, src, dst, apf.paint(), constrain
t); |
| 131 } |
105 } | 132 } |
106 | 133 |
107 void SkPaintFilterCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& ce
nter, | 134 void SkPaintFilterCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& ce
nter, |
108 const SkRect& dst, const SkPaint* pai
nt) { | 135 const SkRect& dst, const SkPaint* pai
nt) { |
109 AutoPaintFilter apf(this, kBitmap_Type, paint); | 136 AutoPaintFilter apf(this, kBitmap_Type, paint); |
110 this->INHERITED::onDrawBitmapNine(bm, center, dst, apf.paint()); | 137 if (apf.shouldDraw()) { |
| 138 this->INHERITED::onDrawBitmapNine(bm, center, dst, apf.paint()); |
| 139 } |
111 } | 140 } |
112 | 141 |
113 void SkPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount, | 142 void SkPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount, |
114 const SkPoint vertices[], const SkPoint
texs[], | 143 const SkPoint vertices[], const SkPoint
texs[], |
115 const SkColor colors[], SkXfermode* xmo
de, | 144 const SkColor colors[], SkXfermode* xmo
de, |
116 const uint16_t indices[], int indexCoun
t, | 145 const uint16_t indices[], int indexCoun
t, |
117 const SkPaint& paint) { | 146 const SkPaint& paint) { |
118 AutoPaintFilter apf(this, kVertices_Type, paint); | 147 AutoPaintFilter apf(this, kVertices_Type, paint); |
119 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors,
xmode, indices, | 148 if (apf.shouldDraw()) { |
120 indexCount, *apf.paint()); | 149 this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colo
rs, xmode, indices, |
| 150 indexCount, *apf.paint()); |
| 151 } |
121 } | 152 } |
122 | 153 |
123 void SkPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColor colo
rs[], | 154 void SkPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColor colo
rs[], |
124 const SkPoint texCoords[], SkXfermode* xmo
de, | 155 const SkPoint texCoords[], SkXfermode* xmo
de, |
125 const SkPaint& paint) { | 156 const SkPaint& paint) { |
126 AutoPaintFilter apf(this, kPatch_Type, paint); | 157 AutoPaintFilter apf(this, kPatch_Type, paint); |
127 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, *apf.paint())
; | 158 if (apf.shouldDraw()) { |
| 159 this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, *apf.pain
t()); |
| 160 } |
128 } | 161 } |
129 | 162 |
130 void SkPaintFilterCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix
* m, | 163 void SkPaintFilterCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix
* m, |
131 const SkPaint* paint) { | 164 const SkPaint* paint) { |
132 AutoPaintFilter apf(this, kPicture_Type, paint); | 165 AutoPaintFilter apf(this, kPicture_Type, paint); |
133 this->INHERITED::onDrawPicture(picture, m, apf.paint()); | 166 if (apf.shouldDraw()) { |
| 167 this->INHERITED::onDrawPicture(picture, m, apf.paint()); |
| 168 } |
134 } | 169 } |
135 | 170 |
136 void SkPaintFilterCanvas::onDrawText(const void* text, size_t byteLength, SkScal
ar x, SkScalar y, | 171 void SkPaintFilterCanvas::onDrawText(const void* text, size_t byteLength, SkScal
ar x, SkScalar y, |
137 const SkPaint& paint) { | 172 const SkPaint& paint) { |
138 AutoPaintFilter apf(this, kText_Type, paint); | 173 AutoPaintFilter apf(this, kText_Type, paint); |
139 this->INHERITED::onDrawText(text, byteLength, x, y, *apf.paint()); | 174 if (apf.shouldDraw()) { |
| 175 this->INHERITED::onDrawText(text, byteLength, x, y, *apf.paint()); |
| 176 } |
140 } | 177 } |
141 | 178 |
142 void SkPaintFilterCanvas::onDrawPosText(const void* text, size_t byteLength, con
st SkPoint pos[], | 179 void SkPaintFilterCanvas::onDrawPosText(const void* text, size_t byteLength, con
st SkPoint pos[], |
143 const SkPaint& paint) { | 180 const SkPaint& paint) { |
144 AutoPaintFilter apf(this, kText_Type, paint); | 181 AutoPaintFilter apf(this, kText_Type, paint); |
145 this->INHERITED::onDrawPosText(text, byteLength, pos, *apf.paint()); | 182 if (apf.shouldDraw()) { |
| 183 this->INHERITED::onDrawPosText(text, byteLength, pos, *apf.paint()); |
| 184 } |
146 } | 185 } |
147 | 186 |
148 void SkPaintFilterCanvas::onDrawPosTextH(const void* text, size_t byteLength, co
nst SkScalar xpos[], | 187 void SkPaintFilterCanvas::onDrawPosTextH(const void* text, size_t byteLength, co
nst SkScalar xpos[], |
149 SkScalar constY, const SkPaint& paint)
{ | 188 SkScalar constY, const SkPaint& paint)
{ |
150 AutoPaintFilter apf(this, kText_Type, paint); | 189 AutoPaintFilter apf(this, kText_Type, paint); |
151 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, *apf.paint()
); | 190 if (apf.shouldDraw()) { |
| 191 this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, *apf.pai
nt()); |
| 192 } |
152 } | 193 } |
153 | 194 |
154 void SkPaintFilterCanvas::onDrawTextOnPath(const void* text, size_t byteLength,
const SkPath& path, | 195 void SkPaintFilterCanvas::onDrawTextOnPath(const void* text, size_t byteLength,
const SkPath& path, |
155 const SkMatrix* matrix, const SkPaint
& paint) { | 196 const SkMatrix* matrix, const SkPaint
& paint) { |
156 AutoPaintFilter apf(this, kText_Type, paint); | 197 AutoPaintFilter apf(this, kText_Type, paint); |
157 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, *apf.paint
()); | 198 if (apf.shouldDraw()) { |
| 199 this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, *apf.p
aint()); |
| 200 } |
158 } | 201 } |
159 | 202 |
160 void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkS
calar y, | 203 void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkS
calar y, |
161 const SkPaint& paint) { | 204 const SkPaint& paint) { |
162 AutoPaintFilter apf(this, kTextBlob_Type, paint); | 205 AutoPaintFilter apf(this, kTextBlob_Type, paint); |
163 this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint()); | 206 if (apf.shouldDraw()) { |
| 207 this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint()); |
| 208 } |
164 } | 209 } |
OLD | NEW |