blob: 1ce6318e5cba54a0b0f780f82c11a5f10d9addd4 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
Mike Reed148b7fd2018-12-18 17:38:18 -05007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/utils/SkNWayCanvas.h"
9#include "src/core/SkCanvasPriv.h"
reed@android.com6c924ad2009-03-31 03:48:49 +000010
Florin Malita439ace92016-12-02 12:05:41 -050011SkNWayCanvas::SkNWayCanvas(int width, int height) : INHERITED(width, height) {}
reed@google.com6ae24e02012-09-26 13:44:13 +000012
reed@android.com6c924ad2009-03-31 03:48:49 +000013SkNWayCanvas::~SkNWayCanvas() {
14 this->removeAll();
15}
16
17void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
18 if (canvas) {
reed@android.com6c924ad2009-03-31 03:48:49 +000019 *fList.append() = canvas;
20 }
21}
22
23void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
24 int index = fList.find(canvas);
25 if (index >= 0) {
reed@android.com6c924ad2009-03-31 03:48:49 +000026 fList.removeShuffle(index);
27 }
28}
29
30void SkNWayCanvas::removeAll() {
reed@android.com6c924ad2009-03-31 03:48:49 +000031 fList.reset();
32}
33
34///////////////////////////////////////////////////////////////////////////
35// These are forwarded to the N canvases we're referencing
36
37class SkNWayCanvas::Iter {
38public:
39 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
40 fIndex = 0;
41 }
42 bool next() {
43 if (fIndex < fList.count()) {
44 fCanvas = fList[fIndex++];
45 return true;
46 }
47 return false;
48 }
49 SkCanvas* operator->() { return fCanvas; }
Mike Reed148b7fd2018-12-18 17:38:18 -050050 SkCanvas* get() const { return fCanvas; }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000051
reed@android.com6c924ad2009-03-31 03:48:49 +000052private:
53 const SkTDArray<SkCanvas*>& fList;
54 int fIndex;
55 SkCanvas* fCanvas;
56};
57
Florin Malita5f6102d2014-06-30 10:13:28 -040058void SkNWayCanvas::willSave() {
reed@android.com6c924ad2009-03-31 03:48:49 +000059 Iter iter(fList);
60 while (iter.next()) {
Florin Malita5f6102d2014-06-30 10:13:28 -040061 iter->save();
reed@android.com6c924ad2009-03-31 03:48:49 +000062 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000063
Florin Malita5f6102d2014-06-30 10:13:28 -040064 this->INHERITED::willSave();
reed@android.com6c924ad2009-03-31 03:48:49 +000065}
66
reed4960eee2015-12-18 07:09:18 -080067SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
reed@android.com6c924ad2009-03-31 03:48:49 +000068 Iter iter(fList);
69 while (iter.next()) {
reed4960eee2015-12-18 07:09:18 -080070 iter->saveLayer(rec);
reed@android.com6c924ad2009-03-31 03:48:49 +000071 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000072
reed4960eee2015-12-18 07:09:18 -080073 this->INHERITED::getSaveLayerStrategy(rec);
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000074 // No need for a layer.
75 return kNoLayer_SaveLayerStrategy;
reed@android.com6c924ad2009-03-31 03:48:49 +000076}
77
Mike Reed148b7fd2018-12-18 17:38:18 -050078bool 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
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000087void SkNWayCanvas::willRestore() {
reed@android.com6c924ad2009-03-31 03:48:49 +000088 Iter iter(fList);
89 while (iter.next()) {
90 iter->restore();
91 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000092 this->INHERITED::willRestore();
reed@android.com6c924ad2009-03-31 03:48:49 +000093}
94
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000095void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
reed@android.com6c924ad2009-03-31 03:48:49 +000096 Iter iter(fList);
97 while (iter.next()) {
98 iter->concat(matrix);
99 }
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000100 this->INHERITED::didConcat(matrix);
reed@android.com6c924ad2009-03-31 03:48:49 +0000101}
102
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000103void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000104 Iter iter(fList);
105 while (iter.next()) {
106 iter->setMatrix(matrix);
107 }
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000108 this->INHERITED::didSetMatrix(matrix);
reed@android.com6c924ad2009-03-31 03:48:49 +0000109}
110
Mike Reedc1f77742016-12-09 09:00:50 -0500111void SkNWayCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000112 Iter iter(fList);
113 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000114 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000115 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000116 this->INHERITED::onClipRect(rect, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000117}
118
Mike Reedc1f77742016-12-09 09:00:50 -0500119void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000120 Iter iter(fList);
121 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000122 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000123 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000124 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000125}
126
Mike Reedc1f77742016-12-09 09:00:50 -0500127void SkNWayCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000128 Iter iter(fList);
129 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000130 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000131 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000132 this->INHERITED::onClipPath(path, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000133}
134
Mike Reedc1f77742016-12-09 09:00:50 -0500135void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000136 Iter iter(fList);
137 while (iter.next()) {
138 iter->clipRegion(deviceRgn, op);
139 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000140 this->INHERITED::onClipRegion(deviceRgn, op);
reed@android.com6c924ad2009-03-31 03:48:49 +0000141}
142
reed41af9662015-01-05 07:49:08 -0800143void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000144 Iter iter(fList);
145 while (iter.next()) {
146 iter->drawPaint(paint);
147 }
148}
149
Mike Reedd5674082019-04-19 15:00:47 -0400150void SkNWayCanvas::onDrawBehind(const SkPaint& paint) {
151 Iter iter(fList);
152 while (iter.next()) {
153 SkCanvasPriv::DrawBehind(iter.get(), paint);
154 }
155}
156
reed41af9662015-01-05 07:49:08 -0800157void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
158 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000159 Iter iter(fList);
160 while (iter.next()) {
161 iter->drawPoints(mode, count, pts, paint);
162 }
163}
164
reed41af9662015-01-05 07:49:08 -0800165void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000166 Iter iter(fList);
167 while (iter.next()) {
168 iter->drawRect(rect, paint);
169 }
170}
171
Brian Osman3adc1222018-03-08 14:52:20 -0500172void SkNWayCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
173 Iter iter(fList);
174 while (iter.next()) {
175 iter->drawRegion(region, paint);
176 }
177}
178
reed41af9662015-01-05 07:49:08 -0800179void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000180 Iter iter(fList);
181 while (iter.next()) {
182 iter->drawOval(rect, paint);
183 }
184}
185
bsalomonac3aa242016-08-19 11:25:19 -0700186void 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
reed41af9662015-01-05 07:49:08 -0800194void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000195 Iter iter(fList);
196 while (iter.next()) {
197 iter->drawRRect(rrect, paint);
198 }
199}
200
reeda5517e22015-07-14 10:54:12 -0700201void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000202 Iter iter(fList);
203 while (iter.next()) {
204 iter->drawDRRect(outer, inner, paint);
205 }
206}
207
reed41af9662015-01-05 07:49:08 -0800208void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000209 Iter iter(fList);
210 while (iter.next()) {
211 iter->drawPath(path, paint);
212 }
213}
214
reed41af9662015-01-05 07:49:08 -0800215void SkNWayCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
216 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000217 Iter iter(fList);
218 while (iter.next()) {
219 iter->drawBitmap(bitmap, x, y, paint);
220 }
221}
222
reed41af9662015-01-05 07:49:08 -0800223void SkNWayCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700224 const SkPaint* paint, SrcRectConstraint constraint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000225 Iter iter(fList);
226 while (iter.next()) {
reede47829b2015-08-06 10:02:53 -0700227 iter->legacy_drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000228 }
229}
230
reed41af9662015-01-05 07:49:08 -0800231void SkNWayCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
232 const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000233 Iter iter(fList);
234 while (iter.next()) {
235 iter->drawBitmapNine(bitmap, center, dst, paint);
236 }
237}
238
Brian Osman3adc1222018-03-08 14:52:20 -0500239void 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
reed41af9662015-01-05 07:49:08 -0800247void SkNWayCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
248 const SkPaint* paint) {
piotaixrb7bac3d2014-09-29 08:56:19 -0700249 Iter iter(fList);
250 while (iter.next()) {
251 iter->drawImage(image, left, top, paint);
252 }
253}
254
reed41af9662015-01-05 07:49:08 -0800255void SkNWayCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700256 const SkPaint* paint, SrcRectConstraint constraint) {
piotaixrb7bac3d2014-09-29 08:56:19 -0700257 Iter iter(fList);
258 while (iter.next()) {
reede47829b2015-08-06 10:02:53 -0700259 iter->legacy_drawImageRect(image, src, dst, paint, constraint);
piotaixrb7bac3d2014-09-29 08:56:19 -0700260 }
261}
262
Brian Osman3adc1222018-03-08 14:52:20 -0500263void 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
271void 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
fmalitab7425172014-08-26 07:56:44 -0700279void 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
reedd5fa1a42014-08-09 11:08:05 -0700287void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
288 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000289 Iter iter(fList);
290 while (iter.next()) {
reedd5fa1a42014-08-09 11:08:05 -0700291 iter->drawPicture(picture, matrix, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000292 }
293}
294
Florin Malitaadaeaed2017-09-21 15:28:29 -0400295void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
296 Iter iter(fList);
297 while (iter.next()) {
298 iter->drawDrawable(drawable, matrix);
299 }
300}
301
Ruiqi Maoc97a3392018-08-15 10:44:19 -0400302void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[],
Ruiqi Maof5101492018-06-29 14:32:21 -0400303 int boneCount, SkBlendMode bmode, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000304 Iter iter(fList);
305 while (iter.next()) {
Ruiqi Maof5101492018-06-29 14:32:21 -0400306 iter->drawVertices(vertices, bones, boneCount, bmode, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000307 }
308}
309
dandovb3c9d1c2014-08-12 08:34:29 -0700310void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400311 const SkPoint texCoords[4], SkBlendMode bmode,
dandovb3c9d1c2014-08-12 08:34:29 -0700312 const SkPaint& paint) {
dandov963137b2014-08-07 07:49:53 -0700313 Iter iter(fList);
314 while (iter.next()) {
Mike Reedfaba3712016-11-03 14:45:31 -0400315 iter->drawPatch(cubics, colors, texCoords, bmode, paint);
dandov963137b2014-08-07 07:49:53 -0700316 }
317}
318
Brian Osman3adc1222018-03-08 14:52:20 -0500319void 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
Mike Reed4204da22017-05-17 08:53:36 -0400328void 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
reedf70b5312016-03-04 16:36:20 -0800335void 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
Michael Ludwig390f0cc2019-03-19 09:16:38 -0400342void SkNWayCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
Michael Ludwiga595f862019-08-27 15:25:49 -0400343 QuadAAFlags aa, const SkColor4f& color, SkBlendMode mode) {
Michael Ludwig390f0cc2019-03-19 09:16:38 -0400344 Iter iter(fList);
345 while (iter.next()) {
346 iter->experimental_DrawEdgeAAQuad(rect, clip, aa, color, mode);
347 }
348}
349
350void 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
Florin Malita1ba5b6b2017-10-12 11:08:46 -0400360void SkNWayCanvas::onFlush() {
361 Iter iter(fList);
362 while (iter.next()) {
363 iter->flush();
364 }
365}