summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_object_vg.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-04-03 16:12:59 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-03 16:12:59 +0200
commit9ba6e1a0ae5d82d10fbe2ea33e9ee0175242d534 (patch)
treeeeeffe724e759b0ef13d92cf5d2905c0776c7dc3 /src/lib/evas/canvas/evas_object_vg.c
parent659d3c4fd7bb49a440662f036af2e0a9b71711c2 (diff)
evas: add initial Evas_Object_VG.
Evas_Object_VG is meant to become an object that can hold a SVG scenegraph inside of it.
Diffstat (limited to 'src/lib/evas/canvas/evas_object_vg.c')
-rw-r--r--src/lib/evas/canvas/evas_object_vg.c315
1 files changed, 315 insertions, 0 deletions
diff --git a/src/lib/evas/canvas/evas_object_vg.c b/src/lib/evas/canvas/evas_object_vg.c
new file mode 100644
index 0000000..c956fb8
--- /dev/null
+++ b/src/lib/evas/canvas/evas_object_vg.c
@@ -0,0 +1,315 @@
1#include "evas_common_private.h"
2#include "evas_private.h"
3
4#include "evas_vg_root_node.eo.h"
5
6#define MY_CLASS EVAS_VG_CLASS
7
8
9/* private magic number for rectangle objects */
10static const char o_type[] = "rectangle";
11
12const char *o_vg_type = o_type;
13
14/* private struct for rectangle object internal data */
15typedef struct _Evas_VG_Data Evas_VG_Data;
16
17struct _Evas_VG_Data
18{
19 void *engine_data;
20 Evas_VG_Node *root;
21};
22
23static void evas_object_vg_render(Evas_Object *eo_obj,
24 Evas_Object_Protected_Data *obj,
25 void *type_private_data,
26 void *output, void *context, void *surface,
27 int x, int y, Eina_Bool do_async);
28static void evas_object_vg_render_pre(Evas_Object *eo_obj,
29 Evas_Object_Protected_Data *obj,
30 void *type_private_data);
31static void evas_object_vg_render_post(Evas_Object *eo_obj,
32 Evas_Object_Protected_Data *obj,
33 void *type_private_data);
34static unsigned int evas_object_vg_id_get(Evas_Object *eo_obj);
35static unsigned int evas_object_vg_visual_id_get(Evas_Object *eo_obj);
36static void *evas_object_vg_engine_data_get(Evas_Object *eo_obj);
37static int evas_object_vg_is_opaque(Evas_Object *eo_obj,
38 Evas_Object_Protected_Data *obj,
39 void *type_private_data);
40static int evas_object_vg_was_opaque(Evas_Object *eo_obj,
41 Evas_Object_Protected_Data *obj,
42 void *type_private_data);
43
44static const Evas_Object_Func object_func =
45{
46 /* methods (compulsory) */
47 NULL,
48 evas_object_vg_render,
49 evas_object_vg_render_pre,
50 evas_object_vg_render_post,
51 evas_object_vg_id_get,
52 evas_object_vg_visual_id_get,
53 evas_object_vg_engine_data_get,
54 /* these are optional. NULL = nothing */
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 evas_object_vg_is_opaque,
60 evas_object_vg_was_opaque,
61 NULL,
62 NULL,
63 NULL,
64 NULL,
65 NULL,
66 NULL,
67 NULL
68};
69
70/* the actual api call to add a vector graphic object */
71EAPI Evas_Object *
72evas_object_vg_add(Evas *e)
73{
74 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
75 return NULL;
76 MAGIC_CHECK_END();
77 Evas_Object *eo_obj = eo_add(MY_CLASS, e);
78 return eo_obj;
79}
80
81void
82_evas_vg_root_node_set(Eo *obj EINA_UNUSED, Evas_VG_Data *pd, Evas_VG_Node *container)
83{
84 Evas_VG_Node *tmp;
85
86 tmp = pd->root;
87 pd->root = eo_ref(container);
88 eo_unref(tmp);
89}
90
91Evas_VG_Node *
92_evas_vg_root_node_get(Eo *obj EINA_UNUSED, Evas_VG_Data *pd)
93{
94 return pd->root;
95}
96
97void
98_evas_vg_eo_base_constructor(Eo *eo_obj, Evas_VG_Data *pd EINA_UNUSED)
99{
100 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
101 Eo *parent = NULL;
102
103 eo_do_super(eo_obj, MY_CLASS, eo_constructor());
104
105 /* set up methods (compulsory) */
106 obj->func = &object_func;
107 obj->private_data = eo_data_ref(eo_obj, MY_CLASS);
108 obj->type = o_type;
109
110 eo_do(eo_obj, parent = eo_parent_get());
111 evas_object_inject(eo_obj, obj, evas_object_evas_get(parent));
112}
113
114static void
115evas_object_vg_render(Evas_Object *eo_obj EINA_UNUSED,
116 Evas_Object_Protected_Data *obj EINA_UNUSED,
117 void *type_private_data EINA_UNUSED,
118 void *output EINA_UNUSED, void *context EINA_UNUSED, void *surface EINA_UNUSED,
119 int x EINA_UNUSED, int y EINA_UNUSED, Eina_Bool do_async EINA_UNUSED)
120{
121 /* render object to surface with context, and offxet by x,y */
122 /* obj->layer->evas->engine.func->context_color_set(output, */
123 /* context, */
124 /* obj->cur->cache.clip.r, */
125 /* obj->cur->cache.clip.g, */
126 /* obj->cur->cache.clip.b, */
127 /* obj->cur->cache.clip.a); */
128 /* obj->layer->evas->engine.func->context_anti_alias_set(output, context, */
129 /* obj->cur->anti_alias); */
130 /* obj->layer->evas->engine.func->context_multiplier_unset(output, */
131 /* context); */
132 /* obj->layer->evas->engine.func->context_render_op_set(output, context, */
133 /* obj->cur->render_op); */
134 /* obj->layer->evas->engine.func->rectangle_draw(output, */
135 /* context, */
136 /* surface, */
137 /* obj->cur->geometry.x + x, */
138 /* obj->cur->geometry.y + y, */
139 /* obj->cur->geometry.w, */
140 /* obj->cur->geometry.h, */
141 /* do_async); */
142 // FIXME: I guess I should create an image, get the pixels data and
143 // start using that for Cairo.
144}
145
146static void
147evas_object_vg_render_pre(Evas_Object *eo_obj,
148 Evas_Object_Protected_Data *obj,
149 void *type_private_data EINA_UNUSED)
150{
151 int is_v, was_v;
152
153 // FIXME: Later on start doing precalc of span and stuff for all shape.
154
155 /* dont pre-render the obj twice! */
156 if (obj->pre_render_done) return;
157 obj->pre_render_done = EINA_TRUE;
158 /* pre-render phase. this does anything an object needs to do just before */
159 /* rendering. this could mean loading the image data, retrieving it from */
160 /* elsewhere, decoding video etc. */
161 /* then when this is done the object needs to figure if it changed and */
162 /* if so what and where and add the appropriate redraw rectangles */
163 /* if someone is clipping this obj - go calculate the clipper */
164 if (obj->cur->clipper)
165 {
166 if (obj->cur->cache.clip.dirty)
167 evas_object_clip_recalc(obj->cur->clipper);
168 obj->cur->clipper->func->render_pre(obj->cur->clipper->object,
169 obj->cur->clipper,
170 obj->cur->clipper->private_data);
171 }
172 /* now figure what changed and add draw rects */
173 /* if it just became visible or invisible */
174 is_v = evas_object_is_visible(eo_obj, obj);
175 was_v = evas_object_was_visible(eo_obj,obj);
176 if (!(is_v | was_v)) goto done;
177 if (is_v != was_v)
178 {
179 evas_object_render_pre_visible_change(&obj->layer->evas->clip_changes, eo_obj, is_v, was_v);
180 goto done;
181 }
182 if (obj->changed_map || obj->changed_src_visible)
183 {
184 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
185 goto done;
186 }
187 /* it's not visible - we accounted for it appearing or not so just abort */
188 if (!is_v) goto done;
189 /* clipper changed this is in addition to anything else for obj */
190 evas_object_render_pre_clipper_change(&obj->layer->evas->clip_changes, eo_obj);
191 /* if we restacked (layer or just within a layer) and don't clip anyone */
192 if ((obj->restack) && (!obj->clip.clipees))
193 {
194 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
195 goto done;
196 }
197 /* if it changed render op */
198 if (obj->cur->render_op != obj->prev->render_op)
199 {
200 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
201 goto done;
202 }
203 /* if it changed color */
204 if ((obj->cur->color.r != obj->prev->color.r) ||
205 (obj->cur->color.g != obj->prev->color.g) ||
206 (obj->cur->color.b != obj->prev->color.b) ||
207 (obj->cur->color.a != obj->prev->color.a))
208 {
209 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
210 goto done;
211 }
212 /* if it changed geometry - and obviously not visibility or color */
213 /* calculate differences since we have a constant color fill */
214 /* we really only need to update the differences */
215 if ((obj->cur->geometry.x != obj->prev->geometry.x) ||
216 (obj->cur->geometry.y != obj->prev->geometry.y) ||
217 (obj->cur->geometry.w != obj->prev->geometry.w) ||
218 (obj->cur->geometry.h != obj->prev->geometry.h))
219 {
220 evas_rects_return_difference_rects(&obj->layer->evas->clip_changes,
221 obj->cur->geometry.x,
222 obj->cur->geometry.y,
223 obj->cur->geometry.w,
224 obj->cur->geometry.h,
225 obj->prev->geometry.x,
226 obj->prev->geometry.y,
227 obj->prev->geometry.w,
228 obj->prev->geometry.h);
229 goto done;
230 }
231 /* it obviously didn't change - add a NO obscure - this "unupdates" this */
232 /* area so if there were updates for it they get wiped. don't do it if we */
233 /* arent fully opaque and we are visible */
234 if (evas_object_is_visible(eo_obj, obj) &&
235 evas_object_is_opaque(eo_obj, obj) &&
236 (!obj->clip.clipees))
237 {
238 Evas_Coord x, y, w, h;
239
240 x = obj->cur->cache.clip.x;
241 y = obj->cur->cache.clip.y;
242 w = obj->cur->cache.clip.w;
243 h = obj->cur->cache.clip.h;
244 if (obj->cur->clipper)
245 {
246 RECTS_CLIP_TO_RECT(x, y, w, h,
247 obj->cur->clipper->cur->cache.clip.x,
248 obj->cur->clipper->cur->cache.clip.y,
249 obj->cur->clipper->cur->cache.clip.w,
250 obj->cur->clipper->cur->cache.clip.h);
251 }
252 obj->layer->evas->engine.func->output_redraws_rect_del
253 (obj->layer->evas->engine.data.output,
254 x + obj->layer->evas->framespace.x,
255 y + obj->layer->evas->framespace.y,
256 w, h);
257 }
258 done:
259 evas_object_render_pre_effect_updates(&obj->layer->evas->clip_changes, eo_obj, is_v, was_v);
260}
261
262static void
263evas_object_vg_render_post(Evas_Object *eo_obj,
264 Evas_Object_Protected_Data *obj EINA_UNUSED,
265 void *type_private_data EINA_UNUSED)
266{
267 /* this moves the current data to the previous state parts of the object */
268 /* in whatever way is safest for the object. also if we don't need object */
269 /* data anymore we can free it if the object deems this is a good idea */
270 /* remove those pesky changes */
271 evas_object_clip_changes_clean(eo_obj);
272 /* move cur to prev safely for object data */
273 evas_object_cur_prev(eo_obj);
274}
275
276static unsigned int
277evas_object_vg_id_get(Evas_Object *eo_obj)
278{
279 Evas_VG_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
280 if (!o) return 0;
281 return MAGIC_OBJ_VG;
282}
283
284static unsigned int
285evas_object_vg_visual_id_get(Evas_Object *eo_obj)
286{
287 Evas_VG_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
288 if (!o) return 0;
289 return MAGIC_OBJ_SHAPE;
290}
291
292static void *
293evas_object_vg_engine_data_get(Evas_Object *eo_obj)
294{
295 Evas_VG_Data *o = eo_data_scope_get(eo_obj, MY_CLASS);
296 return o->engine_data;
297}
298
299static int
300evas_object_vg_is_opaque(Evas_Object *eo_obj EINA_UNUSED,
301 Evas_Object_Protected_Data *obj EINA_UNUSED,
302 void *type_private_data EINA_UNUSED)
303{
304 return 0;
305}
306
307static int
308evas_object_vg_was_opaque(Evas_Object *eo_obj EINA_UNUSED,
309 Evas_Object_Protected_Data *obj EINA_UNUSED,
310 void *type_private_data EINA_UNUSED)
311{
312 return 0;
313}
314
315#include "evas_vg.eo.c"