1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 static const char* svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" stroke-linejoin=\"round\" viewBox=\"50 -100 500 500\"><path fill=\"none\" stroke=\"black\" stroke-width=\"10\" d=\"M 212,220 C 197,171 156,153 123,221 109,157 120,109 159,63.6 190,114 234,115 254,89.8 260,82.3 268,69.6 270,60.3 273,66.5 275,71.6 280,75.6 286,79.5 294,79.8 300,79.8 306,79.8 314,79.5 320,75.6 325,71.6 327,66.5 330,60.3 332,69.6 340,82.3 346,89.8 366,115 410,114 441,63.6 480,109 491,157 477,221 444,153 403,171 388,220 366,188 316,200 300,248 284,200 234,188 212,220 Z\"/></svg>";
10 void tvgDrawCmds(tvg::Canvas* canvas)
15 auto shape = tvg::Shape::gen();
16 shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry
17 shape->fill(255, 255, 255, 255); //r, g, b, a
19 if (canvas->push(move(shape)) != tvg::Result::Success) return;
21 auto picture = tvg::Picture::gen();
22 if (picture->load(svg, strlen(svg)) != tvg::Result::Success) return;
25 picture->viewbox(&x, &y, &w, &h);
27 float rate = (WIDTH/(w > h ? w : h));
37 y -= (WIDTH - h) * 0.5f;
39 x -= (WIDTH - w) * 0.5f;
42 picture->translate(-x, -y);
44 canvas->push(move(picture));
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, tvg::SwCanvas::ARGB8888);
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);
99 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
100 gl->glClear(GL_COLOR_BUFFER_BIT);
102 if (glCanvas->draw() == tvg::Result::Success) {
108 /************************************************************************/
110 /************************************************************************/
112 int main(int argc, char **argv)
114 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
117 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
120 //Initialize ThorVG Engine
121 if (tvgEngine == tvg::CanvasEngine::Sw) {
122 cout << "tvg engine: software" << endl;
124 cout << "tvg engine: opengl" << endl;
128 auto threads = std::thread::hardware_concurrency();
130 //Initialize ThorVG Engine
131 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
133 elm_init(argc, argv);
135 if (tvgEngine == tvg::CanvasEngine::Sw) {
144 //Terminate ThorVG Engine
145 tvg::Initializer::term(tvg::CanvasEngine::Sw);
148 cout << "engine is not supported" << endl;