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