aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/lib/canvas/evas_main.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/evas/src/lib/canvas/evas_main.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/evas/src/lib/canvas/evas_main.c')
-rw-r--r--libraries/evas/src/lib/canvas/evas_main.c671
1 files changed, 671 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/canvas/evas_main.c b/libraries/evas/src/lib/canvas/evas_main.c
new file mode 100644
index 0000000..0a37b2c
--- /dev/null
+++ b/libraries/evas/src/lib/canvas/evas_main.c
@@ -0,0 +1,671 @@
1#include "evas_common.h"
2#include "evas_private.h"
3#include "evas_cs.h"
4
5#ifdef LKDEBUG
6EAPI Eina_Bool lockdebug = EINA_FALSE;
7EAPI int lockmax = 0;
8#endif
9
10static int _evas_init_count = 0;
11int _evas_log_dom_global = -1;
12EAPI int
13evas_init(void)
14{
15 if (++_evas_init_count != 1)
16 return _evas_init_count;
17
18#ifdef LKDEBUG
19 if (getenv("EVAS_LOCK_DEBUG"))
20 {
21 lockdebug = EINA_TRUE;
22 lockmax = atoi(getenv("EVAS_LOCK_DEBUG"));
23 }
24#endif
25
26#ifdef HAVE_EVIL
27 if (!evil_init())
28 return --_evas_init_count;
29#endif
30
31 if (!eina_init())
32 goto shutdown_evil;
33
34 _evas_log_dom_global = eina_log_domain_register
35 ("evas_main", EVAS_DEFAULT_LOG_COLOR);
36 if (_evas_log_dom_global < 0)
37 {
38 EINA_LOG_ERR("Can not create a module log domain.");
39 goto shutdown_eina;
40 }
41
42 evas_module_init();
43#ifdef BUILD_ASYNC_EVENTS
44 if (!evas_async_events_init())
45 goto shutdown_module;
46#endif
47#ifdef EVAS_CSERVE
48 if (getenv("EVAS_CSERVE")) evas_cserve_init();
49#endif
50#ifdef BUILD_ASYNC_PRELOAD
51 _evas_preload_thread_init();
52#endif
53#ifdef EVAS_FRAME_QUEUING
54 evas_common_frameq_init();
55#endif
56
57 return _evas_init_count;
58
59#ifdef BUILD_ASYNC_EVENTS
60 shutdown_module:
61 evas_module_shutdown();
62 eina_log_domain_unregister(_evas_log_dom_global);
63#endif
64 shutdown_eina:
65 eina_shutdown();
66 shutdown_evil:
67#ifdef HAVE_EVIL
68 evil_shutdown();
69#endif
70
71 return --_evas_init_count;
72}
73
74EAPI int
75evas_shutdown(void)
76{
77 if (--_evas_init_count != 0)
78 return _evas_init_count;
79
80#ifdef EVAS_FRAME_QUEUING
81 if (evas_common_frameq_enabled())
82 {
83 evas_common_frameq_finish();
84 evas_common_frameq_destroy();
85 }
86#endif
87#ifdef BUILD_ASYNC_EVENTS
88 _evas_preload_thread_shutdown();
89#endif
90#ifdef EVAS_CSERVE
91 if (getenv("EVAS_CSERVE")) evas_cserve_shutdown();
92#endif
93#ifdef BUILD_ASYNC_EVENTS
94 evas_async_events_shutdown();
95#endif
96 evas_font_dir_cache_free();
97 evas_common_shutdown();
98 evas_module_shutdown();
99 eina_log_domain_unregister(_evas_log_dom_global);
100 eina_shutdown();
101#ifdef HAVE_EVIL
102 evil_shutdown();
103#endif
104
105 return _evas_init_count;
106}
107
108
109EAPI Evas *
110evas_new(void)
111{
112 Evas *e;
113
114 e = calloc(1, sizeof(Evas));
115 if (!e) return NULL;
116
117 e->magic = MAGIC_EVAS;
118 e->output.render_method = RENDER_METHOD_INVALID;
119 e->viewport.w = 1;
120 e->viewport.h = 1;
121 e->hinting = EVAS_FONT_HINTING_BYTECODE;
122 e->name_hash = eina_hash_string_superfast_new(NULL);
123 eina_clist_init(&e->calc_list);
124 eina_clist_init(&e->calc_done);
125
126#define EVAS_ARRAY_SET(E, Array) \
127 eina_array_step_set(&E->Array, sizeof (E->Array), 4096);
128
129 EVAS_ARRAY_SET(e, delete_objects);
130 EVAS_ARRAY_SET(e, active_objects);
131 EVAS_ARRAY_SET(e, restack_objects);
132 EVAS_ARRAY_SET(e, render_objects);
133 EVAS_ARRAY_SET(e, pending_objects);
134 EVAS_ARRAY_SET(e, obscuring_objects);
135 EVAS_ARRAY_SET(e, temporary_objects);
136 EVAS_ARRAY_SET(e, calculate_objects);
137 EVAS_ARRAY_SET(e, clip_changes);
138
139#undef EVAS_ARRAY_SET
140
141 return e;
142}
143
144EAPI void
145evas_free(Evas *e)
146{
147 Eina_Rectangle *r;
148 Evas_Coord_Touch_Point *touch_point;
149 Evas_Layer *lay;
150 int i;
151 int del;
152
153 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
154 return;
155 MAGIC_CHECK_END();
156
157#ifdef EVAS_FRAME_QUEUING
158 evas_common_frameq_flush();
159#endif
160
161 if (e->walking_list == 0) evas_render_idle_flush(e);
162
163 if (e->walking_list > 0) return;
164
165 if (e->callbacks)
166 {
167 if (e->callbacks->deletions_waiting) return;
168
169 e->callbacks->deletions_waiting = 0;
170 evas_event_callback_list_post_free(&e->callbacks->callbacks);
171 if (!e->callbacks->callbacks)
172 {
173 free(e->callbacks);
174 e->callbacks = NULL;
175 }
176
177 _evas_post_event_callback_free(e);
178 }
179
180 del = 1;
181 e->walking_list++;
182 e->cleanup = 1;
183 while (del)
184 {
185 del = 0;
186 EINA_INLIST_FOREACH(e->layers, lay)
187 {
188 Evas_Object *o;
189
190 evas_layer_pre_free(lay);
191
192 EINA_INLIST_FOREACH(lay->objects, o)
193 {
194 if ((o->callbacks) && (o->callbacks->walking_list))
195 {
196 /* Defer free */
197 e->delete_me = 1;
198 e->walking_list--;
199 return;
200 }
201 if (!o->delete_me)
202 del = 1;
203 }
204 }
205 }
206 EINA_INLIST_FOREACH(e->layers, lay)
207 evas_layer_free_objects(lay);
208 evas_layer_clean(e);
209
210 e->walking_list--;
211
212 evas_font_path_clear(e);
213 e->pointer.object.in = eina_list_free(e->pointer.object.in);
214
215 if (e->name_hash) eina_hash_free(e->name_hash);
216 e->name_hash = NULL;
217
218 EINA_LIST_FREE(e->damages, r)
219 eina_rectangle_free(r);
220 EINA_LIST_FREE(e->obscures, r)
221 eina_rectangle_free(r);
222
223 evas_fonts_zero_free(e);
224
225 evas_event_callback_all_del(e);
226 evas_event_callback_cleanup(e);
227
228 if (e->engine.func)
229 {
230 e->engine.func->context_free(e->engine.data.output, e->engine.data.context);
231 e->engine.func->output_free(e->engine.data.output);
232 e->engine.func->info_free(e, e->engine.info);
233 }
234
235 for (i = 0; i < e->modifiers.mod.count; i++)
236 free(e->modifiers.mod.list[i]);
237 if (e->modifiers.mod.list) free(e->modifiers.mod.list);
238
239 for (i = 0; i < e->locks.lock.count; i++)
240 free(e->locks.lock.list[i]);
241 if (e->locks.lock.list) free(e->locks.lock.list);
242
243 if (e->engine.module) evas_module_unref(e->engine.module);
244
245 eina_array_flush(&e->delete_objects);
246 eina_array_flush(&e->active_objects);
247 eina_array_flush(&e->restack_objects);
248 eina_array_flush(&e->render_objects);
249 eina_array_flush(&e->pending_objects);
250 eina_array_flush(&e->obscuring_objects);
251 eina_array_flush(&e->temporary_objects);
252 eina_array_flush(&e->calculate_objects);
253 eina_array_flush(&e->clip_changes);
254
255 EINA_LIST_FREE(e->touch_points, touch_point)
256 free(touch_point);
257
258 e->magic = 0;
259 free(e);
260}
261
262EAPI void
263evas_output_method_set(Evas *e, int render_method)
264{
265 Evas_Module *em;
266
267 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
268 return;
269 MAGIC_CHECK_END();
270
271 /* if our engine to set it to is invalid - abort */
272 if (render_method == RENDER_METHOD_INVALID) return;
273 /* if the engine is already set up - abort */
274 if (e->output.render_method != RENDER_METHOD_INVALID) return;
275 /* Request the right engine. */
276 em = evas_module_engine_get(render_method);
277 if (!em) return ;
278 if (em->id_engine != render_method) return;
279 if (!evas_module_load(em)) return;
280
281 /* set the correct render */
282 e->output.render_method = render_method;
283 e->engine.func = (em->functions);
284 evas_module_use(em);
285 if (e->engine.module) evas_module_unref(e->engine.module);
286 e->engine.module = em;
287 evas_module_ref(em);
288 /* get the engine info struct */
289 if (e->engine.func->info) e->engine.info = e->engine.func->info(e);
290 return;
291}
292
293EAPI int
294evas_output_method_get(const Evas *e)
295{
296 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
297 return RENDER_METHOD_INVALID;
298 MAGIC_CHECK_END();
299
300 return e->output.render_method;
301}
302
303EAPI Evas_Engine_Info *
304evas_engine_info_get(const Evas *e)
305{
306 Evas_Engine_Info *info;
307
308 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
309 return NULL;
310 MAGIC_CHECK_END();
311
312 if (!e->engine.info) return NULL;
313
314 info = e->engine.info;
315 ((Evas *)e)->engine.info_magic = info->magic;
316
317 return info;
318}
319
320EAPI Eina_Bool
321evas_engine_info_set(Evas *e, Evas_Engine_Info *info)
322{
323 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
324 return EINA_FALSE;
325 MAGIC_CHECK_END();
326 if (!info) return EINA_FALSE;
327 if (info != e->engine.info) return EINA_FALSE;
328 if (info->magic != e->engine.info_magic) return EINA_FALSE;
329 return (Eina_Bool)e->engine.func->setup(e, info);
330}
331
332EAPI void
333evas_output_size_set(Evas *e, int w, int h)
334{
335 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
336 return;
337 MAGIC_CHECK_END();
338
339 if ((w == e->output.w) && (h == e->output.h)) return;
340 if (w < 1) w = 1;
341 if (h < 1) h = 1;
342
343#ifdef EVAS_FRAME_QUEUING
344 evas_common_frameq_flush();
345#endif
346
347 e->output.w = w;
348 e->output.h = h;
349 e->output.changed = 1;
350 e->output_validity++;
351 e->changed = 1;
352 evas_render_invalidate(e);
353}
354
355EAPI void
356evas_output_size_get(const Evas *e, int *w, int *h)
357{
358 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
359 if (w) *w = 0;
360 if (h) *h = 0;
361 return;
362 MAGIC_CHECK_END();
363
364 if (w) *w = e->output.w;
365 if (h) *h = e->output.h;
366}
367
368EAPI void
369evas_output_viewport_set(Evas *e, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
370{
371 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
372 return;
373 MAGIC_CHECK_END();
374
375 if ((x == e->viewport.x) && (y == e->viewport.y) &&
376 (w == e->viewport.w) && (h == e->viewport.h)) return;
377 if (w <= 0) return;
378 if (h <= 0) return;
379 if ((x != 0) || (y != 0))
380 {
381 ERR("Compat error. viewport x,y != 0,0 not supported");
382 x = 0;
383 y = 0;
384 }
385 e->viewport.x = x;
386 e->viewport.y = y;
387 e->viewport.w = w;
388 e->viewport.h = h;
389 e->viewport.changed = 1;
390 e->output_validity++;
391 e->changed = 1;
392}
393
394EAPI void
395evas_output_viewport_get(const Evas *e, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
396{
397 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
398 if (x) *x = 0;
399 if (y) *y = 0;
400 if (w) *w = 0;
401 if (h) *h = 0;
402 return;
403 MAGIC_CHECK_END();
404
405 if (x) *x = e->viewport.x;
406 if (y) *y = e->viewport.y;
407 if (w) *w = e->viewport.w;
408 if (h) *h = e->viewport.h;
409}
410
411EAPI Evas_Coord
412evas_coord_screen_x_to_world(const Evas *e, int x)
413{
414 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
415 return 0;
416 MAGIC_CHECK_END();
417 if (e->output.w == e->viewport.w) return e->viewport.x + x;
418 return (long long)e->viewport.x + (((long long)x * (long long)e->viewport.w) / (long long)e->output.w);
419}
420
421EAPI Evas_Coord
422evas_coord_screen_y_to_world(const Evas *e, int y)
423{
424 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
425 return 0;
426 MAGIC_CHECK_END();
427 if (e->output.h == e->viewport.h) return e->viewport.y + y;
428 return (long long)e->viewport.y + (((long long)y * (long long)e->viewport.h) / (long long)e->output.h);
429}
430
431EAPI int
432evas_coord_world_x_to_screen(const Evas *e, Evas_Coord x)
433{
434 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
435 return 0;
436 MAGIC_CHECK_END();
437 if (e->output.w == e->viewport.w) return x - e->viewport.x;
438 return (int)((((long long)x - (long long)e->viewport.x) * (long long)e->output.w) / (long long)e->viewport.w);
439}
440
441EAPI int
442evas_coord_world_y_to_screen(const Evas *e, Evas_Coord y)
443{
444 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
445 return 0;
446 MAGIC_CHECK_END();
447 if (e->output.h == e->viewport.h) return y - e->viewport.y;
448 return (int)((((long long)y - (long long)e->viewport.y) * (long long)e->output.h) / (long long)e->viewport.h);
449}
450
451EAPI int
452evas_render_method_lookup(const char *name)
453{
454 Evas_Module *em;
455
456 if (!name) return RENDER_METHOD_INVALID;
457 /* search on the engines list for the name */
458 em = evas_module_find_type(EVAS_MODULE_TYPE_ENGINE, name);
459 if (!em) return RENDER_METHOD_INVALID;
460
461 return em->id_engine;
462}
463
464EAPI Eina_List *
465evas_render_method_list(void)
466{
467 return evas_module_engine_list();
468}
469
470EAPI void
471evas_render_method_list_free(Eina_List *list)
472{
473 eina_list_free(list);
474}
475
476EAPI Eina_Bool
477evas_object_image_extension_can_load_get(const char *file)
478{
479 const char *tmp;
480 Eina_Bool result;
481
482 tmp = eina_stringshare_add(file);
483 result = evas_common_extension_can_load_get(tmp);
484 eina_stringshare_del(tmp);
485
486 return result;
487}
488
489EAPI Eina_Bool
490evas_object_image_extension_can_load_fast_get(const char *file)
491{
492 return evas_common_extension_can_load_get(file);
493}
494
495EAPI void
496evas_pointer_output_xy_get(const Evas *e, int *x, int *y)
497{
498 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
499 if (x) *x = 0;
500 if (y) *y = 0;
501 return;
502 MAGIC_CHECK_END();
503 if (x) *x = e->pointer.x;
504 if (y) *y = e->pointer.y;
505}
506
507EAPI void
508evas_pointer_canvas_xy_get(const Evas *e, Evas_Coord *x, Evas_Coord *y)
509{
510 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
511 if (x) *x = 0;
512 if (y) *y = 0;
513 return;
514 MAGIC_CHECK_END();
515 if (x) *x = e->pointer.x;
516 if (y) *y = e->pointer.y;
517}
518
519EAPI int
520evas_pointer_button_down_mask_get(const Evas *e)
521{
522 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
523 return 0;
524 MAGIC_CHECK_END();
525 return (int)e->pointer.button;
526}
527
528EAPI Eina_Bool
529evas_pointer_inside_get(const Evas *e)
530{
531 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
532 return 0;
533 MAGIC_CHECK_END();
534 return (int)e->pointer.inside;
535}
536
537EAPI void
538evas_data_attach_set(Evas *e, void *data)
539{
540 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
541 return;
542 MAGIC_CHECK_END();
543 e->attach_data = data;
544}
545
546EAPI void *
547evas_data_attach_get(const Evas *e)
548{
549 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
550 return NULL;
551 MAGIC_CHECK_END();
552 return e->attach_data;
553}
554
555EAPI void
556evas_focus_in(Evas *e)
557{
558 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
559 return;
560 MAGIC_CHECK_END();
561 if (e->focus) return;
562 e->focus = 1;
563 evas_event_callback_call(e, EVAS_CALLBACK_CANVAS_FOCUS_IN, NULL);
564}
565
566EAPI void
567evas_focus_out(Evas *e)
568{
569 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
570 return;
571 MAGIC_CHECK_END();
572 if (!e->focus) return;
573 e->focus = 0;
574 evas_event_callback_call(e, EVAS_CALLBACK_CANVAS_FOCUS_OUT, NULL);
575}
576
577EAPI Eina_Bool
578evas_focus_state_get(const Evas *e)
579{
580 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
581 return 0;
582 MAGIC_CHECK_END();
583 return e->focus;
584}
585
586EAPI void
587evas_nochange_push(Evas *e)
588{
589 e->nochange++;
590}
591
592EAPI void
593evas_nochange_pop(Evas *e)
594{
595 e->nochange--;
596}
597
598void
599_evas_walk(Evas *e)
600{
601 e->walking_list++;
602}
603
604void
605_evas_unwalk(Evas *e)
606{
607 e->walking_list--;
608 if ((e->walking_list == 0) && (e->delete_me)) evas_free(e);
609}
610
611EAPI const char *
612evas_load_error_str(Evas_Load_Error error)
613{
614 switch (error)
615 {
616 case EVAS_LOAD_ERROR_NONE:
617 return "No error on load";
618 case EVAS_LOAD_ERROR_GENERIC:
619 return "A non-specific error occurred";
620 case EVAS_LOAD_ERROR_DOES_NOT_EXIST:
621 return "File (or file path) does not exist";
622 case EVAS_LOAD_ERROR_PERMISSION_DENIED:
623 return "Permission deinied to an existing file (or path)";
624 case EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED:
625 return "Allocation of resources failure prevented load";
626 case EVAS_LOAD_ERROR_CORRUPT_FILE:
627 return "File corrupt (but was detected as a known format)";
628 case EVAS_LOAD_ERROR_UNKNOWN_FORMAT:
629 return "File is not a known format";
630 default:
631 return "Unknown error";
632 }
633}
634
635EAPI void
636evas_color_hsv_to_rgb(float h, float s, float v, int *r, int *g, int *b)
637{
638 evas_common_convert_color_hsv_to_rgb(h, s, v, r, g, b);
639}
640
641EAPI void
642evas_color_rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v)
643{
644 evas_common_convert_color_rgb_to_hsv(r, g, b, h, s, v);
645}
646
647EAPI void
648evas_color_argb_premul(int a, int *r, int *g, int *b)
649{
650 evas_common_convert_color_argb_premul(a, r, g, b);
651}
652
653EAPI void
654evas_color_argb_unpremul(int a, int *r, int *g, int *b)
655{
656 evas_common_convert_color_argb_unpremul(a, r, g, b);
657}
658
659EAPI void
660evas_data_argb_premul(unsigned int *data, unsigned int len)
661{
662 if (!data || (len < 1)) return;
663 evas_common_convert_argb_premul(data, len);
664}
665
666EAPI void
667evas_data_argb_unpremul(unsigned int *data, unsigned int len)
668{
669 if (!data || (len < 1)) return;
670 evas_common_convert_argb_unpremul(data, len);
671}