examples: move tests to src/examples
[platform/core/graphics/tizenvg.git] / src / examples / testArc.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     //Arc Line
12     auto shape1 = tvg::Shape::gen();
13     shape1->appendArc(150, 150, 80, 10, 180, false);
14     shape1->stroke(255, 255, 255, 255);
15     shape1->stroke(2);
16     if (canvas->push(move(shape1)) != tvg::Result::Success) return;
17
18     auto shape2 = tvg::Shape::gen();
19     shape2->appendArc(400, 150, 80, 0, 300, false);
20     shape2->stroke(255, 255, 255, 255);
21     shape2->stroke(2);
22     if (canvas->push(move(shape2)) != tvg::Result::Success) return;
23
24     auto shape3 = tvg::Shape::gen();
25     shape3->appendArc(600, 150, 80, 300, 60, false);
26     shape3->stroke(255, 255, 255, 255);
27     shape3->stroke(2);
28     if (canvas->push(move(shape3)) != tvg::Result::Success) return;
29
30     //Pie Line
31     auto shape4 = tvg::Shape::gen();
32     shape4->appendArc(150, 400, 80, 10, 180, true);
33     shape4->stroke(255, 255, 255, 255);
34     shape4->stroke(2);
35     if (canvas->push(move(shape4)) != tvg::Result::Success) return;
36
37     auto shape5 = tvg::Shape::gen();
38     shape5->appendArc(400, 400, 80, 0, 300, true);
39     shape5->stroke(255, 255, 255, 255);
40     shape5->stroke(2);
41     if (canvas->push(move(shape5)) != tvg::Result::Success) return;
42
43     auto shape6 = tvg::Shape::gen();
44     shape6->appendArc(600, 400, 80, 300, 60, true);
45     shape6->stroke(255, 255, 255, 255);
46     shape6->stroke(2);
47     if (canvas->push(move(shape6)) != tvg::Result::Success) return;
48
49     //Pie Fill
50     auto shape7 = tvg::Shape::gen();
51     shape7->appendArc(150, 650, 80, 10, 180, true);
52     shape7->fill(255, 255, 255, 255);
53     shape7->stroke(255, 0, 0, 255);
54     shape7->stroke(2);
55     if (canvas->push(move(shape7)) != tvg::Result::Success) return;
56
57     auto shape8 = tvg::Shape::gen();
58     shape8->appendArc(400, 650, 80, 0, 300, true);
59     shape8->fill(255, 255, 255, 255);
60     shape8->stroke(255, 0, 0, 255);
61     shape8->stroke(2);
62     if (canvas->push(move(shape8)) != tvg::Result::Success) return;
63
64     auto shape9 = tvg::Shape::gen();
65     shape9->appendArc(600, 650, 80, 300, 60, true);
66     shape9->fill(255, 255, 255, 255);
67     shape9->stroke(255, 0, 0, 255);
68     shape9->stroke(2);
69     if (canvas->push(move(shape9)) != tvg::Result::Success) return;
70 }
71
72 /************************************************************************/
73 /* Sw Engine Test Code                                                  */
74 /************************************************************************/
75
76 static unique_ptr<tvg::SwCanvas> swCanvas;
77
78 void tvgSwTest(uint32_t* buffer)
79 {
80     //Create a Canvas
81     swCanvas = tvg::SwCanvas::gen();
82     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
83
84     /* Push the shape into the Canvas drawing list
85        When this shape is into the canvas list, the shape could update & prepare
86        internal data asynchronously for coming rendering.
87        Canvas keeps this shape node unless user call canvas->clear() */
88     tvgDrawCmds(swCanvas.get());
89 }
90
91 void drawSwView(void* data, Eo* obj)
92 {
93     if (swCanvas->draw() == tvg::Result::Success) {
94         swCanvas->sync();
95     }
96 }
97
98
99 /************************************************************************/
100 /* GL Engine Test Code                                                  */
101 /************************************************************************/
102
103 static unique_ptr<tvg::GlCanvas> glCanvas;
104
105 void initGLview(Evas_Object *obj)
106 {
107     static constexpr auto BPP = 4;
108
109     //Create a Canvas
110     glCanvas = tvg::GlCanvas::gen();
111     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
112
113     /* Push the shape into the Canvas drawing list
114        When this shape is into the canvas list, the shape could update & prepare
115        internal data asynchronously for coming rendering.
116        Canvas keeps this shape node unless user call canvas->clear() */
117     tvgDrawCmds(glCanvas.get());
118 }
119
120 void drawGLview(Evas_Object *obj)
121 {
122     auto gl = elm_glview_gl_api_get(obj);
123     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
124     gl->glClear(GL_COLOR_BUFFER_BIT);
125
126     if (glCanvas->draw() == tvg::Result::Success) {
127         glCanvas->sync();
128     }
129 }
130
131
132 /************************************************************************/
133 /* Main Code                                                            */
134 /************************************************************************/
135
136 int main(int argc, char **argv)
137 {
138     tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
139
140     if (argc > 1) {
141         if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
142     }
143
144     //Initialize ThorVG Engine
145     if (tvgEngine == tvg::CanvasEngine::Sw) {
146         cout << "tvg engine: software" << endl;
147     } else {
148         cout << "tvg engine: opengl" << endl;
149     }
150
151     //Threads Count
152     auto threads = std::thread::hardware_concurrency();
153
154     //Initialize ThorVG Engine
155     if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
156
157         elm_init(argc, argv);
158
159         if (tvgEngine == tvg::CanvasEngine::Sw) {
160             createSwView();
161         } else {
162             createGlView();
163         }
164
165         elm_run();
166         elm_shutdown();
167
168         //Terminate ThorVG Engine
169         tvg::Initializer::term(tvgEngine);
170
171     } else {
172         cout << "engine is not supported" << endl;
173     }
174     return 0;
175 }