1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
10 auto shape1 = tvg::Shape::gen();
13 shape1->moveTo(199, 34);
14 shape1->lineTo(253, 143);
15 shape1->lineTo(374, 160);
16 shape1->lineTo(287, 244);
17 shape1->lineTo(307, 365);
18 shape1->lineTo(199, 309);
19 shape1->lineTo(97, 365);
20 shape1->lineTo(112, 245);
21 shape1->lineTo(26, 161);
22 shape1->lineTo(146, 143);
24 shape1->fill(0, 0, 255, 255);
25 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
29 auto shape2 = tvg::Shape::gen();
34 auto halfRadius = radius * 0.552284f;
37 shape2->moveTo(cx, cy - radius);
38 shape2->cubicTo(cx + halfRadius, cy - radius, cx + radius, cy - halfRadius, cx + radius, cy);
39 shape2->cubicTo(cx + radius, cy + halfRadius, cx + halfRadius, cy + radius, cx, cy+ radius);
40 shape2->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
41 shape2->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
43 shape2->fill(255, 0, 0, 255);
44 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
48 /************************************************************************/
49 /* Sw Engine Test Code */
50 /************************************************************************/
52 static unique_ptr<tvg::SwCanvas> swCanvas;
54 void tvgSwTest(uint32_t* buffer)
57 swCanvas = tvg::SwCanvas::gen();
58 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
60 /* Push the shape into the Canvas drawing list
61 When this shape is into the canvas list, the shape could update & prepare
62 internal data asynchronously for coming rendering.
63 Canvas keeps this shape node unless user call canvas->clear() */
64 tvgDrawCmds(swCanvas.get());
67 void drawSwView(void* data, Eo* obj)
69 if (swCanvas->draw() == tvg::Result::Success) {
75 /************************************************************************/
76 /* GL Engine Test Code */
77 /************************************************************************/
79 static unique_ptr<tvg::GlCanvas> glCanvas;
81 void initGLview(Evas_Object *obj)
83 static constexpr auto BPP = 4;
86 glCanvas = tvg::GlCanvas::gen();
87 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
89 /* Push the shape into the Canvas drawing list
90 When this shape is into the canvas list, the shape could update & prepare
91 internal data asynchronously for coming rendering.
92 Canvas keeps this shape node unless user call canvas->clear() */
93 tvgDrawCmds(glCanvas.get());
96 void drawGLview(Evas_Object *obj)
98 auto gl = elm_glview_gl_api_get(obj);
100 elm_glview_size_get(obj, &w, &h);
101 gl->glViewport(0, 0, w, h);
102 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
103 gl->glClear(GL_COLOR_BUFFER_BIT);
104 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
105 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
106 gl->glEnable(GL_BLEND);
108 if (glCanvas->draw() == tvg::Result::Success) {
114 /************************************************************************/
116 /************************************************************************/
118 int main(int argc, char **argv)
120 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
123 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
126 //Initialize ThorVG Engine
127 if (tvgEngine == tvg::CanvasEngine::Sw) {
128 cout << "tvg engine: software" << endl;
130 cout << "tvg engine: opengl" << endl;
133 //Initialize ThorVG Engine
134 tvg::Initializer::init(tvgEngine);
136 elm_init(argc, argv);
138 if (tvgEngine == tvg::CanvasEngine::Sw) {
147 //Terminate ThorVG Engine
148 tvg::Initializer::term(tvgEngine);