3 #include <Elementary.h>
10 unique_ptr<tvg::Paint> tvgDrawCmds()
12 //Prepare a Shape (Rectangle + Rectangle + Circle + Circle)
13 auto shape1 = tvg::Shape::gen();
14 shape1->appendRect(0, 0, 200, 200, 0); //x, y, w, h, cornerRadius
15 shape1->appendRect(100, 100, 300, 300, 100); //x, y, w, h, cornerRadius
16 shape1->appendCircle(400, 400, 100, 100); //cx, cy, radiusW, radiusH
17 shape1->appendCircle(400, 500, 170, 100); //cx, cy, radiusW, radiusH
18 shape1->fill(255, 255, 0, 255); //r, g, b, a
23 /************************************************************************/
24 /* Sw Engine Test Code */
25 /************************************************************************/
27 void tvgSwTest(uint32_t* buffer)
29 //Initialize ThorVG Engine
30 tvg::Initializer::init(tvg::CanvasEngine::Sw);
33 auto canvas = tvg::SwCanvas::gen();
34 canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
36 /* Push the shape into the Canvas drawing list
37 When this shape is into the canvas list, the shape could update & prepare
38 internal data asynchronously for coming rendering.
39 Canvas keeps this shape node unless user call canvas->clear() */
40 canvas->push(tvgDrawCmds());
44 //Terminate ThorVG Engine
45 tvg::Initializer::term(tvg::CanvasEngine::Sw);
48 /************************************************************************/
49 /* GL Engine Test Code */
50 /************************************************************************/
52 static unique_ptr<tvg::GlCanvas> canvas;
54 void initGLview(Evas_Object *obj)
56 static constexpr auto BPP = 4;
58 //Initialize ThorVG Engine
59 tvg::Initializer::init(tvg::CanvasEngine::Gl);
62 canvas = tvg::GlCanvas::gen();
63 canvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
65 /* Push the shape into the Canvas drawing list
66 When this shape is into the canvas list, the shape could update & prepare
67 internal data asynchronously for coming rendering.
68 Canvas keeps this shape node unless user call canvas->clear() */
69 canvas->push(tvgDrawCmds());
72 void delGLview(Evas_Object *obj)
74 //Terminate ThorVG Engine
75 tvg::Initializer::term(tvg::CanvasEngine::Gl);
78 void drawGLview(Evas_Object *obj)
80 auto gl = elm_glview_gl_api_get(obj);
82 elm_glview_size_get(obj, &w, &h);
83 gl->glViewport(0, 0, w, h);
84 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
85 gl->glClear(GL_COLOR_BUFFER_BIT);
86 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
87 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
88 gl->glEnable(GL_BLEND);
94 /************************************************************************/
95 /* Common Infrastructure Code */
96 /************************************************************************/
98 void win_del(void *data, Evas_Object *o, void *ev)
103 int main(int argc, char **argv)
105 bool swEngine = true;
108 if (!strcmp(argv[1], "gl")) swEngine = false;
111 if (swEngine) cout << "engine: software" << endl;
112 else cout << "engine: opengl" << endl;
114 elm_init(argc, argv);
116 //Show the result using EFL...
117 elm_config_accel_preference_set("gl");
119 Eo* win = elm_win_util_standard_add(NULL, "ThorVG Test");
120 evas_object_smart_callback_add(win, "delete,request", win_del, 0);
125 static uint32_t buffer[WIDTH * HEIGHT];
126 viewer = evas_object_image_filled_add(evas_object_evas_get(win));
127 evas_object_image_size_set(viewer, WIDTH, HEIGHT);
128 evas_object_image_data_set(viewer, buffer);
129 evas_object_size_hint_weight_set(viewer, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
130 evas_object_show(viewer);
134 viewer = elm_glview_add(win);
135 evas_object_size_hint_weight_set(viewer, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136 elm_glview_mode_set(viewer, ELM_GLVIEW_ALPHA);
137 elm_glview_resize_policy_set(viewer, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
138 elm_glview_render_policy_set(viewer, ELM_GLVIEW_RENDER_POLICY_ON_DEMAND);
139 elm_glview_init_func_set(viewer, initGLview);
140 elm_glview_del_func_set(viewer, delGLview);
141 elm_glview_render_func_set(viewer, drawGLview);
142 evas_object_show(viewer);
145 elm_win_resize_object_add(win, viewer);
146 evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
147 evas_object_show(win);