blob: 706c769d7b423a668efda5c77d99a76acbc018eb [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com6c924ad2009-03-31 03:48:49 +00008#include "SkNWayCanvas.h"
9
reed@google.com6ae24e02012-09-26 13:44:13 +000010SkNWayCanvas::SkNWayCanvas(int width, int height)
commit-bot@chromium.orge2543102014-01-31 19:42:58 +000011 : 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) {
19 canvas->ref();
20 *fList.append() = canvas;
21 }
22}
23
24void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
25 int index = fList.find(canvas);
26 if (index >= 0) {
27 canvas->unref();
28 fList.removeShuffle(index);
29 }
30}
31
32void SkNWayCanvas::removeAll() {
33 fList.unrefAll();
34 fList.reset();
35}
36
37///////////////////////////////////////////////////////////////////////////
38// These are forwarded to the N canvases we're referencing
39
40class SkNWayCanvas::Iter {
41public:
42 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
43 fIndex = 0;
44 }
45 bool next() {
46 if (fIndex < fList.count()) {
47 fCanvas = fList[fIndex++];
48 return true;
49 }
50 return false;
51 }
52 SkCanvas* operator->() { return fCanvas; }
vandebo@chromium.org74b46192012-01-28 01:45:11 +000053
reed@android.com6c924ad2009-03-31 03:48:49 +000054private:
55 const SkTDArray<SkCanvas*>& fList;
56 int fIndex;
57 SkCanvas* fCanvas;
58};
59
Florin Malita5f6102d2014-06-30 10:13:28 -040060void SkNWayCanvas::willSave() {
reed@android.com6c924ad2009-03-31 03:48:49 +000061 Iter iter(fList);
62 while (iter.next()) {
Florin Malita5f6102d2014-06-30 10:13:28 -040063 iter->save();
reed@android.com6c924ad2009-03-31 03:48:49 +000064 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000065
Florin Malita5f6102d2014-06-30 10:13:28 -040066 this->INHERITED::willSave();
reed@android.com6c924ad2009-03-31 03:48:49 +000067}
68
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000069SkCanvas::SaveLayerStrategy SkNWayCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
70 SaveFlags flags) {
reed@android.com6c924ad2009-03-31 03:48:49 +000071 Iter iter(fList);
72 while (iter.next()) {
73 iter->saveLayer(bounds, paint, flags);
74 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000075
76 this->INHERITED::willSaveLayer(bounds, paint, flags);
77 // No need for a layer.
78 return kNoLayer_SaveLayerStrategy;
reed@android.com6c924ad2009-03-31 03:48:49 +000079}
80
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000081void SkNWayCanvas::willRestore() {
reed@android.com6c924ad2009-03-31 03:48:49 +000082 Iter iter(fList);
83 while (iter.next()) {
84 iter->restore();
85 }
commit-bot@chromium.orge54a23f2014-03-12 20:21:48 +000086 this->INHERITED::willRestore();
reed@android.com6c924ad2009-03-31 03:48:49 +000087}
88
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000089void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
reed@android.com6c924ad2009-03-31 03:48:49 +000090 Iter iter(fList);
91 while (iter.next()) {
92 iter->concat(matrix);
93 }
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000094 this->INHERITED::didConcat(matrix);
reed@android.com6c924ad2009-03-31 03:48:49 +000095}
96
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +000097void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
reed@android.com6c924ad2009-03-31 03:48:49 +000098 Iter iter(fList);
99 while (iter.next()) {
100 iter->setMatrix(matrix);
101 }
commit-bot@chromium.org44c48d02014-03-13 20:03:58 +0000102 this->INHERITED::didSetMatrix(matrix);
reed@android.com6c924ad2009-03-31 03:48:49 +0000103}
104
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000105void SkNWayCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000106 Iter iter(fList);
107 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000108 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000109 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000110 this->INHERITED::onClipRect(rect, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000111}
112
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000113void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000114 Iter iter(fList);
115 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000116 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000117 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000118 this->INHERITED::onClipRRect(rrect, op, edgeStyle);
reed@google.com4ed0fb72012-12-12 20:48:18 +0000119}
120
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000121void SkNWayCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000122 Iter iter(fList);
123 while (iter.next()) {
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000124 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000125 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000126 this->INHERITED::onClipPath(path, op, edgeStyle);
reed@android.com6c924ad2009-03-31 03:48:49 +0000127}
128
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000129void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000130 Iter iter(fList);
131 while (iter.next()) {
132 iter->clipRegion(deviceRgn, op);
133 }
robertphillips@google.com8f90a892014-02-28 18:19:39 +0000134 this->INHERITED::onClipRegion(deviceRgn, op);
reed@android.com6c924ad2009-03-31 03:48:49 +0000135}
136
reed41af9662015-01-05 07:49:08 -0800137void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000138 Iter iter(fList);
139 while (iter.next()) {
140 iter->drawPaint(paint);
141 }
142}
143
reed41af9662015-01-05 07:49:08 -0800144void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
145 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000146 Iter iter(fList);
147 while (iter.next()) {
148 iter->drawPoints(mode, count, pts, paint);
149 }
150}
151
reed41af9662015-01-05 07:49:08 -0800152void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000153 Iter iter(fList);
154 while (iter.next()) {
155 iter->drawRect(rect, paint);
156 }
157}
158
reed41af9662015-01-05 07:49:08 -0800159void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000160 Iter iter(fList);
161 while (iter.next()) {
162 iter->drawOval(rect, paint);
163 }
164}
165
reed41af9662015-01-05 07:49:08 -0800166void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
reed@google.com4ed0fb72012-12-12 20:48:18 +0000167 Iter iter(fList);
168 while (iter.next()) {
169 iter->drawRRect(rrect, paint);
170 }
171}
172
reeda5517e22015-07-14 10:54:12 -0700173void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
commit-bot@chromium.orgab582732014-02-21 12:20:45 +0000174 Iter iter(fList);
175 while (iter.next()) {
176 iter->drawDRRect(outer, inner, paint);
177 }
178}
179
reed41af9662015-01-05 07:49:08 -0800180void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000181 Iter iter(fList);
182 while (iter.next()) {
183 iter->drawPath(path, paint);
184 }
185}
186
reed41af9662015-01-05 07:49:08 -0800187void SkNWayCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
188 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000189 Iter iter(fList);
190 while (iter.next()) {
191 iter->drawBitmap(bitmap, x, y, paint);
192 }
193}
194
reed41af9662015-01-05 07:49:08 -0800195void SkNWayCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
reeda5517e22015-07-14 10:54:12 -0700196 const SkPaint* paint, SK_VIRTUAL_CONSTRAINT_TYPE constraint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000197 Iter iter(fList);
198 while (iter.next()) {
reeda5517e22015-07-14 10:54:12 -0700199 iter->drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000200 }
201}
202
reed41af9662015-01-05 07:49:08 -0800203void SkNWayCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
204 const SkRect& dst, const SkPaint* paint) {
commit-bot@chromium.orgbe65a4c2013-11-14 19:02:41 +0000205 Iter iter(fList);
206 while (iter.next()) {
207 iter->drawBitmapNine(bitmap, center, dst, paint);
208 }
209}
210
reed41af9662015-01-05 07:49:08 -0800211void SkNWayCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
212 const SkPaint* paint) {
piotaixrb7bac3d2014-09-29 08:56:19 -0700213 Iter iter(fList);
214 while (iter.next()) {
215 iter->drawImage(image, left, top, paint);
216 }
217}
218
reed41af9662015-01-05 07:49:08 -0800219void SkNWayCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
reeda5517e22015-07-14 10:54:12 -0700220 const SkPaint* paint SRC_RECT_CONSTRAINT_PARAM(constraint)) {
piotaixrb7bac3d2014-09-29 08:56:19 -0700221 Iter iter(fList);
222 while (iter.next()) {
reeda5517e22015-07-14 10:54:12 -0700223 iter->drawImageRect(image, src, dst, paint SRC_RECT_CONSTRAINT_ARG(constraint));
piotaixrb7bac3d2014-09-29 08:56:19 -0700224 }
225}
226
reed41af9662015-01-05 07:49:08 -0800227void SkNWayCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000228 Iter iter(fList);
229 while (iter.next()) {
230 iter->drawSprite(bitmap, x, y, paint);
231 }
232}
233
reed@google.come0d9ce82014-04-23 04:00:17 +0000234void SkNWayCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
235 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000236 Iter iter(fList);
237 while (iter.next()) {
238 iter->drawText(text, byteLength, x, y, paint);
239 }
240}
241
reed@google.come0d9ce82014-04-23 04:00:17 +0000242void SkNWayCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
243 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000244 Iter iter(fList);
245 while (iter.next()) {
246 iter->drawPosText(text, byteLength, pos, paint);
247 }
248}
249
reed@google.come0d9ce82014-04-23 04:00:17 +0000250void SkNWayCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
251 SkScalar constY, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000252 Iter iter(fList);
253 while (iter.next()) {
254 iter->drawPosTextH(text, byteLength, xpos, constY, paint);
255 }
256}
257
reed@google.come0d9ce82014-04-23 04:00:17 +0000258void SkNWayCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
259 const SkMatrix* matrix, const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000260 Iter iter(fList);
261 while (iter.next()) {
262 iter->drawTextOnPath(text, byteLength, path, matrix, paint);
263 }
264}
265
fmalitab7425172014-08-26 07:56:44 -0700266void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
267 const SkPaint &paint) {
268 Iter iter(fList);
269 while (iter.next()) {
270 iter->drawTextBlob(blob, x, y, paint);
271 }
272}
273
reedd5fa1a42014-08-09 11:08:05 -0700274void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
275 const SkPaint* paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000276 Iter iter(fList);
277 while (iter.next()) {
reedd5fa1a42014-08-09 11:08:05 -0700278 iter->drawPicture(picture, matrix, paint);
reed@android.com6c924ad2009-03-31 03:48:49 +0000279 }
280}
281
reed41af9662015-01-05 07:49:08 -0800282void SkNWayCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
283 const SkPoint vertices[], const SkPoint texs[],
284 const SkColor colors[], SkXfermode* xmode,
285 const uint16_t indices[], int indexCount,
286 const SkPaint& paint) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000287 Iter iter(fList);
288 while (iter.next()) {
289 iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
290 indices, indexCount, paint);
291 }
292}
293
dandovb3c9d1c2014-08-12 08:34:29 -0700294void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
295 const SkPoint texCoords[4], SkXfermode* xmode,
296 const SkPaint& paint) {
dandov963137b2014-08-07 07:49:53 -0700297 Iter iter(fList);
298 while (iter.next()) {
dandovb3c9d1c2014-08-12 08:34:29 -0700299 iter->drawPatch(cubics, colors, texCoords, xmode, paint);
dandov963137b2014-08-07 07:49:53 -0700300 }
301}
302
reed@android.com6c924ad2009-03-31 03:48:49 +0000303SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
304 Iter iter(fList);
305 while (iter.next()) {
306 iter->setDrawFilter(filter);
307 }
308 return this->INHERITED::setDrawFilter(filter);
309}