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