bindings/capi: fix c compatibility warnings.
[platform/core/graphics/tizenvg.git] / test / testPathCopy.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     /* Star */
12
13     //Prepare Path Commands
14     tvg::PathCommand cmds[11];
15     cmds[0] = tvg::PathCommand::MoveTo;
16     cmds[1] = tvg::PathCommand::LineTo;
17     cmds[2] = tvg::PathCommand::LineTo;
18     cmds[3] = tvg::PathCommand::LineTo;
19     cmds[4] = tvg::PathCommand::LineTo;
20     cmds[5] = tvg::PathCommand::LineTo;
21     cmds[6] = tvg::PathCommand::LineTo;
22     cmds[7] = tvg::PathCommand::LineTo;
23     cmds[8] = tvg::PathCommand::LineTo;
24     cmds[9] = tvg::PathCommand::LineTo;
25     cmds[10] = tvg::PathCommand::Close;
26
27     //Prepare Path Points
28     tvg::Point pts[10];
29     pts[0] = {199, 34};    //MoveTo
30     pts[1] = {253, 143};   //LineTo
31     pts[2] = {374, 160};   //LineTo
32     pts[3] = {287, 244};   //LineTo
33     pts[4] = {307, 365};   //LineTo
34     pts[5] = {199, 309};   //LineTo
35     pts[6] = {97, 365};    //LineTo
36     pts[7] = {112, 245};   //LineTo
37     pts[8] = {26, 161};    //LineTo
38     pts[9] = {146, 143};   //LineTo
39
40     auto shape1 = tvg::Shape::gen();
41     shape1->appendPath(cmds, 11, pts, 10);     //copy path data
42     shape1->fill(0, 255, 0, 255);
43     if (canvas->push(move(shape1)) != tvg::Result::Success) return;
44
45     /* Circle */
46     auto cx = 550.0f;
47     auto cy = 550.0f;
48     auto radius = 125.0f;
49     auto halfRadius = radius * 0.552284f;
50
51     //Prepare Path Commands
52     tvg::PathCommand cmds2[6];
53     cmds2[0] = tvg::PathCommand::MoveTo;
54     cmds2[1] = tvg::PathCommand::CubicTo;
55     cmds2[2] = tvg::PathCommand::CubicTo;
56     cmds2[3] = tvg::PathCommand::CubicTo;
57     cmds2[4] = tvg::PathCommand::CubicTo;
58     cmds2[5] = tvg::PathCommand::Close;
59
60     //Prepare Path Points
61     tvg::Point pts2[13];
62     pts2[0] = {cx, cy - radius};    //MoveTo
63     //CubicTo 1
64     pts2[1] = {cx + halfRadius, cy - radius};      //Ctrl1
65     pts2[2] = {cx + radius, cy - halfRadius};      //Ctrl2
66     pts2[3] = {cx + radius, cy};                   //To
67     //CubicTo 2
68     pts2[4] = {cx + radius, cy + halfRadius};      //Ctrl1
69     pts2[5] = {cx + halfRadius, cy + radius};      //Ctrl2
70     pts2[6] = {cx, cy+ radius};                    //To
71     //CubicTo 3
72     pts2[7] = {cx - halfRadius, cy + radius};      //Ctrl1
73     pts2[8] = {cx - radius, cy + halfRadius};      //Ctrl2
74     pts2[9] = {cx - radius, cy};                   //To
75     //CubicTo 4
76     pts2[10] = {cx - radius, cy - halfRadius};     //Ctrl1
77     pts2[11] = {cx - halfRadius, cy - radius};     //Ctrl2
78     pts2[12] = {cx, cy - radius};                  //To
79
80     auto shape2 = tvg::Shape::gen();
81     shape2->appendPath(cmds2, 6, pts2, 13);     //copy path data
82     shape2->fill(255, 255, 0, 255);
83     if (canvas->push(move(shape2)) != tvg::Result::Success) return;
84
85 }
86
87 /************************************************************************/
88 /* Sw Engine Test Code                                                  */
89 /************************************************************************/
90
91 static unique_ptr<tvg::SwCanvas> swCanvas;
92
93 void tvgSwTest(uint32_t* buffer)
94 {
95     //Create a Canvas
96     swCanvas = tvg::SwCanvas::gen();
97     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
98
99     /* Push the shape into the Canvas drawing list
100        When this shape is into the canvas list, the shape could update & prepare
101        internal data asynchronously for coming rendering.
102        Canvas keeps this shape node unless user call canvas->clear() */
103     tvgDrawCmds(swCanvas.get());
104 }
105
106 void drawSwView(void* data, Eo* obj)
107 {
108     if (swCanvas->draw() == tvg::Result::Success) {
109         swCanvas->sync();
110     }
111 }
112
113
114 /************************************************************************/
115 /* GL Engine Test Code                                                  */
116 /************************************************************************/
117
118 static unique_ptr<tvg::GlCanvas> glCanvas;
119
120 void initGLview(Evas_Object *obj)
121 {
122     static constexpr auto BPP = 4;
123
124     //Create a Canvas
125     glCanvas = tvg::GlCanvas::gen();
126     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
127
128     /* Push the shape into the Canvas drawing list
129        When this shape is into the canvas list, the shape could update & prepare
130        internal data asynchronously for coming rendering.
131        Canvas keeps this shape node unless user call canvas->clear() */
132     tvgDrawCmds(glCanvas.get());
133 }
134
135 void drawGLview(Evas_Object *obj)
136 {
137     auto gl = elm_glview_gl_api_get(obj);
138     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
139     gl->glClear(GL_COLOR_BUFFER_BIT);
140
141     if (glCanvas->draw() == tvg::Result::Success) {
142         glCanvas->sync();
143     }
144 }
145
146
147 /************************************************************************/
148 /* Main Code                                                            */
149 /************************************************************************/
150
151 int main(int argc, char **argv)
152 {
153     tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
154
155     if (argc > 1) {
156         if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
157     }
158
159     //Initialize ThorVG Engine
160     if (tvgEngine == tvg::CanvasEngine::Sw) {
161         cout << "tvg engine: software" << endl;
162     } else {
163         cout << "tvg engine: opengl" << endl;
164     }
165
166     //Threads Count
167     auto threads = std::thread::hardware_concurrency();
168
169     //Initialize ThorVG Engine
170     if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
171
172         elm_init(argc, argv);
173
174         if (tvgEngine == tvg::CanvasEngine::Sw) {
175             createSwView();
176         } else {
177             createGlView();
178         }
179
180         elm_run();
181         elm_shutdown();
182
183         //Terminate ThorVG Engine
184         tvg::Initializer::term(tvgEngine);
185
186     } else {
187         cout << "engine is not supported" << endl;
188     }
189     return 0;
190 }