e2ed1c08e39f65bec120bf51a44abb831a444d35
[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     //Threads Count
124     auto threads = std::thread::hardware_concurrency();
125
126     //Initialize ThorVG Engine
127     if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
128
129         elm_init(argc, argv);
130
131         if (tvgEngine == tvg::CanvasEngine::Sw) {
132             createSwView();
133         } else {
134             createGlView();
135         }
136
137         elm_run();
138         elm_shutdown();
139
140         //Terminate ThorVG Engine
141         tvg::Initializer::term(tvgEngine);
142
143     } else {
144         cout << "engine is not supported" << endl;
145     }
146     return 0;
147 }