Merge "SvgLoader: Supports Path's quadratic_to draw" into tizen
[platform/core/graphics/tizenvg.git] / test / testShape.cpp
1 #include "testCommon.h"
2
3 /************************************************************************/
4 /* Drawing Commands                                                     */
5 /************************************************************************/
6
7 void tvgDrawCmds(tvg::Canvas* canvas)
8 {
9     //Prepare a Shape (Rectangle + Rectangle + Circle + Circle)
10     auto shape1 = tvg::Shape::gen();
11     shape1->appendRect(0, 0, 200, 200, 0);          //x, y, w, h, cornerRadius
12     shape1->appendRect(100, 100, 300, 300, 100);    //x, y, w, h, cornerRadius
13     shape1->appendCircle(400, 400, 100, 100);       //cx, cy, radiusW, radiusH
14     shape1->appendCircle(400, 500, 170, 100);       //cx, cy, radiusW, radiusH
15     shape1->fill(255, 255, 0, 255);                 //r, g, b, a
16
17     canvas->push(move(shape1));
18 }
19
20
21 /************************************************************************/
22 /* Sw Engine Test Code                                                  */
23 /************************************************************************/
24
25 static unique_ptr<tvg::SwCanvas> swCanvas;
26
27 void tvgSwTest(uint32_t* buffer)
28 {
29     //Create a Canvas
30     swCanvas = tvg::SwCanvas::gen();
31     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
32
33     /* Push the shape into the Canvas drawing list
34        When this shape is into the canvas list, the shape could update & prepare
35        internal data asynchronously for coming rendering.
36        Canvas keeps this shape node unless user call canvas->clear() */
37     tvgDrawCmds(swCanvas.get());
38 }
39
40 void drawSwView(void* data, Eo* obj)
41 {
42     swCanvas->draw();
43     swCanvas->sync();
44 }
45
46
47 /************************************************************************/
48 /* GL Engine Test Code                                                  */
49 /************************************************************************/
50
51 static unique_ptr<tvg::GlCanvas> glCanvas;
52
53 void initGLview(Evas_Object *obj)
54 {
55     static constexpr auto BPP = 4;
56
57     //Create a Canvas
58     glCanvas = tvg::GlCanvas::gen();
59     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
60
61     /* Push the shape into the Canvas drawing list
62        When this shape is into the canvas list, the shape could update & prepare
63        internal data asynchronously for coming rendering.
64        Canvas keeps this shape node unless user call canvas->clear() */
65     tvgDrawCmds(glCanvas.get());
66 }
67
68 void drawGLview(Evas_Object *obj)
69 {
70     auto gl = elm_glview_gl_api_get(obj);
71     int w, h;
72     elm_glview_size_get(obj, &w, &h);
73     gl->glViewport(0, 0, w, h);
74     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
75     gl->glClear(GL_COLOR_BUFFER_BIT);
76     gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
77     gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
78     gl->glEnable(GL_BLEND);
79
80     glCanvas->draw();
81     glCanvas->sync();
82 }
83
84
85 /************************************************************************/
86 /* Main Code                                                            */
87 /************************************************************************/
88
89 int main(int argc, char **argv)
90 {
91     tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
92
93     if (argc > 1) {
94         if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
95     }
96
97     //Initialize ThorVG Engine
98     if (tvgEngine == tvg::CanvasEngine::Sw) {
99         cout << "tvg engine: software" << endl;
100     } else {
101         cout << "tvg engine: opengl" << endl;
102     }
103
104     //Initialize ThorVG Engine
105     tvg::Initializer::init(tvgEngine);
106
107     elm_init(argc, argv);
108
109     elm_config_accel_preference_set("gl");
110
111     if (tvgEngine == tvg::CanvasEngine::Sw) {
112         createSwView();
113     } else {
114         createGlView();
115     }
116
117     elm_run();
118     elm_shutdown();
119
120     //Terminate ThorVG Engine
121     tvg::Initializer::term(tvgEngine);
122 }