Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / utils / SkNWayCanvas.cpp
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
10 SkNWayCanvas::SkNWayCanvas(int width, int height)
11         : INHERITED(width, height) {}
12
13 SkNWayCanvas::~SkNWayCanvas() {
14     this->removeAll();
15 }
16
17 void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
18     if (canvas) {
19         canvas->ref();
20         *fList.append() = canvas;
21     }
22 }
23
24 void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
25     int index = fList.find(canvas);
26     if (index >= 0) {
27         canvas->unref();
28         fList.removeShuffle(index);
29     }
30 }
31
32 void SkNWayCanvas::removeAll() {
33     fList.unrefAll();
34     fList.reset();
35 }
36
37 ///////////////////////////////////////////////////////////////////////////
38 // These are forwarded to the N canvases we're referencing
39
40 class SkNWayCanvas::Iter {
41 public:
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; }
53
54 private:
55     const SkTDArray<SkCanvas*>& fList;
56     int fIndex;
57     SkCanvas* fCanvas;
58 };
59
60 int SkNWayCanvas::save(SaveFlags flags) {
61     Iter iter(fList);
62     while (iter.next()) {
63         iter->save(flags);
64     }
65     return this->INHERITED::save(flags);
66 }
67
68 int SkNWayCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
69                                     SaveFlags flags) {
70     Iter iter(fList);
71     while (iter.next()) {
72         iter->saveLayer(bounds, paint, flags);
73     }
74     return this->INHERITED::saveLayer(bounds, paint, flags);
75 }
76
77 void SkNWayCanvas::restore() {
78     Iter iter(fList);
79     while (iter.next()) {
80         iter->restore();
81     }
82     this->INHERITED::restore();
83 }
84
85 bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) {
86     Iter iter(fList);
87     while (iter.next()) {
88         iter->translate(dx, dy);
89     }
90     return this->INHERITED::translate(dx, dy);
91 }
92
93 bool SkNWayCanvas::scale(SkScalar sx, SkScalar sy) {
94     Iter iter(fList);
95     while (iter.next()) {
96         iter->scale(sx, sy);
97     }
98     return this->INHERITED::scale(sx, sy);
99 }
100
101 bool SkNWayCanvas::rotate(SkScalar degrees) {
102     Iter iter(fList);
103     while (iter.next()) {
104         iter->rotate(degrees);
105     }
106     return this->INHERITED::rotate(degrees);
107 }
108
109 bool SkNWayCanvas::skew(SkScalar sx, SkScalar sy) {
110     Iter iter(fList);
111     while (iter.next()) {
112         iter->skew(sx, sy);
113     }
114     return this->INHERITED::skew(sx, sy);
115 }
116
117 bool SkNWayCanvas::concat(const SkMatrix& matrix) {
118     Iter iter(fList);
119     while (iter.next()) {
120         iter->concat(matrix);
121     }
122     return this->INHERITED::concat(matrix);
123 }
124
125 void SkNWayCanvas::setMatrix(const SkMatrix& matrix) {
126     Iter iter(fList);
127     while (iter.next()) {
128         iter->setMatrix(matrix);
129     }
130     this->INHERITED::setMatrix(matrix);
131 }
132
133 bool SkNWayCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) {
134     Iter iter(fList);
135     while (iter.next()) {
136         iter->clipRect(rect, op, doAA);
137     }
138     return this->INHERITED::clipRect(rect, op, doAA);
139 }
140
141 bool SkNWayCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) {
142     Iter iter(fList);
143     while (iter.next()) {
144         iter->clipRRect(rrect, op, doAA);
145     }
146     return this->INHERITED::clipRRect(rrect, op, doAA);
147 }
148
149 bool SkNWayCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) {
150     Iter iter(fList);
151     while (iter.next()) {
152         iter->clipPath(path, op, doAA);
153     }
154     return this->INHERITED::clipPath(path, op, doAA);
155 }
156
157 bool SkNWayCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
158     Iter iter(fList);
159     while (iter.next()) {
160         iter->clipRegion(deviceRgn, op);
161     }
162     return this->INHERITED::clipRegion(deviceRgn, op);
163 }
164
165 void SkNWayCanvas::clear(SkColor color) {
166     Iter iter(fList);
167     while (iter.next()) {
168         iter->clear(color);
169     }
170 }
171
172 void SkNWayCanvas::drawPaint(const SkPaint& paint) {
173     Iter iter(fList);
174     while (iter.next()) {
175         iter->drawPaint(paint);
176     }
177 }
178
179 void SkNWayCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
180                         const SkPaint& paint) {
181     Iter iter(fList);
182     while (iter.next()) {
183         iter->drawPoints(mode, count, pts, paint);
184     }
185 }
186
187 void SkNWayCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
188     Iter iter(fList);
189     while (iter.next()) {
190         iter->drawRect(rect, paint);
191     }
192 }
193
194 void SkNWayCanvas::drawOval(const SkRect& rect, const SkPaint& paint) {
195     Iter iter(fList);
196     while (iter.next()) {
197         iter->drawOval(rect, paint);
198     }
199 }
200
201 void SkNWayCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
202     Iter iter(fList);
203     while (iter.next()) {
204         iter->drawRRect(rrect, paint);
205     }
206 }
207
208 void SkNWayCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
209     Iter iter(fList);
210     while (iter.next()) {
211         iter->drawPath(path, paint);
212     }
213 }
214
215 void SkNWayCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
216                               const SkPaint* paint) {
217     Iter iter(fList);
218     while (iter.next()) {
219         iter->drawBitmap(bitmap, x, y, paint);
220     }
221 }
222
223 void SkNWayCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
224                                   const SkRect& dst, const SkPaint* paint,
225                                   DrawBitmapRectFlags flags) {
226     Iter iter(fList);
227     while (iter.next()) {
228         iter->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
229     }
230 }
231
232 void SkNWayCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
233                                     const SkPaint* paint) {
234     Iter iter(fList);
235     while (iter.next()) {
236         iter->drawBitmapMatrix(bitmap, m, paint);
237     }
238 }
239
240 void SkNWayCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
241                                   const SkRect& dst, const SkPaint* paint) {
242     Iter iter(fList);
243     while (iter.next()) {
244         iter->drawBitmapNine(bitmap, center, dst, paint);
245     }
246 }
247
248 void SkNWayCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
249                               const SkPaint* paint) {
250     Iter iter(fList);
251     while (iter.next()) {
252         iter->drawSprite(bitmap, x, y, paint);
253     }
254 }
255
256 void SkNWayCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
257                             SkScalar y, const SkPaint& paint) {
258     Iter iter(fList);
259     while (iter.next()) {
260         iter->drawText(text, byteLength, x, y, paint);
261     }
262 }
263
264 void SkNWayCanvas::drawPosText(const void* text, size_t byteLength,
265                                const SkPoint pos[], const SkPaint& paint) {
266     Iter iter(fList);
267     while (iter.next()) {
268         iter->drawPosText(text, byteLength, pos, paint);
269     }
270 }
271
272 void SkNWayCanvas::drawPosTextH(const void* text, size_t byteLength,
273                                 const SkScalar xpos[], SkScalar constY,
274                                 const SkPaint& paint) {
275     Iter iter(fList);
276     while (iter.next()) {
277         iter->drawPosTextH(text, byteLength, xpos, constY, paint);
278     }
279 }
280
281 void SkNWayCanvas::drawTextOnPath(const void* text, size_t byteLength,
282                                   const SkPath& path, const SkMatrix* matrix,
283                                   const SkPaint& paint) {
284     Iter iter(fList);
285     while (iter.next()) {
286         iter->drawTextOnPath(text, byteLength, path, matrix, paint);
287     }
288 }
289
290 void SkNWayCanvas::drawPicture(SkPicture& picture) {
291     Iter iter(fList);
292     while (iter.next()) {
293         iter->drawPicture(picture);
294     }
295 }
296
297 void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount,
298                           const SkPoint vertices[], const SkPoint texs[],
299                           const SkColor colors[], SkXfermode* xmode,
300                           const uint16_t indices[], int indexCount,
301                           const SkPaint& paint) {
302     Iter iter(fList);
303     while (iter.next()) {
304         iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
305                            indices, indexCount, paint);
306     }
307 }
308
309 void SkNWayCanvas::drawData(const void* data, size_t length) {
310     Iter iter(fList);
311     while (iter.next()) {
312         iter->drawData(data, length);
313     }
314 }
315
316 SkBounder* SkNWayCanvas::setBounder(SkBounder* bounder) {
317     Iter iter(fList);
318     while (iter.next()) {
319         iter->setBounder(bounder);
320     }
321     return this->INHERITED::setBounder(bounder);
322 }
323
324 SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
325     Iter iter(fList);
326     while (iter.next()) {
327         iter->setDrawFilter(filter);
328     }
329     return this->INHERITED::setDrawFilter(filter);
330 }
331
332 void SkNWayCanvas::beginCommentGroup(const char* description) {
333     Iter iter(fList);
334     while (iter.next()) {
335         iter->beginCommentGroup(description);
336     }
337 }
338
339 void SkNWayCanvas::addComment(const char* kywd, const char* value) {
340     Iter iter(fList);
341     while (iter.next()) {
342         iter->addComment(kywd, value);
343     }
344 }
345
346 void SkNWayCanvas::endCommentGroup() {
347     Iter iter(fList);
348     while (iter.next()) {
349         iter->endCommentGroup();
350     }
351 }