eolian: rename is_ref API to is_ptr to match syntax
[platform/upstream/efl.git] / src / modules / evas / engines / software_x11 / evas_xcb_image.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include "evas_common_private.h"
6 #include "evas_xcb_image.h"
7
8 static void 
9 _evas_xcb_image_update(void *image, int x, int y, int w, int h)
10 {
11    RGBA_Image *im = image;
12    Native *n;
13
14    n = im->native.data;
15
16    if (ecore_x_image_get(n->ns_data.x11.exim, n->ns_data.x11.pixmap, 0, 0, x, y, w, h))
17      {
18         char *pix;
19         int bpl, rows, bpp;
20
21         pix = ecore_x_image_data_get(n->ns_data.x11.exim, &bpl, &rows, &bpp);
22         if (!ecore_x_image_is_argb32_get(n->ns_data.x11.exim))
23           {
24              Ecore_X_Colormap colormap;
25
26              if (!im->image.data)
27                im->image.data = (DATA32 *)malloc(im->cache_entry.w * im->cache_entry.h * sizeof(DATA32));
28              colormap = ecore_x_default_colormap_get(ecore_x_display_get(), ecore_x_default_screen_get());
29              ecore_x_image_to_argb_convert(pix, bpp, bpl, colormap, n->ns_data.x11.visual,
30                                            x, y, w, h, im->image.data, 
31                                            (w * sizeof(int)), 0, 0);
32           }
33         else
34           im->image.data = (DATA32 *)pix;
35      }
36 }
37
38 static void 
39 _native_cb_bind(void *image, int x, int y, int w, int h)
40 {
41    RGBA_Image *im = image;
42    Native *n;
43
44    n = im->native.data;
45
46    if ((n) && (n->ns.type == EVAS_NATIVE_SURFACE_X11))
47      _evas_xcb_image_update(image, x, y, w, h);
48 }
49
50 static void 
51 _native_cb_free(void *image)
52 {
53    RGBA_Image *im;
54    Native *n;
55
56    im = image;
57    n = im->native.data;
58
59    if (n->ns_data.x11.exim)
60      {
61         ecore_x_image_free(n->ns_data.x11.exim);
62         n->ns_data.x11.exim = NULL;
63      }
64    n->ns_data.x11.visual = NULL;
65
66    im->native.data = NULL;
67    im->native.func.bind = NULL;
68    im->native.func.unbind = NULL;
69    im->native.func.free = NULL;
70    im->image.data = NULL;
71
72    free(n);
73 }
74
75 void *
76 evas_xcb_image_native_set(void *data EINA_UNUSED, void *image, void *native)
77 {
78    RGBA_Image *im;
79    Evas_Native_Surface *ns;
80
81    im = image;
82    ns = native;
83    if ((ns) && (ns->type == EVAS_NATIVE_SURFACE_X11))
84      {
85         Native *n = NULL;
86         Ecore_X_Image *exim = NULL;
87         Ecore_X_Visual *vis = NULL;
88         Ecore_X_Pixmap pm = 0;
89         int w, h, depth;
90
91         vis = ns->data.x11.visual;
92         pm = ns->data.x11.pixmap;
93
94         depth = ecore_x_drawable_depth_get(pm);
95         w = im->cache_entry.w;
96         h = im->cache_entry.h;
97
98         n = calloc(1, sizeof(Native));
99         if (!n) return NULL;
100
101         exim = ecore_x_image_new(w, h, vis, depth);
102         if (!exim)
103           {
104              ERR("Failed to create new Ecore_X_Image");
105              free(n);
106              return NULL;
107           }
108
109         memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
110         n->ns_data.x11.pixmap = pm;
111         n->ns_data.x11.visual = vis;
112         n->ns_data.x11.exim = exim;
113
114         im->native.data = n;
115         im->native.func.bind = _native_cb_bind;
116         im->native.func.unbind = NULL;
117         im->native.func.free = _native_cb_free;
118
119         _evas_xcb_image_update(image, 0, 0, w, h);
120      }
121
122    return im;
123 }