Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / utils / SkNWayCanvas.cpp
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7
8 #include "include/utils/SkNWayCanvas.h"
9
10 #include "include/core/SkBlendMode.h"
11 #include "include/core/SkCanvas.h"
12 #include "include/core/SkClipOp.h"
13 #include "include/core/SkColor.h"
14 #include "include/core/SkM44.h"
15 #include "include/core/SkMatrix.h"
16 #include "include/core/SkPoint.h"
17 #include "include/core/SkRect.h"
18 #include "include/core/SkRefCnt.h"
19 #include "include/core/SkSamplingOptions.h"
20 #include "include/core/SkScalar.h"
21 #include "include/core/SkShader.h"
22 #include "include/core/SkTypes.h"
23 #include "include/private/SkTDArray.h"
24 #include "include/utils/SkNoDrawCanvas.h"
25 #include "src/core/SkCanvasPriv.h"
26
27 #include <utility>
28
29 class SkData;
30 class SkDrawable;
31 class SkGlyphRunList;
32 class SkImage;
33 class SkPaint;
34 class SkPath;
35 class SkPicture;
36 class SkRRect;
37 class SkRegion;
38 class SkTextBlob;
39 class SkVertices;
40 struct SkDrawShadowRec;
41
42 SkNWayCanvas::SkNWayCanvas(int width, int height) : INHERITED(width, height) {}
43
44 SkNWayCanvas::~SkNWayCanvas() {
45     this->removeAll();
46 }
47
48 void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
49     if (!fList.isEmpty()) {
50         // We are using the nway canvas as a wrapper for the originally added canvas, and the device
51         // on the nway may contradict calls for the device on this canvas. So, to add a second
52         // canvas, the devices on the first canvas, and the nway base device must be different.
53         SkASSERT(fList[0]->baseDevice() != this->baseDevice());
54     }
55     if (canvas) {
56         *fList.append() = canvas;
57     }
58 }
59
60 void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
61     int index = fList.find(canvas);
62     if (index >= 0) {
63         fList.removeShuffle(index);
64     }
65 }
66
67 void SkNWayCanvas::removeAll() {
68     fList.reset();
69 }
70
71 ///////////////////////////////////////////////////////////////////////////
72 // These are forwarded to the N canvases we're referencing
73
74 class SkNWayCanvas::Iter {
75 public:
76     Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
77         fIndex = 0;
78     }
79     bool next() {
80         if (fIndex < fList.count()) {
81             fCanvas = fList[fIndex++];
82             return true;
83         }
84         return false;
85     }
86     SkCanvas* operator->() { return fCanvas; }
87     SkCanvas* get() const { return fCanvas; }
88
89 private:
90     const SkTDArray<SkCanvas*>& fList;
91     int fIndex;
92     SkCanvas* fCanvas;
93 };
94
95 void SkNWayCanvas::willSave() {
96     Iter iter(fList);
97     while (iter.next()) {
98         iter->save();
99     }
100
101     this->INHERITED::willSave();
102 }
103
104 SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) {
105     Iter iter(fList);
106     while (iter.next()) {
107         iter->saveLayer(rec);
108     }
109
110     this->INHERITED::getSaveLayerStrategy(rec);
111     // No need for a layer.
112     return kNoLayer_SaveLayerStrategy;
113 }
114
115 bool SkNWayCanvas::onDoSaveBehind(const SkRect* bounds) {
116     Iter iter(fList);
117     while (iter.next()) {
118         SkCanvasPriv::SaveBehind(iter.get(), bounds);
119     }
120     this->INHERITED::onDoSaveBehind(bounds);
121     return false;
122 }
123
124 void SkNWayCanvas::willRestore() {
125     Iter iter(fList);
126     while (iter.next()) {
127         iter->restore();
128     }
129     this->INHERITED::willRestore();
130 }
131
132 void SkNWayCanvas::didConcat44(const SkM44& m) {
133     Iter iter(fList);
134     while (iter.next()) {
135         iter->concat(m);
136     }
137 }
138
139 void SkNWayCanvas::didSetM44(const SkM44& matrix) {
140     Iter iter(fList);
141     while (iter.next()) {
142         iter->setMatrix(matrix);
143     }
144 }
145
146 void SkNWayCanvas::didTranslate(SkScalar x, SkScalar y) {
147     Iter iter(fList);
148     while (iter.next()) {
149         iter->translate(x, y);
150     }
151 }
152
153 void SkNWayCanvas::didScale(SkScalar x, SkScalar y) {
154     Iter iter(fList);
155     while (iter.next()) {
156         iter->scale(x, y);
157     }
158 }
159
160 void SkNWayCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) {
161     Iter iter(fList);
162     while (iter.next()) {
163         iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
164     }
165     this->INHERITED::onClipRect(rect, op, edgeStyle);
166 }
167
168 void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) {
169     Iter iter(fList);
170     while (iter.next()) {
171         iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
172     }
173     this->INHERITED::onClipRRect(rrect, op, edgeStyle);
174 }
175
176 void SkNWayCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) {
177     Iter iter(fList);
178     while (iter.next()) {
179         iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
180     }
181     this->INHERITED::onClipPath(path, op, edgeStyle);
182 }
183
184 void SkNWayCanvas::onClipShader(sk_sp<SkShader> sh, SkClipOp op) {
185     Iter iter(fList);
186     while (iter.next()) {
187         iter->clipShader(sh, op);
188     }
189     this->INHERITED::onClipShader(std::move(sh), op);
190 }
191
192 void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) {
193     Iter iter(fList);
194     while (iter.next()) {
195         iter->clipRegion(deviceRgn, op);
196     }
197     this->INHERITED::onClipRegion(deviceRgn, op);
198 }
199
200 void SkNWayCanvas::onResetClip() {
201     Iter iter(fList);
202     while (iter.next()) {
203         SkCanvasPriv::ResetClip(iter.get());
204     }
205     this->INHERITED::onResetClip();
206 }
207
208 void SkNWayCanvas::onDrawPaint(const SkPaint& paint) {
209     Iter iter(fList);
210     while (iter.next()) {
211         iter->drawPaint(paint);
212     }
213 }
214
215 void SkNWayCanvas::onDrawBehind(const SkPaint& paint) {
216     Iter iter(fList);
217     while (iter.next()) {
218         SkCanvasPriv::DrawBehind(iter.get(), paint);
219     }
220 }
221
222 void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
223                                 const SkPaint& paint) {
224     Iter iter(fList);
225     while (iter.next()) {
226         iter->drawPoints(mode, count, pts, paint);
227     }
228 }
229
230 void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
231     Iter iter(fList);
232     while (iter.next()) {
233         iter->drawRect(rect, paint);
234     }
235 }
236
237 void SkNWayCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) {
238     Iter iter(fList);
239     while (iter.next()) {
240         iter->drawRegion(region, paint);
241     }
242 }
243
244 void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
245     Iter iter(fList);
246     while (iter.next()) {
247         iter->drawOval(rect, paint);
248     }
249 }
250
251 void SkNWayCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle,
252                              bool useCenter, const SkPaint& paint) {
253     Iter iter(fList);
254     while (iter.next()) {
255         iter->drawArc(rect, startAngle, sweepAngle, useCenter, paint);
256     }
257 }
258
259 void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
260     Iter iter(fList);
261     while (iter.next()) {
262         iter->drawRRect(rrect, paint);
263     }
264 }
265
266 void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
267     Iter iter(fList);
268     while (iter.next()) {
269         iter->drawDRRect(outer, inner, paint);
270     }
271 }
272
273 void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
274     Iter iter(fList);
275     while (iter.next()) {
276         iter->drawPath(path, paint);
277     }
278 }
279
280 void SkNWayCanvas::onDrawImage2(const SkImage* image, SkScalar left, SkScalar top,
281                                 const SkSamplingOptions& sampling, const SkPaint* paint) {
282     Iter iter(fList);
283     while (iter.next()) {
284         iter->drawImage(image, left, top, sampling, paint);
285     }
286 }
287
288 void SkNWayCanvas::onDrawImageRect2(const SkImage* image, const SkRect& src, const SkRect& dst,
289                                     const SkSamplingOptions& sampling, const SkPaint* paint,
290                                     SrcRectConstraint constraint) {
291     Iter iter(fList);
292     while (iter.next()) {
293         iter->drawImageRect(image, src, dst, sampling, paint, constraint);
294     }
295 }
296
297 void SkNWayCanvas::onDrawImageLattice2(const SkImage* image, const Lattice& lattice,
298                                        const SkRect& dst, SkFilterMode filter,
299                                        const SkPaint* paint) {
300     Iter iter(fList);
301     while (iter.next()) {
302         iter->drawImageLattice(image, lattice, dst, filter, paint);
303     }
304 }
305
306 void SkNWayCanvas::onDrawAtlas2(const SkImage* image, const SkRSXform xform[], const SkRect tex[],
307                                 const SkColor colors[], int count, SkBlendMode bmode,
308                                 const SkSamplingOptions& sampling, const SkRect* cull,
309                                 const SkPaint* paint) {
310     Iter iter(fList);
311     while (iter.next()) {
312         iter->drawAtlas(image, xform, tex, colors, count, bmode, sampling, cull, paint);
313     }
314 }
315
316 void SkNWayCanvas::onDrawGlyphRunList(const SkGlyphRunList& list,
317                                       const SkPaint &paint) {
318     Iter iter(fList);
319     while (iter.next()) {
320         iter->onDrawGlyphRunList(list, paint);
321     }
322 }
323
324 void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
325                                   const SkPaint &paint) {
326     Iter iter(fList);
327     while (iter.next()) {
328         iter->drawTextBlob(blob, x, y, paint);
329     }
330 }
331
332 #if SK_SUPPORT_GPU
333 void SkNWayCanvas::onDrawSlug(const sktext::gpu::Slug* slug) {
334     Iter iter(fList);
335     while (iter.next()) {
336         iter->drawSlug(slug);
337     }
338 }
339 #endif
340
341 void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
342                                  const SkPaint* paint) {
343     Iter iter(fList);
344     while (iter.next()) {
345         iter->drawPicture(picture, matrix, paint);
346     }
347 }
348
349 void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
350     Iter iter(fList);
351     while (iter.next()) {
352         iter->drawDrawable(drawable, matrix);
353     }
354 }
355
356 void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices,
357                                         SkBlendMode bmode, const SkPaint& paint) {
358     Iter iter(fList);
359     while (iter.next()) {
360         iter->drawVertices(vertices, bmode, paint);
361     }
362 }
363
364 void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
365                                const SkPoint texCoords[4], SkBlendMode bmode,
366                                const SkPaint& paint) {
367     Iter iter(fList);
368     while (iter.next()) {
369         iter->drawPatch(cubics, colors, texCoords, bmode, paint);
370     }
371 }
372
373 void SkNWayCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) {
374     Iter iter(fList);
375     while (iter.next()) {
376         iter->private_draw_shadow_rec(path, rec);
377     }
378 }
379
380 void SkNWayCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) {
381     Iter iter(fList);
382     while (iter.next()) {
383         iter->drawAnnotation(rect, key, data);
384     }
385 }
386
387 void SkNWayCanvas::onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4],
388                                     QuadAAFlags aa, const SkColor4f& color, SkBlendMode mode) {
389     Iter iter(fList);
390     while (iter.next()) {
391         iter->experimental_DrawEdgeAAQuad(rect, clip, aa, color, mode);
392     }
393 }
394
395 void SkNWayCanvas::onDrawEdgeAAImageSet2(const ImageSetEntry set[], int count,
396                                          const SkPoint dstClips[], const SkMatrix preViewMatrices[],
397                                          const SkSamplingOptions& sampling, const SkPaint* paint,
398                                          SrcRectConstraint constraint) {
399     Iter iter(fList);
400     while (iter.next()) {
401         iter->experimental_DrawEdgeAAImageSet(
402                 set, count, dstClips, preViewMatrices, sampling, paint, constraint);
403     }
404 }
405
406 void SkNWayCanvas::onFlush() {
407     Iter iter(fList);
408     while (iter.next()) {
409         iter->flush();
410     }
411 }