2 #include "testCommon.h"
4 /************************************************************************/
6 /************************************************************************/
13 static std::vector<unique_ptr<tvg::Picture>> pictures;
15 void svgDirCallback(const char* name, const char* path, void* data)
17 auto picture = tvg::Picture::gen();
20 sprintf(buf, "/%s/%s", path, name);
22 if (picture->load(buf) != tvg::Result::Success) return;
25 picture->viewbox(&x, &y, &w, &h);
27 float rate = (SIZE/(w > h ? w : h));
37 y -= (SIZE - h) * 0.5f;
39 x -= (SIZE - w) * 0.5f;
42 picture->translate((count % NUM_PER_LINE) * SIZE - x, SIZE * (count / NUM_PER_LINE) - y);
44 pictures.push_back(move(picture));
46 cout << "SVG: " << buf << endl;
51 void tvgDrawCmds(tvg::Canvas* canvas)
56 auto shape = tvg::Shape::gen();
57 shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry
58 shape->fill(255, 255, 255, 255); //r, g, b, a
60 if (canvas->push(move(shape)) != tvg::Result::Success) return;
62 eina_file_dir_list(EXAMPLE_DIR, EINA_TRUE, svgDirCallback, canvas);
64 /* This showcase shows you asynchrounous loading of svg.
65 For this, pushing pictures at a certian sync time.
66 This means it earns the time to finish loading svg resources,
67 otherwise you can push pictures immediately. */
68 for (auto& paint : pictures) {
69 canvas->push(move(paint));
76 /************************************************************************/
77 /* Sw Engine Test Code */
78 /************************************************************************/
80 static unique_ptr<tvg::SwCanvas> swCanvas;
82 void tvgSwTest(uint32_t* buffer)
85 swCanvas = tvg::SwCanvas::gen();
86 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
88 /* Push the shape into the Canvas drawing list
89 When this shape is into the canvas list, the shape could update & prepare
90 internal data asynchronously for coming rendering.
91 Canvas keeps this shape node unless user call canvas->clear() */
92 tvgDrawCmds(swCanvas.get());
95 void drawSwView(void* data, Eo* obj)
97 if (swCanvas->draw() == tvg::Result::Success) {
103 /************************************************************************/
104 /* GL Engine Test Code */
105 /************************************************************************/
107 static unique_ptr<tvg::GlCanvas> glCanvas;
109 void initGLview(Evas_Object *obj)
111 static constexpr auto BPP = 4;
114 glCanvas = tvg::GlCanvas::gen();
115 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
117 /* Push the shape into the Canvas drawing list
118 When this shape is into the canvas list, the shape could update & prepare
119 internal data asynchronously for coming rendering.
120 Canvas keeps this shape node unless user call canvas->clear() */
121 tvgDrawCmds(glCanvas.get());
124 void drawGLview(Evas_Object *obj)
126 auto gl = elm_glview_gl_api_get(obj);
127 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
128 gl->glClear(GL_COLOR_BUFFER_BIT);
130 if (glCanvas->draw() == tvg::Result::Success) {
136 /************************************************************************/
138 /************************************************************************/
140 int main(int argc, char **argv)
142 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
145 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
148 //Initialize ThorVG Engine
149 if (tvgEngine == tvg::CanvasEngine::Sw) {
150 cout << "tvg engine: software" << endl;
152 cout << "tvg engine: opengl" << endl;
156 auto threads = std::thread::hardware_concurrency();
158 //Initialize ThorVG Engine
159 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
161 elm_init(argc, argv);
163 if (tvgEngine == tvg::CanvasEngine::Sw) {
172 //Terminate ThorVG Engine
173 tvg::Initializer::term(tvg::CanvasEngine::Sw);
176 cout << "engine is not supported" << endl;