blob: c3b118a51985d0f586924b0dcca391d0e59a896b [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 Reed121c2af2020-03-10 14:02:56 -04008#include "include/core/SkShader.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -05009#include "include/utils/SkNWayCanvas.h"
10#include "src/core/SkCanvasPriv.h"
reed@android.com6c924ad2009-03-31 03:48:49 +000011
Florin Malita439ace92016-12-02 12:05:41 -050012SkNWayCanvas::SkNWayCanvas(int width, int height) : INHERITED(width, height) {}
reed@google.com6ae24e02012-09-26 13:44:13 +000013
reed@android.com6c924ad2009-03-31 03:48:49 +000014SkNWayCanvas::~SkNWayCanvas() {
15 this->removeAll();
16}
17
18void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
19 if (canvas) {
reed@android.com6c924ad2009-03-31 03:48:49 +000020 *fList.append() = canvas;
21 }
22}
23
24void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
25 int index = fList.find(canvas);
26 if (index >= 0) {
reed@android.com6c924ad2009-03-31 03:48:49 +000027 fList.removeShuffle(index);
28 }
29}
30
31void SkNWayCanvas::removeAll() {
reed@android.com6c924ad2009-03-31 03:48:49 +000032 fList.reset();
33}
34
35///////////////////////////////////////////////////////////////////////////
36// These are forwarded to the N canvases we're referencing
37
38class SkNWayCanvas::Iter {
39public:
40 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
41 fIndex = 0;
42 }
43 bool next() {
44 if (fIndex < fList.count()) {
45 fCanvas = fList[fIndex++];
46 return true;
47 }
48 return false;
49 }
50 SkCanvas* operator->() { return fCanvas; }
Mike Reed148b7fd2018-12-18 17:38:18 -050051 SkCanvas* get() const { return fCanvas; }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000052
reed@android.com6c924ad2009-03-31 03:48:49 +000053private:
54 const SkTDArray<SkCanvas*>& fList;
55 int fIndex;
56 SkCanvas* fCanvas;
57};
58
Florin Malita5f6102d2014-06-30 10:13:28 -040059void SkNWayCanvas::willSave() {
reed@android.com6c924ad2009-03-31 03:48:49 +000060 Iter iter(fList);
61 while (iter.next()) {
Florin Malita5f6102d2014-06-30 10:13:28 -040062 iter->save();
reed@android.com6c924ad2009-03-31 03:48:49 +000063 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000064
Florin Malita5f6102d2014-06-30 10:13:28 -040065 this->INHERITED::willSave();
reed@android.com6c924ad2009-03-31 03:48:49 +000066}
67
reed4960eee2015-12-18 07:09:18 -080068SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
reed@android.com6c924ad2009-03-31 03:48:49 +000069 Iter iter(fList);
70 while (iter.next()) {
reed4960eee2015-12-18 07:09:18 -080071 iter->saveLayer(rec);
reed@android.com6c924ad2009-03-31 03:48:49 +000072 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000073
reed4960eee2015-12-18 07:09:18 -080074 this->INHERITED::getSaveLayerStrategy(rec);
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000075 // No need for a layer.
76 return kNoLayer_SaveLayerStrategy;
reed@android.com6c924ad2009-03-31 03:48:49 +000077}
78
Mike Reed148b7fd2018-12-18 17:38:18 -050079bool 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
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000088void SkNWayCanvas::willRestore() {
reed@android.com6c924ad2009-03-31 03:48:49 +000089 Iter iter(fList);
90 while (iter.next()) {
91 iter->restore();
92 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000093 this->INHERITED::willRestore();
reed@android.com6c924ad2009-03-31 03:48:49 +000094}
95
Brian Osman548de742020-04-24 12:02:25 -040096void SkNWayCanvas::onMarkCTM(const char* name) {
Mike Reed7fe6ee32020-04-09 12:35:09 -040097 Iter iter(fList);
98 while (iter.next()) {
Brian Osman548de742020-04-24 12:02:25 -040099 iter->markCTM(name);
Mike Reed7fe6ee32020-04-09 12:35:09 -0400100 }
Brian Osman548de742020-04-24 12:02:25 -0400101 this->INHERITED::onMarkCTM(name);
Mike Reed7fe6ee32020-04-09 12:35:09 -0400102}
103
Mike Reeda735ad92020-04-06 21:32:43 -0400104void SkNWayCanvas::didConcat44(const SkM44& m) {
105 Iter iter(fList);
106 while (iter.next()) {
107 iter->concat(m);
108 }
109}
Mike Reedf6d70a82020-01-10 15:56:32 -0500110
Mike Reed420a9ba2020-11-25 13:37:30 -0500111void SkNWayCanvas::didSetM44(const SkM44& matrix) {
112 Iter iter(fList);
113 while (iter.next()) {
114 iter->setMatrix(matrix);
115 }
116}
117
Mike Reedf6d70a82020-01-10 15:56:32 -0500118void SkNWayCanvas::didTranslate(SkScalar x, SkScalar y) {
119 Iter iter(fList);
120 while (iter.next()) {
121 iter->translate(x, y);
122 }
reed@android.com6c924ad2009-03-31 03:48:49 +0000123}
124
Mike Reeda3a704a2020-01-10 17:21:40 -0500125void SkNWayCanvas::didScale(SkScalar x, SkScalar y) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000126 Iter iter(fList);
127 while (iter.next()) {
Mike Reeda3a704a2020-01-10 17:21:40 -0500128 iter->scale(x, y);
reed@android.com6c924ad2009-03-31 03:48:49 +0000129 }
reed@android.com6c924ad2009-03-31 03:48:49 +0000130}
131
Mike Reedc1f77742016-12-09 09:00:50 -0500132void SkNWayCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000133 Iter iter(fList);
134 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000135 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000136 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000137 this->INHERITED::onClipRect(rect, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000138}
139
Mike Reedc1f77742016-12-09 09:00:50 -0500140void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000141 Iter iter(fList);
142 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000143 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000144 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000145 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000146}
147
Mike Reedc1f77742016-12-09 09:00:50 -0500148void SkNWayCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000149 Iter iter(fList);
150 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000151 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000152 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000153 this->INHERITED::onClipPath(path, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000154}
155
Mike Reed121c2af2020-03-10 14:02:56 -0400156void 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
Mike Reedc1f77742016-12-09 09:00:50 -0500164void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000165 Iter iter(fList);
166 while (iter.next()) {
167 iter->clipRegion(deviceRgn, op);
168 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000169 this->INHERITED::onClipRegion(deviceRgn, op);
reed@android.com6c924ad2009-03-31 03:48:49 +0000170}
171
Michael Ludwigcfd204a2021-07-23 11:48:34 -0400172void SkNWayCanvas::onResetClip() {
173 Iter iter(fList);
174 while (iter.next()) {
175 SkCanvasPriv::ResetClip(iter.get());
176 }
177 this->INHERITED::onResetClip();
178}
179
reed41af9662015-01-05 07:49:08 -0800180void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000181 Iter iter(fList);
182 while (iter.next()) {
183 iter->drawPaint(paint);
184 }
185}
186
Mike Reedd5674082019-04-19 15:00:47 -0400187void SkNWayCanvas::onDrawBehind(const SkPaint& paint) {
188 Iter iter(fList);
189 while (iter.next()) {
190 SkCanvasPriv::DrawBehind(iter.get(), paint);
191 }
192}
193
reed41af9662015-01-05 07:49:08 -0800194void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
195 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000196 Iter iter(fList);
197 while (iter.next()) {
198 iter->drawPoints(mode, count, pts, paint);
199 }
200}
201
reed41af9662015-01-05 07:49:08 -0800202void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000203 Iter iter(fList);
204 while (iter.next()) {
205 iter->drawRect(rect, paint);
206 }
207}
208
Brian Osman3adc1222018-03-08 14:52:20 -0500209void SkNWayCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
210 Iter iter(fList);
211 while (iter.next()) {
212 iter->drawRegion(region, paint);
213 }
214}
215
reed41af9662015-01-05 07:49:08 -0800216void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000217 Iter iter(fList);
218 while (iter.next()) {
219 iter->drawOval(rect, paint);
220 }
221}
222
bsalomonac3aa242016-08-19 11:25:19 -0700223void 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
reed41af9662015-01-05 07:49:08 -0800231void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000232 Iter iter(fList);
233 while (iter.next()) {
234 iter->drawRRect(rrect, paint);
235 }
236}
237
reeda5517e22015-07-14 10:54:12 -0700238void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000239 Iter iter(fList);
240 while (iter.next()) {
241 iter->drawDRRect(outer, inner, paint);
242 }
243}
244
reed41af9662015-01-05 07:49:08 -0800245void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000246 Iter iter(fList);
247 while (iter.next()) {
248 iter->drawPath(path, paint);
249 }
250}
251
Mike Reed4f23dec2020-12-30 14:22:42 +0000252void 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
260void 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
269void 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
278void 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}
Brian Osman3adc1222018-03-08 14:52:20 -0500287
Mike Reed35c894e2021-04-16 10:27:01 -0400288void SkNWayCanvas::onDrawGlyphRunList(const SkGlyphRunList& list, const SkPaint &paint) {
289 Iter iter(fList);
290 while (iter.next()) {
291 iter->onDrawGlyphRunList(list, paint);
292 }
293}
294
fmalitab7425172014-08-26 07:56:44 -0700295void 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
reedd5fa1a42014-08-09 11:08:05 -0700303void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
304 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000305 Iter iter(fList);
306 while (iter.next()) {
reedd5fa1a42014-08-09 11:08:05 -0700307 iter->drawPicture(picture, matrix, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000308 }
309}
310
Florin Malitaadaeaed2017-09-21 15:28:29 -0400311void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
312 Iter iter(fList);
313 while (iter.next()) {
314 iter->drawDrawable(drawable, matrix);
315 }
316}
317
Mike Reeda2cf8ae2020-03-02 17:08:01 -0500318void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices,
Mike Reeda2cf8ae2020-03-02 17:08:01 -0500319 SkBlendMode bmode, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000320 Iter iter(fList);
321 while (iter.next()) {
Mike Reed5caf9352020-03-02 14:57:09 -0500322 iter->drawVertices(vertices, bmode, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000323 }
324}
325
dandovb3c9d1c2014-08-12 08:34:29 -0700326void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -0400327 const SkPoint texCoords[4], SkBlendMode bmode,
dandovb3c9d1c2014-08-12 08:34:29 -0700328 const SkPaint& paint) {
dandov963137b2014-08-07 07:49:53 -0700329 Iter iter(fList);
330 while (iter.next()) {
Mike Reedfaba3712016-11-03 14:45:31 -0400331 iter->drawPatch(cubics, colors, texCoords, bmode, paint);
dandov963137b2014-08-07 07:49:53 -0700332 }
333}
334
Mike Reed4204da22017-05-17 08:53:36 -0400335void 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
reedf70b5312016-03-04 16:36:20 -0800342void 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
Michael Ludwig390f0cc2019-03-19 09:16:38 -0400349void SkNWayCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
Michael Ludwiga595f862019-08-27 15:25:49 -0400350 QuadAAFlags aa, const SkColor4f& color, SkBlendMode mode) {
Michael Ludwig390f0cc2019-03-19 09:16:38 -0400351 Iter iter(fList);
352 while (iter.next()) {
353 iter->experimental_DrawEdgeAAQuad(rect, clip, aa, color, mode);
354 }
355}
356
Mike Reed4f509342021-01-05 12:03:47 -0500357void SkNWayCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], int count,
358 const SkPoint dstClips[], const SkMatrix preViewMatrices[],
359 const SkSamplingOptions& sampling, const SkPaint* paint,
360 SrcRectConstraint constraint) {
Michael Ludwig390f0cc2019-03-19 09:16:38 -0400361 Iter iter(fList);
362 while (iter.next()) {
363 iter->experimental_DrawEdgeAAImageSet(
Mike Reed4f509342021-01-05 12:03:47 -0500364 set, count, dstClips, preViewMatrices, sampling, paint, constraint);
Michael Ludwig390f0cc2019-03-19 09:16:38 -0400365 }
366}
367
Florin Malita1ba5b6b2017-10-12 11:08:46 -0400368void SkNWayCanvas::onFlush() {
369 Iter iter(fList);
370 while (iter.next()) {
371 iter->flush();
372 }
373}