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 tvg::Canvas* canvas = static_cast<tvg::Canvas*>(data);
19 auto picture = tvg::Picture::gen();
22 sprintf(buf,"%s/%s", path, name);
24 if (picture->load(buf) != tvg::Result::Success) return;
27 picture->viewbox(&x, &y, &w, &h);
29 float rate = (SIZE/(w > h ? w : h));
39 y -= (SIZE - h) * 0.5f;
41 x -= (SIZE - w) * 0.5f;
44 picture->translate((count % NUM_PER_LINE) * SIZE - x, SIZE * (count / NUM_PER_LINE) - y);
46 pictures.push_back(move(picture));
48 cout << "SVG: " << buf << endl;
53 void tvgDrawCmds(tvg::Canvas* canvas)
58 auto shape = tvg::Shape::gen();
59 shape->appendRect(0, 0, WIDTH, HEIGHT, 0, 0); //x, y, w, h, rx, ry
60 shape->fill(255, 255, 255, 255); //r, g, b, a
62 if (canvas->push(move(shape)) != tvg::Result::Success) return;
64 eina_file_dir_list("./svgs", EINA_TRUE, svgDirCallback, canvas);
66 /* This showcase shows you asynchrounous loading of svg.
67 For this, pushing pictures at a certian sync time.
68 This means it earns the time to finish loading svg resources,
69 otherwise you can push pictures immediately. */
70 for (auto& paint : pictures) {
71 canvas->push(move(paint));
78 /************************************************************************/
79 /* Sw Engine Test Code */
80 /************************************************************************/
82 static unique_ptr<tvg::SwCanvas> swCanvas;
84 void tvgSwTest(uint32_t* buffer)
87 swCanvas = tvg::SwCanvas::gen();
88 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
90 /* Push the shape into the Canvas drawing list
91 When this shape is into the canvas list, the shape could update & prepare
92 internal data asynchronously for coming rendering.
93 Canvas keeps this shape node unless user call canvas->clear() */
94 tvgDrawCmds(swCanvas.get());
97 void drawSwView(void* data, Eo* obj)
99 if (swCanvas->draw() == tvg::Result::Success) {
105 /************************************************************************/
106 /* GL Engine Test Code */
107 /************************************************************************/
109 static unique_ptr<tvg::GlCanvas> glCanvas;
111 void initGLview(Evas_Object *obj)
113 static constexpr auto BPP = 4;
116 glCanvas = tvg::GlCanvas::gen();
117 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
119 /* Push the shape into the Canvas drawing list
120 When this shape is into the canvas list, the shape could update & prepare
121 internal data asynchronously for coming rendering.
122 Canvas keeps this shape node unless user call canvas->clear() */
123 tvgDrawCmds(glCanvas.get());
126 void drawGLview(Evas_Object *obj)
128 auto gl = elm_glview_gl_api_get(obj);
129 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
130 gl->glClear(GL_COLOR_BUFFER_BIT);
132 if (glCanvas->draw() == tvg::Result::Success) {
138 /************************************************************************/
140 /************************************************************************/
142 int main(int argc, char **argv)
144 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
147 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
150 //Initialize ThorVG Engine
151 if (tvgEngine == tvg::CanvasEngine::Sw) {
152 cout << "tvg engine: software" << endl;
154 cout << "tvg engine: opengl" << endl;
158 auto threads = std::thread::hardware_concurrency();
160 //Initialize ThorVG Engine
161 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
163 elm_init(argc, argv);
165 if (tvgEngine == tvg::CanvasEngine::Sw) {
174 //Terminate ThorVG Engine
175 tvg::Initializer::term(tvg::CanvasEngine::Sw);
178 cout << "engine is not supported" << endl;