1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
12 auto scene = tvg::Scene::gen();
13 scene->reserve(3); //reserve 3 shape nodes (optional)
15 //Prepare Round Rectangle
16 auto shape1 = tvg::Shape::gen();
17 shape1->appendRect(0, 0, 400, 400, 50, 50); //x, y, w, h, rx, ry
18 shape1->fill(0, 255, 0, 255); //r, g, b, a
19 scene->push(move(shape1));
22 auto shape2 = tvg::Shape::gen();
23 shape2->appendCircle(400, 400, 200, 200); //cx, cy, radiusW, radiusH
24 shape2->fill(255, 255, 0, 255); //r, g, b, a
25 scene->push(move(shape2));
28 auto shape3 = tvg::Shape::gen();
29 shape3->appendCircle(600, 600, 150, 100); //cx, cy, radiusW, radiusH
30 shape3->fill(0, 255, 255, 255); //r, g, b, a
31 scene->push(move(shape3));
33 //Create another Scene
34 auto scene2 = tvg::Scene::gen();
35 scene2->reserve(2); //reserve 2 shape nodes (optional)
38 auto shape4 = tvg::Shape::gen();
41 shape4->moveTo(199, 34);
42 shape4->lineTo(253, 143);
43 shape4->lineTo(374, 160);
44 shape4->lineTo(287, 244);
45 shape4->lineTo(307, 365);
46 shape4->lineTo(199, 309);
47 shape4->lineTo(97, 365);
48 shape4->lineTo(112, 245);
49 shape4->lineTo(26, 161);
50 shape4->lineTo(146, 143);
52 shape4->fill(0, 0, 255, 255);
53 scene2->push(move(shape4));
56 auto shape5 = tvg::Shape::gen();
61 auto halfRadius = radius * 0.552284f;
64 shape5->moveTo(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->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
68 shape5->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
69 shape5->fill(255, 0, 0, 255);
70 scene2->push(move(shape5));
72 //Push scene2 onto the scene
73 scene->push(move(scene2));
75 //Draw the Scene onto the Canvas
76 canvas->push(move(scene));
80 /************************************************************************/
81 /* Sw Engine Test Code */
82 /************************************************************************/
84 static unique_ptr<tvg::SwCanvas> swCanvas;
86 void tvgSwTest(uint32_t* buffer)
89 swCanvas = tvg::SwCanvas::gen();
90 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
92 /* Push the shape into the Canvas drawing list
93 When this shape is into the canvas list, the shape could update & prepare
94 internal data asynchronously for coming rendering.
95 Canvas keeps this shape node unless user call canvas->clear() */
96 tvgDrawCmds(swCanvas.get());
99 void drawSwView(void* data, Eo* obj)
101 if (swCanvas->draw() == tvg::Result::Success) {
107 /************************************************************************/
108 /* GL Engine Test Code */
109 /************************************************************************/
111 static unique_ptr<tvg::GlCanvas> glCanvas;
113 void initGLview(Evas_Object *obj)
115 static constexpr auto BPP = 4;
118 glCanvas = tvg::GlCanvas::gen();
119 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
121 /* Push the shape into the Canvas drawing list
122 When this shape is into the canvas list, the shape could update & prepare
123 internal data asynchronously for coming rendering.
124 Canvas keeps this shape node unless user call canvas->clear() */
125 tvgDrawCmds(glCanvas.get());
128 void drawGLview(Evas_Object *obj)
130 auto gl = elm_glview_gl_api_get(obj);
131 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
132 gl->glClear(GL_COLOR_BUFFER_BIT);
134 if (glCanvas->draw() == tvg::Result::Success) {
140 /************************************************************************/
142 /************************************************************************/
144 int main(int argc, char **argv)
146 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
149 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
152 //Initialize ThorVG Engine
153 if (tvgEngine == tvg::CanvasEngine::Sw) {
154 cout << "tvg engine: software" << endl;
156 cout << "tvg engine: opengl" << endl;
160 auto threads = std::thread::hardware_concurrency();
162 //Initialize ThorVG Engine
163 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
166 elm_init(argc, argv);
168 if (tvgEngine == tvg::CanvasEngine::Sw) {
177 //Terminate ThorVG Engine
178 tvg::Initializer::term(tvgEngine);
181 cout << "engine is not supported" << endl;