2 #include <Elementary.h>
9 unique_ptr<tvg::Paint> tvgDrawCmds()
11 //Prepare a Shape (Rectangle + Rectangle + Circle + Circle)
12 auto shape1 = tvg::Shape::gen();
13 shape1->appendRect(0, 0, 200, 200, 0); //x, y, w, h, cornerRadius
14 shape1->appendRect(100, 100, 300, 300, 100); //x, y, w, h, cornerRadius
15 shape1->appendCircle(400, 400, 100, 100); //cx, cy, radiusW, radiusH
16 shape1->appendCircle(400, 500, 170, 100); //cx, cy, radiusW, radiusH
17 shape1->fill(255, 255, 0, 255); //r, g, b, a
22 /************************************************************************/
23 /* Sw Engine Test Code */
24 /************************************************************************/
26 void tvgSwTest(uint32_t* buffer)
28 //Initialize ThorVG Engine
29 tvg::Initializer::init(tvg::CanvasEngine::Sw);
32 auto canvas = tvg::SwCanvas::gen();
33 canvas->target(buffer, WIDTH, WIDTH, HEIGHT);
35 /* Push the shape into the Canvas drawing list
36 When this shape is into the canvas list, the shape could update & prepare
37 internal data asynchronously for coming rendering.
38 Canvas keeps this shape node unless user call canvas->clear() */
39 canvas->push(tvgDrawCmds());
43 //Terminate ThorVG Engine
44 tvg::Initializer::term(tvg::CanvasEngine::Sw);
47 /************************************************************************/
48 /* GL Engine Test Code */
49 /************************************************************************/
51 static unique_ptr<tvg::GlCanvas> canvas;
53 void initGLview(Evas_Object *obj)
55 static constexpr auto BPP = 4;
57 //Initialize ThorVG Engine
58 tvg::Initializer::init(tvg::CanvasEngine::Gl);
61 canvas = tvg::GlCanvas::gen();
62 canvas->target(nullptr, WIDTH * BPP, WIDTH, HEIGHT);
64 /* Push the shape into the Canvas drawing list
65 When this shape is into the canvas list, the shape could update & prepare
66 internal data asynchronously for coming rendering.
67 Canvas keeps this shape node unless user call canvas->clear() */
68 canvas->push(tvgDrawCmds());
71 void delGLview(Evas_Object *obj)
73 //Terminate ThorVG Engine
74 tvg::Initializer::term(tvg::CanvasEngine::Gl);
77 void drawGLview(Evas_Object *obj)
79 auto gl = elm_glview_gl_api_get(obj);
81 elm_glview_size_get(obj, &w, &h);
82 gl->glViewport(0, 0, w, h);
83 gl->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
84 gl->glClear(GL_COLOR_BUFFER_BIT);
85 gl->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
86 gl->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
87 gl->glEnable(GL_BLEND);
93 /************************************************************************/
94 /* Common Infrastructure Code */
95 /************************************************************************/
97 void win_del(void *data, Evas_Object *o, void *ev)
102 int main(int argc, char **argv)
104 bool swEngine = true;
107 if (!strcmp(argv[1], "gl")) swEngine = false;
110 elm_init(argc, argv);
112 //Show the result using EFL...
113 elm_config_accel_preference_set("gl");
115 Eo* win = elm_win_util_standard_add(NULL, "ThorVG Test");
116 evas_object_smart_callback_add(win, "delete,request", win_del, 0);
121 static uint32_t buffer[WIDTH * HEIGHT];
122 viewer = evas_object_image_filled_add(evas_object_evas_get(win));
123 evas_object_image_size_set(viewer, WIDTH, HEIGHT);
124 evas_object_image_data_set(viewer, buffer);
125 evas_object_size_hint_weight_set(viewer, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
126 evas_object_show(viewer);
130 viewer = elm_glview_add(win);
131 evas_object_size_hint_weight_set(viewer, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132 elm_glview_mode_set(viewer, ELM_GLVIEW_ALPHA);
133 elm_glview_resize_policy_set(viewer, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
134 elm_glview_render_policy_set(viewer, ELM_GLVIEW_RENDER_POLICY_ON_DEMAND);
135 elm_glview_init_func_set(viewer, initGLview);
136 elm_glview_del_func_set(viewer, delGLview);
137 elm_glview_render_func_set(viewer, drawGLview);
138 evas_object_show(viewer);
141 elm_win_resize_object_add(win, viewer);
142 evas_object_geometry_set(win, 0, 0, WIDTH, HEIGHT);
143 evas_object_show(win);