1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
12 auto shape1 = tvg::Shape::gen();
15 shape1->moveTo(199, 34);
16 shape1->lineTo(253, 143);
17 shape1->lineTo(374, 160);
18 shape1->lineTo(287, 244);
19 shape1->lineTo(307, 365);
20 shape1->lineTo(199, 309);
21 shape1->lineTo(97, 365);
22 shape1->lineTo(112, 245);
23 shape1->lineTo(26, 161);
24 shape1->lineTo(146, 143);
26 shape1->fill(0, 0, 255, 255);
27 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
31 auto shape2 = tvg::Shape::gen();
36 auto halfRadius = radius * 0.552284f;
39 shape2->moveTo(cx, cy - radius);
40 shape2->cubicTo(cx + halfRadius, cy - radius, cx + radius, cy - halfRadius, cx + radius, cy);
41 shape2->cubicTo(cx + radius, cy + halfRadius, cx + halfRadius, cy + radius, cx, cy+ radius);
42 shape2->cubicTo(cx - halfRadius, cy + radius, cx - radius, cy + halfRadius, cx - radius, cy);
43 shape2->cubicTo(cx - radius, cy - halfRadius, cx - halfRadius, cy - radius, cx, cy - radius);
45 shape2->fill(255, 0, 0, 255);
46 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
50 /************************************************************************/
51 /* Sw Engine Test Code */
52 /************************************************************************/
54 static unique_ptr<tvg::SwCanvas> swCanvas;
56 void tvgSwTest(uint32_t* buffer)
59 swCanvas = tvg::SwCanvas::gen();
60 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
62 /* Push the shape into the Canvas drawing list
63 When this shape is into the canvas list, the shape could update & prepare
64 internal data asynchronously for coming rendering.
65 Canvas keeps this shape node unless user call canvas->clear() */
66 tvgDrawCmds(swCanvas.get());
69 void drawSwView(void* data, Eo* obj)
71 if (swCanvas->draw() == tvg::Result::Success) {
77 /************************************************************************/
78 /* GL Engine Test Code */
79 /************************************************************************/
81 static unique_ptr<tvg::GlCanvas> glCanvas;
83 void initGLview(Evas_Object *obj)
85 static constexpr auto BPP = 4;
88 glCanvas = tvg::GlCanvas::gen();
89 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
91 /* Push the shape into the Canvas drawing list
92 When this shape is into the canvas list, the shape could update & prepare
93 internal data asynchronously for coming rendering.
94 Canvas keeps this shape node unless user call canvas->clear() */
95 tvgDrawCmds(glCanvas.get());
98 void drawGLview(Evas_Object *obj)
100 auto gl = elm_glview_gl_api_get(obj);
101 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
102 gl->glClear(GL_COLOR_BUFFER_BIT);
104 if (glCanvas->draw() == tvg::Result::Success) {
110 /************************************************************************/
112 /************************************************************************/
114 int main(int argc, char **argv)
116 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
119 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
122 //Initialize ThorVG Engine
123 if (tvgEngine == tvg::CanvasEngine::Sw) {
124 cout << "tvg engine: software" << endl;
126 cout << "tvg engine: opengl" << endl;
130 auto threads = std::thread::hardware_concurrency();
132 //Initialize ThorVG Engine
133 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
135 elm_init(argc, argv);
137 if (tvgEngine == tvg::CanvasEngine::Sw) {
146 //Terminate ThorVG Engine
147 tvg::Initializer::term(tvgEngine);
150 cout << "engine is not supported" << endl;