summaryrefslogtreecommitdiff
path: root/legacy/evas
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-09-25 05:44:43 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-09-25 05:44:43 +0000
commit06fa0ad166fc0ee9031031868fc206d8d0f105b0 (patch)
treed22a674e8c9a8d345aa7a3538183ba989aa278f9 /legacy/evas
parent45d4f2a3f208816672411e0235b087548c66ba34 (diff)
this is the start of something inteteresting. it is the start of using
egl with software rendering only (no gl just egl). ie get access to buffer and do swaps etc. etc. etc. it's meant to be totally dynamic - ie dlopen libEGL if u have it and then start checking if it can do this thing so it doesnt add any dependencies at all. SVN revision: 77043
Diffstat (limited to 'legacy/evas')
-rw-r--r--legacy/evas/src/modules/engines/software_x11/Makefile.am8
-rw-r--r--legacy/evas/src/modules/engines/software_x11/evas_engine.c34
-rw-r--r--legacy/evas/src/modules/engines/software_x11/evas_x_egl.c251
3 files changed, 290 insertions, 3 deletions
diff --git a/legacy/evas/src/modules/engines/software_x11/Makefile.am b/legacy/evas/src/modules/engines/software_x11/Makefile.am
index 8c0961d25d..9343381aee 100644
--- a/legacy/evas/src/modules/engines/software_x11/Makefile.am
+++ b/legacy/evas/src/modules/engines/software_x11/Makefile.am
@@ -3,7 +3,9 @@ MAINTAINERCLEANFILES = Makefile.in
3 3
4if BUILD_ENGINE_SOFTWARE_X11 4if BUILD_ENGINE_SOFTWARE_X11
5 5
6SOFTWARE_X11_SOURCES = evas_engine.c 6SOFTWARE_X11_SOURCES = \
7evas_engine.c \
8evas_x_egl.c
7 9
8if BUILD_ENGINE_SOFTWARE_XLIB 10if BUILD_ENGINE_SOFTWARE_XLIB
9 11
@@ -25,7 +27,7 @@ evas_xlib_buffer.c \
25evas_xlib_color.c \ 27evas_xlib_color.c \
26evas_xlib_main.c 28evas_xlib_main.c
27 29
28SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xlib_libs@ 30SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xlib_libs@ @dlopen_libs@
29 31
30endif 32endif
31 33
@@ -49,7 +51,7 @@ evas_xcb_buffer.c \
49evas_xcb_color.c \ 51evas_xcb_color.c \
50evas_xcb_main.c 52evas_xcb_main.c
51 53
52SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @PIXMAN_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xcb_libs@ 54SOFTWARE_X11_LIBADD = @FREETYPE_LIBS@ @PIXMAN_LIBS@ @EVAS_GENERAL_LIBS@ @evas_engine_software_xcb_libs@ @dlopen_libs@
53 55
54endif 56endif
55 57
diff --git a/legacy/evas/src/modules/engines/software_x11/evas_engine.c b/legacy/evas/src/modules/engines/software_x11/evas_engine.c
index d9d1bf6b8a..21c80acc35 100644
--- a/legacy/evas/src/modules/engines/software_x11/evas_engine.c
+++ b/legacy/evas/src/modules/engines/software_x11/evas_engine.c
@@ -15,6 +15,8 @@
15# include "evas_xcb_xdefaults.h" 15# include "evas_xcb_xdefaults.h"
16#endif 16#endif
17 17
18#include "evas_x_egl.h"
19
18int _evas_engine_soft_x11_log_dom = -1; 20int _evas_engine_soft_x11_log_dom = -1;
19 21
20/* function tables - filled in later (func and parent func) */ 22/* function tables - filled in later (func and parent func) */
@@ -63,6 +65,38 @@ static void eng_output_idle_flush(void *data);
63/* internal engine routines */ 65/* internal engine routines */
64 66
65#ifdef BUILD_ENGINE_SOFTWARE_XLIB 67#ifdef BUILD_ENGINE_SOFTWARE_XLIB
68
69static void *
70_output_egl_setup(int w, int h, int rot, Display *disp, Drawable draw,
71 Visual *vis, Colormap cmap, int depth, int debug,
72 int grayscale, int max_colors, Pixmap mask,
73 int shape_dither, int destination_alpha)
74{
75 Render_Engine *re;
76
77 if (!(re = calloc(1, sizeof(Render_Engine)))) return NULL;
78 // _egl_x_disp_get()
79 // then
80 // _egl_x_disp_init()
81 // then
82 // _egl_x_disp_choose_config()
83 // then
84 // _egl_x_win_surf_new()
85 //
86 // and on cleaup
87 //
88 // _egl_x_win_surf_free()
89 //
90 // to access pixels
91 //
92 // _egl_x_map_surf()
93 //
94 // to give back pixels
95 //
96 // _egl_x_unmap_surf()
97 return re;
98}
99
66static void * 100static void *
67_output_xlib_setup(int w, int h, int rot, Display *disp, Drawable draw, 101_output_xlib_setup(int w, int h, int rot, Display *disp, Drawable draw,
68 Visual *vis, Colormap cmap, int depth, int debug, 102 Visual *vis, Colormap cmap, int depth, int debug,
diff --git a/legacy/evas/src/modules/engines/software_x11/evas_x_egl.c b/legacy/evas/src/modules/engines/software_x11/evas_x_egl.c
new file mode 100644
index 0000000000..b91da996cc
--- /dev/null
+++ b/legacy/evas/src/modules/engines/software_x11/evas_x_egl.c
@@ -0,0 +1,251 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#ifdef EVAS_CSERVE2
6#include "evas_cs2_private.h"
7#endif
8#include "evas_common.h"
9#include "evas_macros.h"
10#include "evas_x_egl.h"
11
12#ifdef HAVE_DLSYM
13# include <dlfcn.h> /* dlopen,dlclose,etc */
14#else
15# undef BUILD_ENGINE_SOFTWARE_XLIB
16#endif
17
18#ifdef BUILD_ENGINE_SOFTWARE_XLIB
19
20#define EGL_SURFACE_TYPE 0x3033
21#define EGL_WINDOW_BIT 0x0004
22#define EGL_RENDERABLE_TYPE 0x3040
23#define EGL_ALPHA_SIZE 0x3021
24#define EGL_BLUE_SIZE 0x3022
25#define EGL_GREEN_SIZE 0x3023
26#define EGL_RED_SIZE 0x3024
27#define EGL_DEPTH_SIZE 0x3025
28#define EGL_STENCIL_SIZE 0x3026
29#define EGL_SURFACE_TYPE 0x3033
30#define EGL_NONE 0x3038
31#define EGL_FALSE 0
32#define EGL_TRUE 1
33
34#define EGL_NATIVE_BIT 0x0010
35
36#define EGL_LOCK_SURFACE_BIT_KHR 0x0080
37#define EGL_OPTIMAL_FORMAT_BIT_KHR 0x0100
38#define EGL_MATCH_FORMAT_KHR 0x3043
39#define EGL_FORMAT_RGB_565_EXACT_KHR 0x30C0
40#define EGL_FORMAT_RGB_565_KHR 0x30C1
41#define EGL_FORMAT_RGBA_8888_EXACT_KHR 0x30C2
42#define EGL_FORMAT_RGBA_8888_KHR 0x30C3
43#define EGL_MAP_PRESERVE_PIXELS_KHR 0x30C4
44#define EGL_LOCK_USAGE_HINT_KHR 0x30C5
45#define EGL_READ_SURFACE_BIT_KHR 0x0001
46#define EGL_WRITE_SURFACE_BIT_KHR 0x0002
47#define EGL_BITMAP_POINTER_KHR 0x30C6
48#define EGL_BITMAP_PITCH_KHR 0x30C7
49#define EGL_BITMAP_ORIGIN_KHR 0x30C8
50#define EGL_BITMAP_PIXEL_RED_OFFSET_KHR 0x30C9
51#define EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR 0x30CA
52#define EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR 0x30CB
53#define EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR 0x30CC
54#define EGL_BITMAP_PIXEL_LUMINANCE_OFFSET_KHR 0x30CD
55#define EGL_LOWER_LEFT_KHR 0x30CE
56#define EGL_UPPER_LEFT_KHR 0x30CF
57
58static int egl_found = -1;
59static void *egl_lib = NULL;
60
61static struct {
62 void * (*GetProcAddress) (const char *name);
63 void * (*GetDisplay) (void *d);
64 unsigned int (*Initialize) (void *ed, int *vmaj, int *vmin);
65 unsigned int (*Terminate) (void *ed);
66 const char * (*QueryString) (void *ed, int name);
67 unsigned int (*ChooseConfig) (void *ed, int *attr, void **configs, int config_size, int *num_config);
68 unsigned int (*GetConfigAttrib) (void *ed, void *config, int attr, int *val);
69 unsigned int (*QuerySurface) (void *ed, void *surf, int attr, int *val);
70 void * (*CreateWindowSurface) (void *ed, void *config, Window win, int *attr);
71 unsigned int (*DestroySurface) (void *ed, void *surf);
72
73 unsigned int (*LockSurface) (void *ed, void *surf, int *attr);
74 unsigned int (*UnlockSurface) (void *ed, void *surf);
75} egl;
76
77static int
78_egl_find(void)
79{
80 if (egl_found == 0) return 0;
81 if (!egl_lib) egl_lib = dlopen("libEGL.so.1", RTLD_NOW | RTLD_LOCAL);
82 if (!egl_lib)
83 {
84 egl_found = 0;
85 return 0;
86 }
87 if (!(egl.GetProcAddress = dlsym(egl_lib, "eglGetProcAddress"))) goto err;
88
89#define SYM(x, y) if (!(egl.x = egl.GetProcAddress(y))) goto err
90// core syms used
91 SYM(GetDisplay , "eglGetDisplay");
92 SYM(Initialize, "eglInitialize");
93 SYM(Terminate, "eglTerminate");
94 SYM(QueryString, "eglQueryString");
95 SYM(ChooseConfig, "eglChooseConfig");
96 SYM(UnlockSurface, "eglGetConfigAttrib");
97 SYM(QuerySurface, "eglQuerySurface");
98 SYM(CreateWindowSurface, "eglCreateWindowSurface");
99 SYM(DestroySurface, "eglDestroySurface");
100
101#undef SYM
102#define SYM(x, y) egl.x = egl.GetProcAddress(y)
103// extns
104 SYM(LockSurface, "eglLockSurface");
105 if (!egl.LockSurface) SYM(LockSurface, "eglLockSurfaceKHR");
106 SYM(UnlockSurface, "eglUnlockSurface");
107 if (!egl.UnlockSurface) SYM(UnlockSurface, "eglUnlockSurfaceKHR");
108
109 if (!egl.LockSurface) goto err;
110 if (!egl.UnlockSurface) goto err;
111
112 egl_found = 1;
113 return 1;
114err:
115 if (egl_lib) dlclose(egl_lib);
116 egl_lib = NULL;
117 return 0;
118}
119#endif
120
121void *
122_egl_x_disp_get(void *d)
123{
124#ifdef BUILD_ENGINE_SOFTWARE_XLIB
125 if (!_egl_find()) return NULL;
126 return egl.GetDisplay(d);
127#else
128 return NULL;
129#endif
130}
131
132int
133_egl_x_disp_init(void *ed)
134{
135#ifdef BUILD_ENGINE_SOFTWARE_XLIB
136 int vmaj = 0, vmin = 0;
137 if (!_egl_find()) return 0;
138 if (!egl.Initialize(ed, &vmaj, &vmin)) return 0;
139 return 1;
140#else
141 return 0;
142#endif
143}
144
145void *
146_egl_x_disp_choose_config(void *ed)
147{
148#ifdef BUILD_ENGINE_SOFTWARE_XLIB
149 int config_attrs[40], n = 0, num_config = 0;
150 void *eglconfig = NULL;
151
152 if (!_egl_find()) return NULL;
153 config_attrs[n++] = EGL_SURFACE_TYPE;
154 config_attrs[n++] = EGL_WINDOW_BIT;
155 config_attrs[n++] = EGL_RENDERABLE_TYPE;
156 config_attrs[n++] = EGL_NATIVE_BIT;
157 config_attrs[n++] = EGL_RED_SIZE;
158 config_attrs[n++] = 8;
159 config_attrs[n++] = EGL_GREEN_SIZE;
160 config_attrs[n++] = 8;
161 config_attrs[n++] = EGL_BLUE_SIZE;
162 config_attrs[n++] = 8;
163 config_attrs[n++] = EGL_ALPHA_SIZE;
164 config_attrs[n++] = 8;
165 config_attrs[n++] = EGL_DEPTH_SIZE;
166 config_attrs[n++] = 0;
167 config_attrs[n++] = EGL_STENCIL_SIZE;
168 config_attrs[n++] = 0;
169 config_attrs[n++] = EGL_SURFACE_TYPE;
170 config_attrs[n++] = EGL_LOCK_SURFACE_BIT_KHR;
171 config_attrs[n++] = EGL_MATCH_FORMAT_KHR;
172 config_attrs[n++] = EGL_FORMAT_RGBA_8888_KHR;
173
174 config_attrs[n++] = EGL_NONE;
175
176 if (!egl.ChooseConfig(ed, config_attrs, &eglconfig, 1, &num_config))
177 return NULL;
178 return eglconfig;
179#else
180 return NULL;
181#endif
182}
183
184void *
185_egl_x_win_surf_new(void *ed, Window win, void *config)
186{
187#ifdef BUILD_ENGINE_SOFTWARE_XLIB
188 if (!_egl_find()) return NULL;
189 return egl.CreateWindowSurface(ed, config, win, NULL);
190#else
191 return NULL;
192#endif
193}
194
195void
196_egl_x_win_surf_free(void *ed, void *surf)
197{
198#ifdef BUILD_ENGINE_SOFTWARE_XLIB
199 if (!_egl_find()) return;
200 egl.DestroySurface(ed, surf);
201#endif
202}
203
204void *
205_egl_x_map_surf(void *ed, void *surf, int *stride)
206{
207#ifdef BUILD_ENGINE_SOFTWARE_XLIB
208 int config_attrs[40], n = 0;
209 void *ptr = NULL;
210 int pitch = 0, origin = 0;
211 int r_offset = 0, g_offset = 0, b_offset = 0, a_offset = 0;
212
213 if (!_egl_find()) return NULL;
214
215 config_attrs[n++] = EGL_MAP_PRESERVE_PIXELS_KHR;
216 config_attrs[n++] = EGL_TRUE;
217 config_attrs[n++] = EGL_LOCK_USAGE_HINT_KHR;
218 config_attrs[n++] = EGL_READ_SURFACE_BIT_KHR | EGL_WRITE_SURFACE_BIT_KHR;
219 config_attrs[n++] = EGL_NONE;
220
221 if (!egl.LockSurface(ed, surf, config_attrs)) return NULL;
222 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_POINTER_KHR, (int *)&ptr)) goto err;
223 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PITCH_KHR, &pitch)) goto err;
224 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_ORIGIN_KHR, &origin)) goto err;
225 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_RED_OFFSET_KHR, &r_offset)) goto err;
226 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_GREEN_OFFSET_KHR, &g_offset)) goto err;
227 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_BLUE_OFFSET_KHR, &b_offset)) goto err;
228 if (!egl.QuerySurface(ed, surf, EGL_BITMAP_PIXEL_ALPHA_OFFSET_KHR, &a_offset)) goto err;
229
230 if (!ptr) goto err;
231 if (pitch <= 0) goto err;
232 // need to check rgb offset matiching sw pixel fmt
233 // do we add origin to ptr?
234 // is pitch in bytes?
235 *stride = pitch;
236 return ptr;
237err:
238 egl.UnlockSurface(ed, surf);
239 return NULL;
240#else
241 return NULL;
242#endif
243}
244
245void
246_egl_x_unmap_surf(void *ed, void *surf)
247{
248#ifdef BUILD_ENGINE_SOFTWARE_XLIB
249 egl.UnlockSurface(ed, surf);
250#endif
251}