diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/ecore/src/lib/ecore_evas/ecore_evas_psl1ght.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-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 '')
-rw-r--r-- | libraries/ecore/src/lib/ecore_evas/ecore_evas_psl1ght.c | 476 |
1 files changed, 476 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_evas/ecore_evas_psl1ght.c b/libraries/ecore/src/lib/ecore_evas/ecore_evas_psl1ght.c new file mode 100644 index 0000000..0849c79 --- /dev/null +++ b/libraries/ecore/src/lib/ecore_evas/ecore_evas_psl1ght.c | |||
@@ -0,0 +1,476 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include <config.h> | ||
3 | #endif | ||
4 | |||
5 | #include <Ecore.h> | ||
6 | #include <Ecore_Input.h> | ||
7 | #include <Ecore_Input_Evas.h> | ||
8 | |||
9 | #include "ecore_evas_private.h" | ||
10 | #include "Ecore_Evas.h" | ||
11 | |||
12 | #ifdef BUILD_ECORE_EVAS_PSL1GHT | ||
13 | #include <Ecore_Psl1ght.h> | ||
14 | #include <Evas_Engine_PSL1GHT.h> | ||
15 | |||
16 | static int _ecore_evas_init_count = 0; | ||
17 | |||
18 | static Ecore_Evas *psl1ght_ee = NULL; | ||
19 | static Ecore_Event_Handler *ecore_evas_event_handlers[4] = { | ||
20 | NULL, NULL, NULL, NULL | ||
21 | }; | ||
22 | |||
23 | static const char *ecore_evas_psl1ght_default = "EFL PSL1GHT"; | ||
24 | static int _ecore_evas_fps_debug = 0; | ||
25 | static Ecore_Poller *ecore_evas_event; | ||
26 | |||
27 | static unsigned int | ||
28 | _ecore_evas_time_get() | ||
29 | { | ||
30 | return (unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff; | ||
31 | } | ||
32 | |||
33 | static Ecore_Evas * | ||
34 | _ecore_evas_psl1ght_match(void) | ||
35 | { | ||
36 | return psl1ght_ee; | ||
37 | } | ||
38 | |||
39 | static Eina_Bool | ||
40 | _ecore_evas_psl1ght_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) | ||
41 | { | ||
42 | Ecore_Evas *ee; | ||
43 | |||
44 | ee = _ecore_evas_psl1ght_match(); | ||
45 | |||
46 | if (!ee) return ECORE_CALLBACK_PASS_ON; | ||
47 | /* pass on event */ | ||
48 | ee->prop.focused = 1; | ||
49 | evas_focus_in(ee->evas); | ||
50 | if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee); | ||
51 | |||
52 | return ECORE_CALLBACK_PASS_ON; | ||
53 | } | ||
54 | |||
55 | static Eina_Bool | ||
56 | _ecore_evas_psl1ght_event_lost_focus(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) | ||
57 | { | ||
58 | Ecore_Evas *ee; | ||
59 | |||
60 | ee = _ecore_evas_psl1ght_match(); | ||
61 | |||
62 | if (!ee) return ECORE_CALLBACK_PASS_ON; | ||
63 | /* pass on event */ | ||
64 | evas_focus_out(ee->evas); | ||
65 | ee->prop.focused = 0; | ||
66 | if (ee->func.fn_focus_out) ee->func.fn_focus_out(ee); | ||
67 | |||
68 | return ECORE_CALLBACK_PASS_ON; | ||
69 | } | ||
70 | |||
71 | static Eina_Bool | ||
72 | _ecore_evas_psl1ght_event_video_expose(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__) | ||
73 | { | ||
74 | Ecore_Evas *ee; | ||
75 | int w; | ||
76 | int h; | ||
77 | |||
78 | ee = _ecore_evas_psl1ght_match(); | ||
79 | |||
80 | if (!ee) return ECORE_CALLBACK_PASS_ON; | ||
81 | evas_output_size_get(ee->evas, &w, &h); | ||
82 | evas_damage_rectangle_add(ee->evas, 0, 0, w, h); | ||
83 | |||
84 | return ECORE_CALLBACK_PASS_ON; | ||
85 | } | ||
86 | |||
87 | static Eina_Bool | ||
88 | _ecore_evas_psl1ght_event_key_modifiers(void *data __UNUSED__, int type __UNUSED__, void *event) | ||
89 | { | ||
90 | Ecore_Evas *ee; | ||
91 | Ecore_Psl1ght_Event_Key_Modifiers *e = event; | ||
92 | |||
93 | ee = _ecore_evas_psl1ght_match(); | ||
94 | |||
95 | if (!ee) return ECORE_CALLBACK_PASS_ON; | ||
96 | ecore_event_evas_modifier_lock_update(ee->evas, e->modifiers); | ||
97 | |||
98 | return ECORE_CALLBACK_PASS_ON; | ||
99 | } | ||
100 | |||
101 | static int | ||
102 | _ecore_evas_render(Ecore_Evas *ee) | ||
103 | { | ||
104 | Eina_List *updates; | ||
105 | |||
106 | updates = evas_render_updates(ee->evas); | ||
107 | if (updates) | ||
108 | { | ||
109 | evas_render_updates_free(updates); | ||
110 | _ecore_evas_idle_timeout_update(ee); | ||
111 | } | ||
112 | return updates ? 1 : 0; | ||
113 | } | ||
114 | |||
115 | static int | ||
116 | _ecore_evas_psl1ght_render(Ecore_Evas *ee) | ||
117 | { | ||
118 | int rend = 0; | ||
119 | |||
120 | #ifdef BUILD_ECORE_EVAS_SOFTWARE_BUFFER | ||
121 | Eina_List *ll; | ||
122 | Ecore_Evas *ee2; | ||
123 | |||
124 | EINA_LIST_FOREACH(ee->sub_ecore_evas, ll, ee2) | ||
125 | { | ||
126 | if (ee2->func.fn_pre_render) ee2->func.fn_pre_render(ee2); | ||
127 | rend |= _ecore_evas_buffer_render(ee2); | ||
128 | if (ee2->func.fn_post_render) ee2->func.fn_post_render(ee2); | ||
129 | } | ||
130 | #endif | ||
131 | |||
132 | if (ee->func.fn_pre_render) ee->func.fn_pre_render(ee); | ||
133 | |||
134 | if (ee->prop.avoid_damage) rend = _ecore_evas_render(ee); | ||
135 | else if ((ee->visible) || | ||
136 | ((ee->should_be_visible) && (ee->prop.fullscreen)) || | ||
137 | ((ee->should_be_visible) && (ee->prop.override))) | ||
138 | rend |= _ecore_evas_render(ee); | ||
139 | else | ||
140 | evas_norender(ee->evas); | ||
141 | |||
142 | if (ee->func.fn_post_render) ee->func.fn_post_render(ee); | ||
143 | return rend; | ||
144 | } | ||
145 | |||
146 | static Eina_Bool | ||
147 | _ecore_evas_psl1ght_event(void *data __UNUSED__) | ||
148 | { | ||
149 | ecore_psl1ght_poll_events(); | ||
150 | return ECORE_CALLBACK_RENEW; | ||
151 | } | ||
152 | |||
153 | static int | ||
154 | _ecore_evas_psl1ght_init(int w __UNUSED__, int h __UNUSED__) | ||
155 | { | ||
156 | _ecore_evas_init_count++; | ||
157 | if (_ecore_evas_init_count > 1) return _ecore_evas_init_count; | ||
158 | |||
159 | _ecore_evas_fps_debug = 1; | ||
160 | |||
161 | // this is pretty bad: poller? and set poll time? pol time is meant to be | ||
162 | // adjustable for things like polling battery state, or amoutn of spare | ||
163 | // memory etc. | ||
164 | // | ||
165 | ecore_evas_event = ecore_poller_add(ECORE_POLLER_CORE, 1, _ecore_evas_psl1ght_event, NULL); | ||
166 | ecore_poller_poll_interval_set(ECORE_POLLER_CORE, 0.006); | ||
167 | |||
168 | if (_ecore_evas_fps_debug) | ||
169 | _ecore_evas_fps_debug_init(); | ||
170 | |||
171 | ecore_event_evas_init(); | ||
172 | |||
173 | ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_PSL1GHT_EVENT_GOT_FOCUS, _ecore_evas_psl1ght_event_got_focus, NULL); | ||
174 | ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_PSL1GHT_EVENT_LOST_FOCUS, _ecore_evas_psl1ght_event_lost_focus, NULL); | ||
175 | ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_PSL1GHT_EVENT_EXPOSE, _ecore_evas_psl1ght_event_video_expose, NULL); | ||
176 | ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_PSL1GHT_EVENT_KEY_MODIFIERS, _ecore_evas_psl1ght_event_key_modifiers, NULL); | ||
177 | |||
178 | return _ecore_evas_init_count; | ||
179 | } | ||
180 | |||
181 | static int | ||
182 | _ecore_evas_psl1ght_shutdown(void) | ||
183 | { | ||
184 | _ecore_evas_init_count--; | ||
185 | if (_ecore_evas_init_count == 0) | ||
186 | { | ||
187 | unsigned int i; | ||
188 | |||
189 | for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler *); i++) | ||
190 | ecore_event_handler_del(ecore_evas_event_handlers[i]); | ||
191 | ecore_event_evas_shutdown(); | ||
192 | ecore_poller_del(ecore_evas_event); | ||
193 | ecore_evas_event = NULL; | ||
194 | if (_ecore_evas_fps_debug) | ||
195 | _ecore_evas_fps_debug_shutdown(); | ||
196 | } | ||
197 | if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0; | ||
198 | return _ecore_evas_init_count; | ||
199 | } | ||
200 | |||
201 | static void | ||
202 | _ecore_evas_psl1ght_free(Ecore_Evas *ee) | ||
203 | { | ||
204 | if (psl1ght_ee == ee) psl1ght_ee = NULL; | ||
205 | |||
206 | ecore_event_window_unregister(0); | ||
207 | _ecore_evas_psl1ght_shutdown(); | ||
208 | ecore_psl1ght_shutdown(); | ||
209 | } | ||
210 | |||
211 | static void | ||
212 | _ecore_evas_screen_resized(Ecore_Evas *ee) | ||
213 | { | ||
214 | int w, h; | ||
215 | |||
216 | /* Do not resize if the window is not fullscreen */ | ||
217 | if (ee->prop.fullscreen == 0) return; | ||
218 | |||
219 | ecore_psl1ght_screen_resolution_get (&w, &h); | ||
220 | |||
221 | if (w != ee->w || h != ee->h) | ||
222 | { | ||
223 | ee->req.w = ee->w = w; | ||
224 | ee->req.h = ee->h = h; | ||
225 | evas_output_size_set(ee->evas, ee->w, ee->h); | ||
226 | evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h); | ||
227 | ecore_psl1ght_resolution_set (w, h); | ||
228 | evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h); | ||
229 | |||
230 | _ecore_evas_mouse_move_process(ee, ee->mouse.x, ee->mouse.y, | ||
231 | _ecore_evas_time_get()); | ||
232 | if (ee->func.fn_resize) ee->func.fn_resize(ee); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | static void | ||
237 | _ecore_evas_resize(Ecore_Evas *ee, int w, int h) | ||
238 | { | ||
239 | if ((w == ee->w) && (h == ee->h)) return; | ||
240 | ee->w = w; | ||
241 | ee->h = h; | ||
242 | |||
243 | evas_output_size_set(ee->evas, ee->w, ee->h); | ||
244 | |||
245 | evas_output_viewport_set(ee->evas, 0, 0, ee->w, ee->h); | ||
246 | evas_damage_rectangle_add(ee->evas, 0, 0, ee->w, ee->h); | ||
247 | |||
248 | ecore_psl1ght_resolution_set (w, h); | ||
249 | |||
250 | if (ee->func.fn_resize) ee->func.fn_resize(ee); | ||
251 | |||
252 | _ecore_evas_screen_resized (ee); | ||
253 | } | ||
254 | |||
255 | static void | ||
256 | _ecore_evas_move_resize(Ecore_Evas *ee, int x __UNUSED__, int y __UNUSED__, int w, int h) | ||
257 | { | ||
258 | _ecore_evas_resize (ee, w, h); | ||
259 | } | ||
260 | |||
261 | static void | ||
262 | _ecore_evas_show(Ecore_Evas *ee) | ||
263 | { | ||
264 | if (ee->prop.focused) return; | ||
265 | ee->prop.focused = 1; | ||
266 | evas_focus_in(ee->evas); | ||
267 | if (ee->func.fn_focus_in) ee->func.fn_focus_in(ee); | ||
268 | } | ||
269 | |||
270 | static void | ||
271 | _ecore_evas_screen_geometry_get(const Ecore_Evas *ee __UNUSED__, int *x, int *y, int *w, int *h) | ||
272 | { | ||
273 | if (x) *x = 0; | ||
274 | if (y) *y = 0; | ||
275 | ecore_psl1ght_screen_resolution_get (w, h); | ||
276 | } | ||
277 | |||
278 | static void | ||
279 | _ecore_evas_object_cursor_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) | ||
280 | { | ||
281 | Ecore_Evas *ee; | ||
282 | |||
283 | ee = data; | ||
284 | if (ee) | ||
285 | ee->prop.cursor.object = NULL; | ||
286 | } | ||
287 | |||
288 | static void | ||
289 | _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y) | ||
290 | { | ||
291 | int x, y; | ||
292 | |||
293 | if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object); | ||
294 | |||
295 | if (!obj) | ||
296 | { | ||
297 | ee->prop.cursor.object = NULL; | ||
298 | ee->prop.cursor.layer = 0; | ||
299 | ee->prop.cursor.hot.x = 0; | ||
300 | ee->prop.cursor.hot.y = 0; | ||
301 | return; | ||
302 | } | ||
303 | |||
304 | ee->prop.cursor.object = obj; | ||
305 | ee->prop.cursor.layer = layer; | ||
306 | ee->prop.cursor.hot.x = hot_x; | ||
307 | ee->prop.cursor.hot.y = hot_y; | ||
308 | evas_pointer_output_xy_get(ee->evas, &x, &y); | ||
309 | evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer); | ||
310 | evas_object_move(ee->prop.cursor.object, | ||
311 | x - ee->prop.cursor.hot.x, | ||
312 | y - ee->prop.cursor.hot.y); | ||
313 | evas_object_pass_events_set(ee->prop.cursor.object, 1); | ||
314 | if (evas_pointer_inside_get(ee->evas)) | ||
315 | evas_object_show(ee->prop.cursor.object); | ||
316 | |||
317 | evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee); | ||
318 | } | ||
319 | |||
320 | static Ecore_Evas_Engine_Func _ecore_psl1ght_engine_func = | ||
321 | { | ||
322 | _ecore_evas_psl1ght_free, | ||
323 | NULL, | ||
324 | NULL, | ||
325 | NULL, | ||
326 | NULL, | ||
327 | NULL, | ||
328 | NULL, | ||
329 | NULL, | ||
330 | NULL, | ||
331 | NULL, | ||
332 | NULL, | ||
333 | NULL, | ||
334 | NULL, | ||
335 | NULL, | ||
336 | NULL, | ||
337 | NULL, | ||
338 | NULL, | ||
339 | _ecore_evas_resize, | ||
340 | _ecore_evas_move_resize, | ||
341 | NULL, | ||
342 | NULL, | ||
343 | _ecore_evas_show, | ||
344 | NULL, | ||
345 | NULL, | ||
346 | NULL, | ||
347 | NULL, | ||
348 | NULL, | ||
349 | NULL, | ||
350 | NULL, | ||
351 | NULL, | ||
352 | NULL, | ||
353 | NULL, | ||
354 | _ecore_evas_object_cursor_set, | ||
355 | NULL, | ||
356 | NULL, | ||
357 | NULL, | ||
358 | NULL, | ||
359 | NULL, | ||
360 | NULL, | ||
361 | NULL, | ||
362 | NULL, | ||
363 | NULL, | ||
364 | NULL, | ||
365 | NULL, | ||
366 | NULL, | ||
367 | NULL, //transparent | ||
368 | |||
369 | NULL, // render | ||
370 | _ecore_evas_screen_geometry_get // screen_geometry_get | ||
371 | }; | ||
372 | |||
373 | EAPI Ecore_Evas * | ||
374 | ecore_evas_psl1ght_new(const char *name, int w, int h) | ||
375 | { | ||
376 | void *einfo; | ||
377 | Ecore_Evas *ee; | ||
378 | |||
379 | if (!name) | ||
380 | name = ecore_evas_psl1ght_default; | ||
381 | |||
382 | ee = calloc(1, sizeof(Ecore_Evas)); | ||
383 | if (!ee) return NULL; | ||
384 | |||
385 | ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS); | ||
386 | |||
387 | ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_psl1ght_engine_func; | ||
388 | |||
389 | ee->driver = "psl1ght"; | ||
390 | if (name) ee->name = strdup(name); | ||
391 | |||
392 | if (w < 1) w = 1; | ||
393 | if (h < 1) h = 1; | ||
394 | ee->visible = 1; | ||
395 | ee->w = w; | ||
396 | ee->h = h; | ||
397 | |||
398 | ee->prop.max.w = 0; | ||
399 | ee->prop.max.h = 0; | ||
400 | ee->prop.layer = 0; | ||
401 | ee->prop.focused = 1; | ||
402 | ee->prop.borderless = 1; | ||
403 | ee->prop.override = 1; | ||
404 | ee->prop.maximized = 1; | ||
405 | ee->prop.fullscreen = 0; | ||
406 | ee->prop.withdrawn = 0; | ||
407 | ee->prop.sticky = 0; | ||
408 | ee->prop.window = 0; | ||
409 | |||
410 | /* init evas here */ | ||
411 | ee->evas = evas_new(); | ||
412 | evas_data_attach_set(ee->evas, ee); | ||
413 | evas_output_method_set(ee->evas, evas_render_method_lookup("psl1ght")); | ||
414 | |||
415 | evas_output_size_set(ee->evas, w, h); | ||
416 | evas_output_viewport_set(ee->evas, 0, 0, w, h); | ||
417 | |||
418 | einfo = evas_engine_info_get(ee->evas); | ||
419 | if (einfo) | ||
420 | { | ||
421 | if (!evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo)) | ||
422 | { | ||
423 | ERR("evas_engine_info_set() for engine '%s' failed.", ee->driver); | ||
424 | ecore_evas_free(ee); | ||
425 | return NULL; | ||
426 | } | ||
427 | } | ||
428 | else | ||
429 | { | ||
430 | ERR("evas_engine_info_set() init engine '%s' failed.", ee->driver); | ||
431 | ecore_evas_free(ee); | ||
432 | return NULL; | ||
433 | } | ||
434 | |||
435 | if (!ecore_psl1ght_init(name)) | ||
436 | { | ||
437 | evas_free(ee->evas); | ||
438 | if (ee->name) free(ee->name); | ||
439 | free(ee); | ||
440 | return NULL; | ||
441 | } | ||
442 | ecore_psl1ght_resolution_set (w, h); | ||
443 | |||
444 | _ecore_evas_psl1ght_init(w, h); | ||
445 | |||
446 | ecore_event_window_register(0, ee, ee->evas, | ||
447 | (Ecore_Event_Mouse_Move_Cb)_ecore_evas_mouse_move_process, | ||
448 | (Ecore_Event_Multi_Move_Cb)_ecore_evas_mouse_multi_move_process, | ||
449 | (Ecore_Event_Multi_Down_Cb)_ecore_evas_mouse_multi_down_process, | ||
450 | (Ecore_Event_Multi_Up_Cb)_ecore_evas_mouse_multi_up_process); | ||
451 | |||
452 | ee->engine.func->fn_render = _ecore_evas_psl1ght_render; | ||
453 | _ecore_evas_register(ee); | ||
454 | |||
455 | psl1ght_ee = ee; | ||
456 | |||
457 | _ecore_evas_screen_resized (ee); | ||
458 | |||
459 | if (getenv("ECORE_EVAS_PSL1GHT_CURSOR_PATH")) | ||
460 | ecore_evas_cursor_set(ee, getenv("ECORE_EVAS_PSL1GHT_CURSOR_PATH"), EVAS_LAYER_MAX, 0, 0); | ||
461 | |||
462 | evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL); | ||
463 | |||
464 | return ee; | ||
465 | } | ||
466 | |||
467 | #else /* BUILD_ECORE_EVAS_PSL1GHT */ | ||
468 | |||
469 | EAPI Ecore_Evas * | ||
470 | ecore_evas_psl1ght_new(const char *name __UNUSED__, int w __UNUSED__, int h __UNUSED__) | ||
471 | { | ||
472 | ERR("OUTCH !"); | ||
473 | return NULL; | ||
474 | } | ||
475 | |||
476 | #endif /* BUILD_ECORE_EVAS_PSL1GHT */ | ||