1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
10 auto scene = tvg::Scene::gen();
11 scene->reserve(3); //reserve 3 shape nodes (optional)
13 //Prepare Round Rectangle
14 auto shape1 = tvg::Shape::gen();
15 shape1->appendRect(0, 0, 400, 400, 50); //x, y, w, h, cornerRadius
16 shape1->fill(0, 255, 0, 255); //r, g, b, a
17 scene->push(move(shape1));
20 auto shape2 = tvg::Shape::gen();
21 shape2->appendCircle(400, 400, 200, 200); //cx, cy, radiusW, radiusH
22 shape2->fill(255, 255, 0, 255); //r, g, b, a
23 scene->push(move(shape2));
26 auto shape3 = tvg::Shape::gen();
27 shape3->appendCircle(600, 600, 150, 100); //cx, cy, radiusW, radiusH
28 shape3->fill(0, 255, 255, 255); //r, g, b, a
29 scene->push(move(shape3));
31 //Create another Scene
32 auto scene2 = tvg::Scene::gen();
33 scene2->reserve(2); //reserve 2 shape nodes (optional)
36 auto shape4 = tvg::Shape::gen();
39 shape4->moveTo(199, 34);
40 shape4->lineTo(253, 143);
41 shape4->lineTo(374, 160);
42 shape4->lineTo(287, 244);
43 shape4->lineTo(307, 365);
44 shape4->lineTo(199, 309);
45 shape4->lineTo(97, 365);
46 shape4->lineTo(112, 245);
47 shape4->lineTo(26, 161);
48 shape4->lineTo(146, 143);
50 shape4->fill(0, 0, 255, 255);
51 scene2->push(move(shape4));
54 auto shape5 = tvg::Shape::gen();
59 auto halfRadius = radius * 0.552284f;
62 shape5->moveTo(cx, cy - radius);
63 shape5->cubicTo(cx + halfRadius, cy - radius, cx + radius, cy - halfRadius, cx + radius, cy);
64 shape5->cubicTo(cx + radius, cy + halfRadius, cx + halfRadius, cy + radius, cx, cy+ radius);
65 shape5->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
66 shape5->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
67 shape5->fill(255, 0, 0, 255);
68 scene2->push(move(shape5));
70 //Push scene2 onto the scene
71 scene->push(move(scene2));
73 //Draw the Scene onto the Canvas
74 canvas->push(move(scene));
78 /************************************************************************/
79 /* Sw Engine Test Code */
80 /************************************************************************/
82 static unique_ptr<tvg::SwCanvas> swCanvas;
84 void tvgSwTest(uint32_t* buffer)
87 swCanvas = tvg::SwCanvas::gen();
88 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
90 /* Push the shape into the Canvas drawing list
91 When this shape is into the canvas list, the shape could update & prepare
92 internal data asynchronously for coming rendering.
93 Canvas keeps this shape node unless user call canvas->clear() */
94 tvgDrawCmds(swCanvas.get());
97 void drawSwView(void* data, Eo* obj)
99 if (swCanvas->draw() == tvg::Result::Success) {
105 /************************************************************************/
106 /* GL Engine Test Code */
107 /************************************************************************/
109 static unique_ptr<tvg::GlCanvas> glCanvas;
111 void initGLview(Evas_Object *obj)
113 static constexpr auto BPP = 4;
116 glCanvas = tvg::GlCanvas::gen();
117 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
119 /* Push the shape into the Canvas drawing list
120 When this shape is into the canvas list, the shape could update & prepare
121 internal data asynchronously for coming rendering.
122 Canvas keeps this shape node unless user call canvas->clear() */
123 tvgDrawCmds(glCanvas.get());
126 void drawGLview(Evas_Object *obj)
128 auto gl = elm_glview_gl_api_get(obj);
130 elm_glview_size_get(obj, &w, &h);
131 gl->glViewport(0, 0, w, h);
132 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
133 gl->glClear(GL_COLOR_BUFFER_BIT);
134 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
135 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
136 gl->glEnable(GL_BLEND);
138 if (glCanvas->draw() == tvg::Result::Success) {
144 /************************************************************************/
146 /************************************************************************/
148 int main(int argc, char **argv)
150 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
153 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
156 //Initialize ThorVG Engine
157 if (tvgEngine == tvg::CanvasEngine::Sw) {
158 cout << "tvg engine: software" << endl;
160 cout << "tvg engine: opengl" << endl;
163 //Initialize ThorVG Engine
164 tvg::Initializer::init(tvgEngine);
166 elm_init(argc, argv);
168 if (tvgEngine == tvg::CanvasEngine::Sw) {
177 //Terminate ThorVG Engine
178 tvg::Initializer::term(tvgEngine);