1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
11 canvas->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, 50); //x, y, w, h, rx, ry
16 shape1->fill(0, 255, 0, 255); //r, g, b, a
17 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
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 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
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 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
33 /************************************************************************/
34 /* Sw Engine Test Code */
35 /************************************************************************/
37 static unique_ptr<tvg::SwCanvas> swCanvas;
39 void tvgSwTest(uint32_t* buffer)
42 swCanvas = tvg::SwCanvas::gen();
43 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
45 /* Push the shape into the Canvas drawing list
46 When this shape is into the canvas list, the shape could update & prepare
47 internal data asynchronously for coming rendering.
48 Canvas keeps this shape node unless user call canvas->clear() */
49 tvgDrawCmds(swCanvas.get());
52 void drawSwView(void* data, Eo* obj)
54 if (swCanvas->draw() == tvg::Result::Success) {
60 /************************************************************************/
61 /* GL Engine Test Code */
62 /************************************************************************/
64 static unique_ptr<tvg::GlCanvas> glCanvas;
66 void initGLview(Evas_Object *obj)
68 static constexpr auto BPP = 4;
71 glCanvas = tvg::GlCanvas::gen();
72 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
74 /* Push the shape into the Canvas drawing list
75 When this shape is into the canvas list, the shape could update & prepare
76 internal data asynchronously for coming rendering.
77 Canvas keeps this shape node unless user call canvas->clear() */
78 tvgDrawCmds(glCanvas.get());
81 void drawGLview(Evas_Object *obj)
83 auto gl = elm_glview_gl_api_get(obj);
84 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
85 gl->glClear(GL_COLOR_BUFFER_BIT);
87 if (glCanvas->draw() == tvg::Result::Success) {
93 /************************************************************************/
95 /************************************************************************/
97 int main(int argc, char **argv)
99 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
102 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
105 //Initialize ThorVG Engine
106 if (tvgEngine == tvg::CanvasEngine::Sw) {
107 cout << "tvg engine: software" << endl;
109 cout << "tvg engine: opengl" << endl;
112 //Initialize ThorVG Engine
113 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
115 elm_init(argc, argv);
117 if (tvgEngine == tvg::CanvasEngine::Sw) {
126 //Terminate ThorVG Engine
127 tvg::Initializer::term(tvgEngine);
130 cout << "engine is not supported" << endl;