blob: 06cf32d052786fb6ebc598a080fad00dc5229181 [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
10SkNWayCanvas::SkNWayCanvas() {}
11
12SkNWayCanvas::~SkNWayCanvas() {
13 this->removeAll();
14}
15
16void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
17 if (canvas) {
18 canvas->ref();
19 *fList.append() = canvas;
20 }
21}
22
23void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
24 int index = fList.find(canvas);
25 if (index >= 0) {
26 canvas->unref();
27 fList.removeShuffle(index);
28 }
29}
30
31void SkNWayCanvas::removeAll() {
32 fList.unrefAll();
33 fList.reset();
34}
35
36///////////////////////////////////////////////////////////////////////////
37// These are forwarded to the N canvases we're referencing
38
39class SkNWayCanvas::Iter {
40public:
41 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
42 fIndex = 0;
43 }
44 bool next() {
45 if (fIndex < fList.count()) {
46 fCanvas = fList[fIndex++];
47 return true;
48 }
49 return false;
50 }
51 SkCanvas* operator->() { 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
59int SkNWayCanvas::save(SaveFlags flags) {
60 Iter iter(fList);
61 while (iter.next()) {
62 iter->save(flags);
63 }
64 return this->INHERITED::save(flags);
65}
66
67int SkNWayCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
68 SaveFlags flags) {
69 Iter iter(fList);
70 while (iter.next()) {
71 iter->saveLayer(bounds, paint, flags);
72 }
73 return this->INHERITED::saveLayer(bounds, paint, flags);
74}
75
76void SkNWayCanvas::restore() {
77 Iter iter(fList);
78 while (iter.next()) {
79 iter->restore();
80 }
81 this->INHERITED::restore();
82}
83
84bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) {
85 Iter iter(fList);
86 while (iter.next()) {
87 iter->translate(dx, dy);
88 }
89 return this->INHERITED::translate(dx, dy);
90}
91
92bool SkNWayCanvas::scale(SkScalar sx, SkScalar sy) {
93 Iter iter(fList);
94 while (iter.next()) {
95 iter->scale(sx, sy);
96 }
97 return this->INHERITED::scale(sx, sy);
98}
99
100bool SkNWayCanvas::rotate(SkScalar degrees) {
101 Iter iter(fList);
102 while (iter.next()) {
103 iter->rotate(degrees);
104 }
105 return this->INHERITED::rotate(degrees);
106}
107
108bool SkNWayCanvas::skew(SkScalar sx, SkScalar sy) {
109 Iter iter(fList);
110 while (iter.next()) {
111 iter->skew(sx, sy);
112 }
113 return this->INHERITED::skew(sx, sy);
114}
115
116bool SkNWayCanvas::concat(const SkMatrix& matrix) {
117 Iter iter(fList);
118 while (iter.next()) {
119 iter->concat(matrix);
120 }
121 return this->INHERITED::concat(matrix);
122}
123
124void SkNWayCanvas::setMatrix(const SkMatrix& matrix) {
125 Iter iter(fList);
126 while (iter.next()) {
127 iter->setMatrix(matrix);
128 }
129 this->INHERITED::setMatrix(matrix);
130}
131
reed@google.com071eef92011-10-12 11:52:53 +0000132bool SkNWayCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000133 Iter iter(fList);
134 while (iter.next()) {
reed@google.com071eef92011-10-12 11:52:53 +0000135 iter->clipRect(rect, op, doAA);
reed@android.com6c924ad2009-03-31 03:48:49 +0000136 }
reed@google.com071eef92011-10-12 11:52:53 +0000137 return this->INHERITED::clipRect(rect, op, doAA);
reed@android.com6c924ad2009-03-31 03:48:49 +0000138}
139
reed@google.com071eef92011-10-12 11:52:53 +0000140bool SkNWayCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
reed@android.com6c924ad2009-03-31 03:48:49 +0000141 Iter iter(fList);
142 while (iter.next()) {
reed@google.com071eef92011-10-12 11:52:53 +0000143 iter->clipPath(path, op, doAA);
reed@android.com6c924ad2009-03-31 03:48:49 +0000144 }
reed@google.com071eef92011-10-12 11:52:53 +0000145 return this->INHERITED::clipPath(path, op, doAA);
reed@android.com6c924ad2009-03-31 03:48:49 +0000146}
147
148bool SkNWayCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
149 Iter iter(fList);
150 while (iter.next()) {
151 iter->clipRegion(deviceRgn, op);
152 }
153 return this->INHERITED::clipRegion(deviceRgn, op);
154}
155
156void SkNWayCanvas::drawPaint(const SkPaint& paint) {
157 Iter iter(fList);
158 while (iter.next()) {
159 iter->drawPaint(paint);
160 }
161}
162
163void SkNWayCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
164 const SkPaint& paint) {
165 Iter iter(fList);
166 while (iter.next()) {
167 iter->drawPoints(mode, count, pts, paint);
168 }
169}
170
171void SkNWayCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
172 Iter iter(fList);
173 while (iter.next()) {
174 iter->drawRect(rect, paint);
175 }
176}
177
178void SkNWayCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
179 Iter iter(fList);
180 while (iter.next()) {
181 iter->drawPath(path, paint);
182 }
183}
184
185void SkNWayCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
186 const SkPaint* paint) {
187 Iter iter(fList);
188 while (iter.next()) {
189 iter->drawBitmap(bitmap, x, y, paint);
190 }
191}
192
193void SkNWayCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
194 const SkRect& dst, const SkPaint* paint) {
195 Iter iter(fList);
196 while (iter.next()) {
197 iter->drawBitmapRect(bitmap, src, dst, paint);
198 }
199}
200
201void SkNWayCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
202 const SkPaint* paint) {
203 Iter iter(fList);
204 while (iter.next()) {
205 iter->drawBitmapMatrix(bitmap, m, paint);
206 }
207}
208
209void SkNWayCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
210 const SkPaint* paint) {
211 Iter iter(fList);
212 while (iter.next()) {
213 iter->drawSprite(bitmap, x, y, paint);
214 }
215}
216
217void SkNWayCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
218 SkScalar y, const SkPaint& paint) {
219 Iter iter(fList);
220 while (iter.next()) {
221 iter->drawText(text, byteLength, x, y, paint);
222 }
223}
224
225void SkNWayCanvas::drawPosText(const void* text, size_t byteLength,
226 const SkPoint pos[], const SkPaint& paint) {
227 Iter iter(fList);
228 while (iter.next()) {
229 iter->drawPosText(text, byteLength, pos, paint);
230 }
231}
232
233void SkNWayCanvas::drawPosTextH(const void* text, size_t byteLength,
234 const SkScalar xpos[], SkScalar constY,
235 const SkPaint& paint) {
236 Iter iter(fList);
237 while (iter.next()) {
238 iter->drawPosTextH(text, byteLength, xpos, constY, paint);
239 }
240}
241
242void SkNWayCanvas::drawTextOnPath(const void* text, size_t byteLength,
243 const SkPath& path, const SkMatrix* matrix,
244 const SkPaint& paint) {
245 Iter iter(fList);
246 while (iter.next()) {
247 iter->drawTextOnPath(text, byteLength, path, matrix, paint);
248 }
249}
250
251void SkNWayCanvas::drawPicture(SkPicture& picture) {
252 Iter iter(fList);
253 while (iter.next()) {
254 iter->drawPicture(picture);
255 }
256}
257
reed@android.com6c924ad2009-03-31 03:48:49 +0000258void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount,
259 const SkPoint vertices[], const SkPoint texs[],
260 const SkColor colors[], SkXfermode* xmode,
261 const uint16_t indices[], int indexCount,
262 const SkPaint& paint) {
263 Iter iter(fList);
264 while (iter.next()) {
265 iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
266 indices, indexCount, paint);
267 }
268}
269
270SkBounder* SkNWayCanvas::setBounder(SkBounder* bounder) {
271 Iter iter(fList);
272 while (iter.next()) {
273 iter->setBounder(bounder);
274 }
275 return this->INHERITED::setBounder(bounder);
276}
277
278SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
279 Iter iter(fList);
280 while (iter.next()) {
281 iter->setDrawFilter(filter);
282 }
283 return this->INHERITED::setDrawFilter(filter);
284}
285
286