1 /*
2 * Copyright 2011 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 #include "include/utils/SkNWayCanvas.h"
9 #include "src/core/SkCanvasPriv.h"
10
SkNWayCanvas(int width,int height)11 SkNWayCanvas::SkNWayCanvas(int width, int height) : 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 *fList.append() = canvas;
20 }
21 }
22
removeCanvas(SkCanvas * canvas)23 void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
24 int index = fList.find(canvas);
25 if (index >= 0) {
26 fList.removeShuffle(index);
27 }
28 }
29
removeAll()30 void SkNWayCanvas::removeAll() {
31 fList.reset();
32 }
33
34 ///////////////////////////////////////////////////////////////////////////
35 // These are forwarded to the N canvases we're referencing
36
37 class SkNWayCanvas::Iter {
38 public:
Iter(const SkTDArray<SkCanvas * > & list)39 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
40 fIndex = 0;
41 }
next()42 bool next() {
43 if (fIndex < fList.count()) {
44 fCanvas = fList[fIndex++];
45 return true;
46 }
47 return false;
48 }
operator ->()49 SkCanvas* operator->() { return fCanvas; }
get() const50 SkCanvas* get() const { return fCanvas; }
51
52 private:
53 const SkTDArray<SkCanvas*>& fList;
54 int fIndex;
55 SkCanvas* fCanvas;
56 };
57
willSave()58 void SkNWayCanvas::willSave() {
59 Iter iter(fList);
60 while (iter.next()) {
61 iter->save();
62 }
63
64 this->INHERITED::willSave();
65 }
66
getSaveLayerStrategy(const SaveLayerRec & rec)67 SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
68 Iter iter(fList);
69 while (iter.next()) {
70 iter->saveLayer(rec);
71 }
72
73 this->INHERITED::getSaveLayerStrategy(rec);
74 // No need for a layer.
75 return kNoLayer_SaveLayerStrategy;
76 }
77
onDoSaveBehind(const SkRect * bounds)78 bool SkNWayCanvas::onDoSaveBehind(const SkRect* bounds) {
79 Iter iter(fList);
80 while (iter.next()) {
81 SkCanvasPriv::SaveBehind(iter.get(), bounds);
82 }
83 this->INHERITED::onDoSaveBehind(bounds);
84 return false;
85 }
86
willRestore()87 void SkNWayCanvas::willRestore() {
88 Iter iter(fList);
89 while (iter.next()) {
90 iter->restore();
91 }
92 this->INHERITED::willRestore();
93 }
94
didConcat(const SkMatrix & matrix)95 void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
96 Iter iter(fList);
97 while (iter.next()) {
98 iter->concat(matrix);
99 }
100 this->INHERITED::didConcat(matrix);
101 }
102
didSetMatrix(const SkMatrix & matrix)103 void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
104 Iter iter(fList);
105 while (iter.next()) {
106 iter->setMatrix(matrix);
107 }
108 this->INHERITED::didSetMatrix(matrix);
109 }
110
onClipRect(const SkRect & rect,SkClipOp op,ClipEdgeStyle edgeStyle)111 void SkNWayCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
112 Iter iter(fList);
113 while (iter.next()) {
114 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
115 }
116 this->INHERITED::onClipRect(rect, op, edgeStyle);
117 }
118
onClipRRect(const SkRRect & rrect,SkClipOp op,ClipEdgeStyle edgeStyle)119 void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
120 Iter iter(fList);
121 while (iter.next()) {
122 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
123 }
124 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
125 }
126
onClipPath(const SkPath & path,SkClipOp op,ClipEdgeStyle edgeStyle)127 void SkNWayCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
128 Iter iter(fList);
129 while (iter.next()) {
130 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
131 }
132 this->INHERITED::onClipPath(path, op, edgeStyle);
133 }
134
onClipRegion(const SkRegion & deviceRgn,SkClipOp op)135 void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
136 Iter iter(fList);
137 while (iter.next()) {
138 iter->clipRegion(deviceRgn, op);
139 }
140 this->INHERITED::onClipRegion(deviceRgn, op);
141 }
142
onDrawPaint(const SkPaint & paint)143 void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
144 Iter iter(fList);
145 while (iter.next()) {
146 iter->drawPaint(paint);
147 }
148 }
149
onDrawBehind(const SkPaint & paint)150 void SkNWayCanvas::onDrawBehind(const SkPaint& paint) {
151 Iter iter(fList);
152 while (iter.next()) {
153 SkCanvasPriv::DrawBehind(iter.get(), paint);
154 }
155 }
156
onDrawPoints(PointMode mode,size_t count,const SkPoint pts[],const SkPaint & paint)157 void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
158 const SkPaint& paint) {
159 Iter iter(fList);
160 while (iter.next()) {
161 iter->drawPoints(mode, count, pts, paint);
162 }
163 }
164
onDrawRect(const SkRect & rect,const SkPaint & paint)165 void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
166 Iter iter(fList);
167 while (iter.next()) {
168 iter->drawRect(rect, paint);
169 }
170 }
171
onDrawRegion(const SkRegion & region,const SkPaint & paint)172 void SkNWayCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
173 Iter iter(fList);
174 while (iter.next()) {
175 iter->drawRegion(region, paint);
176 }
177 }
178
onDrawOval(const SkRect & rect,const SkPaint & paint)179 void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
180 Iter iter(fList);
181 while (iter.next()) {
182 iter->drawOval(rect, paint);
183 }
184 }
185
onDrawArc(const SkRect & rect,SkScalar startAngle,SkScalar sweepAngle,bool useCenter,const SkPaint & paint)186 void SkNWayCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
187 bool useCenter, const SkPaint& paint) {
188 Iter iter(fList);
189 while (iter.next()) {
190 iter->drawArc(rect, startAngle, sweepAngle, useCenter, paint);
191 }
192 }
193
onDrawRRect(const SkRRect & rrect,const SkPaint & paint)194 void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
195 Iter iter(fList);
196 while (iter.next()) {
197 iter->drawRRect(rrect, paint);
198 }
199 }
200
onDrawDRRect(const SkRRect & outer,const SkRRect & inner,const SkPaint & paint)201 void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
202 Iter iter(fList);
203 while (iter.next()) {
204 iter->drawDRRect(outer, inner, paint);
205 }
206 }
207
onDrawPath(const SkPath & path,const SkPaint & paint)208 void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
209 Iter iter(fList);
210 while (iter.next()) {
211 iter->drawPath(path, paint);
212 }
213 }
214
onDrawBitmap(const SkBitmap & bitmap,SkScalar x,SkScalar y,const SkPaint * paint)215 void SkNWayCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
216 const SkPaint* paint) {
217 Iter iter(fList);
218 while (iter.next()) {
219 iter->drawBitmap(bitmap, x, y, paint);
220 }
221 }
222
onDrawBitmapRect(const SkBitmap & bitmap,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)223 void SkNWayCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
224 const SkPaint* paint, SrcRectConstraint constraint) {
225 Iter iter(fList);
226 while (iter.next()) {
227 iter->legacy_drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
228 }
229 }
230
onDrawBitmapNine(const SkBitmap & bitmap,const SkIRect & center,const SkRect & dst,const SkPaint * paint)231 void SkNWayCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
232 const SkRect& dst, const SkPaint* paint) {
233 Iter iter(fList);
234 while (iter.next()) {
235 iter->drawBitmapNine(bitmap, center, dst, paint);
236 }
237 }
238
onDrawBitmapLattice(const SkBitmap & bitmap,const Lattice & lattice,const SkRect & dst,const SkPaint * paint)239 void SkNWayCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
240 const SkRect& dst, const SkPaint* paint) {
241 Iter iter(fList);
242 while (iter.next()) {
243 iter->drawBitmapLattice(bitmap, lattice, dst, paint);
244 }
245 }
246
onDrawImage(const SkImage * image,SkScalar left,SkScalar top,const SkPaint * paint)247 void SkNWayCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
248 const SkPaint* paint) {
249 Iter iter(fList);
250 while (iter.next()) {
251 iter->drawImage(image, left, top, paint);
252 }
253 }
254
onDrawImageRect(const SkImage * image,const SkRect * src,const SkRect & dst,const SkPaint * paint,SrcRectConstraint constraint)255 void SkNWayCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
256 const SkPaint* paint, SrcRectConstraint constraint) {
257 Iter iter(fList);
258 while (iter.next()) {
259 iter->legacy_drawImageRect(image, src, dst, paint, constraint);
260 }
261 }
262
onDrawImageNine(const SkImage * image,const SkIRect & center,const SkRect & dst,const SkPaint * paint)263 void SkNWayCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
264 const SkPaint* paint) {
265 Iter iter(fList);
266 while (iter.next()) {
267 iter->drawImageNine(image, center, dst, paint);
268 }
269 }
270
onDrawImageLattice(const SkImage * image,const Lattice & lattice,const SkRect & dst,const SkPaint * paint)271 void SkNWayCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
272 const SkRect& dst, const SkPaint* paint) {
273 Iter iter(fList);
274 while (iter.next()) {
275 iter->drawImageLattice(image, lattice, dst, paint);
276 }
277 }
278
onDrawTextBlob(const SkTextBlob * blob,SkScalar x,SkScalar y,const SkPaint & paint)279 void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
280 const SkPaint &paint) {
281 Iter iter(fList);
282 while (iter.next()) {
283 iter->drawTextBlob(blob, x, y, paint);
284 }
285 }
286
onDrawPicture(const SkPicture * picture,const SkMatrix * matrix,const SkPaint * paint)287 void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
288 const SkPaint* paint) {
289 Iter iter(fList);
290 while (iter.next()) {
291 iter->drawPicture(picture, matrix, paint);
292 }
293 }
294
onDrawDrawable(SkDrawable * drawable,const SkMatrix * matrix)295 void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
296 Iter iter(fList);
297 while (iter.next()) {
298 iter->drawDrawable(drawable, matrix);
299 }
300 }
301
onDrawVerticesObject(const SkVertices * vertices,const SkVertices::Bone bones[],int boneCount,SkBlendMode bmode,const SkPaint & paint)302 void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[],
303 int boneCount, SkBlendMode bmode, const SkPaint& paint) {
304 Iter iter(fList);
305 while (iter.next()) {
306 iter->drawVertices(vertices, bones, boneCount, bmode, paint);
307 }
308 }
309
onDrawPatch(const SkPoint cubics[12],const SkColor colors[4],const SkPoint texCoords[4],SkBlendMode bmode,const SkPaint & paint)310 void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
311 const SkPoint texCoords[4], SkBlendMode bmode,
312 const SkPaint& paint) {
313 Iter iter(fList);
314 while (iter.next()) {
315 iter->drawPatch(cubics, colors, texCoords, bmode, paint);
316 }
317 }
318
onDrawAtlas(const SkImage * image,const SkRSXform xform[],const SkRect tex[],const SkColor colors[],int count,SkBlendMode bmode,const SkRect * cull,const SkPaint * paint)319 void SkNWayCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], const SkRect tex[],
320 const SkColor colors[], int count, SkBlendMode bmode,
321 const SkRect* cull, const SkPaint* paint) {
322 Iter iter(fList);
323 while (iter.next()) {
324 iter->drawAtlas(image, xform, tex, colors, count, bmode, cull, paint);
325 }
326 }
327
onDrawShadowRec(const SkPath & path,const SkDrawShadowRec & rec)328 void SkNWayCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
329 Iter iter(fList);
330 while (iter.next()) {
331 iter->private_draw_shadow_rec(path, rec);
332 }
333 }
334
onDrawAnnotation(const SkRect & rect,const char key[],SkData * data)335 void SkNWayCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) {
336 Iter iter(fList);
337 while (iter.next()) {
338 iter->drawAnnotation(rect, key, data);
339 }
340 }
341
onDrawEdgeAAQuad(const SkRect & rect,const SkPoint clip[4],QuadAAFlags aa,SkColor color,SkBlendMode mode)342 void SkNWayCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
343 QuadAAFlags aa, SkColor color, SkBlendMode mode) {
344 Iter iter(fList);
345 while (iter.next()) {
346 iter->experimental_DrawEdgeAAQuad(rect, clip, aa, color, mode);
347 }
348 }
349
onDrawEdgeAAImageSet(const ImageSetEntry set[],int count,const SkPoint dstClips[],const SkMatrix preViewMatrices[],const SkPaint * paint,SrcRectConstraint constraint)350 void SkNWayCanvas::onDrawEdgeAAImageSet(const ImageSetEntry set[], int count,
351 const SkPoint dstClips[], const SkMatrix preViewMatrices[],
352 const SkPaint* paint, SrcRectConstraint constraint) {
353 Iter iter(fList);
354 while (iter.next()) {
355 iter->experimental_DrawEdgeAAImageSet(
356 set, count, dstClips, preViewMatrices, paint, constraint);
357 }
358 }
359
onFlush()360 void SkNWayCanvas::onFlush() {
361 Iter iter(fList);
362 while (iter.next()) {
363 iter->flush();
364 }
365 }
366