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