1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
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;
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
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;
49 auto halfRadius = radius * 0.552284f;
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;
62 pts2[0] = {cx, cy - radius}; //MoveTo
64 pts2[1] = {cx + halfRadius, cy - radius}; //Ctrl1
65 pts2[2] = {cx + radius, cy - halfRadius}; //Ctrl2
66 pts2[3] = {cx + radius, cy}; //To
68 pts2[4] = {cx + radius, cy + halfRadius}; //Ctrl1
69 pts2[5] = {cx + halfRadius, cy + radius}; //Ctrl2
70 pts2[6] = {cx, cy+ radius}; //To
72 pts2[7] = {cx - halfRadius, cy + radius}; //Ctrl1
73 pts2[8] = {cx - radius, cy + halfRadius}; //Ctrl2
74 pts2[9] = {cx - radius, cy}; //To
76 pts2[10] = {cx - radius, cy - halfRadius}; //Ctrl1
77 pts2[11] = {cx - halfRadius, cy - radius}; //Ctrl2
78 pts2[12] = {cx, cy - radius}; //To
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;
87 /************************************************************************/
88 /* Sw Engine Test Code */
89 /************************************************************************/
91 static unique_ptr<tvg::SwCanvas> swCanvas;
93 void tvgSwTest(uint32_t* buffer)
96 swCanvas = tvg::SwCanvas::gen();
97 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
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());
106 void drawSwView(void* data, Eo* obj)
108 if (swCanvas->draw() == tvg::Result::Success) {
114 /************************************************************************/
115 /* GL Engine Test Code */
116 /************************************************************************/
118 static unique_ptr<tvg::GlCanvas> glCanvas;
120 void initGLview(Evas_Object *obj)
122 static constexpr auto BPP = 4;
125 glCanvas = tvg::GlCanvas::gen();
126 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
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());
135 void drawGLview(Evas_Object *obj)
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);
141 if (glCanvas->draw() == tvg::Result::Success) {
147 /************************************************************************/
149 /************************************************************************/
151 int main(int argc, char **argv)
153 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
156 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
159 //Initialize ThorVG Engine
160 if (tvgEngine == tvg::CanvasEngine::Sw) {
161 cout << "tvg engine: software" << endl;
163 cout << "tvg engine: opengl" << endl;
166 //Initialize ThorVG Engine
167 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
169 elm_init(argc, argv);
171 if (tvgEngine == tvg::CanvasEngine::Sw) {
180 //Terminate ThorVG Engine
181 tvg::Initializer::term(tvgEngine);
184 cout << "engine is not supported" << endl;