1 #include "evas_common_private.h"
2 #include "evas_private.h"
3
4 #define MY_CLASS EFL_CANVAS_RECTANGLE_CLASS
5
6 /* private magic number for rectangle objects */
7 static const char o_type[] = "rectangle";
8
9 const char *o_rect_type = o_type;
10
11 /* private struct for rectangle object internal data */
12 typedef struct _Efl_Canvas_Rectangle_Data Efl_Canvas_Rectangle_Data;
13
14 struct _Efl_Canvas_Rectangle_Data
15 {
16 void *engine_data;
17 };
18
19 /* private methods for rectangle objects */
20 static void evas_object_rectangle_init(Evas_Object *eo_obj);
21 static void evas_object_rectangle_render(Evas_Object *eo_obj,
22 Evas_Object_Protected_Data *obj,
23 void *type_private_data,
24 void *engine, void *output, void *context, void *surface,
25 int x, int y, Eina_Bool do_async);
26 static void evas_object_rectangle_render_pre(Evas_Object *eo_obj,
27 Evas_Object_Protected_Data *obj,
28 void *type_private_data);
29 static void evas_object_rectangle_render_post(Evas_Object *eo_obj,
30 Evas_Object_Protected_Data *obj,
31 void *type_private_data);
32
33 static void *evas_object_rectangle_engine_data_get(Evas_Object *eo_obj);
34
35 static int evas_object_rectangle_is_opaque(Evas_Object *eo_obj,
36 Evas_Object_Protected_Data *obj,
37 void *type_private_data);
38 static int evas_object_rectangle_was_opaque(Evas_Object *eo_obj,
39 Evas_Object_Protected_Data *obj,
40 void *type_private_data);
41
42
43 #if 0 /* usless calls for a rect object. much more useful for images etc. */
44 static void evas_object_rectangle_store(Evas_Object *eo_obj);
45 static void evas_object_rectangle_unstore(Evas_Object *eo_obj);
46 static int evas_object_rectangle_is_visible(Evas_Object *eo_obj);
47 static int evas_object_rectangle_was_visible(Evas_Object *eo_obj);
48 static int evas_object_rectangle_is_inside(Evas_Object *eo_obj, double x, double y);
49 static int evas_object_rectangle_was_inside(Evas_Object *eo_obj, double x, double y);
50 #endif
51
52 static const Evas_Object_Func object_func =
53 {
54 /* methods (compulsory) */
55 NULL,
56 evas_object_rectangle_render,
57 evas_object_rectangle_render_pre,
58 evas_object_rectangle_render_post,
59 evas_object_rectangle_engine_data_get,
60 /* these are optional. NULL = nothing */
61 NULL,
62 NULL,
63 evas_object_rectangle_is_opaque,
64 evas_object_rectangle_was_opaque,
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 NULL,
70 NULL,
71 NULL, // render_prepare
72 };
73
74 /* the actual api call to add a rect */
75 /* it has no other api calls as all properties are standard */
76
77 EAPI Evas_Object *
evas_object_rectangle_add(Evas * e)78 evas_object_rectangle_add(Evas *e)
79 {
80 e = evas_find(e);
81 EINA_SAFETY_ON_FALSE_RETURN_VAL(efl_isa(e, EVAS_CANVAS_CLASS), NULL);
82 return efl_add(EFL_CANVAS_RECTANGLE_CLASS, e, efl_canvas_object_legacy_ctor(efl_added));
83 }
84
85 EOLIAN static Eo *
_efl_canvas_rectangle_efl_object_constructor(Eo * eo_obj,Efl_Canvas_Rectangle_Data * class_data EINA_UNUSED)86 _efl_canvas_rectangle_efl_object_constructor(Eo *eo_obj, Efl_Canvas_Rectangle_Data *class_data EINA_UNUSED)
87 {
88 eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS));
89
90 evas_object_rectangle_init(eo_obj);
91
92 return eo_obj;
93 }
94
95 /* all nice and private */
96 static void
evas_object_rectangle_init(Evas_Object * eo_obj)97 evas_object_rectangle_init(Evas_Object *eo_obj)
98 {
99 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
100 /* set up methods (compulsory) */
101 obj->func = &object_func;
102 obj->private_data = efl_data_ref(eo_obj, MY_CLASS);
103 obj->type = o_type;
104 }
105
106 static void
evas_object_rectangle_render(Evas_Object * eo_obj EINA_UNUSED,Evas_Object_Protected_Data * obj,void * type_private_data EINA_UNUSED,void * engine,void * output,void * context,void * surface,int x,int y,Eina_Bool do_async)107 evas_object_rectangle_render(Evas_Object *eo_obj EINA_UNUSED,
108 Evas_Object_Protected_Data *obj,
109 void *type_private_data EINA_UNUSED,
110 void *engine, void *output, void *context, void *surface, int x, int y, Eina_Bool do_async)
111 {
112 /* render object to surface with context, and offxet by x,y */
113 obj->layer->evas->engine.func->context_color_set(engine,
114 context,
115 obj->cur->cache.clip.r,
116 obj->cur->cache.clip.g,
117 obj->cur->cache.clip.b,
118 obj->cur->cache.clip.a);
119 obj->layer->evas->engine.func->context_anti_alias_set(engine, context,
120 obj->cur->anti_alias);
121 obj->layer->evas->engine.func->context_multiplier_unset(engine, context);
122 obj->layer->evas->engine.func->context_render_op_set(engine, context,
123 obj->cur->render_op);
124 obj->layer->evas->engine.func->rectangle_draw(engine,
125 output,
126 context,
127 surface,
128 obj->cur->geometry.x + x,
129 obj->cur->geometry.y + y,
130 obj->cur->geometry.w,
131 obj->cur->geometry.h,
132 do_async);
133 }
134
135 static void
evas_object_rectangle_render_pre(Evas_Object * eo_obj,Evas_Object_Protected_Data * obj,void * type_private_data EINA_UNUSED)136 evas_object_rectangle_render_pre(Evas_Object *eo_obj,
137 Evas_Object_Protected_Data *obj,
138 void *type_private_data EINA_UNUSED)
139 {
140 int is_v, was_v;
141
142 /* dont pre-render the obj twice! */
143 if (obj->pre_render_done) return;
144 obj->pre_render_done = EINA_TRUE;
145 /* pre-render phase. this does anything an object needs to do just before */
146 /* rendering. this could mean loading the image data, retrieving it from */
147 /* elsewhere, decoding video etc. */
148 /* then when this is done the object needs to figure if it changed and */
149 /* if so what and where and add the appropriate redraw rectangles */
150 /* if someone is clipping this obj - go calculate the clipper */
151 if (obj->cur->clipper)
152 {
153 if (obj->cur->cache.clip.dirty)
154 evas_object_clip_recalc(obj->cur->clipper);
155 obj->cur->clipper->func->render_pre(obj->cur->clipper->object,
156 obj->cur->clipper,
157 obj->cur->clipper->private_data);
158 }
159 /* now figure what changed and add draw rects */
160 /* if it just became visible or invisible */
161 is_v = evas_object_is_visible(obj);
162 was_v = evas_object_was_visible(obj);
163 if (!(is_v | was_v)) goto done;
164 if (is_v != was_v)
165 {
166 evas_object_render_pre_visible_change(&obj->layer->evas->clip_changes, eo_obj, is_v, was_v);
167 goto done;
168 }
169 if (obj->changed_map || obj->changed_src_visible)
170 {
171 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
172 goto done;
173 }
174 /* it's not visible - we accounted for it appearing or not so just abort */
175 if (!is_v) goto done;
176 /* clipper changed this is in addition to anything else for obj */
177 evas_object_render_pre_clipper_change(&obj->layer->evas->clip_changes, eo_obj);
178 /* if we restacked (layer or just within a layer) and don't clip anyone */
179 if ((obj->restack) && (!obj->clip.clipees))
180 {
181 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
182 goto done;
183 }
184 /* if it changed render op */
185 if (obj->cur->render_op != obj->prev->render_op)
186 {
187 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
188 goto done;
189 }
190 /* if it changed color */
191 if ((obj->cur->color.r != obj->prev->color.r) ||
192 (obj->cur->color.g != obj->prev->color.g) ||
193 (obj->cur->color.b != obj->prev->color.b) ||
194 (obj->cur->color.a != obj->prev->color.a) ||
195 (obj->cur->cache.clip.r != obj->prev->cache.clip.r) ||
196 (obj->cur->cache.clip.g != obj->prev->cache.clip.g) ||
197 (obj->cur->cache.clip.b != obj->prev->cache.clip.b) ||
198 (obj->cur->cache.clip.a != obj->prev->cache.clip.a))
199 {
200 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
201 goto done;
202 }
203 /* it obviously didn't change - add a NO obscure - this "unupdates" this */
204 /* area so if there were updates for it they get wiped. don't do it if we */
205 /* arent fully opaque and we are visible */
206 if (evas_object_is_visible(obj) &&
207 evas_object_is_opaque(obj) &&
208 (!obj->clip.clipees))
209 {
210 Evas_Coord x, y, w, h;
211
212 x = obj->cur->cache.clip.x;
213 y = obj->cur->cache.clip.y;
214 w = obj->cur->cache.clip.w;
215 h = obj->cur->cache.clip.h;
216 if (obj->cur->clipper)
217 {
218 RECTS_CLIP_TO_RECT(x, y, w, h,
219 obj->cur->clipper->cur->cache.clip.x,
220 obj->cur->clipper->cur->cache.clip.y,
221 obj->cur->clipper->cur->cache.clip.w,
222 obj->cur->clipper->cur->cache.clip.h);
223 }
224 evas_render_update_del(obj->layer->evas,
225 x + obj->layer->evas->framespace.x,
226 y + obj->layer->evas->framespace.y,
227 w, h);
228 }
229 /* if it changed geometry - and obviously not visibility or color */
230 /* calculate differences since we have a constant color fill */
231 /* we really only need to update the differences */
232 if ((obj->cur->geometry.x != obj->prev->geometry.x) ||
233 (obj->cur->geometry.y != obj->prev->geometry.y) ||
234 (obj->cur->geometry.w != obj->prev->geometry.w) ||
235 (obj->cur->geometry.h != obj->prev->geometry.h))
236 {
237 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, eo_obj, obj);
238
239 //This Performance is not so good ...!
240 #if 0
241 evas_rects_return_difference_rects(&obj->layer->evas->clip_changes,
242 obj->cur->geometry.x,
243 obj->cur->geometry.y,
244 obj->cur->geometry.w,
245 obj->cur->geometry.h,
246 obj->prev->geometry.x,
247 obj->prev->geometry.y,
248 obj->prev->geometry.w,
249 obj->prev->geometry.h);
250 #endif
251 }
252 done:
253 evas_object_render_pre_effect_updates(&obj->layer->evas->clip_changes, eo_obj, is_v, was_v);
254 }
255
256 static void
evas_object_rectangle_render_post(Evas_Object * eo_obj EINA_UNUSED,Evas_Object_Protected_Data * obj,void * type_private_data EINA_UNUSED)257 evas_object_rectangle_render_post(Evas_Object *eo_obj EINA_UNUSED,
258 Evas_Object_Protected_Data *obj,
259 void *type_private_data EINA_UNUSED)
260 {
261
262 /* this moves the current data to the previous state parts of the object */
263 /* in whatever way is safest for the object. also if we don't need object */
264 /* data anymore we can free it if the object deems this is a good idea */
265 /* remove those pesky changes */
266 evas_object_clip_changes_clean(obj);
267 /* move cur to prev safely for object data */
268 evas_object_cur_prev(obj);
269 }
270
271 static int
evas_object_rectangle_is_opaque(Evas_Object * eo_obj EINA_UNUSED,Evas_Object_Protected_Data * obj,void * type_private_data EINA_UNUSED)272 evas_object_rectangle_is_opaque(Evas_Object *eo_obj EINA_UNUSED,
273 Evas_Object_Protected_Data *obj,
274 void *type_private_data EINA_UNUSED)
275 {
276 /* this returns 1 if the internal object data implies that the object is */
277 /* currently fully opaque over the entire rectangle it occupies */
278 if ((obj->map->cur.map) && (obj->map->cur.usemap)) return 0;
279 if (obj->cur->render_op == EVAS_RENDER_COPY)
280 return 1;
281 if (obj->cur->render_op != EVAS_RENDER_BLEND)
282 return 0;
283 return (obj->cur->cache.clip.a == 255) ? 1 : 0;
284 }
285
286 static int
evas_object_rectangle_was_opaque(Evas_Object * eo_obj EINA_UNUSED,Evas_Object_Protected_Data * obj,void * type_private_data EINA_UNUSED)287 evas_object_rectangle_was_opaque(Evas_Object *eo_obj EINA_UNUSED,
288 Evas_Object_Protected_Data *obj,
289 void *type_private_data EINA_UNUSED)
290 {
291 /* this returns 1 if the internal object data implies that the object was */
292 /* previously fully opaque over the entire rectangle it occupies */
293 if (obj->prev->render_op == EVAS_RENDER_COPY)
294 return 1;
295 if (obj->prev->render_op != EVAS_RENDER_BLEND)
296 return 0;
297 return (obj->prev->cache.clip.a == 255) ? 1 : 0;
298 }
299
evas_object_rectangle_engine_data_get(Evas_Object * eo_obj)300 static void *evas_object_rectangle_engine_data_get(Evas_Object *eo_obj)
301 {
302 Efl_Canvas_Rectangle_Data *o = efl_data_scope_get(eo_obj, MY_CLASS);
303 return o->engine_data;
304 }
305
306 #if 0 /* usless calls for a rect object. much more useful for images etc. */
307 static void
308 evas_object_rectangle_store(Evas_Object *eo_obj)
309 {
310 /* store... nothing for rectangle objects... it's a bit silly */
311 /* but for others that may have expensive caluclations to do to */
312 /* generate the object data, hint that they might want to be pre-calced */
313 /* once and stored */
314 }
315
316 static void
317 evas_object_rectangle_unstore(Evas_Object *eo_obj)
318 {
319 /* store... nothing for rectangle objects... it's a bit silly */
320 }
321
322 static int
323 evas_object_rectangle_is_visible(Evas_Object *eo_obj)
324 {
325 /* this returns 1 if the internal object data would imply that it is */
326 /* visible (ie drawing it draws something. this is not to do with events */
327 return 1;
328 }
329
330 static int
331 evas_object_rectangle_was_visible(Evas_Object *eo_obj)
332 {
333 /* this returns 1 if the internal object data would imply that it was */
334 /* visible (ie drawing it draws something. this is not to do with events */
335 return 1;
336 }
337
338 static int
339 evas_object_rectangle_is_inside(Evas_Object *eo_obj, double x, double y)
340 {
341 /* this returns 1 if the canvas co-ordinates are inside the object based */
342 /* on object private data. not much use for rects, but for polys, images */
343 /* and other complex objects it might be */
344 return 1;
345 }
346
347 static int
348 evas_object_rectangle_was_inside(Evas_Object *eo_obj, double x, double y)
349 {
350 /* this returns 1 if the canvas co-ordinates were inside the object based */
351 /* on object private data. not much use for rects, but for polys, images */
352 /* and other complex objects it might be */
353 return 1;
354 }
355 #endif
356
357 #include "canvas/efl_canvas_rectangle.eo.c"
358