1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_Software_16_X11.h"
5 #include "evas_common_soft16.h"
7 /* function tables - filled in later (func and parent func) */
8 static Evas_Func func, pfunc;
10 /* engine struct data */
11 typedef struct _Render_Engine Render_Engine;
21 Tilebuf_Rect *cur_rect;
22 X_Output_Buffer *shbuf;
23 Soft16_Image *tmp_out; /* used by indirect render, like rotation */
25 unsigned char end : 1;
26 unsigned char shm : 1;
29 /* prototypes we will use here */
31 static void *eng_info(Evas *e);
32 static void eng_info_free(Evas *e, void *info);
33 static void eng_setup(Evas *e, void *info);
34 static void eng_output_free(void *data);
35 static void eng_output_resize(void *data, int w, int h);
36 static void eng_output_tile_size_set(void *data, int w, int h);
37 static void eng_output_redraws_rect_add(void *data, int x, int y, int w, int h);
38 static void eng_output_redraws_rect_del(void *data, int x, int y, int w, int h);
39 static void eng_output_redraws_clear(void *data);
40 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);
41 static void eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h);
42 static void eng_output_flush(void *data);
43 static void eng_output_idle_flush(void *data);
45 /* engine api this module provides */
49 Evas_Engine_Info_Software_16_X11 *info;
51 info = calloc(1, sizeof(Evas_Engine_Info_Software_16_X11));
52 if (!info) return NULL;
53 info->magic.magic = rand();
59 eng_info_free(Evas *e, void *info)
61 Evas_Engine_Info_Software_16_X11 *in;
63 in = (Evas_Engine_Info_Software_16_X11 *)info;
68 _tmp_out_alloc(Render_Engine *re)
73 for (r = re->rects; r; r = (Tilebuf_Rect *)(r->_list_data.next))
75 if (r->w > w) w = r->w;
76 if (r->h > h) h = r->h;
81 if ((re->tmp_out->cache_entry.w < w) || (re->tmp_out->cache_entry.h < h))
83 evas_cache_image_drop(&re->tmp_out->cache_entry);
92 im = (Soft16_Image *) evas_cache_image_empty(evas_common_soft16_image_cache_get());
93 im->cache_entry.flags.alpha = 0;
94 evas_cache_image_surface_alloc(&im->cache_entry, w, h);
102 eng_setup(Evas *e, void *in)
105 Evas_Engine_Info_Software_16_X11 *info;
106 /* X_Output_Buffer *xob; */
109 info = (Evas_Engine_Info_Software_16_X11 *)in;
110 if (!e->engine.data.output)
112 /* the only check - simplistic, i know, but enough for this
113 * "special purpose" engine. Remember it is meant to be used
114 * for limited power devices that have a 16bit display mode
115 * and no real other acceleration, and high resolution so we
116 * can pre-dither into 16bpp. */
117 // if (DefaultDepth(info->info.display,
118 // DefaultScreen(info->info.display)) != 16)
120 /* do common routine init - we wil at least use it for core
121 * image loading and font loading/glyph rendering & placement */
122 evas_common_cpu_init();
124 evas_common_blend_init();
125 evas_common_image_init();
126 evas_common_convert_init();
127 evas_common_scale_init();
128 evas_common_rectangle_init();
129 evas_common_gradient_init();
130 evas_common_polygon_init();
131 evas_common_line_init();
132 evas_common_font_init();
133 evas_common_draw_init();
134 evas_common_tilebuf_init();
135 evas_common_soft16_image_init();
137 /* render engine specific data */
138 re = calloc(1, sizeof(Render_Engine));
139 e->engine.data.output = re;
140 re->disp = info->info.display;
141 re->draw = info->info.drawable;
142 re->gc = XCreateGC(re->disp, re->draw, 0, &gcv);
145 re->rot = info->info.rotation;
146 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
148 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
152 /* we changed the info after first init - do a re-eval where
154 // if (DefaultDepth(info->info.display,
155 // DefaultScreen(info->info.display)) != 16)
157 re = e->engine.data.output;
158 if (re->tb) evas_common_tilebuf_free(re->tb);
159 re->disp = info->info.display;
160 re->draw = info->info.drawable;
161 XFreeGC(re->disp, re->gc);
162 re->gc = XCreateGC(re->disp, re->draw, 0, &gcv);
165 re->rot = info->info.rotation;
166 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
168 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
171 evas_cache_image_drop(&re->tmp_out->cache_entry);
175 if (!e->engine.data.output) return;
176 /* add a draw context if we dont have one */
177 if (!e->engine.data.context)
178 e->engine.data.context =
179 e->engine.func->context_new(e->engine.data.output);
180 /* check if the display can do shm */
181 re->shm = evas_software_x11_x_can_do_shm(re->disp);
185 eng_output_free(void *data)
189 re = (Render_Engine *)data;
190 if (re->shbuf) evas_software_x11_x_output_buffer_free(re->shbuf, 0);
191 if (re->clip_rects) XDestroyRegion(re->clip_rects);
192 if (re->gc) XFreeGC(re->disp, re->gc);
193 if (re->tb) evas_common_tilebuf_free(re->tb);
194 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
195 if (re->tmp_out) evas_cache_image_drop(&re->tmp_out->cache_entry);
198 evas_common_font_shutdown();
199 evas_common_image_shutdown();
200 evas_common_soft16_image_shutdown();
204 eng_output_resize(void *data, int w, int h)
208 re = (Render_Engine *)data;
210 if ((re->w == w) && (re->h == h)) return;
212 evas_common_tilebuf_free(re->tb);
215 re->tb = evas_common_tilebuf_new(w, h);
217 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
220 evas_software_x11_x_output_buffer_free(re->shbuf, 0);
225 XDestroyRegion(re->clip_rects);
226 re->clip_rects = NULL;
230 evas_cache_image_drop(&re->tmp_out->cache_entry);
236 eng_output_tile_size_set(void *data, int w, int h)
240 re = (Render_Engine *)data;
241 evas_common_tilebuf_set_tile_size(re->tb, w, h);
245 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
249 re = (Render_Engine *)data;
250 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
254 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
258 re = (Render_Engine *)data;
259 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
263 eng_output_redraws_clear(void *data)
267 re = (Render_Engine *)data;
268 evas_common_tilebuf_clear(re->tb);
272 _output_buffer_alloc(Render_Engine *re)
275 if (re->shbuf) return;
277 if ((re->rot == 0) || (re->rot == 180))
288 re->shbuf = evas_software_x11_x_output_buffer_new
289 (re->disp, DefaultVisual(re->disp, DefaultScreen(re->disp)),
290 DefaultDepth(re->disp, DefaultScreen(re->disp)),
295 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
301 re = (Render_Engine *)data;
309 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
310 if (!re->rects) return NULL;
312 re->cur_rect = re->rects;
313 _output_buffer_alloc(re);
314 if (re->rot != 0) _tmp_out_alloc(re); /* grows if required */
318 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
323 ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h;
324 re->cur_rect = (Tilebuf_Rect *)(re->cur_rect->_list_data.next);
327 evas_common_tilebuf_free_render_rects(re->rects);
332 *x = ux; *y = uy; *w = uw; *h = uh;
335 *cx = ux; *cy = uy; *cw = uw; *ch = uh;
336 return re->shbuf->im;
340 *cx = 0; *cy = 0; *cw = uw; *ch = uh;
346 _blit_rot_90(Soft16_Image *dst, const Soft16_Image *src,
347 int out_x, int out_y, int w, int h)
353 dp = dst->pixels + (out_x +
354 (w + out_y - 1) * dst->stride);
356 for (y = 0; y < h; y++)
358 DATA16 *dp_itr, *sp_itr;
363 for (x = 0; x < w; x++)
368 dp_itr -= dst->stride;
376 _blit_rot_180(Soft16_Image *dst, const Soft16_Image *src,
377 int out_x, int out_y, int w, int h)
383 dp = dst->pixels + ((w + out_x - 1) +
384 (h + out_y - 1) * dst->stride);
386 for (y = 0; y < h; y++)
388 DATA16 *dp_itr, *sp_itr;
393 for (x = 0; x < w; x++)
406 _blit_rot_270(Soft16_Image *dst, const Soft16_Image *src,
407 int out_x, int out_y, int w, int h)
413 dp = dst->pixels + ((h + out_x - 1) +
414 out_y * dst->stride);
416 for (y = 0; y < h; y++)
418 DATA16 *dp_itr, *sp_itr;
423 for (x = 0; x < w; x++)
428 dp_itr += dst->stride;
436 _tmp_out_process(Render_Engine *re, int out_x, int out_y, int w, int h)
445 if ((w < 1) || (h < 1) || (out_x >= d->cache_entry.w) || (out_y >= d->cache_entry.h))
449 _blit_rot_90(d, s, out_x, out_y, w, h);
450 else if (re->rot == 180)
451 _blit_rot_180(d, s, out_x, out_y, w, h);
452 else if (re->rot == 270)
453 _blit_rot_270(d, s, out_x, out_y, w, h);
457 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
462 re = (Render_Engine *)data;
465 re->clip_rects = XCreateRegion();
474 else if (re->rot == 90)
481 else if (re->rot == 180)
488 else if (re->rot == 270)
497 _tmp_out_process(re, r.x, r.y, w, h);
498 XUnionRectWithRegion(&r, re->clip_rects, re->clip_rects);
502 eng_output_flush(void *data)
507 re = (Render_Engine *)data;
510 XSetRegion(re->disp, re->gc, re->clip_rects);
511 XDestroyRegion(re->clip_rects);
512 re->clip_rects = NULL;
516 evas_software_x11_x_output_buffer_paste
517 (re->shbuf, re->draw, re->gc, 0, 0, re->shbuf->im->cache_entry.w, re->shbuf->im->cache_entry.h, 1);
518 XSetClipMask(re->disp, re->gc, None);
522 eng_output_idle_flush(void *data)
526 re = (Render_Engine *)data;
529 evas_software_x11_x_output_buffer_free(re->shbuf, 0);
534 XDestroyRegion(re->clip_rects);
535 re->clip_rects = NULL;
539 evas_cache_image_drop(&re->tmp_out->cache_entry);
545 /* module advertising code */
547 module_open(Evas_Module *em)
550 /* get whatever engine module we inherit from */
551 if (!_evas_module_engine_inherit(&pfunc, "software_16")) return 0;
552 /* store it for later use */
554 /* now to override methods */
555 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
561 ORD(output_tile_size_set);
562 ORD(output_redraws_rect_add);
563 ORD(output_redraws_rect_del);
564 ORD(output_redraws_clear);
565 ORD(output_redraws_next_update_get);
566 ORD(output_redraws_next_update_push);
568 ORD(output_idle_flush);
569 /* now advertise out own api */
570 em->functions = (void *)(&func);
579 EAPI Evas_Module_Api evas_modapi =
581 EVAS_MODULE_API_VERSION,
582 EVAS_MODULE_TYPE_ENGINE,