1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
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, 170); //r, g, b, a
23 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
26 auto shape3 = tvg::Shape::gen();
27 shape3->appendCircle(400, 400, 250, 100); //cx, cy, radiusW, radiusH
28 shape3->fill(255, 255, 255, 100); //r, g, b, a
29 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
32 auto shape4 = tvg::Shape::gen();
33 shape4->moveTo(199, 234);
34 shape4->lineTo(253, 343);
35 shape4->lineTo(374, 360);
36 shape4->lineTo(287, 444);
37 shape4->lineTo(307, 565);
38 shape4->lineTo(199, 509);
39 shape4->lineTo(97, 565);
40 shape4->lineTo(112, 445);
41 shape4->lineTo(26, 361);
42 shape4->lineTo(146, 343);
44 shape4->fill(255, 0, 200, 200);
45 if (canvas->push(move(shape4)) != tvg::Result::Success) return;
47 //Prepare Opaque Ellipse
48 auto shape5 = tvg::Shape::gen();
49 shape5->appendCircle(600, 650, 200, 150);
50 shape5->fill(0, 0, 255, 255);
51 if (canvas->push(move(shape5)) != tvg::Result::Success) return;
55 /************************************************************************/
56 /* Sw Engine Test Code */
57 /************************************************************************/
59 static unique_ptr<tvg::SwCanvas> swCanvas;
61 void tvgSwTest(uint32_t* buffer)
64 swCanvas = tvg::SwCanvas::gen();
65 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
67 /* Push the shape into the Canvas drawing list
68 When this shape is into the canvas list, the shape could update & prepare
69 internal data asynchronously for coming rendering.
70 Canvas keeps this shape node unless user call canvas->clear() */
71 tvgDrawCmds(swCanvas.get());
74 void drawSwView(void* data, Eo* obj)
76 if (swCanvas->draw() == tvg::Result::Success) {
82 /************************************************************************/
83 /* GL Engine Test Code */
84 /************************************************************************/
86 static unique_ptr<tvg::GlCanvas> glCanvas;
88 void initGLview(Evas_Object *obj)
90 static constexpr auto BPP = 4;
93 glCanvas = tvg::GlCanvas::gen();
94 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
96 /* Push the shape into the Canvas drawing list
97 When this shape is into the canvas list, the shape could update & prepare
98 internal data asynchronously for coming rendering.
99 Canvas keeps this shape node unless user call canvas->clear() */
100 tvgDrawCmds(glCanvas.get());
103 void drawGLview(Evas_Object *obj)
105 auto gl = elm_glview_gl_api_get(obj);
106 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
107 gl->glClear(GL_COLOR_BUFFER_BIT);
109 if (glCanvas->draw() == tvg::Result::Success) {
115 /************************************************************************/
117 /************************************************************************/
119 int main(int argc, char **argv)
121 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
124 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
127 //Initialize ThorVG Engine
128 if (tvgEngine == tvg::CanvasEngine::Sw) {
129 cout << "tvg engine: software" << endl;
131 cout << "tvg engine: opengl" << endl;
134 //Initialize ThorVG Engine
135 if (tvg::Initializer::init(tvgEngine) == tvg::Result::Success) {
137 elm_init(argc, argv);
139 if (tvgEngine == tvg::CanvasEngine::Sw) {
148 //Terminate ThorVG Engine
149 tvg::Initializer::term(tvgEngine);
152 cout << "engine is not supported" << endl;