summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/software_generic/evas_native_dmabuf.c
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2016-05-18 10:27:32 -0500
committerDerek Foreman <derekf@osg.samsung.com>2016-05-18 11:52:24 -0500
commitd485e1f161c297bbc77a1cff63ccd993d0bc4765 (patch)
tree7acd6b5d9831de6668271ac6db9790232f446a6f /src/modules/evas/engines/software_generic/evas_native_dmabuf.c
parent5f0aea2e24c8f17b9852949a4554bb9f9424c9d7 (diff)
software_generic: Add wayland dmabuf native surface support
Diffstat (limited to 'src/modules/evas/engines/software_generic/evas_native_dmabuf.c')
-rw-r--r--src/modules/evas/engines/software_generic/evas_native_dmabuf.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/src/modules/evas/engines/software_generic/evas_native_dmabuf.c b/src/modules/evas/engines/software_generic/evas_native_dmabuf.c
new file mode 100644
index 0000000000..e19db5b8dc
--- /dev/null
+++ b/src/modules/evas/engines/software_generic/evas_native_dmabuf.c
@@ -0,0 +1,137 @@
1#include "evas_common_private.h"
2#include "evas_private.h"
3#include "evas_native_common.h"
4
5#if defined HAVE_DLSYM && ! defined _WIN32
6# include <dlfcn.h> /* dlopen,dlclose,etc */
7#else
8# warning native_dmabuf should not get compiled if dlsym is not found on the system!
9#endif
10
11#include <sys/mman.h>
12
13#define DRM_FORMAT_ARGB8888 0x34325241
14#define DRM_FORMAT_XRGB8888 0x34325258
15
16static void
17_native_bind_cb(void *image, int x EINA_UNUSED, int y EINA_UNUSED, int w EINA_UNUSED, int h EINA_UNUSED)
18{
19 struct dmabuf_attributes *a;
20 int size;
21 RGBA_Image *im = image;
22 Native *n = im->native.data;
23
24 if (!im || !n) return;
25 if (n->ns.type != EVAS_NATIVE_SURFACE_WL_DMABUF)
26 return;
27
28 if (im->image.data) return;
29
30 a = (struct dmabuf_attributes *)&n->ns_data.wl_surface_dmabuf;
31 if (n->ns_data.wl_surface_dmabuf.ptr)
32 {
33 im->image.data = n->ns_data.wl_surface_dmabuf.ptr;
34 return;
35 }
36 size = a->height * a->stride[0];
37 im->image.data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, a->fd[0], 0);
38 if (im->image.data == MAP_FAILED) im->image.data = NULL;
39 n->ns_data.wl_surface_dmabuf.size = size;
40 n->ns_data.wl_surface_dmabuf.ptr = im->image.data;
41}
42
43static void
44_native_unbind_cb(void *image)
45{
46 RGBA_Image *im = image;
47 Native *n = im->native.data;
48
49 if (!im || !n) return;
50 if (n->ns.type != EVAS_NATIVE_SURFACE_WL_DMABUF)
51 return;
52}
53
54static void
55_native_free_cb(void *image)
56{
57 RGBA_Image *im = image;
58 Native *n = im->native.data;
59
60 if (!im) return;
61
62 if (im->image.data)
63 munmap(n->ns_data.wl_surface_dmabuf.ptr,
64 n->ns_data.wl_surface_dmabuf.size);
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
75void *
76_evas_native_dmabuf_surface_image_set(void *image, void *native)
77{
78 Evas_Native_Surface *ns = native;
79 RGBA_Image *im = image;
80
81 if (!im) return NULL;
82 if (ns)
83 {
84 struct dmabuf_attributes *a;
85 int h, stride;
86 int32_t format;
87 Native *n;
88
89 if (ns->type != EVAS_NATIVE_SURFACE_WL_DMABUF)
90 return NULL;
91
92 n = im->native.data;
93 if (n)
94 {
95 if (n->ns_data.wl_surface_dmabuf.ptr)
96 {
97 munmap(n->ns_data.wl_surface_dmabuf.ptr,
98 n->ns_data.wl_surface_dmabuf.size);
99 n->ns_data.wl_surface_dmabuf.size = 0;
100 n->ns_data.wl_surface_dmabuf.ptr = NULL;
101 }
102 free(im->native.data);
103 }
104 n = calloc(1, sizeof(Native));
105 if (!n) return NULL;
106
107 a = ns->data.wl_dmabuf.attr;
108 if (a->version != 1)
109 {
110 free(n);
111 return NULL;
112 }
113
114 h = a->height;
115 stride = a->stride[0];
116 format = a->format;
117 im->cache_entry.w = stride;
118 im->cache_entry.h = h;
119
120 /* This block assumes single planar formats, which are all we
121 * currently support. */
122 im->cache_entry.w = stride / 4;
123 evas_cache_image_colorspace(&im->cache_entry, EVAS_COLORSPACE_ARGB8888);
124 im->cache_entry.flags.alpha = (format == DRM_FORMAT_XRGB8888 ? 0 : 1);
125 im->image.data = NULL;;
126 im->image.no_free = 1;
127
128 memcpy(n, ns, sizeof(Evas_Native_Surface));
129 memcpy(&n->ns_data.wl_surface_dmabuf.attr, a, sizeof(*a));
130 im->native.data = n;
131 im->native.func.bind = _native_bind_cb;
132 im->native.func.unbind = _native_unbind_cb;
133 im->native.func.free = _native_free_cb;
134 }
135
136 return im;
137}