1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
9 canvas->reserve(5); //reserve 5 shape nodes (optional)
12 auto shape1 = tvg::Shape::gen();
13 shape1->appendRect(-100, -100, 1000, 1000, 50, 50);
14 shape1->fill(255, 255, 255, 255);
15 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
18 auto shape2 = tvg::Shape::gen();
19 shape2->appendRect(-100, -100, 250, 250, 50, 50);
20 shape2->fill(0, 0, 255, 255);
21 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
24 auto shape3 = tvg::Shape::gen();
25 shape3->appendRect(500, 500, 550, 550, 0, 0);
26 shape3->fill(0, 255, 255, 255);
27 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
30 auto shape4 = tvg::Shape::gen();
31 shape4->appendCircle(800, 100, 200, 200);
32 shape4->fill(255, 255, 0, 255);
33 if (canvas->push(move(shape4)) != tvg::Result::Success) return;
36 auto shape5 = tvg::Shape::gen();
37 shape5->appendCircle(200, 650, 250, 200);
38 shape5->fill(0, 0, 0, 255);
39 if (canvas->push(move(shape5)) != tvg::Result::Success) return;
42 /************************************************************************/
43 /* Sw Engine Test Code */
44 /************************************************************************/
46 static unique_ptr<tvg::SwCanvas> swCanvas;
48 void tvgSwTest(uint32_t* buffer)
51 swCanvas = tvg::SwCanvas::gen();
52 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
54 /* Push the shape into the Canvas drawing list
55 When this shape is into the canvas list, the shape could update & prepare
56 internal data asynchronously for coming rendering.
57 Canvas keeps this shape node unless user call canvas->clear() */
58 tvgDrawCmds(swCanvas.get());
61 void drawSwView(void* data, Eo* obj)
63 if (swCanvas->draw() == tvg::Result::Success) {
69 /************************************************************************/
70 /* GL Engine Test Code */
71 /************************************************************************/
73 static unique_ptr<tvg::GlCanvas> glCanvas;
75 void initGLview(Evas_Object *obj)
77 static constexpr auto BPP = 4;
80 glCanvas = tvg::GlCanvas::gen();
81 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
83 /* Push the shape into the Canvas drawing list
84 When this shape is into the canvas list, the shape could update & prepare
85 internal data asynchronously for coming rendering.
86 Canvas keeps this shape node unless user call canvas->clear() */
87 tvgDrawCmds(glCanvas.get());
90 void drawGLview(Evas_Object *obj)
92 auto gl = elm_glview_gl_api_get(obj);
94 elm_glview_size_get(obj, &w, &h);
95 gl->glViewport(0, 0, w, h);
96 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
97 gl->glClear(GL_COLOR_BUFFER_BIT);
98 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
99 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
100 gl->glEnable(GL_BLEND);
102 if (glCanvas->draw() == tvg::Result::Success) {
108 /************************************************************************/
110 /************************************************************************/
112 int main(int argc, char **argv)
114 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
117 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
120 //Initialize ThorVG Engine
121 if (tvgEngine == tvg::CanvasEngine::Sw) {
122 cout << "tvg engine: software" << endl;
124 cout << "tvg engine: opengl" << endl;
127 //Initialize ThorVG Engine
128 tvg::Initializer::init(tvgEngine);
130 elm_init(argc, argv);
132 if (tvgEngine == tvg::CanvasEngine::Sw) {
141 //Terminate ThorVG Engine
142 tvg::Initializer::term(tvgEngine);