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/evas/src/modules/engines/buffer/evas_engine.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 'libraries/evas/src/modules/engines/buffer/evas_engine.c')
-rw-r--r-- | libraries/evas/src/modules/engines/buffer/evas_engine.c | 403 |
1 files changed, 403 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/buffer/evas_engine.c b/libraries/evas/src/modules/engines/buffer/evas_engine.c new file mode 100644 index 0000000..e8dff7a --- /dev/null +++ b/libraries/evas/src/modules/engines/buffer/evas_engine.c | |||
@@ -0,0 +1,403 @@ | |||
1 | #include "evas_common.h" | ||
2 | #include "evas_private.h" | ||
3 | #include "evas_engine.h" | ||
4 | #include "Evas_Engine_Buffer.h" | ||
5 | |||
6 | /* domain for eina_log */ | ||
7 | /* the log macros are defined in evas_common.h */ | ||
8 | /* theirs names are EVAS_ERR, EVAS_DBG, EVAS_CRIT, EVAS_WRN and EVAS_INF */ | ||
9 | /* although we can use the EVAS_ERROR, etc... macros it will not work | ||
10 | when the -fvisibility=hidden option is passed to gcc */ | ||
11 | |||
12 | int _evas_engine_buffer_log_dom = -1; | ||
13 | |||
14 | /* function tables - filled in later (func and parent func) */ | ||
15 | |||
16 | static Evas_Func func, pfunc; | ||
17 | |||
18 | |||
19 | /* engine struct data */ | ||
20 | typedef struct _Render_Engine Render_Engine; | ||
21 | |||
22 | struct _Render_Engine | ||
23 | { | ||
24 | Tilebuf *tb; | ||
25 | Outbuf *ob; | ||
26 | Tilebuf_Rect *rects; | ||
27 | Eina_Inlist *cur_rect; | ||
28 | int end : 1; | ||
29 | }; | ||
30 | |||
31 | /* prototypes we will use here */ | ||
32 | static void *_output_setup(int w, int h, void *dest_buffer, int dest_buffer_row_bytes, int depth_type, int use_color_key, int alpha_threshold, int color_key_r, int color_key_g, int color_key_b, void *(*new_update_region) (int x, int y, int w, int h, int *row_bytes), void (*free_update_region) (int x, int y, int w, int h, void *data)); | ||
33 | |||
34 | static void *eng_info(Evas *e __UNUSED__); | ||
35 | static void eng_info_free(Evas *e __UNUSED__, void *info); | ||
36 | static int eng_setup(Evas *e, void *info); | ||
37 | static void eng_output_free(void *data); | ||
38 | static void eng_output_resize(void *data, int w, int h); | ||
39 | static void eng_output_tile_size_set(void *data, int w, int h); | ||
40 | static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h); | ||
41 | static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h); | ||
42 | static void eng_output_redraws_clear(void *data); | ||
43 | static void *eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch); | ||
44 | static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h); | ||
45 | static void eng_output_flush(void *data); | ||
46 | static void eng_output_idle_flush(void *data); | ||
47 | |||
48 | /* internal engine routines */ | ||
49 | static void * | ||
50 | _output_setup(int w, | ||
51 | int h, | ||
52 | void *dest_buffer, | ||
53 | int dest_buffer_row_bytes, | ||
54 | int depth_type, | ||
55 | int use_color_key, | ||
56 | int alpha_threshold, | ||
57 | int color_key_r, | ||
58 | int color_key_g, | ||
59 | int color_key_b, | ||
60 | void *(*new_update_region) (int x, int y, int w, int h, int *row_bytes), | ||
61 | void (*free_update_region) (int x, int y, int w, int h, void *data) | ||
62 | ) | ||
63 | { | ||
64 | Render_Engine *re; | ||
65 | |||
66 | re = calloc(1, sizeof(Render_Engine)); | ||
67 | if (!re) | ||
68 | return NULL; | ||
69 | /* if we haven't initialized - init (automatic abort if already done) */ | ||
70 | evas_common_cpu_init(); | ||
71 | |||
72 | evas_common_blend_init(); | ||
73 | evas_common_image_init(); | ||
74 | evas_common_convert_init(); | ||
75 | evas_common_scale_init(); | ||
76 | evas_common_rectangle_init(); | ||
77 | evas_common_polygon_init(); | ||
78 | evas_common_line_init(); | ||
79 | evas_common_font_init(); | ||
80 | evas_common_draw_init(); | ||
81 | evas_common_tilebuf_init(); | ||
82 | |||
83 | evas_buffer_outbuf_buf_init(); | ||
84 | |||
85 | { | ||
86 | Outbuf_Depth dep; | ||
87 | DATA32 color_key = 0; | ||
88 | |||
89 | dep = OUTBUF_DEPTH_BGR_24BPP_888_888; | ||
90 | if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_ARGB32) | ||
91 | dep = OUTBUF_DEPTH_ARGB_32BPP_8888_8888; | ||
92 | else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_RGB32) | ||
93 | dep = OUTBUF_DEPTH_RGB_32BPP_888_8888; | ||
94 | else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_BGRA32) | ||
95 | dep = OUTBUF_DEPTH_BGRA_32BPP_8888_8888; | ||
96 | else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_RGB24) | ||
97 | dep = OUTBUF_DEPTH_RGB_24BPP_888_888; | ||
98 | else if (depth_type == EVAS_ENGINE_BUFFER_DEPTH_BGR24) | ||
99 | dep = OUTBUF_DEPTH_BGR_24BPP_888_888; | ||
100 | R_VAL(&color_key) = color_key_r; | ||
101 | G_VAL(&color_key) = color_key_g; | ||
102 | B_VAL(&color_key) = color_key_b; | ||
103 | A_VAL(&color_key) = 0; | ||
104 | re->ob = evas_buffer_outbuf_buf_setup_fb(w, | ||
105 | h, | ||
106 | dep, | ||
107 | dest_buffer, | ||
108 | dest_buffer_row_bytes, | ||
109 | use_color_key, | ||
110 | color_key, | ||
111 | alpha_threshold, | ||
112 | new_update_region, | ||
113 | free_update_region); | ||
114 | } | ||
115 | re->tb = evas_common_tilebuf_new(w, h); | ||
116 | evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); | ||
117 | return re; | ||
118 | } | ||
119 | |||
120 | /* engine api this module provides */ | ||
121 | static void * | ||
122 | eng_info(Evas *e __UNUSED__) | ||
123 | { | ||
124 | Evas_Engine_Info_Buffer *info; | ||
125 | info = calloc(1, sizeof(Evas_Engine_Info_Buffer)); | ||
126 | if (!info) return NULL; | ||
127 | info->magic.magic = rand(); | ||
128 | info->render_mode = EVAS_RENDER_MODE_BLOCKING; | ||
129 | return info; | ||
130 | } | ||
131 | |||
132 | static void | ||
133 | eng_info_free(Evas *e __UNUSED__, void *info) | ||
134 | { | ||
135 | Evas_Engine_Info_Buffer *in; | ||
136 | in = (Evas_Engine_Info_Buffer *)info; | ||
137 | free(in); | ||
138 | } | ||
139 | |||
140 | static int | ||
141 | eng_setup(Evas *e, void *in) | ||
142 | { | ||
143 | Render_Engine *re; | ||
144 | Evas_Engine_Info_Buffer *info; | ||
145 | |||
146 | info = (Evas_Engine_Info_Buffer *)in; | ||
147 | re = _output_setup(e->output.w, | ||
148 | e->output.h, | ||
149 | info->info.dest_buffer, | ||
150 | info->info.dest_buffer_row_bytes, | ||
151 | info->info.depth_type, | ||
152 | info->info.use_color_key, | ||
153 | info->info.alpha_threshold, | ||
154 | info->info.color_key_r, | ||
155 | info->info.color_key_g, | ||
156 | info->info.color_key_b, | ||
157 | info->info.func.new_update_region, | ||
158 | info->info.func.free_update_region); | ||
159 | if (e->engine.data.output) | ||
160 | eng_output_free(e->engine.data.output); | ||
161 | e->engine.data.output = re; | ||
162 | if (!e->engine.data.output) return 0; | ||
163 | if (!e->engine.data.context) | ||
164 | e->engine.data.context = e->engine.func->context_new(e->engine.data.output); | ||
165 | return 1; | ||
166 | } | ||
167 | |||
168 | static void | ||
169 | eng_output_free(void *data) | ||
170 | { | ||
171 | Render_Engine *re; | ||
172 | |||
173 | re = (Render_Engine *)data; | ||
174 | evas_buffer_outbuf_buf_free(re->ob); | ||
175 | evas_common_tilebuf_free(re->tb); | ||
176 | if (re->rects) evas_common_tilebuf_free_render_rects(re->rects); | ||
177 | free(re); | ||
178 | |||
179 | evas_common_font_shutdown(); | ||
180 | evas_common_image_shutdown(); | ||
181 | } | ||
182 | |||
183 | static void | ||
184 | eng_output_resize(void *data, int w, int h) | ||
185 | { | ||
186 | Render_Engine *re; | ||
187 | |||
188 | re = (Render_Engine *)data; | ||
189 | { | ||
190 | int depth; | ||
191 | void *dest; | ||
192 | int dest_row_bytes; | ||
193 | int alpha_level; | ||
194 | DATA32 color_key; | ||
195 | char use_color_key; | ||
196 | void * (*new_update_region) (int x, int y, int w, int h, int *row_bytes); | ||
197 | void (*free_update_region) (int x, int y, int w, int h, void *data); | ||
198 | |||
199 | depth = re->ob->depth; | ||
200 | dest = re->ob->dest; | ||
201 | dest_row_bytes = re->ob->dest_row_bytes; | ||
202 | alpha_level = re->ob->alpha_level; | ||
203 | color_key = re->ob->color_key; | ||
204 | use_color_key = re->ob->use_color_key; | ||
205 | new_update_region = re->ob->func.new_update_region; | ||
206 | free_update_region = re->ob->func.free_update_region; | ||
207 | evas_buffer_outbuf_buf_free(re->ob); | ||
208 | re->ob = evas_buffer_outbuf_buf_setup_fb(w, | ||
209 | h, | ||
210 | depth, | ||
211 | dest, | ||
212 | dest_row_bytes, | ||
213 | use_color_key, | ||
214 | color_key, | ||
215 | alpha_level, | ||
216 | new_update_region, | ||
217 | free_update_region); | ||
218 | } | ||
219 | evas_common_tilebuf_free(re->tb); | ||
220 | re->tb = evas_common_tilebuf_new(w, h); | ||
221 | if (re->tb) | ||
222 | evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE); | ||
223 | } | ||
224 | |||
225 | static void | ||
226 | eng_output_tile_size_set(void *data, int w, int h) | ||
227 | { | ||
228 | Render_Engine *re; | ||
229 | |||
230 | re = (Render_Engine *)data; | ||
231 | evas_common_tilebuf_set_tile_size(re->tb, w, h); | ||
232 | } | ||
233 | |||
234 | static void | ||
235 | eng_output_redraws_rect_add(void *data, int x, int y, int w, int h) | ||
236 | { | ||
237 | Render_Engine *re; | ||
238 | |||
239 | re = (Render_Engine *)data; | ||
240 | evas_common_tilebuf_add_redraw(re->tb, x, y, w, h); | ||
241 | } | ||
242 | |||
243 | static void | ||
244 | eng_output_redraws_rect_del(void *data, int x, int y, int w, int h) | ||
245 | { | ||
246 | Render_Engine *re; | ||
247 | |||
248 | re = (Render_Engine *)data; | ||
249 | evas_common_tilebuf_del_redraw(re->tb, x, y, w, h); | ||
250 | } | ||
251 | |||
252 | static void | ||
253 | eng_output_redraws_clear(void *data) | ||
254 | { | ||
255 | Render_Engine *re; | ||
256 | |||
257 | re = (Render_Engine *)data; | ||
258 | evas_common_tilebuf_clear(re->tb); | ||
259 | } | ||
260 | |||
261 | static void * | ||
262 | eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch) | ||
263 | { | ||
264 | Render_Engine *re; | ||
265 | RGBA_Image *surface; | ||
266 | Tilebuf_Rect *rect; | ||
267 | int ux, uy, uw, uh; | ||
268 | |||
269 | re = (Render_Engine *)data; | ||
270 | if (re->end) | ||
271 | { | ||
272 | re->end = 0; | ||
273 | return NULL; | ||
274 | } | ||
275 | if (!re->rects) | ||
276 | { | ||
277 | re->rects = evas_common_tilebuf_get_render_rects(re->tb); | ||
278 | re->cur_rect = EINA_INLIST_GET(re->rects); | ||
279 | } | ||
280 | if (!re->cur_rect) return NULL; | ||
281 | rect = (Tilebuf_Rect *)re->cur_rect; | ||
282 | ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h; | ||
283 | re->cur_rect = re->cur_rect->next; | ||
284 | if (!re->cur_rect) | ||
285 | { | ||
286 | evas_common_tilebuf_free_render_rects(re->rects); | ||
287 | re->rects = NULL; | ||
288 | re->end = 1; | ||
289 | } | ||
290 | |||
291 | if ((ux + uw) > re->ob->w) uw = re->ob->w - ux; | ||
292 | if ((uy + uh) > re->ob->h) uh = re->ob->h - uy; | ||
293 | if ((uw <= 0) || (uh <= 0)) return NULL; | ||
294 | surface = evas_buffer_outbuf_buf_new_region_for_update(re->ob, | ||
295 | ux, uy, uw, uh, | ||
296 | cx, cy, cw, ch); | ||
297 | *x = ux; *y = uy; *w = uw; *h = uh; | ||
298 | return surface; | ||
299 | } | ||
300 | |||
301 | static void | ||
302 | eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h) | ||
303 | { | ||
304 | Render_Engine *re; | ||
305 | |||
306 | re = (Render_Engine *)data; | ||
307 | #ifdef BUILD_PIPE_RENDER | ||
308 | evas_common_pipe_map_begin(surface); | ||
309 | #endif | ||
310 | evas_buffer_outbuf_buf_push_updated_region(re->ob, surface, x, y, w, h); | ||
311 | evas_buffer_outbuf_buf_free_region_for_update(re->ob, surface); | ||
312 | evas_common_cpu_end_opt(); | ||
313 | } | ||
314 | |||
315 | static void | ||
316 | eng_output_flush(void *data) | ||
317 | { | ||
318 | Render_Engine *re; | ||
319 | |||
320 | re = (Render_Engine *)data; | ||
321 | } | ||
322 | |||
323 | static void | ||
324 | eng_output_idle_flush(void *data) | ||
325 | { | ||
326 | Render_Engine *re; | ||
327 | |||
328 | re = (Render_Engine *)data; | ||
329 | } | ||
330 | |||
331 | static Eina_Bool | ||
332 | eng_canvas_alpha_get(void *data, void *context __UNUSED__) | ||
333 | { | ||
334 | Render_Engine *re; | ||
335 | |||
336 | re = (Render_Engine *)data; | ||
337 | if (re->ob->priv.back_buf) | ||
338 | return re->ob->priv.back_buf->cache_entry.flags.alpha; | ||
339 | return EINA_TRUE; | ||
340 | } | ||
341 | |||
342 | /* module advertising code */ | ||
343 | static int | ||
344 | module_open(Evas_Module *em) | ||
345 | { | ||
346 | if (!em) return 0; | ||
347 | /* get whatever engine module we inherit from */ | ||
348 | if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0; | ||
349 | |||
350 | _evas_engine_buffer_log_dom = eina_log_domain_register | ||
351 | ("evas-buffer", EINA_COLOR_BLUE); | ||
352 | if (_evas_engine_buffer_log_dom < 0) | ||
353 | { | ||
354 | EINA_LOG_ERR("Can not create a module log domain."); | ||
355 | return 0; | ||
356 | } | ||
357 | |||
358 | /* store it for later use */ | ||
359 | func = pfunc; | ||
360 | /* now to override methods */ | ||
361 | #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_) | ||
362 | ORD(info); | ||
363 | ORD(info_free); | ||
364 | ORD(setup); | ||
365 | ORD(canvas_alpha_get); | ||
366 | ORD(output_free); | ||
367 | ORD(output_resize); | ||
368 | ORD(output_tile_size_set); | ||
369 | ORD(output_redraws_rect_add); | ||
370 | ORD(output_redraws_rect_del); | ||
371 | ORD(output_redraws_clear); | ||
372 | ORD(output_redraws_next_update_get); | ||
373 | ORD(output_redraws_next_update_push); | ||
374 | ORD(output_flush); | ||
375 | ORD(output_idle_flush); | ||
376 | /* now advertise out own api */ | ||
377 | em->functions = (void *)(&func); | ||
378 | return 1; | ||
379 | } | ||
380 | |||
381 | static void | ||
382 | module_close(Evas_Module *em __UNUSED__) | ||
383 | { | ||
384 | eina_log_domain_unregister(_evas_engine_buffer_log_dom); | ||
385 | } | ||
386 | |||
387 | static Evas_Module_Api evas_modapi = | ||
388 | { | ||
389 | EVAS_MODULE_API_VERSION, | ||
390 | "buffer", | ||
391 | "none", | ||
392 | { | ||
393 | module_open, | ||
394 | module_close | ||
395 | } | ||
396 | }; | ||
397 | |||
398 | EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, buffer); | ||
399 | |||
400 | #ifndef EVAS_STATIC_BUILD_BUFFER | ||
401 | EVAS_EINA_MODULE_DEFINE(engine, buffer); | ||
402 | #endif | ||
403 | |||