blob: 7d1e98106b283696a91ad77e1f97ce11f9d6fe96 [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 */
reed@android.com6c924ad2009-03-31 03:48:49 +00007#include "SkNWayCanvas.h"
8
Florin Malita439ace92016-12-02 12:05:41 -05009SkNWayCanvas::SkNWayCanvas(int width, int height) : INHERITED(width, height) {}
reed@google.com6ae24e02012-09-26 13:44:13 +000010
reed@android.com6c924ad2009-03-31 03:48:49 +000011SkNWayCanvas::~SkNWayCanvas() {
12 this->removeAll();
13}
14
15void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
16 if (canvas) {
reed@android.com6c924ad2009-03-31 03:48:49 +000017 *fList.append() = canvas;
18 }
19}
20
21void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
22 int index = fList.find(canvas);
23 if (index >= 0) {
reed@android.com6c924ad2009-03-31 03:48:49 +000024 fList.removeShuffle(index);
25 }
26}
27
28void SkNWayCanvas::removeAll() {
reed@android.com6c924ad2009-03-31 03:48:49 +000029 fList.reset();
30}
31
32///////////////////////////////////////////////////////////////////////////
33// These are forwarded to the N canvases we're referencing
34
35class SkNWayCanvas::Iter {
36public:
37 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
38 fIndex = 0;
39 }
40 bool next() {
41 if (fIndex < fList.count()) {
42 fCanvas = fList[fIndex++];
43 return true;
44 }
45 return false;
46 }
47 SkCanvas* operator->() { return fCanvas; }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000048
reed@android.com6c924ad2009-03-31 03:48:49 +000049private:
50 const SkTDArray<SkCanvas*>& fList;
51 int fIndex;
52 SkCanvas* fCanvas;
53};
54
Florin Malita5f6102d2014-06-30 10:13:28 -040055void SkNWayCanvas::willSave() {
reed@android.com6c924ad2009-03-31 03:48:49 +000056 Iter iter(fList);
57 while (iter.next()) {
Florin Malita5f6102d2014-06-30 10:13:28 -040058 iter->save();
reed@android.com6c924ad2009-03-31 03:48:49 +000059 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000060
Florin Malita5f6102d2014-06-30 10:13:28 -040061 this->INHERITED::willSave();
reed@android.com6c924ad2009-03-31 03:48:49 +000062}
63
reed4960eee2015-12-18 07:09:18 -080064SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
reed@android.com6c924ad2009-03-31 03:48:49 +000065 Iter iter(fList);
66 while (iter.next()) {
reed4960eee2015-12-18 07:09:18 -080067 iter->saveLayer(rec);
reed@android.com6c924ad2009-03-31 03:48:49 +000068 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000069
reed4960eee2015-12-18 07:09:18 -080070 this->INHERITED::getSaveLayerStrategy(rec);
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000071 // No need for a layer.
72 return kNoLayer_SaveLayerStrategy;
reed@android.com6c924ad2009-03-31 03:48:49 +000073}
74
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000075void SkNWayCanvas::willRestore() {
reed@android.com6c924ad2009-03-31 03:48:49 +000076 Iter iter(fList);
77 while (iter.next()) {
78 iter->restore();
79 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000080 this->INHERITED::willRestore();
reed@android.com6c924ad2009-03-31 03:48:49 +000081}
82
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000083void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
reed@android.com6c924ad2009-03-31 03:48:49 +000084 Iter iter(fList);
85 while (iter.next()) {
86 iter->concat(matrix);
87 }
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000088 this->INHERITED::didConcat(matrix);
reed@android.com6c924ad2009-03-31 03:48:49 +000089}
90
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000091void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
reed@android.com6c924ad2009-03-31 03:48:49 +000092 Iter iter(fList);
93 while (iter.next()) {
94 iter->setMatrix(matrix);
95 }
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000096 this->INHERITED::didSetMatrix(matrix);
reed@android.com6c924ad2009-03-31 03:48:49 +000097}
98
Mike Reedc1f77742016-12-09 09:00:50 -050099void SkNWayCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000100 Iter iter(fList);
101 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000102 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000103 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000104 this->INHERITED::onClipRect(rect, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000105}
106
Mike Reedc1f77742016-12-09 09:00:50 -0500107void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000108 Iter iter(fList);
109 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000110 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000111 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000112 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000113}
114
Mike Reedc1f77742016-12-09 09:00:50 -0500115void SkNWayCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000116 Iter iter(fList);
117 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000118 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000119 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000120 this->INHERITED::onClipPath(path, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000121}
122
Mike Reedc1f77742016-12-09 09:00:50 -0500123void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000124 Iter iter(fList);
125 while (iter.next()) {
126 iter->clipRegion(deviceRgn, op);
127 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000128 this->INHERITED::onClipRegion(deviceRgn, op);
reed@android.com6c924ad2009-03-31 03:48:49 +0000129}
130
reed41af9662015-01-05 07:49:08 -0800131void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000132 Iter iter(fList);
133 while (iter.next()) {
134 iter->drawPaint(paint);
135 }
136}
137
reed41af9662015-01-05 07:49:08 -0800138void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
139 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000140 Iter iter(fList);
141 while (iter.next()) {
142 iter->drawPoints(mode, count, pts, paint);
143 }
144}
145
reed41af9662015-01-05 07:49:08 -0800146void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000147 Iter iter(fList);
148 while (iter.next()) {
149 iter->drawRect(rect, paint);
150 }
151}
152
Brian Osman3adc1222018-03-08 14:52:20 -0500153void SkNWayCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
154 Iter iter(fList);
155 while (iter.next()) {
156 iter->drawRegion(region, paint);
157 }
158}
159
reed41af9662015-01-05 07:49:08 -0800160void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000161 Iter iter(fList);
162 while (iter.next()) {
163 iter->drawOval(rect, paint);
164 }
165}
166
bsalomonac3aa242016-08-19 11:25:19 -0700167void SkNWayCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
168 bool useCenter, const SkPaint& paint) {
169 Iter iter(fList);
170 while (iter.next()) {
171 iter->drawArc(rect, startAngle, sweepAngle, useCenter, paint);
172 }
173}
174
reed41af9662015-01-05 07:49:08 -0800175void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000176 Iter iter(fList);
177 while (iter.next()) {
178 iter->drawRRect(rrect, paint);
179 }
180}
181
reeda5517e22015-07-14 10:54:12 -0700182void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000183 Iter iter(fList);
184 while (iter.next()) {
185 iter->drawDRRect(outer, inner, paint);
186 }
187}
188
reed41af9662015-01-05 07:49:08 -0800189void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000190 Iter iter(fList);
191 while (iter.next()) {
192 iter->drawPath(path, paint);
193 }
194}
195
reed41af9662015-01-05 07:49:08 -0800196void SkNWayCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
197 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000198 Iter iter(fList);
199 while (iter.next()) {
200 iter->drawBitmap(bitmap, x, y, paint);
201 }
202}
203
reed41af9662015-01-05 07:49:08 -0800204void SkNWayCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700205 const SkPaint* paint, SrcRectConstraint constraint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000206 Iter iter(fList);
207 while (iter.next()) {
reede47829b2015-08-06 10:02:53 -0700208 iter->legacy_drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000209 }
210}
211
reed41af9662015-01-05 07:49:08 -0800212void SkNWayCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
213 const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000214 Iter iter(fList);
215 while (iter.next()) {
216 iter->drawBitmapNine(bitmap, center, dst, paint);
217 }
218}
219
Brian Osman3adc1222018-03-08 14:52:20 -0500220void SkNWayCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
221 const SkRect& dst, const SkPaint* paint) {
222 Iter iter(fList);
223 while (iter.next()) {
224 iter->drawBitmapLattice(bitmap, lattice, dst, paint);
225 }
226}
227
reed41af9662015-01-05 07:49:08 -0800228void SkNWayCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
229 const SkPaint* paint) {
piotaixrb7bac3d2014-09-29 08:56:19 -0700230 Iter iter(fList);
231 while (iter.next()) {
232 iter->drawImage(image, left, top, paint);
233 }
234}
235
reed41af9662015-01-05 07:49:08 -0800236void SkNWayCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
reed562fe472015-07-28 07:35:14 -0700237 const SkPaint* paint, SrcRectConstraint constraint) {
piotaixrb7bac3d2014-09-29 08:56:19 -0700238 Iter iter(fList);
239 while (iter.next()) {
reede47829b2015-08-06 10:02:53 -0700240 iter->legacy_drawImageRect(image, src, dst, paint, constraint);
piotaixrb7bac3d2014-09-29 08:56:19 -0700241 }
242}
243
Brian Osman3adc1222018-03-08 14:52:20 -0500244void SkNWayCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
245 const SkPaint* paint) {
246 Iter iter(fList);
247 while (iter.next()) {
248 iter->drawImageNine(image, center, dst, paint);
249 }
250}
251
252void SkNWayCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
253 const SkRect& dst, const SkPaint* paint) {
254 Iter iter(fList);
255 while (iter.next()) {
256 iter->drawImageLattice(image, lattice, dst, paint);
257 }
258}
259
reed@google.come0d9ce82014-04-23 04:00:17 +0000260void SkNWayCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
261 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000262 Iter iter(fList);
263 while (iter.next()) {
264 iter->drawText(text, byteLength, x, y, paint);
265 }
266}
267
reed@google.come0d9ce82014-04-23 04:00:17 +0000268void SkNWayCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
269 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000270 Iter iter(fList);
271 while (iter.next()) {
272 iter->drawPosText(text, byteLength, pos, paint);
273 }
274}
275
reed@google.come0d9ce82014-04-23 04:00:17 +0000276void SkNWayCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
277 SkScalar constY, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000278 Iter iter(fList);
279 while (iter.next()) {
280 iter->drawPosTextH(text, byteLength, xpos, constY, paint);
281 }
282}
283
reed@google.come0d9ce82014-04-23 04:00:17 +0000284void SkNWayCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
285 const SkMatrix* matrix, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000286 Iter iter(fList);
287 while (iter.next()) {
288 iter->drawTextOnPath(text, byteLength, path, matrix, paint);
289 }
290}
291
reed45561a02016-07-07 12:47:17 -0700292void SkNWayCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
293 const SkRect* cull, const SkPaint& paint) {
294 Iter iter(fList);
295 while (iter.next()) {
296 iter->drawTextRSXform(text, byteLength, xform, cull, paint);
297 }
298}
299
fmalitab7425172014-08-26 07:56:44 -0700300void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
301 const SkPaint &paint) {
302 Iter iter(fList);
303 while (iter.next()) {
304 iter->drawTextBlob(blob, x, y, paint);
305 }
306}
307
reedd5fa1a42014-08-09 11:08:05 -0700308void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
309 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000310 Iter iter(fList);
311 while (iter.next()) {
reedd5fa1a42014-08-09 11:08:05 -0700312 iter->drawPicture(picture, matrix, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000313 }
314}
315
Florin Malitaadaeaed2017-09-21 15:28:29 -0400316void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
317 Iter iter(fList);
318 while (iter.next()) {
319 iter->drawDrawable(drawable, matrix);
320 }
321}
322
Ruiqi Maof5101492018-06-29 14:32:21 -0400323void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkMatrix* bones,
324 int boneCount, SkBlendMode bmode, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000325 Iter iter(fList);
326 while (iter.next()) {
Ruiqi Maof5101492018-06-29 14:32:21 -0400327 iter->drawVertices(vertices, bones, boneCount, bmode, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000328 }
329}
330
dandovb3c9d1c2014-08-12 08:34:29 -0700331void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400332 const SkPoint texCoords[4], SkBlendMode bmode,
dandovb3c9d1c2014-08-12 08:34:29 -0700333 const SkPaint& paint) {
dandov963137b2014-08-07 07:49:53 -0700334 Iter iter(fList);
335 while (iter.next()) {
Mike Reedfaba3712016-11-03 14:45:31 -0400336 iter->drawPatch(cubics, colors, texCoords, bmode, paint);
dandov963137b2014-08-07 07:49:53 -0700337 }
338}
339
Brian Osman3adc1222018-03-08 14:52:20 -0500340void SkNWayCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], const SkRect tex[],
341 const SkColor colors[], int count, SkBlendMode bmode,
342 const SkRect* cull, const SkPaint* paint) {
343 Iter iter(fList);
344 while (iter.next()) {
345 iter->drawAtlas(image, xform, tex, colors, count, bmode, cull, paint);
346 }
347}
348
Mike Reed4204da22017-05-17 08:53:36 -0400349void SkNWayCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
350 Iter iter(fList);
351 while (iter.next()) {
352 iter->private_draw_shadow_rec(path, rec);
353 }
354}
355
reedf70b5312016-03-04 16:36:20 -0800356void SkNWayCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) {
357 Iter iter(fList);
358 while (iter.next()) {
359 iter->drawAnnotation(rect, key, data);
360 }
361}
362
Florin Malita1ba5b6b2017-10-12 11:08:46 -0400363void SkNWayCanvas::onFlush() {
364 Iter iter(fList);
365 while (iter.next()) {
366 iter->flush();
367 }
368}