383068778e8df98a643448907783af61b47f7613
[platform/core/graphics/tizenvg.git] / test / testBoundary.cpp
1 #include "testCommon.h"
2
3 /************************************************************************/
4 /* Drawing Commands                                                     */
5 /************************************************************************/
6
7 void tvgDrawCmds(tvg::Canvas* canvas)
8 {
9     if (!canvas) return;
10
11     canvas->reserve(5);             //reserve 5 shape nodes (optional)
12
13     //Prepare Shape1
14     auto shape1 = tvg::Shape::gen();
15     shape1->appendRect(-100, -100, 1000, 1000, 50, 50);
16     shape1->fill(255, 255, 255, 255);
17     if (canvas->push(move(shape1)) != tvg::Result::Success) return;
18
19     //Prepare Shape2
20     auto shape2 = tvg::Shape::gen();
21     shape2->appendRect(-100, -100, 250, 250, 50, 50);
22     shape2->fill(0, 0, 255, 255);
23     if (canvas->push(move(shape2)) != tvg::Result::Success) return;
24
25     //Prepare Shape3
26     auto shape3 = tvg::Shape::gen();
27     shape3->appendRect(500, 500, 550, 550, 0, 0);
28     shape3->fill(0, 255, 255, 255);
29     if (canvas->push(move(shape3)) != tvg::Result::Success) return;
30
31     //Prepare Shape4
32     auto shape4 = tvg::Shape::gen();
33     shape4->appendCircle(800, 100, 200, 200);
34     shape4->fill(255, 255, 0, 255);
35     if (canvas->push(move(shape4)) != tvg::Result::Success) return;
36
37     //Prepare Shape5
38     auto shape5 = tvg::Shape::gen();
39     shape5->appendCircle(200, 650, 250, 200);
40     shape5->fill(0, 0, 0, 255);
41     if (canvas->push(move(shape5)) != tvg::Result::Success) return;
42 }
43
44 /************************************************************************/
45 /* Sw Engine Test Code                                                  */
46 /************************************************************************/
47
48 static unique_ptr<tvg::SwCanvas> swCanvas;
49
50 void tvgSwTest(uint32_t* buffer)
51 {
52     //Create a Canvas
53     swCanvas = tvg::SwCanvas::gen();
54     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
55
56     /* Push the shape into the Canvas drawing list
57        When this shape is into the canvas list, the shape could update & prepare
58        internal data asynchronously for coming rendering.
59        Canvas keeps this shape node unless user call canvas->clear() */
60     tvgDrawCmds(swCanvas.get());
61 }
62
63 void drawSwView(void* data, Eo* obj)
64 {
65     if (swCanvas->draw() == tvg::Result::Success) {
66         swCanvas->sync();
67     }
68 }
69
70
71 /************************************************************************/
72 /* GL Engine Test Code                                                  */
73 /************************************************************************/
74
75 static unique_ptr<tvg::GlCanvas> glCanvas;
76
77 void initGLview(Evas_Object *obj)
78 {
79     static constexpr auto BPP = 4;
80
81     //Create a Canvas
82     glCanvas = tvg::GlCanvas::gen();
83     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
84
85     /* Push the shape into the Canvas drawing list
86        When this shape is into the canvas list, the shape could update & prepare
87        internal data asynchronously for coming rendering.
88        Canvas keeps this shape node unless user call canvas->clear() */
89     tvgDrawCmds(glCanvas.get());
90 }
91
92 void drawGLview(Evas_Object *obj)
93 {
94     auto gl = elm_glview_gl_api_get(obj);
95     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
96     gl->glClear(GL_COLOR_BUFFER_BIT);
97
98     if (glCanvas->draw() == tvg::Result::Success) {
99         glCanvas->sync();
100     }
101 }
102
103
104 /************************************************************************/
105 /* Main Code                                                            */
106 /************************************************************************/
107
108 int main(int argc, char **argv)
109 {
110     tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
111
112     if (argc > 1) {
113         if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
114     }
115
116     //Initialize ThorVG Engine
117     if (tvgEngine == tvg::CanvasEngine::Sw) {
118         cout << "tvg engine: software" << endl;
119     } else {
120         cout << "tvg engine: opengl" << endl;
121     }
122
123     //Initialize ThorVG Engine
124     if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
125
126         elm_init(argc, argv);
127
128         if (tvgEngine == tvg::CanvasEngine::Sw) {
129             createSwView();
130         } else {
131             createGlView();
132         }
133
134         elm_run();
135         elm_shutdown();
136
137         //Terminate ThorVG Engine
138         tvg::Initializer::term(tvgEngine);
139
140     } else {
141         cout << "engine is not supported" << endl;
142     }
143     return 0;
144 }