Merge "SvgLoader: Supports Path's quadratic_to draw" into tizen
[platform/core/graphics/tizenvg.git] / test / testStroke.cpp
1 #include "testCommon.h"
2
3 /************************************************************************/
4 /* Drawing Commands                                                     */
5 /************************************************************************/
6
7 void tvgDrawCmds(tvg::Canvas* canvas)
8 {
9     //Shape 1
10     auto shape1 = tvg::Shape::gen();
11     shape1->appendRect(50, 50, 200, 200, 0);
12     shape1->fill(50, 50, 50, 255);
13     shape1->stroke(255, 255, 255, 255);       //color: r, g, b, a
14     shape1->stroke(tvg::StrokeJoin::Bevel);   //default is Bevel
15     shape1->stroke(10);                       //width: 10px
16
17     canvas->push(move(shape1));
18
19     //Shape 2
20     auto shape2 = tvg::Shape::gen();
21     shape2->appendRect(300, 50, 200, 200, 0);
22     shape2->fill(50, 50, 50, 255);
23     shape2->stroke(255, 255, 255, 255);
24     shape2->stroke(tvg::StrokeJoin::Round);
25     shape2->stroke(10);
26
27     canvas->push(move(shape2));
28
29     //Shape 3
30     auto shape3 = tvg::Shape::gen();
31     shape3->appendRect(550, 50, 200, 200, 0);
32     shape3->fill(50, 50, 50, 255);
33     shape3->stroke(255, 255, 255, 255);
34     shape3->stroke(tvg::StrokeJoin::Miter);
35     shape3->stroke(10);
36
37     canvas->push(move(shape3));
38
39     //Shape 4
40     auto shape4 = tvg::Shape::gen();
41     shape4->appendCircle(150, 450, 100, 100);
42     shape4->fill(50, 50, 50, 255);
43     shape4->stroke(255, 255, 255, 255);
44     shape4->stroke(1);
45
46     canvas->push(move(shape4));
47
48     //Shape 5
49     auto shape5 = tvg::Shape::gen();
50     shape5->appendCircle(400, 450, 100, 100);
51     shape5->fill(50, 50, 50, 255);
52     shape5->stroke(255, 255, 255, 255);
53     shape5->stroke(2);
54
55     canvas->push(move(shape5));
56
57     //Shape 6
58     auto shape6 = tvg::Shape::gen();
59     shape6->appendCircle(650, 450, 100, 100);
60     shape6->fill(50, 50, 50, 255);
61     shape6->stroke(255, 255, 255, 255);
62     shape6->stroke(4);
63
64     canvas->push(move(shape6));
65 }
66
67
68 /************************************************************************/
69 /* Sw Engine Test Code                                                  */
70 /************************************************************************/
71
72 static unique_ptr<tvg::SwCanvas> swCanvas;
73
74 void tvgSwTest(uint32_t* buffer)
75 {
76     //Create a Canvas
77     swCanvas = tvg::SwCanvas::gen();
78     swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
79
80     /* Push the shape into the Canvas drawing list
81        When this shape is into the canvas list, the shape could update & prepare
82        internal data asynchronously for coming rendering.
83        Canvas keeps this shape node unless user call canvas->clear() */
84     tvgDrawCmds(swCanvas.get());
85 }
86
87 void drawSwView(void* data, Eo* obj)
88 {
89     swCanvas->draw();
90     swCanvas->sync();
91 }
92
93
94 /************************************************************************/
95 /* GL Engine Test Code                                                  */
96 /************************************************************************/
97
98 static unique_ptr<tvg::GlCanvas> glCanvas;
99
100 void initGLview(Evas_Object *obj)
101 {
102     static constexpr auto BPP = 4;
103
104     //Create a Canvas
105     glCanvas = tvg::GlCanvas::gen();
106     glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
107
108     /* Push the shape into the Canvas drawing list
109        When this shape is into the canvas list, the shape could update & prepare
110        internal data asynchronously for coming rendering.
111        Canvas keeps this shape node unless user call canvas->clear() */
112     tvgDrawCmds(glCanvas.get());
113 }
114
115 void drawGLview(Evas_Object *obj)
116 {
117     auto gl = elm_glview_gl_api_get(obj);
118     int w, h;
119     elm_glview_size_get(obj, &w, &h);
120     gl->glViewport(0, 0, w, h);
121     gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
122     gl->glClear(GL_COLOR_BUFFER_BIT);
123     gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
124     gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
125     gl->glEnable(GL_BLEND);
126
127     glCanvas->draw();
128     glCanvas->sync();
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     //Initialize ThorVG Engine
152     tvg::Initializer::init(tvgEngine);
153
154     elm_init(argc, argv);
155
156     elm_config_accel_preference_set("gl");
157
158     if (tvgEngine == tvg::CanvasEngine::Sw) {
159         createSwView();
160     } else {
161         createGlView();
162     }
163
164     elm_run();
165     elm_shutdown();
166
167     //Terminate ThorVG Engine
168     tvg::Initializer::term(tvgEngine);
169 }