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