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);
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 canvas->push(move(shape1));
20 auto shape2 = tvg::Shape::gen();
21 shape2->appendRect(300, 50, 200, 200, 0);
22 shape2->fill(50, 50, 50, 255);
23 shape2->stroke(255, 255, 255, 255);
24 shape2->stroke(tvg::StrokeJoin::Round);
27 canvas->push(move(shape2));
30 auto shape3 = tvg::Shape::gen();
31 shape3->appendRect(550, 50, 200, 200, 0);
32 shape3->fill(50, 50, 50, 255);
33 shape3->stroke(255, 255, 255, 255);
34 shape3->stroke(tvg::StrokeJoin::Miter);
37 canvas->push(move(shape3));
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 canvas->push(move(shape4));
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 canvas->push(move(shape5));
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 canvas->push(move(shape6));
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)
94 /************************************************************************/
95 /* GL Engine Test Code */
96 /************************************************************************/
98 static unique_ptr<tvg::GlCanvas> glCanvas;
100 void initGLview(Evas_Object *obj)
102 static constexpr auto BPP = 4;
105 glCanvas = tvg::GlCanvas::gen();
106 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
108 /* Push the shape into the Canvas drawing list
109 When this shape is into the canvas list, the shape could update & prepare
110 internal data asynchronously for coming rendering.
111 Canvas keeps this shape node unless user call canvas->clear() */
112 tvgDrawCmds(glCanvas.get());
115 void drawGLview(Evas_Object *obj)
117 auto gl = elm_glview_gl_api_get(obj);
119 elm_glview_size_get(obj, &w, &h);
120 gl->glViewport(0, 0, w, h);
121 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
122 gl->glClear(GL_COLOR_BUFFER_BIT);
123 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
124 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
125 gl->glEnable(GL_BLEND);
132 /************************************************************************/
134 /************************************************************************/
136 int main(int argc, char **argv)
138 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
141 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
144 //Initialize ThorVG Engine
145 if (tvgEngine == tvg::CanvasEngine::Sw) {
146 cout << "tvg engine: software" << endl;
148 cout << "tvg engine: opengl" << endl;
151 //Initialize ThorVG Engine
152 tvg::Initializer::init(tvgEngine);
154 elm_init(argc, argv);
156 elm_config_accel_preference_set("gl");
158 if (tvgEngine == tvg::CanvasEngine::Sw) {
167 //Terminate ThorVG Engine
168 tvg::Initializer::term(tvgEngine);