test SwEngine: increasing lines coverage (#767)
[platform/core/graphics/tizenvg.git] / test / testSwEngine.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
3
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 #include <thorvg.h>
24 #include "catch.hpp"
25
26 using namespace tvg;
27
28
29 TEST_CASE("Basic draw", "[tvgSwEngine]")
30 {
31     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
32
33     auto canvas = SwCanvas::gen();
34     REQUIRE(canvas);
35
36     uint32_t buffer[100*100];
37     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
38
39     //Arc Line
40     auto shape1 = tvg::Shape::gen();
41     REQUIRE(shape1);
42
43     REQUIRE(shape1->appendArc(150, 150, 80, 10, 180, false) == Result::Success);
44     REQUIRE(shape1->stroke(255, 255, 255, 255) == Result::Success);
45     REQUIRE(shape1->stroke(2) == Result::Success);
46     REQUIRE(canvas->push(move(shape1)) == Result::Success);
47
48     //Cubic
49     auto shape2 = tvg::Shape::gen();
50     REQUIRE(shape2);
51
52     REQUIRE(shape2->moveTo(50, 25) == Result::Success);
53     REQUIRE(shape2->cubicTo(62, 25, 75, 38, 75, 50) == Result::Success);
54     REQUIRE(shape2->close() == Result::Success);
55     REQUIRE(shape2->stroke(1) == Result::Success);
56     REQUIRE(canvas->push(move(shape2)) == Result::Success);
57
58     //Line
59     auto shape3 = tvg::Shape::gen();
60     REQUIRE(shape3);
61
62     REQUIRE(shape3->moveTo(0, 0) == Result::Success);
63     REQUIRE(shape3->lineTo(20, 0) == Result::Success);
64     REQUIRE(shape3->lineTo(20, 20) == Result::Success);
65     REQUIRE(shape3->lineTo(0, 20) == Result::Success);
66     REQUIRE(shape3->close() == Result::Success);
67     REQUIRE(shape3->fill(255, 255, 255, 255) == Result::Success);
68     REQUIRE(canvas->push(move(shape3)) == Result::Success);
69
70     //Dashed shape
71     auto shape4 = tvg::Shape::gen();
72     REQUIRE(shape4);
73     float dashPattern[2] = {2.5f, 5.0f};
74
75     REQUIRE(shape4->moveTo(0, 0) == Result::Success);
76     REQUIRE(shape4->lineTo(25, 25) == Result::Success);
77     REQUIRE(shape4->cubicTo(50, 50, 75, -75, 50, 100) == Result::Success);
78     REQUIRE(shape4->close() == Result::Success);
79     REQUIRE(shape4->stroke(255, 0, 0, 255) == Result::Success);
80     REQUIRE(shape4->stroke(2) == Result::Success);
81     REQUIRE(shape4->stroke(dashPattern, 2) == Result::Success);
82     REQUIRE(shape4->stroke(StrokeCap::Round) == Result::Success);
83     REQUIRE(canvas->push(move(shape4)) == Result::Success);
84
85     //Draw
86     REQUIRE(canvas->draw() == Result::Success);
87     REQUIRE(canvas->sync() == Result::Success);
88
89     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
90 }
91
92
93 TEST_CASE("Image Draw", "[tvgSwEngine]")
94 {
95     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
96
97     auto canvas = SwCanvas::gen();
98     REQUIRE(canvas);
99
100     uint32_t buffer[100*100];
101     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
102
103
104     //Not transformed images
105     auto basicPicture = Picture::gen();
106     REQUIRE(basicPicture);
107     REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
108     auto rectMask = tvg::Shape::gen();
109     REQUIRE(rectMask);
110     REQUIRE(rectMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);
111     auto rleMask = tvg::Shape::gen();
112     REQUIRE(rleMask);
113     REQUIRE(rleMask->appendRect(0, 10, 20, 30, 5, 5) == Result::Success);
114
115     // Rect images
116     auto basicPicture2 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
117     REQUIRE(basicPicture2);
118     auto rectMask2 = std::unique_ptr<Shape>(static_cast<Shape*>(rectMask->duplicate()));
119     REQUIRE(rectMask2);
120
121     auto basicPicture3 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
122     REQUIRE(basicPicture3);
123     auto rectMask3 = std::unique_ptr<Shape>(static_cast<Shape*>(rectMask->duplicate()));
124     REQUIRE(rectMask3);
125
126     auto basicPicture4 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
127     REQUIRE(basicPicture4);
128
129     // Rle images
130     auto basicPicture5 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
131     REQUIRE(basicPicture5);
132
133     auto basicPicture6 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
134     REQUIRE(basicPicture6);
135     auto rleMask6 = std::unique_ptr<Shape>(static_cast<Shape*>(rleMask->duplicate()));
136     REQUIRE(rleMask6);
137
138     // Rect
139     REQUIRE(basicPicture->composite(move(rectMask), tvg::CompositeMethod::AlphaMask) == Result::Success);
140     REQUIRE(canvas->push(move(basicPicture)) == Result::Success);
141
142     REQUIRE(basicPicture2->composite(move(rectMask2), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
143     REQUIRE(canvas->push(move(basicPicture2)) == Result::Success);
144
145     REQUIRE(basicPicture3->composite(move(rectMask3), tvg::CompositeMethod::ClipPath) == Result::Success);
146     REQUIRE(canvas->push(move(basicPicture3)) == Result::Success);
147
148     REQUIRE(basicPicture4->opacity(100) == Result::Success);
149     REQUIRE(canvas->push(move(basicPicture4)) == Result::Success);
150
151     // Rle
152     REQUIRE(basicPicture5->composite(move(rleMask), tvg::CompositeMethod::ClipPath) == Result::Success);
153     REQUIRE(canvas->push(move(basicPicture5)) == Result::Success);
154
155     REQUIRE(basicPicture6->composite(move(rleMask6), tvg::CompositeMethod::ClipPath) == Result::Success);
156     REQUIRE(basicPicture6->opacity(100) == Result::Success);
157     REQUIRE(canvas->push(move(basicPicture6)) == Result::Success);
158
159
160     // Transformed images
161     basicPicture = Picture::gen();
162     REQUIRE(basicPicture);
163     REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
164     REQUIRE(basicPicture->rotate(45) == Result::Success);
165     rectMask = tvg::Shape::gen();
166     REQUIRE(rectMask);
167     REQUIRE(rectMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);
168     rleMask = tvg::Shape::gen();
169     REQUIRE(rleMask);
170     REQUIRE(rleMask->appendRect(0, 10, 20, 30, 5, 5) == Result::Success);
171
172     // Rect images
173     basicPicture2 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
174     REQUIRE(basicPicture2);
175     rectMask2 = std::unique_ptr<Shape>(static_cast<Shape*>(rectMask->duplicate()));
176     REQUIRE(rectMask2);
177
178     basicPicture3 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
179     REQUIRE(basicPicture3);
180     rectMask3 = std::unique_ptr<Shape>(static_cast<Shape*>(rectMask->duplicate()));
181     REQUIRE(rectMask3);
182
183     basicPicture4 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
184     REQUIRE(basicPicture4);
185
186     // Rle images
187     basicPicture5 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
188     REQUIRE(basicPicture5);
189
190     basicPicture6 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
191     REQUIRE(basicPicture6);
192     rleMask6 = std::unique_ptr<Shape>(static_cast<Shape*>(rleMask->duplicate()));
193     REQUIRE(rleMask6);
194
195     // Rect
196     REQUIRE(basicPicture->composite(move(rectMask), tvg::CompositeMethod::AlphaMask) == Result::Success);
197     REQUIRE(canvas->push(move(basicPicture)) == Result::Success);
198
199     REQUIRE(basicPicture2->composite(move(rectMask2), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
200     REQUIRE(canvas->push(move(basicPicture2)) == Result::Success);
201
202     REQUIRE(basicPicture3->composite(move(rectMask3), tvg::CompositeMethod::ClipPath) == Result::Success);
203     REQUIRE(canvas->push(move(basicPicture3)) == Result::Success);
204
205     REQUIRE(basicPicture4->opacity(100) == Result::Success);
206     REQUIRE(canvas->push(move(basicPicture4)) == Result::Success);
207
208     // Rle
209     REQUIRE(basicPicture5->composite(move(rleMask), tvg::CompositeMethod::ClipPath) == Result::Success);
210     REQUIRE(canvas->push(move(basicPicture5)) == Result::Success);
211
212     REQUIRE(basicPicture6->composite(move(rleMask6), tvg::CompositeMethod::ClipPath) == Result::Success);
213     REQUIRE(basicPicture6->opacity(100) == Result::Success);
214     REQUIRE(canvas->push(move(basicPicture6)) == Result::Success);
215
216
217     // Upscaled images
218     basicPicture = Picture::gen();
219     REQUIRE(basicPicture);
220     REQUIRE(basicPicture->load(TEST_DIR"/test.png") == Result::Success);
221     REQUIRE(basicPicture->scale(2) == Result::Success);
222     rectMask = tvg::Shape::gen();
223     REQUIRE(rectMask);
224     REQUIRE(rectMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);
225     rleMask = tvg::Shape::gen();
226     REQUIRE(rleMask);
227     REQUIRE(rleMask->appendRect(0, 10, 20, 30, 5, 5) == Result::Success);
228
229     // Rect images
230     basicPicture2 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
231     REQUIRE(basicPicture2);
232     rectMask2 = std::unique_ptr<Shape>(static_cast<Shape*>(rectMask->duplicate()));
233     REQUIRE(rectMask2);
234
235     basicPicture3 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
236     REQUIRE(basicPicture3);
237     rectMask3 = std::unique_ptr<Shape>(static_cast<Shape*>(rectMask->duplicate()));
238     REQUIRE(rectMask3);
239
240     basicPicture4 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
241     REQUIRE(basicPicture4);
242
243     // Rle images
244     basicPicture5 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
245     REQUIRE(basicPicture5);
246
247     basicPicture6 = std::unique_ptr<Picture>(static_cast<Picture*>(basicPicture->duplicate()));
248     REQUIRE(basicPicture6);
249     rleMask6 = std::unique_ptr<Shape>(static_cast<Shape*>(rleMask->duplicate()));
250     REQUIRE(rleMask6);
251
252     // Rect
253     REQUIRE(basicPicture->composite(move(rectMask), tvg::CompositeMethod::AlphaMask) == Result::Success);
254     REQUIRE(canvas->push(move(basicPicture)) == Result::Success);
255
256     REQUIRE(basicPicture2->composite(move(rectMask2), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
257     REQUIRE(canvas->push(move(basicPicture2)) == Result::Success);
258
259     REQUIRE(basicPicture3->composite(move(rectMask3), tvg::CompositeMethod::ClipPath) == Result::Success);
260     REQUIRE(canvas->push(move(basicPicture3)) == Result::Success);
261
262     REQUIRE(basicPicture4->opacity(100) == Result::Success);
263     REQUIRE(canvas->push(move(basicPicture4)) == Result::Success);
264
265     // Rle
266     REQUIRE(basicPicture5->composite(move(rleMask), tvg::CompositeMethod::ClipPath) == Result::Success);
267     REQUIRE(canvas->push(move(basicPicture5)) == Result::Success);
268
269     REQUIRE(basicPicture6->composite(move(rleMask6), tvg::CompositeMethod::ClipPath) == Result::Success);
270     REQUIRE(basicPicture6->opacity(100) == Result::Success);
271     REQUIRE(canvas->push(move(basicPicture6)) == Result::Success);
272
273
274     //Draw
275     REQUIRE(canvas->draw() == Result::Success);
276     REQUIRE(canvas->sync() == Result::Success);
277
278     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
279 }
280
281
282 TEST_CASE("Rect Draw", "[tvgSwEngine]")
283 {
284     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
285
286     auto canvas = SwCanvas::gen();
287     REQUIRE(canvas);
288
289     uint32_t buffer[100*100];
290     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
291
292     //Basic shapes and masking
293     auto basicShape = tvg::Shape::gen();
294     REQUIRE(basicShape);
295     auto basicMask = tvg::Shape::gen();
296     REQUIRE(basicMask);
297     REQUIRE(basicShape->appendRect(0, 0, 50, 50, 0, 0) == Result::Success);
298     REQUIRE(basicMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);
299     REQUIRE(basicShape->fill(255, 255, 255, 155) == Result::Success);
300
301     auto basicShape2 = std::unique_ptr<Shape>(static_cast<Shape*>(basicShape->duplicate()));
302     REQUIRE(basicShape2);
303     auto basicMask2 = std::unique_ptr<Shape>(static_cast<Shape*>(basicMask->duplicate()));
304     REQUIRE(basicMask2);
305
306     auto basicShape3 = std::unique_ptr<Shape>(static_cast<Shape*>(basicShape->duplicate()));
307     REQUIRE(basicShape3);
308     auto basicMask3 = std::unique_ptr<Shape>(static_cast<Shape*>(basicMask->duplicate()));
309     REQUIRE(basicMask3);
310
311     auto basicShape4 = std::unique_ptr<Shape>(static_cast<Shape*>(basicShape->duplicate()));
312     REQUIRE(basicShape4);
313
314     REQUIRE(basicShape->composite(move(basicMask), tvg::CompositeMethod::AlphaMask) == Result::Success);
315     REQUIRE(canvas->push(move(basicShape)) == Result::Success);
316
317     REQUIRE(basicShape2->composite(move(basicMask2), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
318     REQUIRE(canvas->push(move(basicShape2)) == Result::Success);
319
320     REQUIRE(basicShape3->composite(move(basicMask3), tvg::CompositeMethod::ClipPath) == Result::Success);
321     REQUIRE(canvas->push(move(basicShape3)) == Result::Success);
322
323     REQUIRE(canvas->push(move(basicShape4)) == Result::Success);
324
325     //Draw
326     REQUIRE(canvas->draw() == Result::Success);
327     REQUIRE(canvas->sync() == Result::Success);
328
329     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
330 }
331
332
333 TEST_CASE("RLE Draw", "[tvgSwEngine]")
334 {
335     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
336
337     auto canvas = SwCanvas::gen();
338     REQUIRE(canvas);
339
340     uint32_t buffer[100*100];
341     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
342
343     //Basic shapes and masking
344     auto basicShape = tvg::Shape::gen();
345     REQUIRE(basicShape);
346     auto basicMask = tvg::Shape::gen();
347     REQUIRE(basicMask);
348     REQUIRE(basicShape->appendRect(0, 0, 50, 50, 50, 50) == Result::Success);
349     REQUIRE(basicMask->appendRect(10, 10, 30, 30, 0, 0) == Result::Success);
350     REQUIRE(basicShape->fill(255, 255, 255, 100) == Result::Success);
351
352     auto basicShape2 = std::unique_ptr<Shape>(static_cast<Shape*>(basicShape->duplicate()));
353     REQUIRE(basicShape2);
354     auto basicMask2 = std::unique_ptr<Shape>(static_cast<Shape*>(basicMask->duplicate()));
355     REQUIRE(basicMask2);
356
357     auto basicShape3 = std::unique_ptr<Shape>(static_cast<Shape*>(basicShape->duplicate()));
358     REQUIRE(basicShape3);
359     auto basicMask3 = std::unique_ptr<Shape>(static_cast<Shape*>(basicMask->duplicate()));
360     REQUIRE(basicMask3);
361
362     auto basicShape4 = std::unique_ptr<Shape>(static_cast<Shape*>(basicShape->duplicate()));
363     REQUIRE(basicShape4);
364
365     REQUIRE(basicShape->composite(move(basicMask), tvg::CompositeMethod::AlphaMask) == Result::Success);
366     REQUIRE(canvas->push(move(basicShape)) == Result::Success);
367
368     REQUIRE(basicShape2->composite(move(basicMask2), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
369     REQUIRE(canvas->push(move(basicShape2)) == Result::Success);
370
371     REQUIRE(basicShape3->composite(move(basicMask3), tvg::CompositeMethod::ClipPath) == Result::Success);
372     REQUIRE(canvas->push(move(basicShape3)) == Result::Success);
373
374     REQUIRE(canvas->push(move(basicShape4)) == Result::Success);
375
376     //Draw
377     REQUIRE(canvas->draw() == Result::Success);
378     REQUIRE(canvas->sync() == Result::Success);
379
380     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
381 }
382
383
384 TEST_CASE("Filling Draw", "[tvgSwEngine]")
385 {
386     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
387
388     auto canvas = SwCanvas::gen();
389     REQUIRE(canvas);
390
391     uint32_t buffer[100*100];
392     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
393
394     //Fill
395     auto linearFill = LinearGradient::gen();
396     REQUIRE(linearFill);
397
398     auto radialFill = RadialGradient::gen();
399     REQUIRE(radialFill);
400
401     Fill::ColorStop cs[4] = {
402         {0.0f, 0, 0, 0, 0},
403         {0.2f, 50, 25, 50, 25},
404         {0.5f, 100, 100, 100, 125},
405         {1.0f, 255, 255, 255, 255}
406     };
407     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
408     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
409     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
410     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
411
412     //Filled Shapes
413     auto shape3 = tvg::Shape::gen();
414     REQUIRE(shape3);
415     auto shape4 = tvg::Shape::gen();
416     REQUIRE(shape4);
417     REQUIRE(shape3->appendRect(0, 0, 50, 50, 0, 0) == Result::Success);
418     REQUIRE(shape4->appendRect(50, 0, 50, 50, 0, 0) == Result::Success);
419
420     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
421     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
422
423     REQUIRE(canvas->push(move(shape3)) == Result::Success);
424     REQUIRE(canvas->push(move(shape4)) == Result::Success);
425
426     //Draw
427     REQUIRE(canvas->draw() == Result::Success);
428     REQUIRE(canvas->sync() == Result::Success);
429
430     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
431 }
432
433
434 TEST_CASE("Filling Opaque Draw", "[tvgSwEngine]")
435 {
436     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
437
438     auto canvas = SwCanvas::gen();
439     REQUIRE(canvas);
440
441     uint32_t buffer[100*100];
442     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
443
444     //Fill
445     auto linearFill = LinearGradient::gen();
446     REQUIRE(linearFill);
447
448     auto radialFill = RadialGradient::gen();
449     REQUIRE(radialFill);
450
451     Fill::ColorStop cs[4] = {
452         {0.0f, 0, 0, 0, 255},
453         {0.2f, 50, 25, 50, 255},
454         {0.5f, 100, 100, 100, 255},
455         {1.0f, 255, 255, 255, 255}
456     };
457     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
458     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
459     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
460     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
461
462     //Filled Shapes
463     auto shape3 = tvg::Shape::gen();
464     REQUIRE(shape3);
465     auto shape4 = tvg::Shape::gen();
466     REQUIRE(shape4);
467     REQUIRE(shape3->appendRect(0, 0, 50, 50, 0, 0) == Result::Success);
468     REQUIRE(shape4->appendRect(50, 0, 50, 50, 0, 0) == Result::Success);
469
470     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
471     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
472
473     REQUIRE(canvas->push(move(shape3)) == Result::Success);
474     REQUIRE(canvas->push(move(shape4)) == Result::Success);
475
476     //Draw
477     REQUIRE(canvas->draw() == Result::Success);
478     REQUIRE(canvas->sync() == Result::Success);
479
480     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
481 }
482
483
484 TEST_CASE("Filling AlphaMask", "[tvgSwEngine]")
485 {
486     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
487
488     auto canvas = SwCanvas::gen();
489     REQUIRE(canvas);
490
491     uint32_t buffer[100*100];
492     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
493
494     //Fill
495     auto linearFill = LinearGradient::gen();
496     REQUIRE(linearFill);
497
498     auto radialFill = RadialGradient::gen();
499     REQUIRE(radialFill);
500
501     Fill::ColorStop cs[4] = {
502         {0.0f, 0, 0, 0, 0},
503         {0.2f, 50, 25, 50, 25},
504         {0.5f, 100, 100, 100, 125},
505         {1.0f, 255, 255, 255, 255}
506     };
507     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
508     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
509     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
510     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
511
512     //Mask
513     auto mask = tvg::Shape::gen();
514     REQUIRE(mask);
515     REQUIRE(mask->appendCircle(50, 50, 50, 50) == Result::Success);
516
517     //Filled Shapes
518     auto shape3 = tvg::Shape::gen();
519     REQUIRE(shape3);
520     auto shape4 = tvg::Shape::gen();
521     REQUIRE(shape4);
522     REQUIRE(shape3->appendRect(0, 0, 50, 50, 0, 0) == Result::Success);
523     REQUIRE(shape4->appendRect(50, 0, 50, 50, 0, 0) == Result::Success);
524
525     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
526     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
527
528     //Scene
529     auto scene = tvg::Scene::gen();
530     REQUIRE(scene);
531     REQUIRE(scene->push(move(shape3)) == Result::Success);
532     REQUIRE(scene->push(move(shape4)) == Result::Success);
533     REQUIRE(scene->composite(move(mask), tvg::CompositeMethod::AlphaMask) == Result::Success);
534     REQUIRE(canvas->push(move(scene)) == Result::Success);
535
536     //Draw
537     REQUIRE(canvas->draw() == Result::Success);
538     REQUIRE(canvas->sync() == Result::Success);
539
540     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
541 }
542
543
544 TEST_CASE("Filling InvAlphaMask", "[tvgSwEngine]")
545 {
546     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
547
548     auto canvas = SwCanvas::gen();
549     REQUIRE(canvas);
550
551     uint32_t buffer[100*100];
552     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
553
554     //Fill
555     auto linearFill = LinearGradient::gen();
556     REQUIRE(linearFill);
557
558     auto radialFill = RadialGradient::gen();
559     REQUIRE(radialFill);
560
561     Fill::ColorStop cs[4] = {
562         {0.0f, 0, 0, 0, 0},
563         {0.2f, 50, 25, 50, 25},
564         {0.5f, 100, 100, 100, 125},
565         {1.0f, 255, 255, 255, 255}
566     };
567     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
568     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
569     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
570     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
571
572     //Mask
573     auto mask = tvg::Shape::gen();
574     REQUIRE(mask);
575     REQUIRE(mask->appendCircle(50, 50, 50, 50) == Result::Success);
576
577     //Filled Shapes
578     auto shape3 = tvg::Shape::gen();
579     REQUIRE(shape3);
580     auto shape4 = tvg::Shape::gen();
581     REQUIRE(shape4);
582     REQUIRE(shape3->appendRect(0, 0, 50, 50, 0, 0) == Result::Success);
583     REQUIRE(shape4->appendRect(50, 0, 50, 50, 0, 0) == Result::Success);
584
585     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
586     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
587
588     //Scene
589     auto scene = tvg::Scene::gen();
590     REQUIRE(scene);
591     REQUIRE(scene->push(move(shape3)) == Result::Success);
592     REQUIRE(scene->push(move(shape4)) == Result::Success);
593     REQUIRE(scene->composite(move(mask), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
594     REQUIRE(canvas->push(move(scene)) == Result::Success);
595
596     //Draw
597     REQUIRE(canvas->draw() == Result::Success);
598     REQUIRE(canvas->sync() == Result::Success);
599
600     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
601 }
602
603
604 TEST_CASE("Filling ClipPath", "[tvgSwEngine]")
605 {
606     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
607
608     auto canvas = SwCanvas::gen();
609     REQUIRE(canvas);
610
611     uint32_t buffer[100*100];
612     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
613
614     //Fill
615     auto linearFill = LinearGradient::gen();
616     REQUIRE(linearFill);
617
618     auto radialFill = RadialGradient::gen();
619     REQUIRE(radialFill);
620
621     Fill::ColorStop cs[4] = {
622         {0.0f, 0, 0, 0, 0},
623         {0.2f, 50, 25, 50, 25},
624         {0.5f, 100, 100, 100, 125},
625         {1.0f, 255, 255, 255, 255}
626     };
627     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
628     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
629     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
630     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
631
632     //Mask
633     auto mask = tvg::Shape::gen();
634     REQUIRE(mask);
635     REQUIRE(mask->appendCircle(50, 50, 50, 50) == Result::Success);
636
637     //Filled Shapes
638     auto shape3 = tvg::Shape::gen();
639     REQUIRE(shape3);
640     auto shape4 = tvg::Shape::gen();
641     REQUIRE(shape4);
642     REQUIRE(shape3->appendRect(0, 0, 50, 50, 0, 0) == Result::Success);
643     REQUIRE(shape4->appendRect(50, 0, 50, 50, 0, 0) == Result::Success);
644
645     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
646     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
647
648     //Scene
649     auto scene = tvg::Scene::gen();
650     REQUIRE(scene);
651     REQUIRE(scene->push(move(shape3)) == Result::Success);
652     REQUIRE(scene->push(move(shape4)) == Result::Success);
653     REQUIRE(scene->composite(move(mask), tvg::CompositeMethod::ClipPath) == Result::Success);
654     REQUIRE(canvas->push(move(scene)) == Result::Success);
655
656     //Draw
657     REQUIRE(canvas->draw() == Result::Success);
658     REQUIRE(canvas->sync() == Result::Success);
659
660     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
661 }
662
663
664 TEST_CASE("RLE Filling Draw", "[tvgSwEngine]")
665 {
666     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
667
668     auto canvas = SwCanvas::gen();
669     REQUIRE(canvas);
670
671     uint32_t buffer[100*100];
672     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
673
674     //Fill
675     auto linearFill = LinearGradient::gen();
676     REQUIRE(linearFill);
677
678     auto radialFill = RadialGradient::gen();
679     REQUIRE(radialFill);
680
681     Fill::ColorStop cs[4] = {
682         {0.0f, 0, 0, 0, 0},
683         {0.2f, 50, 25, 50, 25},
684         {0.5f, 100, 100, 100, 125},
685         {1.0f, 255, 255, 255, 255}
686     };
687     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
688     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
689     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
690     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
691
692     //Filled Shapes
693     auto shape3 = tvg::Shape::gen();
694     REQUIRE(shape3);
695     auto shape4 = tvg::Shape::gen();
696     REQUIRE(shape4);
697     REQUIRE(shape3->appendRect(0, 0, 50, 50, 10, 10) == Result::Success);
698     REQUIRE(shape4->appendRect(50, 0, 50, 50, 10, 10) == Result::Success);
699
700     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
701     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
702
703     REQUIRE(canvas->push(move(shape3)) == Result::Success);
704     REQUIRE(canvas->push(move(shape4)) == Result::Success);
705
706     //Draw
707     REQUIRE(canvas->draw() == Result::Success);
708     REQUIRE(canvas->sync() == Result::Success);
709
710     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
711 }
712
713
714 TEST_CASE("RLE Filling Opaque Draw", "[tvgSwEngine]")
715 {
716     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
717
718     auto canvas = SwCanvas::gen();
719     REQUIRE(canvas);
720
721     uint32_t buffer[100*100];
722     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
723
724     //Fill
725     auto linearFill = LinearGradient::gen();
726     REQUIRE(linearFill);
727
728     auto radialFill = RadialGradient::gen();
729     REQUIRE(radialFill);
730
731     Fill::ColorStop cs[4] = {
732         {0.0f, 0, 0, 0, 255},
733         {0.2f, 50, 25, 50, 255},
734         {0.5f, 100, 100, 100, 255},
735         {1.0f, 255, 255, 255, 255}
736     };
737     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
738     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
739     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
740     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
741
742     //Filled Shapes
743     auto shape3 = tvg::Shape::gen();
744     REQUIRE(shape3);
745     auto shape4 = tvg::Shape::gen();
746     REQUIRE(shape4);
747     REQUIRE(shape3->appendRect(0, 0, 50, 50, 10, 10) == Result::Success);
748     REQUIRE(shape4->appendRect(50, 0, 50, 50, 10, 10) == Result::Success);
749
750     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
751     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
752
753     REQUIRE(canvas->push(move(shape3)) == Result::Success);
754     REQUIRE(canvas->push(move(shape4)) == Result::Success);
755
756     //Draw
757     REQUIRE(canvas->draw() == Result::Success);
758     REQUIRE(canvas->sync() == Result::Success);
759
760     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
761 }
762
763
764 TEST_CASE("RLE Filling AlphaMask", "[tvgSwEngine]")
765 {
766     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
767
768     auto canvas = SwCanvas::gen();
769     REQUIRE(canvas);
770
771     uint32_t buffer[100*100];
772     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
773
774     //Fill
775     auto linearFill = LinearGradient::gen();
776     REQUIRE(linearFill);
777
778     auto radialFill = RadialGradient::gen();
779     REQUIRE(radialFill);
780
781     Fill::ColorStop cs[4] = {
782         {0.0f, 0, 0, 0, 0},
783         {0.2f, 50, 25, 50, 25},
784         {0.5f, 100, 100, 100, 125},
785         {1.0f, 255, 255, 255, 255}
786     };
787     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
788     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
789     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
790     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
791
792     //Mask
793     auto mask = tvg::Shape::gen();
794     REQUIRE(mask);
795     REQUIRE(mask->appendCircle(50, 50, 50, 50) == Result::Success);
796
797     //Filled Shapes
798     auto shape3 = tvg::Shape::gen();
799     REQUIRE(shape3);
800     auto shape4 = tvg::Shape::gen();
801     REQUIRE(shape4);
802     REQUIRE(shape3->appendRect(0, 0, 50, 50, 10, 10) == Result::Success);
803     REQUIRE(shape4->appendRect(50, 0, 50, 50, 10, 10) == Result::Success);
804
805     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
806     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
807
808     //Scene
809     auto scene = tvg::Scene::gen();
810     REQUIRE(scene);
811     REQUIRE(scene->push(move(shape3)) == Result::Success);
812     REQUIRE(scene->push(move(shape4)) == Result::Success);
813     REQUIRE(scene->composite(move(mask), tvg::CompositeMethod::AlphaMask) == Result::Success);
814     REQUIRE(canvas->push(move(scene)) == Result::Success);
815
816     //Draw
817     REQUIRE(canvas->draw() == Result::Success);
818     REQUIRE(canvas->sync() == Result::Success);
819
820     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
821 }
822
823
824 TEST_CASE("RLE Filling InvAlphaMask", "[tvgSwEngine]")
825 {
826     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
827
828     auto canvas = SwCanvas::gen();
829     REQUIRE(canvas);
830
831     uint32_t buffer[100*100];
832     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
833
834     //Fill
835     auto linearFill = LinearGradient::gen();
836     REQUIRE(linearFill);
837
838     auto radialFill = RadialGradient::gen();
839     REQUIRE(radialFill);
840
841     Fill::ColorStop cs[4] = {
842         {0.0f, 0, 0, 0, 0},
843         {0.2f, 50, 25, 50, 25},
844         {0.5f, 100, 100, 100, 125},
845         {1.0f, 255, 255, 255, 255}
846     };
847     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
848     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
849     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
850     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
851
852     //Mask
853     auto mask = tvg::Shape::gen();
854     REQUIRE(mask);
855     REQUIRE(mask->appendCircle(50, 50, 50, 50) == Result::Success);
856
857     //Filled Shapes
858     auto shape3 = tvg::Shape::gen();
859     REQUIRE(shape3);
860     auto shape4 = tvg::Shape::gen();
861     REQUIRE(shape4);
862     REQUIRE(shape3->appendRect(0, 0, 50, 50, 10, 10) == Result::Success);
863     REQUIRE(shape4->appendRect(50, 0, 50, 50, 10, 10) == Result::Success);
864
865     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
866     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
867
868     //Scene
869     auto scene = tvg::Scene::gen();
870     REQUIRE(scene);
871     REQUIRE(scene->push(move(shape3)) == Result::Success);
872     REQUIRE(scene->push(move(shape4)) == Result::Success);
873     REQUIRE(scene->composite(move(mask), tvg::CompositeMethod::InvAlphaMask) == Result::Success);
874     REQUIRE(canvas->push(move(scene)) == Result::Success);
875
876     //Draw
877     REQUIRE(canvas->draw() == Result::Success);
878     REQUIRE(canvas->sync() == Result::Success);
879
880     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
881 }
882
883
884 TEST_CASE("RLE Filling ClipPath", "[tvgSwEngine]")
885 {
886     REQUIRE(Initializer::init(CanvasEngine::Sw, 0) == Result::Success);
887
888     auto canvas = SwCanvas::gen();
889     REQUIRE(canvas);
890
891     uint32_t buffer[100*100];
892     REQUIRE(canvas->target(buffer, 100, 100, 100, SwCanvas::Colorspace::ABGR8888) == Result::Success);
893
894     //Fill
895     auto linearFill = LinearGradient::gen();
896     REQUIRE(linearFill);
897
898     auto radialFill = RadialGradient::gen();
899     REQUIRE(radialFill);
900
901     Fill::ColorStop cs[4] = {
902         {0.0f, 0, 0, 0, 0},
903         {0.2f, 50, 25, 50, 25},
904         {0.5f, 100, 100, 100, 125},
905         {1.0f, 255, 255, 255, 255}
906     };
907     REQUIRE(linearFill->colorStops(cs, 4) == Result::Success);
908     REQUIRE(radialFill->colorStops(cs, 4) == Result::Success);
909     REQUIRE(linearFill->linear(0.0f, 0.0f, 100.0f, 120.0f) == Result::Success);
910     REQUIRE(radialFill->radial(50.0f, 50.0f, 50.0f) == Result::Success);
911
912     //Mask
913     auto mask = tvg::Shape::gen();
914     REQUIRE(mask);
915     REQUIRE(mask->appendCircle(50, 50, 50, 50) == Result::Success);
916
917     //Filled Shapes
918     auto shape3 = tvg::Shape::gen();
919     REQUIRE(shape3);
920     auto shape4 = tvg::Shape::gen();
921     REQUIRE(shape4);
922     REQUIRE(shape3->appendRect(0, 0, 50, 50, 10, 10) == Result::Success);
923     REQUIRE(shape4->appendRect(50, 0, 50, 50, 10, 10) == Result::Success);
924
925     REQUIRE(shape3->fill(move(linearFill)) == Result::Success);
926     REQUIRE(shape4->fill(move(radialFill)) == Result::Success);
927
928     //Scene
929     auto scene = tvg::Scene::gen();
930     REQUIRE(scene);
931     REQUIRE(scene->push(move(shape3)) == Result::Success);
932     REQUIRE(scene->push(move(shape4)) == Result::Success);
933     REQUIRE(scene->composite(move(mask), tvg::CompositeMethod::ClipPath) == Result::Success);
934     REQUIRE(canvas->push(move(scene)) == Result::Success);
935
936     //Draw
937     REQUIRE(canvas->draw() == Result::Success);
938     REQUIRE(canvas->sync() == Result::Success);
939
940     REQUIRE(Initializer::term(CanvasEngine::Sw) == Result::Success);
941 }