1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
10 auto shape1 = tvg::Shape::gen();
11 shape1->appendRect(50, 50, 200, 200, 0, 0);
12 shape1->fill(50, 50, 50, 255);
13 shape1->stroke(255, 255, 255, 255); //color: r, g, b, a
14 shape1->stroke(tvg::StrokeJoin::Bevel); //default is Bevel
15 shape1->stroke(10); //width: 10px
17 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
20 auto shape2 = tvg::Shape::gen();
21 shape2->appendRect(300, 50, 200, 200, 0, 0);
22 shape2->fill(50, 50, 50, 255);
23 shape2->stroke(255, 255, 255, 255);
24 shape2->stroke(tvg::StrokeJoin::Round);
27 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
30 auto shape3 = tvg::Shape::gen();
31 shape3->appendRect(550, 50, 200, 200, 0, 0);
32 shape3->fill(50, 50, 50, 255);
33 shape3->stroke(255, 255, 255, 255);
34 shape3->stroke(tvg::StrokeJoin::Miter);
37 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
40 auto shape4 = tvg::Shape::gen();
41 shape4->appendCircle(150, 450, 100, 100);
42 shape4->fill(50, 50, 50, 255);
43 shape4->stroke(255, 255, 255, 255);
46 if (canvas->push(move(shape4)) != tvg::Result::Success) return;
49 auto shape5 = tvg::Shape::gen();
50 shape5->appendCircle(400, 450, 100, 100);
51 shape5->fill(50, 50, 50, 255);
52 shape5->stroke(255, 255, 255, 255);
55 if (canvas->push(move(shape5)) != tvg::Result::Success) return;
58 auto shape6 = tvg::Shape::gen();
59 shape6->appendCircle(650, 450, 100, 100);
60 shape6->fill(50, 50, 50, 255);
61 shape6->stroke(255, 255, 255, 255);
64 if (canvas->push(move(shape6)) != tvg::Result::Success) return;
68 /************************************************************************/
69 /* Sw Engine Test Code */
70 /************************************************************************/
72 static unique_ptr<tvg::SwCanvas> swCanvas;
74 void tvgSwTest(uint32_t* buffer)
77 swCanvas = tvg::SwCanvas::gen();
78 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT);
80 /* Push the shape into the Canvas drawing list
81 When this shape is into the canvas list, the shape could update & prepare
82 internal data asynchronously for coming rendering.
83 Canvas keeps this shape node unless user call canvas->clear() */
84 tvgDrawCmds(swCanvas.get());
87 void drawSwView(void* data, Eo* obj)
89 if (swCanvas->draw() == tvg::Result::Success) {
95 /************************************************************************/
96 /* GL Engine Test Code */
97 /************************************************************************/
99 static unique_ptr<tvg::GlCanvas> glCanvas;
101 void initGLview(Evas_Object *obj)
103 static constexpr auto BPP = 4;
106 glCanvas = tvg::GlCanvas::gen();
107 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
109 /* Push the shape into the Canvas drawing list
110 When this shape is into the canvas list, the shape could update & prepare
111 internal data asynchronously for coming rendering.
112 Canvas keeps this shape node unless user call canvas->clear() */
113 tvgDrawCmds(glCanvas.get());
116 void drawGLview(Evas_Object *obj)
118 auto gl = elm_glview_gl_api_get(obj);
120 elm_glview_size_get(obj, &w, &h);
121 gl->glViewport(0, 0, w, h);
122 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
123 gl->glClear(GL_COLOR_BUFFER_BIT);
124 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
125 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
126 gl->glEnable(GL_BLEND);
128 if (glCanvas->draw() == tvg::Result::Success) {
134 /************************************************************************/
136 /************************************************************************/
138 int main(int argc, char **argv)
140 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
143 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
146 //Initialize ThorVG Engine
147 if (tvgEngine == tvg::CanvasEngine::Sw) {
148 cout << "tvg engine: software" << endl;
150 cout << "tvg engine: opengl" << endl;
153 //Initialize ThorVG Engine
154 tvg::Initializer::init(tvgEngine);
156 elm_init(argc, argv);
158 if (tvgEngine == tvg::CanvasEngine::Sw) {
167 //Terminate ThorVG Engine
168 tvg::Initializer::term(tvgEngine);