1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
12 void svgDirCallback(const char* name, const char* path, void* data)
14 tvg::Canvas* canvas = static_cast<tvg::Canvas*>(data);
16 auto picture = tvg::Picture::gen();
19 sprintf(buf,"%s/%s", path, name);
21 if (picture->load(buf) != tvg::Result::Success) return;
24 picture->viewbox(&x, &y, &w, &h);
26 float rate = (SIZE/(w > h ? w : h));
36 y -= (SIZE - h) * 0.5f;
38 x -= (SIZE - w) * 0.5f;
41 picture->translate((count % NUM_PER_LINE) * SIZE - x, SIZE * (count / NUM_PER_LINE) - y);
43 canvas->push(move(picture));
45 cout << "SVG: " << buf << endl;
50 void tvgDrawCmds(tvg::Canvas* canvas)
55 auto shape = tvg::Shape::gen();
56 shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry
57 shape->fill(255, 255, 255, 255); //r, g, b, a
59 if (canvas->push(move(shape)) != tvg::Result::Success) return;
61 eina_file_dir_list("./svgs", EINA_TRUE, svgDirCallback, canvas);
65 /************************************************************************/
66 /* Sw Engine Test Code */
67 /************************************************************************/
69 static unique_ptr<tvg::SwCanvas> swCanvas;
71 void tvgSwTest(uint32_t* buffer)
74 swCanvas = tvg::SwCanvas::gen();
75 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
77 /* Push the shape into the Canvas drawing list
78 When this shape is into the canvas list, the shape could update & prepare
79 internal data asynchronously for coming rendering.
80 Canvas keeps this shape node unless user call canvas->clear() */
81 tvgDrawCmds(swCanvas.get());
84 void drawSwView(void* data, Eo* obj)
86 if (swCanvas->draw() == tvg::Result::Success) {
92 /************************************************************************/
93 /* GL Engine Test Code */
94 /************************************************************************/
96 static unique_ptr<tvg::GlCanvas> glCanvas;
98 void initGLview(Evas_Object *obj)
100 static constexpr auto BPP = 4;
103 glCanvas = tvg::GlCanvas::gen();
104 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
106 /* Push the shape into the Canvas drawing list
107 When this shape is into the canvas list, the shape could update & prepare
108 internal data asynchronously for coming rendering.
109 Canvas keeps this shape node unless user call canvas->clear() */
110 tvgDrawCmds(glCanvas.get());
113 void drawGLview(Evas_Object *obj)
115 auto gl = elm_glview_gl_api_get(obj);
116 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
117 gl->glClear(GL_COLOR_BUFFER_BIT);
119 if (glCanvas->draw() == tvg::Result::Success) {
125 /************************************************************************/
127 /************************************************************************/
129 int main(int argc, char **argv)
131 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
134 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
137 //Initialize ThorVG Engine
138 if (tvgEngine == tvg::CanvasEngine::Sw) {
139 cout << "tvg engine: software" << endl;
141 cout << "tvg engine: opengl" << endl;
145 auto threads = std::thread::hardware_concurrency();
147 //Initialize ThorVG Engine
148 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
150 elm_init(argc, argv);
152 if (tvgEngine == tvg::CanvasEngine::Sw) {
161 //Terminate ThorVG Engine
162 tvg::Initializer::term(tvg::CanvasEngine::Sw);
165 cout << "engine is not supported" << endl;