1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_Software_16_WinCE.h"
5 #include "evas_common_soft16.h"
7 int _evas_engine_soft16_wince_log_dom = -1;
12 EVAS_ENGINE_WINCE_GAPI,
13 EVAS_ENGINE_WINCE_DDRAW,
15 } Evas_Engine_WinCE_Backend;
18 /* function tables - filled in later (func and parent func) */
19 static Evas_Func func, pfunc;
21 /* engine struct data */
22 typedef struct _Render_Engine Render_Engine;
26 Evas_Engine_WinCE_Backend backend; /* 1: raw, 2: gapi, 3: ddraw, 4: GDI */
28 void (*backend_shutdown)(void *priv);
29 FB_Output_Buffer *(*backend_output_buffer_new)(void *priv,
32 void (*backend_output_buffer_free)(FB_Output_Buffer *fbob);
33 void (*backend_output_buffer_paste)(FB_Output_Buffer *fbob);
34 void (*backend_surface_resize)(FB_Output_Buffer *fbob);
41 Tilebuf_Rect *cur_rect;
42 FB_Output_Buffer *fbob;
43 Soft16_Image *tmp_out; /* used by indirect render, like rotation */
45 unsigned char end : 1;
48 /* prototypes we will use here */
50 static void *eng_info(Evas *e);
51 static void eng_info_free(Evas *e, void *info);
52 static int eng_setup(Evas *e, void *info);
53 static void eng_output_free(void *data);
54 static void eng_output_resize(void *data, int w, int h);
55 static void eng_output_tile_size_set(void *data, int w, int h);
56 static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h);
57 static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h);
58 static void eng_output_redraws_clear(void *data);
59 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);
60 static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h);
61 static void eng_output_flush(void *data);
62 static void eng_output_idle_flush(void *data);
70 return evas_software_wince_gapi_suspend();
71 default: /* other engines do not need it */
82 return evas_software_wince_gapi_resume();
83 default: /* other engines do not need it */
88 /* engine api this module provides */
92 Evas_Engine_Info_Software_16_WinCE *info;
93 info = calloc(1, sizeof(Evas_Engine_Info_Software_16_WinCE));
94 if (!info) return NULL;
95 info->magic.magic = rand();
96 info->func.suspend = _suspend;
97 info->func.resume = _resume;
98 info->render_mode = EVAS_RENDER_MODE_BLOCKING;
104 eng_info_free(Evas *e, void *info)
106 Evas_Engine_Info_Software_16_WinCE *in;
107 in = (Evas_Engine_Info_Software_16_WinCE *)info;
112 _tmp_out_alloc(Render_Engine *re)
117 EINA_INLIST_FOREACH(re->rects, r)
119 if (r->w > w) w = r->w;
120 if (r->h > h) h = r->h;
125 if ((re->tmp_out->cache_entry.w < w) || (re->tmp_out->cache_entry.h < h))
127 evas_cache_image_drop(&re->tmp_out->cache_entry);
136 im = (Soft16_Image *) evas_cache_image_empty(evas_common_soft16_image_cache_get());
137 im->cache_entry.flags.alpha = 0;
138 evas_cache_image_surface_alloc(&im->cache_entry, w, h);
146 eng_setup(Evas *e, void *in)
149 Evas_Engine_Info_Software_16_WinCE *info;
151 info = (Evas_Engine_Info_Software_16_WinCE *)in;
152 if (!e->engine.data.output)
154 /* do common routine init - we wil at least use it for core
155 * image loading and font loading/glyph rendering & placement */
156 evas_common_cpu_init();
158 evas_common_blend_init();
159 evas_common_image_init();
160 evas_common_convert_init();
161 evas_common_scale_init();
162 evas_common_rectangle_init();
163 evas_common_gradient_init();
164 evas_common_polygon_init();
165 evas_common_line_init();
166 evas_common_font_init();
167 evas_common_draw_init();
168 evas_common_tilebuf_init();
169 evas_common_soft16_image_init();
171 /* render engine specific data */
172 re = calloc(1, sizeof(Render_Engine));
175 e->engine.data.output = re;
177 switch(info->info.backend)
180 re->backend = EVAS_ENGINE_WINCE_FB;
181 re->backend_priv = evas_software_wince_fb_init(info->info.window, info->info.width, info->info.height);
182 if (!re->backend_priv)
187 re->backend_shutdown = evas_software_wince_fb_shutdown;
188 re->backend_output_buffer_new = evas_software_wince_fb_output_buffer_new;
189 re->backend_output_buffer_free = evas_software_wince_fb_output_buffer_free;
190 re->backend_output_buffer_paste = evas_software_wince_fb_output_buffer_paste;
191 re->backend_surface_resize = evas_software_wince_fb_surface_resize;
194 re->backend = EVAS_ENGINE_WINCE_GAPI;
195 re->backend_priv = evas_software_wince_gapi_init(info->info.window, info->info.width, info->info.height);
196 if (!re->backend_priv)
201 re->backend_shutdown = evas_software_wince_gapi_shutdown;
202 re->backend_output_buffer_new = evas_software_wince_gapi_output_buffer_new;
203 re->backend_output_buffer_free = evas_software_wince_gapi_output_buffer_free;
204 re->backend_output_buffer_paste = evas_software_wince_gapi_output_buffer_paste;
205 re->backend_surface_resize = evas_software_wince_gapi_surface_resize;
207 case 3: /* DirectDraw */
208 re->backend = EVAS_ENGINE_WINCE_DDRAW;
209 re->backend_priv = evas_software_wince_ddraw_init(info->info.window, info->info.width, info->info.height);
210 if (!re->backend_priv)
215 re->backend_shutdown = evas_software_wince_ddraw_shutdown;
216 re->backend_output_buffer_new = evas_software_wince_ddraw_output_buffer_new;
217 re->backend_output_buffer_free = evas_software_wince_ddraw_output_buffer_free;
218 re->backend_output_buffer_paste = evas_software_wince_ddraw_output_buffer_paste;
219 re->backend_surface_resize = evas_software_wince_ddraw_surface_resize;
222 re->backend = EVAS_ENGINE_WINCE_GDI;
223 re->backend_priv = evas_software_wince_gdi_init(info->info.window, info->info.width, info->info.height, info->info.fullscreen);
224 if (!re->backend_priv)
229 re->backend_shutdown = evas_software_wince_gdi_shutdown;
230 re->backend_output_buffer_new = evas_software_wince_gdi_output_buffer_new;
231 re->backend_output_buffer_free = evas_software_wince_gdi_output_buffer_free;
232 re->backend_output_buffer_paste = evas_software_wince_gdi_output_buffer_paste;
233 re->backend_surface_resize = evas_software_wince_gdi_surface_resize;
240 re->width = e->output.w;
241 re->height = e->output.h;
242 re->rotation = info->info.rotation;
243 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
245 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
249 re = e->engine.data.output;
250 if (re->tb) evas_common_tilebuf_free(re->tb);
252 switch(info->info.backend)
255 re->backend = EVAS_ENGINE_WINCE_FB;
256 re->backend_priv = evas_software_wince_fb_init(info->info.window, info->info.width, info->info.height);
257 if (!re->backend_priv)
262 re->backend_shutdown = evas_software_wince_fb_shutdown;
263 re->backend_output_buffer_new = evas_software_wince_fb_output_buffer_new;
264 re->backend_output_buffer_free = evas_software_wince_fb_output_buffer_free;
265 re->backend_output_buffer_paste = evas_software_wince_fb_output_buffer_paste;
266 re->backend_surface_resize = evas_software_wince_fb_surface_resize;
269 re->backend = EVAS_ENGINE_WINCE_GAPI;
270 re->backend_priv = evas_software_wince_gapi_init(info->info.window, info->info.width, info->info.height);
271 if (!re->backend_priv)
276 re->backend_shutdown = evas_software_wince_gapi_shutdown;
277 re->backend_output_buffer_new = evas_software_wince_gapi_output_buffer_new;
278 re->backend_output_buffer_free = evas_software_wince_gapi_output_buffer_free;
279 re->backend_output_buffer_paste = evas_software_wince_gapi_output_buffer_paste;
280 re->backend_surface_resize = evas_software_wince_gapi_surface_resize;
282 case 3: /* DirectDraw */
283 re->backend = EVAS_ENGINE_WINCE_DDRAW;
284 re->backend_priv = evas_software_wince_ddraw_init(info->info.window, info->info.width, info->info.height);
285 if (!re->backend_priv)
290 re->backend_shutdown = evas_software_wince_ddraw_shutdown;
291 re->backend_output_buffer_new = evas_software_wince_ddraw_output_buffer_new;
292 re->backend_output_buffer_free = evas_software_wince_ddraw_output_buffer_free;
293 re->backend_output_buffer_paste = evas_software_wince_ddraw_output_buffer_paste;
294 re->backend_surface_resize = evas_software_wince_ddraw_surface_resize;
297 re->backend = EVAS_ENGINE_WINCE_GDI;
298 re->backend_priv = evas_software_wince_gdi_init(info->info.window, info->info.width, info->info.height, info->info.fullscreen);
299 if (!re->backend_priv)
304 re->backend_shutdown = evas_software_wince_gdi_shutdown;
305 re->backend_output_buffer_new = evas_software_wince_gdi_output_buffer_new;
306 re->backend_output_buffer_free = evas_software_wince_gdi_output_buffer_free;
307 re->backend_output_buffer_paste = evas_software_wince_gdi_output_buffer_paste;
308 re->backend_surface_resize = evas_software_wince_gdi_surface_resize;
315 re->width = e->output.w;
316 re->height = e->output.h;
317 re->rotation = info->info.rotation;
318 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
320 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
323 evas_cache_image_drop(&re->tmp_out->cache_entry);
327 if (!e->engine.data.output) return 0;
328 /* add a draw context if we dont have one */
329 if (!e->engine.data.context)
330 e->engine.data.context =
331 e->engine.func->context_new(e->engine.data.output);
337 eng_output_free(void *data)
341 re = (Render_Engine *)data;
342 if (re->fbob) re->backend_output_buffer_free(re->backend_priv);
343 re->backend_shutdown(re->backend_priv);
344 if (re->clip_rects) DeleteObject(re->clip_rects);
345 if (re->tb) evas_common_tilebuf_free(re->tb);
346 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
347 if (re->tmp_out) evas_cache_image_drop(&re->tmp_out->cache_entry);
350 evas_common_font_shutdown();
351 evas_common_image_shutdown();
352 evas_common_soft16_image_shutdown();
356 eng_output_resize(void *data, int w, int h)
360 re = (Render_Engine *)data;
362 if ((re->width == w) && (re->height == h)) return;
364 /* FIXME: is it needed ?? */
366 re->backend_surface_resize(re->fbob);
368 evas_common_tilebuf_free(re->tb);
371 re->tb = evas_common_tilebuf_new(w, h);
373 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
376 re->backend_output_buffer_free(re->fbob);
381 DeleteObject(re->clip_rects);
382 re->clip_rects = NULL;
386 evas_cache_image_drop(&re->tmp_out->cache_entry);
392 eng_output_tile_size_set(void *data, int w, int h)
396 re = (Render_Engine *)data;
397 evas_common_tilebuf_set_tile_size(re->tb, w, h);
401 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
405 re = (Render_Engine *)data;
406 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
410 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
414 re = (Render_Engine *)data;
415 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
419 eng_output_redraws_clear(void *data)
423 re = (Render_Engine *)data;
424 evas_common_tilebuf_clear(re->tb);
428 _output_buffer_alloc(Render_Engine *re)
433 if (re->fbob) return;
435 if ((re->rotation == 0) || (re->rotation == 180))
446 re->fbob = re->backend_output_buffer_new(re->backend_priv,
452 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
458 re = (Render_Engine *)data;
466 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
467 if (!re->rects) return NULL;
469 re->cur_rect = re->rects;
470 _output_buffer_alloc(re);
471 if (re->rotation != 0) _tmp_out_alloc(re); /* grows if required */
475 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
480 ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h;
481 re->cur_rect = (Tilebuf_Rect *)((EINA_INLIST_GET(re->cur_rect))->next);
484 evas_common_tilebuf_free_render_rects(re->rects);
489 *x = ux; *y = uy; *w = uw; *h = uh;
490 if (re->rotation == 0)
492 *cx = ux; *cy = uy; *cw = uw; *ch = uh;
497 *cx = 0; *cy = 0; *cw = uw; *ch = uh;
503 _blit_rot_90(Soft16_Image *dst, const Soft16_Image *src,
504 int out_x, int out_y, int w, int h)
510 dp = dst->pixels + (out_x +
511 (w + out_y - 1) * dst->stride);
513 for (y = 0; y < h; y++)
515 DATA16 *dp_itr, *sp_itr;
520 for (x = 0; x < w; x++)
525 dp_itr -= dst->stride;
533 _blit_rot_180(Soft16_Image *dst, const Soft16_Image *src,
534 int out_x, int out_y, int w, int h)
540 dp = dst->pixels + ((w + out_x - 1) +
541 (h + out_y - 1) * dst->stride);
543 for (y = 0; y < h; y++)
545 DATA16 *dp_itr, *sp_itr;
550 for (x = 0; x < w; x++)
563 _blit_rot_270(Soft16_Image *dst, const Soft16_Image *src,
564 int out_x, int out_y, int w, int h)
570 dp = dst->pixels + ((h + out_x - 1) +
571 out_y * dst->stride);
573 for (y = 0; y < h; y++)
575 DATA16 *dp_itr, *sp_itr;
580 for (x = 0; x < w; x++)
585 dp_itr += dst->stride;
593 _tmp_out_process(Render_Engine *re, int out_x, int out_y, int w, int h)
600 if ((w < 1) || (h < 1) || (out_x >= d->cache_entry.w) || (out_y >= d->cache_entry.h))
603 if (re->rotation == 90)
604 _blit_rot_90(d, s, out_x, out_y, w, h);
605 else if (re->rotation == 180)
606 _blit_rot_180(d, s, out_x, out_y, w, h);
607 else if (re->rotation == 270)
608 _blit_rot_270(d, s, out_x, out_y, w, h);
612 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
621 re = (Render_Engine *)data;
624 re->clip_rects = CreateRectRgn(0, 0, 0, 0);
626 if (re->rotation == 0)
633 else if (re->rotation == 90)
636 yy = re->width - w - x;
640 else if (re->rotation == 180)
642 xx = re->width - w - x;
643 yy = re->height - h - y;
647 else if (re->rotation == 270)
649 xx = re->height - h - y;
655 region = CreateRectRgn(xx, yy, xx + width, yy + height);
657 if (re->rotation != 0)
658 _tmp_out_process(re, xx, yy, w, h);
659 CombineRgn(re->clip_rects, re->clip_rects, region, RGN_OR);
663 eng_output_flush(void *data)
667 re = (Render_Engine *)data;
670 /* FIXME : i have to manage that */
671 /* XSetRegion(re->disp, re->gc, re->clip_rects); */
672 DeleteObject(re->clip_rects);
673 re->clip_rects = NULL;
677 re->backend_output_buffer_paste(re->fbob);
679 /* FIXME : i have to manage that */
680 /* XSetClipMask(re->disp, re->gc, None); */
684 eng_output_idle_flush(void *data)
688 re = (Render_Engine *)data;
691 re->backend_output_buffer_free(re->fbob);
696 DeleteObject(re->clip_rects);
697 re->clip_rects = NULL;
701 evas_cache_image_drop(&re->tmp_out->cache_entry);
707 eng_canvas_alpha_get(void *data, void *context)
712 /* module advertising code */
714 module_open(Evas_Module *em)
717 /* get whatever engine module we inherit from */
718 if (!_evas_module_engine_inherit(&pfunc, "software_16")) return 0;
719 _evas_engine_soft16_wince_log_dom = eina_log_domain_register("EvasSoft16Wince", EVAS_DEFAULT_LOG_COLOR);
721 if(_evas_engine_soft16_wince_log_dom < 0)
723 EINA_LOG_ERR("Impossible to create a log domain for the Soft16 Wince engine.");
727 /* store it for later use */
729 /* now to override methods */
730 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
734 ORD(canvas_alpha_get);
737 ORD(output_tile_size_set);
738 ORD(output_redraws_rect_add);
739 ORD(output_redraws_rect_del);
740 ORD(output_redraws_clear);
741 ORD(output_redraws_next_update_get);
742 ORD(output_redraws_next_update_push);
744 ORD(output_idle_flush);
745 /* now advertise out own api */
746 em->functions = (void *)(&func);
751 module_close(Evas_Module *em)
753 eina_log_domain_unregister(_evas_engine_soft16_wince_log_dom);
756 static Evas_Module_Api evas_modapi =
758 EVAS_MODULE_API_VERSION,
767 EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_16_wince);
769 #ifndef EVAS_STATIC_BUILD_SOFTWARE_16_WINCE
770 EVAS_EINA_MODULE_DEFINE(engine, software_16_wince);