1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "evas_engine.h"
4 #include "Evas_Engine_XRender_Xcb.h"
6 /* function tables - filled in later (func and parent func) */
7 static Evas_Func func, pfunc;
9 /* engine struct data */
10 typedef struct _Render_Engine Render_Engine;
11 typedef struct _Render_Engine_Update Render_Engine_Update;
13 struct _Render_Engine_Update
19 Xcb_Render_Surface *surface;
24 xcb_connection_t *conn;
28 unsigned char destination_alpha : 1;
30 Xcb_Image_Info *xcbinf;
31 Xcb_Render_Surface *output;
32 Xcb_Render_Surface *mask_output;
36 Evas_Object_List *cur_rect;
42 /* internal engine routines */
44 /* engine api this module provides */
49 Evas_Engine_Info_XRender_Xcb *info;
51 info = calloc(1, sizeof(Evas_Engine_Info_XRender_Xcb));
52 if (!info) return NULL;
53 info->magic.magic = rand();
59 eng_info_free(Evas *e, void *info)
61 Evas_Engine_Info_XRender_Xcb *in;
63 in = (Evas_Engine_Info_XRender_Xcb *)info;
67 eng_setup(Evas *e, void *in)
70 Evas_Engine_Info_XRender_Xcb *info;
73 info = (Evas_Engine_Info_XRender_Xcb *)in;
74 if (!e->engine.data.output)
76 re = calloc(1, sizeof(Render_Engine));
77 evas_common_cpu_init();
78 evas_common_blend_init();
79 evas_common_image_init();
80 evas_common_convert_init();
81 evas_common_scale_init();
82 evas_common_rectangle_init();
83 evas_common_gradient_init();
84 evas_common_polygon_init();
85 evas_common_line_init();
86 evas_common_font_init();
87 evas_common_draw_init();
88 evas_common_tilebuf_init();
89 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
91 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
92 e->engine.data.output = re;
95 re = e->engine.data.output;
98 if (!e->engine.data.context) e->engine.data.context = e->engine.func->context_new(e->engine.data.output);
100 re->conn = info->info.conn;
101 re->vis = info->info.visual;
102 re->win = info->info.drawable;
103 re->mask = info->info.mask;
104 re->destination_alpha = info->info.destination_alpha;
106 if (re->xcbinf) _xr_image_info_free(re->xcbinf);
107 re->xcbinf = _xr_image_info_get(re->conn, re->win, re->vis);
109 if (re->output) _xr_render_surface_free(re->output);
110 if (re->mask_output) _xr_render_surface_free(re->mask_output);
112 re->output = _xr_render_surface_adopt(re->xcbinf, re->win, e->output.w, e->output.h, re->destination_alpha);
114 re->output = _xr_render_surface_adopt(re->xcbinf, re->win, e->output.w, e->output.h, 0);
119 re->mask_output = _xr_render_surface_format_adopt(re->xcbinf, draw,
120 e->output.w, e->output.h,
121 re->xcbinf->fmt1, 1);
124 re->mask_output = NULL;
127 if (re->tb) evas_common_tilebuf_free(re->tb);
128 if ((e->output.w > 0) && (e->output.h > 0))
129 re->tb = evas_common_tilebuf_new(e->output.w, e->output.h);
131 re->tb = evas_common_tilebuf_new(1, 1);
133 evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
138 eng_output_free(void *data)
142 re = (Render_Engine *)data;
143 evas_common_font_shutdown();
144 evas_common_image_shutdown();
147 Render_Engine_Update *reu;
149 reu = re->updates->data;
150 re->updates = evas_list_remove_list(re->updates, re->updates);
151 _xr_render_surface_free(reu->surface);
154 if (re->tb) evas_common_tilebuf_free(re->tb);
155 if (re->output) _xr_render_surface_free(re->output);
156 if (re->mask_output) _xr_render_surface_free(re->mask_output);
157 if (re->rects) evas_common_tilebuf_free_render_rects(re->rects);
158 if (re->xcbinf) _xr_image_info_free(re->xcbinf);
163 eng_output_resize(void *data, int w, int h)
167 re = (Render_Engine *)data;
170 if ((re->output->w == w) && (re->output->h ==h)) return;
171 if (re->output) _xr_render_surface_free(re->output);
173 re->output = _xr_render_surface_adopt(re->xcbinf, re->win, w, h, 0);
178 if (re->mask_output) _xr_render_surface_free(re->mask_output);
180 re->mask_output = _xr_render_surface_format_adopt(re->xcbinf, draw,
182 re->xcbinf->fmt1, 1);
184 evas_common_tilebuf_free(re->tb);
185 re->tb = evas_common_tilebuf_new(w, h);
186 if (re->tb) evas_common_tilebuf_set_tile_size(re->tb, TILESIZE, TILESIZE);
190 eng_output_tile_size_set(void *data, int w, int h)
194 re = (Render_Engine *)data;
195 evas_common_tilebuf_set_tile_size(re->tb, w, h);
199 eng_output_redraws_rect_add(void *data, int x, int y, int w, int h)
203 re = (Render_Engine *)data;
204 evas_common_tilebuf_add_redraw(re->tb, x, y, w, h);
208 eng_output_redraws_rect_del(void *data, int x, int y, int w, int h)
212 re = (Render_Engine *)data;
213 evas_common_tilebuf_del_redraw(re->tb, x, y, w, h);
217 eng_output_redraws_clear(void *data)
221 re = (Render_Engine *)data;
222 evas_common_tilebuf_clear(re->tb);
226 eng_output_redraws_next_update_get(void *data, int *x, int *y, int *w, int *h, int *cx, int *cy, int *cw, int *ch)
232 re = (Render_Engine *)data;
240 re->rects = evas_common_tilebuf_get_render_rects(re->tb);
241 re->cur_rect = (Evas_Object_List *)re->rects;
243 if (!re->cur_rect) return NULL;
244 rect = (Tilebuf_Rect *)re->cur_rect;
245 ux = rect->x; uy = rect->y; uw = rect->w; uh = rect->h;
246 re->cur_rect = re->cur_rect->next;
249 evas_common_tilebuf_free_render_rects(re->rects);
254 *x = ux; *y = uy; *w = uw; *h = uh;
255 *cx = 0; *cy = 0; *cw = uw; *ch = uh;
256 if ((re->destination_alpha) || (re->mask))
258 Xcb_Render_Surface *surface;
260 surface = _xr_render_surface_new(re->xcbinf, uw, uh, re->xcbinf->fmt32, 1);
261 _xr_render_surface_solid_rectangle_set(surface, 0, 0, 0, 0, 0, 0, uw, uh);
264 return _xr_render_surface_new(re->xcbinf, uw, uh, re->xcbinf->fmt24, 0);
268 eng_output_redraws_next_update_push(void *data, void *surface, int x, int y, int w, int h)
271 Render_Engine_Update *reu;
273 re = (Render_Engine *)data;
274 reu = malloc(sizeof(Render_Engine_Update));
280 reu->surface = (Xcb_Render_Surface *)surface;
281 re->updates = evas_list_append(re->updates, reu);
285 eng_output_flush(void *data)
288 xcb_get_input_focus_reply_t *reply;
290 re = (Render_Engine *)data;
293 Render_Engine_Update *reu;
295 reu = re->updates->data;
296 re->updates = evas_list_remove_list(re->updates, re->updates);
299 Xcb_Render_Surface *tsurf;
301 _xr_render_surface_copy(reu->surface, re->output, 0, 0,
302 reu->x, reu->y, reu->w, reu->h);
303 tsurf = _xr_render_surface_new(re->xcbinf, reu->w, reu->h, re->xcbinf->fmt1, 1);
306 _xr_render_surface_copy(reu->surface, tsurf, 0, 0,
307 0, 0, reu->w, reu->h);
308 _xr_render_surface_copy(tsurf, re->mask_output, 0, 0,
309 reu->x, reu->y, reu->w, reu->h);
310 _xr_render_surface_free(tsurf);
315 _xr_render_surface_copy(reu->surface, re->output, 0, 0,
316 reu->x, reu->y, reu->w, reu->h);
318 _xr_render_surface_free(reu->surface);
322 reply = xcb_get_input_focus_reply(re->conn,
323 xcb_get_input_focus_unchecked(re->conn),
326 _xr_image_info_pool_flush(re->xcbinf, 0, 0);
330 eng_output_idle_flush(void *data)
334 re = (Render_Engine *)data;
338 eng_rectangle_draw(void *data, void *context, void *surface, int x, int y, int w, int h)
340 _xr_render_surface_rectangle_draw((Xcb_Render_Surface *)surface,
341 (RGBA_Draw_Context *)context,
346 eng_line_draw(void *data, void *context, void *surface, int x1, int y1, int x2, int y2)
348 _xr_render_surface_line_draw((Xcb_Render_Surface *)surface, (RGBA_Draw_Context *)context, x1, y1, x2, y2);
352 eng_polygon_draw(void *data, void *context, void *surface, void *polygon)
354 _xre_poly_draw((Xcb_Render_Surface *)surface, (RGBA_Draw_Context *)context, (RGBA_Polygon_Point *)polygon);
358 eng_gradient_new(void *data)
360 Render_Engine *re = (Render_Engine *)data;
362 return _xre_gradient_new(re->xcbinf);
366 eng_gradient_free(void *data, void *gradient)
368 _xre_gradient_free(gradient);
372 eng_gradient_color_stop_add(void *data, void *gradient, int r, int g, int b, int a, int delta)
374 _xre_gradient_color_stop_add(gradient, r, g, b, a, delta);
378 eng_gradient_alpha_stop_add(void *data, void *gradient, int a, int delta)
380 _xre_gradient_alpha_stop_add(gradient, a, delta);
384 eng_gradient_color_data_set(void *data, void *gradient, void *map, int len, int has_alpha)
386 _xre_gradient_color_data_set(gradient, map, len, has_alpha);
390 eng_gradient_alpha_data_set(void *data, void *gradient, void *alpha_map, int len)
392 _xre_gradient_alpha_data_set(gradient, alpha_map, len);
396 eng_gradient_clear(void *data, void *gradient)
398 _xre_gradient_clear(gradient);
402 eng_gradient_fill_set(void *data, void *gradient, int x, int y, int w, int h)
404 _xre_gradient_fill_set(gradient, x, y, w, h);
408 eng_gradient_fill_angle_set(void *data, void *gradient, double angle)
410 _xre_gradient_fill_angle_set(gradient, angle);
414 eng_gradient_fill_spread_set(void *data, void *gradient, int spread)
416 _xre_gradient_fill_spread_set(gradient, spread);
420 eng_gradient_angle_set(void *data, void *gradient, double angle)
422 _xre_gradient_angle_set(gradient, angle);
426 eng_gradient_offset_set(void *data, void *gradient, float offset)
428 _xre_gradient_offset_set(gradient, offset);
432 eng_gradient_direction_set(void *data, void *gradient, int direction)
434 _xre_gradient_direction_set(gradient, direction);
438 eng_gradient_type_set(void *data, void *gradient, char *name, char *params)
440 _xre_gradient_type_set(gradient, name, params);
444 eng_gradient_is_opaque(void *data, void *context, void *gradient, int x, int y, int w, int h)
447 RGBA_Draw_Context *dc = (RGBA_Draw_Context *)context;
449 if (!dc || !gradient) return 0;
450 grad = ((XR_Gradient *)gradient)->grad;
451 if(!grad || !grad->type.geometer) return 0;
452 return !(grad->type.geometer->has_alpha(grad, dc->render_op) |
453 grad->type.geometer->has_mask(grad, dc->render_op));
457 eng_gradient_is_visible(void *data, void *context, void *gradient, int x, int y, int w, int h)
459 if (!context || !gradient) return 0;
464 eng_gradient_render_pre(void *data, void *context, void *gradient)
469 if (!context || !gradient) return;
470 grad = ((XR_Gradient *)gradient)->grad;
471 if(!grad || !grad->type.geometer) return;
472 grad->type.geometer->geom_set(grad);
473 len = grad->type.geometer->get_map_len(grad);
474 evas_common_gradient_map(context, grad, len);
478 eng_gradient_render_post(void *data, void *gradient)
483 eng_gradient_draw(void *data, void *context, void *surface, void *gradient, int x, int y, int w, int h)
485 _xre_gradient_draw(surface, context, gradient, x, y, w, h);
489 eng_image_load(void *data, const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo)
494 re = (Render_Engine *)data;
496 im = _xre_image_load(re->xcbinf, file, key, lo);
501 eng_image_new_from_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
506 re = (Render_Engine *)data;
507 im = _xre_image_new_from_data(re->xcbinf, w, h, image_data);
512 eng_image_new_from_copied_data(void *data, int w, int h, DATA32 *image_data, int alpha, int cspace)
517 re = (Render_Engine *)data;
518 im = _xre_image_new_from_copied_data(re->xcbinf, w, h, image_data);
523 eng_image_free(void *data, void *image)
526 _xre_image_free((XR_Image *)image);
530 eng_image_size_get(void *data, void *image, int *w, int *h)
533 if (w) *w = ((XR_Image *)image)->w;
534 if (h) *h = ((XR_Image *)image)->h;
538 eng_image_size_set(void *data, void *image, int w, int h)
540 if (!image) return image;
541 if ((w <= 0) || (h <= 0))
543 _xre_image_free((XR_Image *)image);
546 if (((XR_Image *)image)->references > 1)
550 old_image = (XR_Image *)image;
551 image = _xre_image_copy((XR_Image *)old_image);
554 ((XR_Image *)image)->alpha = old_image->alpha;
555 _xre_image_free(old_image);
561 _xre_image_dirty((XR_Image *)image);
562 _xre_image_resize((XR_Image *)image, w, h);
567 eng_image_dirty_region(void *data, void *image, int x, int y, int w, int h)
569 if (!image) return image;
570 _xre_image_dirty((XR_Image *)image);
571 _xre_image_region_dirty((XR_Image *)image, x, y, w, h);
576 eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data)
578 if (!image) return image;
581 if (((XR_Image *)image)->references > 1)
585 old_image = (XR_Image *)image;
586 image = _xre_image_copy((XR_Image *)old_image);
589 ((XR_Image *)image)->alpha = old_image->alpha;
590 _xre_image_free(old_image);
596 _xre_image_dirty((XR_Image *)image);
598 if (image_data) *image_data = _xre_image_data_get((XR_Image *)image);
603 eng_image_data_put(void *data, void *image, DATA32 *image_data)
605 if (!image) return image;
606 if (_xre_image_data_get((XR_Image *)image) != image_data)
610 old_image = (XR_Image *)image;
611 image = _xre_image_data_find(image_data);
612 if (image != old_image)
616 image = _xre_image_new_from_data(old_image->xcbinf, old_image->w, old_image->h, image_data);
619 ((XR_Image *)image)->alpha = old_image->alpha;
620 _xre_image_free(old_image);
627 _xre_image_free(old_image);
632 _xre_image_free(image);
639 eng_image_alpha_set(void *data, void *image, int has_alpha)
641 if (!image) return image;
642 if (((((XR_Image *)image)->alpha) && (has_alpha)) ||
643 ((!((XR_Image *)image)->alpha) && (!has_alpha)))
645 if (((XR_Image *)image)->references > 1)
649 old_image = (XR_Image *)image;
650 image = _xre_image_copy((XR_Image *)old_image);
653 ((XR_Image *)image)->alpha = old_image->alpha;
654 _xre_image_free(old_image);
660 _xre_image_dirty((XR_Image *)image);
661 _xre_image_alpha_set((XR_Image *)image, has_alpha);
666 eng_image_alpha_get(void *data, void *image)
668 if (!image) return 0;
669 return _xre_image_alpha_get((XR_Image *)image);
673 eng_image_border_set(void *data, void *image, int l, int r, int t, int b)
675 if (!image) return image;
676 _xre_image_border_set((XR_Image *)image, l, r, t, b);
681 eng_image_border_get(void *data, void *image, int *l, int *r, int *t, int *b)
684 _xre_image_border_get((XR_Image *)image, l, r, t, b);
688 eng_image_draw(void *data, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth)
690 if ((!image) || (!surface)) return;
691 _xre_image_surface_gen((XR_Image *)image);
692 if (((XR_Image *)image)->surface)
693 _xr_render_surface_composite(((XR_Image *)image)->surface,
694 (Xcb_Render_Surface *)surface,
695 (RGBA_Draw_Context *)context,
696 src_x, src_y, src_w, src_h,
697 dst_x, dst_y, dst_w, dst_h,
702 eng_image_comment_get(void *data, void *image, char *key)
704 if (!image) return NULL;
705 return ((XR_Image *)image)->comment;
709 eng_image_format_get(void *data, void *image)
711 if (!image) return NULL;
712 return ((XR_Image *)image)->format;
716 eng_image_colorspace_set(void *data, void *image, int cspace)
721 eng_image_colorspace_get(void *data, void *image)
723 return EVAS_COLORSPACE_ARGB8888;
727 eng_image_native_set(void *data, void *image, void *native)
732 eng_image_native_get(void *data, void *image)
738 eng_image_cache_flush(void *data)
742 tmp_size = _xre_image_cache_get();
743 pfunc.image_cache_flush(data);
744 _xre_image_cache_set(0);
745 _xre_image_cache_set(tmp_size);
749 eng_image_cache_set(void *data, int bytes)
751 pfunc.image_cache_set(data, bytes);
752 _xre_image_cache_set(bytes);
756 eng_image_cache_get(void *data)
758 return pfunc.image_cache_get(data);
762 eng_font_draw(void *data, void *context, void *surface, void *font, int x, int y, int w, int h, int ow, int oh, const char *text)
767 re = (Render_Engine *)data;
769 im = (RGBA_Image *) evas_cache_image_data(evas_common_image_cache_get(),
770 ((Xcb_Render_Surface *)surface)->w,
771 ((Xcb_Render_Surface *)surface)->h,
773 0, EVAS_COLORSPACE_ARGB8888);
775 _xr_render_surface_clips_set((Xcb_Render_Surface *)surface, (RGBA_Draw_Context *)context, x, y, w, h);
777 evas_common_draw_context_font_ext_set(context,
779 _xre_font_surface_new,
780 _xre_font_surface_free,
781 _xre_font_surface_draw);
782 evas_common_font_draw(im, context, font, x, y, text);
783 evas_common_draw_context_font_ext_set(context,
788 evas_common_cpu_end_opt();
791 /* module advertising code */
793 module_open(Evas_Module *em)
796 /* get whatever engine module we inherit from */
797 if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
798 /* store it for later use */
800 /* now to override methods */
801 #define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
807 ORD(output_tile_size_set);
808 ORD(output_redraws_rect_add);
809 ORD(output_redraws_rect_del);
810 ORD(output_redraws_clear);
811 ORD(output_redraws_next_update_get);
812 ORD(output_redraws_next_update_push);
814 ORD(output_idle_flush);
820 ORD(gradient_color_stop_add);
821 ORD(gradient_alpha_stop_add);
822 ORD(gradient_color_data_set);
823 ORD(gradient_alpha_data_set);
825 ORD(gradient_fill_set);
826 ORD(gradient_fill_angle_set);
827 ORD(gradient_fill_spread_set);
828 ORD(gradient_angle_set);
829 ORD(gradient_offset_set);
830 ORD(gradient_direction_set);
831 ORD(gradient_type_set);
832 ORD(gradient_is_opaque);
833 ORD(gradient_is_visible);
834 ORD(gradient_render_pre);
835 ORD(gradient_render_post);
838 ORD(image_new_from_data);
839 ORD(image_new_from_copied_data);
843 ORD(image_dirty_region);
846 ORD(image_alpha_set);
847 ORD(image_alpha_get);
848 ORD(image_border_set);
849 ORD(image_border_get);
851 ORD(image_comment_get);
852 ORD(image_format_get);
853 ORD(image_colorspace_set);
854 ORD(image_colorspace_get);
855 ORD(image_native_set);
856 ORD(image_native_get);
857 ORD(image_cache_flush);
858 ORD(image_cache_set);
859 ORD(image_cache_get);
861 /* now advertise out own api */
862 em->functions = (void *)(&func);
871 EAPI Evas_Module_Api evas_modapi =
873 EVAS_MODULE_API_VERSION,
874 EVAS_MODULE_TYPE_ENGINE,