Update To 11.40.268.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 void SkNWayCanvas::willSave() {
61     Iter iter(fList);
62     while (iter.next()) {
63         iter->save();
64     }
65
66     this->INHERITED::willSave();
67 }
68
69 SkCanvas::SaveLayerStrategy SkNWayCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
70                                                         SaveFlags flags) {
71     Iter iter(fList);
72     while (iter.next()) {
73         iter->saveLayer(bounds, paint, flags);
74     }
75
76     this->INHERITED::willSaveLayer(bounds, paint, flags);
77     // No need for a layer.
78     return kNoLayer_SaveLayerStrategy;
79 }
80
81 void SkNWayCanvas::willRestore() {
82     Iter iter(fList);
83     while (iter.next()) {
84         iter->restore();
85     }
86     this->INHERITED::willRestore();
87 }
88
89 void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
90     Iter iter(fList);
91     while (iter.next()) {
92         iter->concat(matrix);
93     }
94     this->INHERITED::didConcat(matrix);
95 }
96
97 void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
98     Iter iter(fList);
99     while (iter.next()) {
100         iter->setMatrix(matrix);
101     }
102     this->INHERITED::didSetMatrix(matrix);
103 }
104
105 void SkNWayCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
106     Iter iter(fList);
107     while (iter.next()) {
108         iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
109     }
110     this->INHERITED::onClipRect(rect, op, edgeStyle);
111 }
112
113 void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
114     Iter iter(fList);
115     while (iter.next()) {
116         iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
117     }
118     this->INHERITED::onClipRRect(rrect, op, edgeStyle);
119 }
120
121 void SkNWayCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
122     Iter iter(fList);
123     while (iter.next()) {
124         iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
125     }
126     this->INHERITED::onClipPath(path, op, edgeStyle);
127 }
128
129 void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
130     Iter iter(fList);
131     while (iter.next()) {
132         iter->clipRegion(deviceRgn, op);
133     }
134     this->INHERITED::onClipRegion(deviceRgn, op);
135 }
136
137 void SkNWayCanvas::clear(SkColor color) {
138     Iter iter(fList);
139     while (iter.next()) {
140         iter->clear(color);
141     }
142 }
143
144 void SkNWayCanvas::drawPaint(const SkPaint& paint) {
145     Iter iter(fList);
146     while (iter.next()) {
147         iter->drawPaint(paint);
148     }
149 }
150
151 void SkNWayCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
152                         const SkPaint& paint) {
153     Iter iter(fList);
154     while (iter.next()) {
155         iter->drawPoints(mode, count, pts, paint);
156     }
157 }
158
159 void SkNWayCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
160     Iter iter(fList);
161     while (iter.next()) {
162         iter->drawRect(rect, paint);
163     }
164 }
165
166 void SkNWayCanvas::drawOval(const SkRect& rect, const SkPaint& paint) {
167     Iter iter(fList);
168     while (iter.next()) {
169         iter->drawOval(rect, paint);
170     }
171 }
172
173 void SkNWayCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
174     Iter iter(fList);
175     while (iter.next()) {
176         iter->drawRRect(rrect, paint);
177     }
178 }
179
180 void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
181                                 const SkPaint& paint) {
182     Iter iter(fList);
183     while (iter.next()) {
184         iter->drawDRRect(outer, inner, paint);
185     }
186 }
187
188 void SkNWayCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
189     Iter iter(fList);
190     while (iter.next()) {
191         iter->drawPath(path, paint);
192     }
193 }
194
195 void SkNWayCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
196                               const SkPaint* paint) {
197     Iter iter(fList);
198     while (iter.next()) {
199         iter->drawBitmap(bitmap, x, y, paint);
200     }
201 }
202
203 void SkNWayCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
204                                   const SkRect& dst, const SkPaint* paint,
205                                   DrawBitmapRectFlags flags) {
206     Iter iter(fList);
207     while (iter.next()) {
208         iter->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
209     }
210 }
211
212 void SkNWayCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
213                                     const SkPaint* paint) {
214     Iter iter(fList);
215     while (iter.next()) {
216         iter->drawBitmapMatrix(bitmap, m, paint);
217     }
218 }
219
220 void SkNWayCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
221                                   const SkRect& dst, const SkPaint* paint) {
222     Iter iter(fList);
223     while (iter.next()) {
224         iter->drawBitmapNine(bitmap, center, dst, paint);
225     }
226 }
227
228 void SkNWayCanvas::drawImage(const SkImage* image, SkScalar left, SkScalar top,
229                              const SkPaint* paint) {
230     Iter iter(fList);
231     while (iter.next()) {
232         iter->drawImage(image, left, top, paint);
233     }
234 }
235
236 void SkNWayCanvas::drawImageRect(const SkImage* image, const SkRect* src,
237                                  const SkRect& dst,
238                                  const SkPaint* paint) {
239     Iter iter(fList);
240     while (iter.next()) {
241         iter->drawImageRect(image, src, dst, paint);
242     }
243 }
244
245 void SkNWayCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
246                               const SkPaint* paint) {
247     Iter iter(fList);
248     while (iter.next()) {
249         iter->drawSprite(bitmap, x, y, paint);
250     }
251 }
252
253 void SkNWayCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
254                               const SkPaint& paint) {
255     Iter iter(fList);
256     while (iter.next()) {
257         iter->drawText(text, byteLength, x, y, paint);
258     }
259 }
260
261 void SkNWayCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
262                                  const SkPaint& paint) {
263     Iter iter(fList);
264     while (iter.next()) {
265         iter->drawPosText(text, byteLength, pos, paint);
266     }
267 }
268
269 void SkNWayCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
270                                   SkScalar constY, const SkPaint& paint) {
271     Iter iter(fList);
272     while (iter.next()) {
273         iter->drawPosTextH(text, byteLength, xpos, constY, paint);
274     }
275 }
276
277 void SkNWayCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
278                                     const SkMatrix* matrix, const SkPaint& paint) {
279     Iter iter(fList);
280     while (iter.next()) {
281         iter->drawTextOnPath(text, byteLength, path, matrix, paint);
282     }
283 }
284
285 void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
286                                   const SkPaint &paint) {
287     Iter iter(fList);
288     while (iter.next()) {
289         iter->drawTextBlob(blob, x, y, paint);
290     }
291 }
292
293 void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
294                                  const SkPaint* paint) {
295     Iter iter(fList);
296     while (iter.next()) {
297         iter->drawPicture(picture, matrix, paint);
298     }
299 }
300
301 void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount,
302                           const SkPoint vertices[], const SkPoint texs[],
303                           const SkColor colors[], SkXfermode* xmode,
304                           const uint16_t indices[], int indexCount,
305                           const SkPaint& paint) {
306     Iter iter(fList);
307     while (iter.next()) {
308         iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
309                            indices, indexCount, paint);
310     }
311 }
312
313 void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
314                                const SkPoint texCoords[4], SkXfermode* xmode,
315                                const SkPaint& paint) {
316     Iter iter(fList);
317     while (iter.next()) {
318         iter->drawPatch(cubics, colors, texCoords, xmode, paint);
319     }
320 }
321
322 void SkNWayCanvas::drawData(const void* data, size_t length) {
323     Iter iter(fList);
324     while (iter.next()) {
325         iter->drawData(data, length);
326     }
327 }
328
329 SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
330     Iter iter(fList);
331     while (iter.next()) {
332         iter->setDrawFilter(filter);
333     }
334     return this->INHERITED::setDrawFilter(filter);
335 }
336
337 void SkNWayCanvas::beginCommentGroup(const char* description) {
338     Iter iter(fList);
339     while (iter.next()) {
340         iter->beginCommentGroup(description);
341     }
342 }
343
344 void SkNWayCanvas::addComment(const char* kywd, const char* value) {
345     Iter iter(fList);
346     while (iter.next()) {
347         iter->addComment(kywd, value);
348     }
349 }
350
351 void SkNWayCanvas::endCommentGroup() {
352     Iter iter(fList);
353     while (iter.next()) {
354         iter->endCommentGroup();
355     }
356 }