1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
11 canvas->reserve(5); //reserve 5 shape nodes (optional)
14 auto shape1 = tvg::Shape::gen();
15 shape1->appendRect(-100, -100, 1000, 1000, 50, 50);
16 shape1->fill(255, 255, 255, 255);
17 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
20 auto shape2 = tvg::Shape::gen();
21 shape2->appendRect(-100, -100, 250, 250, 50, 50);
22 shape2->fill(0, 0, 255, 255);
23 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
26 auto shape3 = tvg::Shape::gen();
27 shape3->appendRect(500, 500, 550, 550, 0, 0);
28 shape3->fill(0, 255, 255, 255);
29 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
32 auto shape4 = tvg::Shape::gen();
33 shape4->appendCircle(800, 100, 200, 200);
34 shape4->fill(255, 255, 0, 255);
35 if (canvas->push(move(shape4)) != tvg::Result::Success) return;
38 auto shape5 = tvg::Shape::gen();
39 shape5->appendCircle(200, 650, 250, 200);
40 shape5->fill(0, 0, 0, 255);
41 if (canvas->push(move(shape5)) != tvg::Result::Success) return;
44 /************************************************************************/
45 /* Sw Engine Test Code */
46 /************************************************************************/
48 static unique_ptr<tvg::SwCanvas> swCanvas;
50 void tvgSwTest(uint32_t* buffer)
53 swCanvas = tvg::SwCanvas::gen();
54 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
56 /* Push the shape into the Canvas drawing list
57 When this shape is into the canvas list, the shape could update & prepare
58 internal data asynchronously for coming rendering.
59 Canvas keeps this shape node unless user call canvas->clear() */
60 tvgDrawCmds(swCanvas.get());
63 void drawSwView(void* data, Eo* obj)
65 if (swCanvas->draw() == tvg::Result::Success) {
71 /************************************************************************/
72 /* GL Engine Test Code */
73 /************************************************************************/
75 static unique_ptr<tvg::GlCanvas> glCanvas;
77 void initGLview(Evas_Object *obj)
79 static constexpr auto BPP = 4;
82 glCanvas = tvg::GlCanvas::gen();
83 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
85 /* Push the shape into the Canvas drawing list
86 When this shape is into the canvas list, the shape could update & prepare
87 internal data asynchronously for coming rendering.
88 Canvas keeps this shape node unless user call canvas->clear() */
89 tvgDrawCmds(glCanvas.get());
92 void drawGLview(Evas_Object *obj)
94 auto gl = elm_glview_gl_api_get(obj);
95 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
96 gl->glClear(GL_COLOR_BUFFER_BIT);
98 if (glCanvas->draw() == tvg::Result::Success) {
104 /************************************************************************/
106 /************************************************************************/
108 int main(int argc, char **argv)
110 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
113 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
116 //Initialize ThorVG Engine
117 if (tvgEngine == tvg::CanvasEngine::Sw) {
118 cout << "tvg engine: software" << endl;
120 cout << "tvg engine: opengl" << endl;
124 auto threads = std::thread::hardware_concurrency();
126 //Initialize ThorVG Engine
127 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
129 elm_init(argc, argv);
131 if (tvgEngine == tvg::CanvasEngine::Sw) {
140 //Terminate ThorVG Engine
141 tvg::Initializer::term(tvgEngine);
144 cout << "engine is not supported" << endl;