1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
13 void svgDirCallback(const char* name, const char* path, void* data)
15 tvg::Canvas* canvas = static_cast<tvg::Canvas*>(data);
17 auto scene = tvg::Scene::gen();
20 sprintf(buf,"%s/%s", path, name);
22 if (scene->load(buf) != tvg::Result::Success) return;
24 scene->translate(((WIDTH - (x * 2)) / NUM_PER_LINE) * (count % NUM_PER_LINE) + x, ((HEIGHT - (y * 2))/ NUM_PER_LINE) * (int)((float)count / (float)NUM_PER_LINE) + y);
25 canvas->push(move(scene));
29 cout << "SVG: " << buf << endl;
32 void tvgDrawCmds(tvg::Canvas* canvas)
35 auto shape = tvg::Shape::gen();
36 shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry
37 shape->fill(255, 255, 255, 255); //r, g, b, a
39 if (canvas->push(move(shape)) != tvg::Result::Success) return;
41 eina_file_dir_list("./svgs", EINA_TRUE, svgDirCallback, canvas);
45 /************************************************************************/
46 /* Sw Engine Test Code */
47 /************************************************************************/
49 static unique_ptr<tvg::SwCanvas> swCanvas;
51 void tvgSwTest(uint32_t* buffer)
54 swCanvas = tvg::SwCanvas::gen();
55 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
57 /* Push the shape into the Canvas drawing list
58 When this shape is into the canvas list, the shape could update & prepare
59 internal data asynchronously for coming rendering.
60 Canvas keeps this shape node unless user call canvas->clear() */
61 tvgDrawCmds(swCanvas.get());
64 void drawSwView(void* data, Eo* obj)
66 if (swCanvas->draw() == tvg::Result::Success) {
72 /************************************************************************/
73 /* GL Engine Test Code */
74 /************************************************************************/
76 static unique_ptr<tvg::GlCanvas> glCanvas;
78 void initGLview(Evas_Object *obj)
80 static constexpr auto BPP = 4;
83 glCanvas = tvg::GlCanvas::gen();
84 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
86 /* Push the shape into the Canvas drawing list
87 When this shape is into the canvas list, the shape could update & prepare
88 internal data asynchronously for coming rendering.
89 Canvas keeps this shape node unless user call canvas->clear() */
90 tvgDrawCmds(glCanvas.get());
93 void drawGLview(Evas_Object *obj)
95 auto gl = elm_glview_gl_api_get(obj);
97 elm_glview_size_get(obj, &w, &h);
98 gl->glViewport(0, 0, w, h);
99 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
100 gl->glClear(GL_COLOR_BUFFER_BIT);
101 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
102 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
103 gl->glEnable(GL_BLEND);
105 if (glCanvas->draw() == tvg::Result::Success) {
111 /************************************************************************/
113 /************************************************************************/
115 int main(int argc, char **argv)
117 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
120 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
123 //Initialize ThorVG Engine
124 if (tvgEngine == tvg::CanvasEngine::Sw) {
125 cout << "tvg engine: software" << endl;
127 cout << "tvg engine: opengl" << endl;
130 //Initialize ThorVG Engine
131 tvg::Initializer::init(tvgEngine);
133 elm_init(argc, argv);
135 if (tvgEngine == tvg::CanvasEngine::Sw) {
144 //Terminate ThorVG Engine
145 tvg::Initializer::term(tvg::CanvasEngine::Sw);