1 #include "testCommon.h"
3 /************************************************************************/
5 /************************************************************************/
7 void tvgDrawCmds(tvg::Canvas* canvas)
12 auto shape1 = tvg::Shape::gen();
13 shape1->appendRect(50, 50, 200, 200, 0, 0);
14 shape1->fill(50, 50, 50, 255);
15 shape1->stroke(255, 255, 255, 255); //color: r, g, b, a
16 shape1->stroke(tvg::StrokeJoin::Bevel); //default is Bevel
17 shape1->stroke(10); //width: 10px
19 if (canvas->push(move(shape1)) != tvg::Result::Success) return;
22 auto shape2 = tvg::Shape::gen();
23 shape2->appendRect(300, 50, 200, 200, 0, 0);
24 shape2->fill(50, 50, 50, 255);
25 shape2->stroke(255, 255, 255, 255);
26 shape2->stroke(tvg::StrokeJoin::Round);
29 if (canvas->push(move(shape2)) != tvg::Result::Success) return;
32 auto shape3 = tvg::Shape::gen();
33 shape3->appendRect(550, 50, 200, 200, 0, 0);
34 shape3->fill(50, 50, 50, 255);
35 shape3->stroke(255, 255, 255, 255);
36 shape3->stroke(tvg::StrokeJoin::Miter);
39 if (canvas->push(move(shape3)) != tvg::Result::Success) return;
42 auto shape4 = tvg::Shape::gen();
43 shape4->appendCircle(150, 450, 100, 100);
44 shape4->fill(50, 50, 50, 255);
45 shape4->stroke(255, 255, 255, 255);
48 if (canvas->push(move(shape4)) != tvg::Result::Success) return;
51 auto shape5 = tvg::Shape::gen();
52 shape5->appendCircle(400, 450, 100, 100);
53 shape5->fill(50, 50, 50, 255);
54 shape5->stroke(255, 255, 255, 255);
57 if (canvas->push(move(shape5)) != tvg::Result::Success) return;
60 auto shape6 = tvg::Shape::gen();
61 shape6->appendCircle(650, 450, 100, 100);
62 shape6->fill(50, 50, 50, 255);
63 shape6->stroke(255, 255, 255, 255);
66 if (canvas->push(move(shape6)) != tvg::Result::Success) return;
70 /************************************************************************/
71 /* Sw Engine Test Code */
72 /************************************************************************/
74 static unique_ptr<tvg::SwCanvas> swCanvas;
76 void tvgSwTest(uint32_t* buffer)
79 swCanvas = tvg::SwCanvas::gen();
80 swCanvas->target(buffer, WIDTH, WIDTH, HEIGHT, tvg::SwCanvas::ARGB8888);
82 /* Push the shape into the Canvas drawing list
83 When this shape is into the canvas list, the shape could update & prepare
84 internal data asynchronously for coming rendering.
85 Canvas keeps this shape node unless user call canvas->clear() */
86 tvgDrawCmds(swCanvas.get());
89 void drawSwView(void* data, Eo* obj)
91 if (swCanvas->draw() == tvg::Result::Success) {
97 /************************************************************************/
98 /* GL Engine Test Code */
99 /************************************************************************/
101 static unique_ptr<tvg::GlCanvas> glCanvas;
103 void initGLview(Evas_Object *obj)
105 static constexpr auto BPP = 4;
108 glCanvas = tvg::GlCanvas::gen();
109 glCanvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
111 /* Push the shape into the Canvas drawing list
112 When this shape is into the canvas list, the shape could update & prepare
113 internal data asynchronously for coming rendering.
114 Canvas keeps this shape node unless user call canvas->clear() */
115 tvgDrawCmds(glCanvas.get());
118 void drawGLview(Evas_Object *obj)
120 auto gl = elm_glview_gl_api_get(obj);
121 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
122 gl->glClear(GL_COLOR_BUFFER_BIT);
124 if (glCanvas->draw() == tvg::Result::Success) {
130 /************************************************************************/
132 /************************************************************************/
134 int main(int argc, char **argv)
136 tvg::CanvasEngine tvgEngine = tvg::CanvasEngine::Sw;
139 if (!strcmp(argv[1], "gl")) tvgEngine = tvg::CanvasEngine::Gl;
142 //Initialize ThorVG Engine
143 if (tvgEngine == tvg::CanvasEngine::Sw) {
144 cout << "tvg engine: software" << endl;
146 cout << "tvg engine: opengl" << endl;
150 auto threads = std::thread::hardware_concurrency();
152 //Initialize ThorVG Engine
153 if (tvg::Initializer::init(tvgEngine, threads) == tvg::Result::Success) {
155 elm_init(argc, argv);
157 if (tvgEngine == tvg::CanvasEngine::Sw) {
166 //Terminate ThorVG Engine
167 tvg::Initializer::term(tvgEngine);
170 cout << "engine is not supported" << endl;