1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "SkNWayCanvas.h"
9
SkNWayCanvas(int width,int height)10 SkNWayCanvas::SkNWayCanvas(int width, int height)
11 : INHERITED(width, height) {}
12
~SkNWayCanvas()13 SkNWayCanvas::~SkNWayCanvas() {
14 this->removeAll();
15 }
16
addCanvas(SkCanvas * canvas)17 void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
18 if (canvas) {
19 canvas->ref();
20 *fList.append() = canvas;
21 }
22 }
23
removeCanvas(SkCanvas * canvas)24 void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
25 int index = fList.find(canvas);
26 if (index >= 0) {
27 canvas->unref();
28 fList.removeShuffle(index);
29 }
30 }
31
removeAll()32 void SkNWayCanvas::removeAll() {
33 fList.unrefAll();
34 fList.reset();
35 }
36
37 ///////////////////////////////////////////////////////////////////////////
38 // These are forwarded to the N canvases we're referencing
39
40 class SkNWayCanvas::Iter {
41 public:
Iter(const SkTDArray<SkCanvas * > & list)42 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
43 fIndex = 0;
44 }
next()45 bool next() {
46 if (fIndex < fList.count()) {
47 fCanvas = fList[fIndex++];
48 return true;
49 }
50 return false;
51 }
operator ->()52 SkCanvas* operator->() { return fCanvas; }
53
54 private:
55 const SkTDArray<SkCanvas*>& fList;
56 int fIndex;
57 SkCanvas* fCanvas;
58 };
59
willSave()60 void SkNWayCanvas::willSave() {
61 Iter iter(fList);
62 while (iter.next()) {
63 iter->save();
64 }
65
66 this->INHERITED::willSave();
67 }
68
willSaveLayer(const SkRect * bounds,const SkPaint * paint,SaveFlags flags)69 SkCanvas::SaveLayerStrategy SkNWayCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
70 SaveFlags flags) {
71 Iter iter(fList);
72 while (iter.next()) {
73 iter->saveLayer(bounds, paint, flags);
74 }
75
76 this->INHERITED::willSaveLayer(bounds, paint, flags);
77 // No need for a layer.
78 return kNoLayer_SaveLayerStrategy;
79 }
80
willRestore()81 void SkNWayCanvas::willRestore() {
82 Iter iter(fList);
83 while (iter.next()) {
84 iter->restore();
85 }
86 this->INHERITED::willRestore();
87 }
88
didConcat(const SkMatrix & matrix)89 void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
90 Iter iter(fList);
91 while (iter.next()) {
92 iter->concat(matrix);
93 }
94 this->INHERITED::didConcat(matrix);
95 }
96
didSetMatrix(const SkMatrix & matrix)97 void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
98 Iter iter(fList);
99 while (iter.next()) {
100 iter->setMatrix(matrix);
101 }
102 this->INHERITED::didSetMatrix(matrix);
103 }
104
onClipRect(const SkRect & rect,SkRegion::Op op,ClipEdgeStyle edgeStyle)105 void SkNWayCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
106 Iter iter(fList);
107 while (iter.next()) {
108 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
109 }
110 this->INHERITED::onClipRect(rect, op, edgeStyle);
111 }
112
onClipRRect(const SkRRect & rrect,SkRegion::Op op,ClipEdgeStyle edgeStyle)113 void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
114 Iter iter(fList);
115 while (iter.next()) {
116 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
117 }
118 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
119 }
120
onClipPath(const SkPath & path,SkRegion::Op op,ClipEdgeStyle edgeStyle)121 void SkNWayCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
122 Iter iter(fList);
123 while (iter.next()) {
124 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
125 }
126 this->INHERITED::onClipPath(path, op, edgeStyle);
127 }
128
onClipRegion(const SkRegion & deviceRgn,SkRegion::Op op)129 void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
130 Iter iter(fList);
131 while (iter.next()) {
132 iter->clipRegion(deviceRgn, op);
133 }
134 this->INHERITED::onClipRegion(deviceRgn, op);
135 }
136
onDrawPaint(const SkPaint & paint)137 void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
138 Iter iter(fList);
139 while (iter.next()) {
140 iter->drawPaint(paint);
141 }
142 }
143
onDrawPoints(PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)144 void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
145 const SkPaint& paint) {
146 Iter iter(fList);
147 while (iter.next()) {
148 iter->drawPoints(mode, count, pts, paint);
149 }
150 }
151
onDrawRect(const SkRect & rect,const SkPaint & paint)152 void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
153 Iter iter(fList);
154 while (iter.next()) {
155 iter->drawRect(rect, paint);
156 }
157 }
158
onDrawOval(const SkRect & rect,const SkPaint & paint)159 void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
160 Iter iter(fList);
161 while (iter.next()) {
162 iter->drawOval(rect, paint);
163 }
164 }
165
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)166 void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
167 Iter iter(fList);
168 while (iter.next()) {
169 iter->drawRRect(rrect, paint);
170 }
171 }
172
onDrawDRRect(const SkRRect & outer,const SkRRect & inner,const SkPaint & paint)173 void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
174 const SkPaint& paint) {
175 Iter iter(fList);
176 while (iter.next()) {
177 iter->drawDRRect(outer, inner, paint);
178 }
179 }
180
onDrawPath(const SkPath & path,const SkPaint & paint)181 void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
182 Iter iter(fList);
183 while (iter.next()) {
184 iter->drawPath(path, paint);
185 }
186 }
187
onDrawBitmap(const SkBitmap & bitmap,SkScalar x,SkScalar y,const SkPaint * paint)188 void SkNWayCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
189 const SkPaint* paint) {
190 Iter iter(fList);
191 while (iter.next()) {
192 iter->drawBitmap(bitmap, x, y, paint);
193 }
194 }
195
onDrawBitmapRect(const SkBitmap & bitmap,const SkRect * src,const SkRect & dst,const SkPaint * paint,DrawBitmapRectFlags flags)196 void SkNWayCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
197 const SkPaint* paint, DrawBitmapRectFlags flags) {
198 Iter iter(fList);
199 while (iter.next()) {
200 iter->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
201 }
202 }
203
onDrawBitmapNine(const SkBitmap & bitmap,const SkIRect & center,const SkRect & dst,const SkPaint * paint)204 void SkNWayCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
205 const SkRect& dst, const SkPaint* paint) {
206 Iter iter(fList);
207 while (iter.next()) {
208 iter->drawBitmapNine(bitmap, center, dst, paint);
209 }
210 }
211
onDrawImage(const SkImage * image,SkScalar left,SkScalar top,const SkPaint * paint)212 void SkNWayCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
213 const SkPaint* paint) {
214 Iter iter(fList);
215 while (iter.next()) {
216 iter->drawImage(image, left, top, paint);
217 }
218 }
219
onDrawImageRect(const SkImage * image,const SkRect * src,const SkRect & dst,const SkPaint * paint)220 void SkNWayCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
221 const SkPaint* paint) {
222 Iter iter(fList);
223 while (iter.next()) {
224 iter->drawImageRect(image, src, dst, paint);
225 }
226 }
227
onDrawSprite(const SkBitmap & bitmap,int x,int y,const SkPaint * paint)228 void SkNWayCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint* paint) {
229 Iter iter(fList);
230 while (iter.next()) {
231 iter->drawSprite(bitmap, x, y, paint);
232 }
233 }
234
onDrawText(const void * text,size_t byteLength,SkScalar x,SkScalar y,const SkPaint & paint)235 void SkNWayCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
236 const SkPaint& paint) {
237 Iter iter(fList);
238 while (iter.next()) {
239 iter->drawText(text, byteLength, x, y, paint);
240 }
241 }
242
onDrawPosText(const void * text,size_t byteLength,const SkPoint pos[],const SkPaint & paint)243 void SkNWayCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
244 const SkPaint& paint) {
245 Iter iter(fList);
246 while (iter.next()) {
247 iter->drawPosText(text, byteLength, pos, paint);
248 }
249 }
250
onDrawPosTextH(const void * text,size_t byteLength,const SkScalar xpos[],SkScalar constY,const SkPaint & paint)251 void SkNWayCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
252 SkScalar constY, const SkPaint& paint) {
253 Iter iter(fList);
254 while (iter.next()) {
255 iter->drawPosTextH(text, byteLength, xpos, constY, paint);
256 }
257 }
258
onDrawTextOnPath(const void * text,size_t byteLength,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)259 void SkNWayCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
260 const SkMatrix* matrix, const SkPaint& paint) {
261 Iter iter(fList);
262 while (iter.next()) {
263 iter->drawTextOnPath(text, byteLength, path, matrix, paint);
264 }
265 }
266
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)267 void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
268 const SkPaint &paint) {
269 Iter iter(fList);
270 while (iter.next()) {
271 iter->drawTextBlob(blob, x, y, paint);
272 }
273 }
274
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)275 void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
276 const SkPaint* paint) {
277 Iter iter(fList);
278 while (iter.next()) {
279 iter->drawPicture(picture, matrix, paint);
280 }
281 }
282
onDrawVertices(VertexMode vmode,int vertexCount,const SkPoint vertices[],const SkPoint texs[],const SkColor colors[],SkXfermode * xmode,const uint16_t indices[],int indexCount,const SkPaint & paint)283 void SkNWayCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
284 const SkPoint vertices[], const SkPoint texs[],
285 const SkColor colors[], SkXfermode* xmode,
286 const uint16_t indices[], int indexCount,
287 const SkPaint& paint) {
288 Iter iter(fList);
289 while (iter.next()) {
290 iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
291 indices, indexCount, paint);
292 }
293 }
294
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkXfermode * xmode,const SkPaint & paint)295 void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
296 const SkPoint texCoords[4], SkXfermode* xmode,
297 const SkPaint& paint) {
298 Iter iter(fList);
299 while (iter.next()) {
300 iter->drawPatch(cubics, colors, texCoords, xmode, paint);
301 }
302 }
303
setDrawFilter(SkDrawFilter * filter)304 SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
305 Iter iter(fList);
306 while (iter.next()) {
307 iter->setDrawFilter(filter);
308 }
309 return this->INHERITED::setDrawFilter(filter);
310 }
311
beginCommentGroup(const char * description)312 void SkNWayCanvas::beginCommentGroup(const char* description) {
313 Iter iter(fList);
314 while (iter.next()) {
315 iter->beginCommentGroup(description);
316 }
317 }
318
addComment(const char * kywd,const char * value)319 void SkNWayCanvas::addComment(const char* kywd, const char* value) {
320 Iter iter(fList);
321 while (iter.next()) {
322 iter->addComment(kywd, value);
323 }
324 }
325
endCommentGroup()326 void SkNWayCanvas::endCommentGroup() {
327 Iter iter(fList);
328 while (iter.next()) {
329 iter->endCommentGroup();
330 }
331 }
332