aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c')
-rw-r--r--libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c323
1 files changed, 323 insertions, 0 deletions
diff --git a/libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c b/libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c
new file mode 100644
index 0000000..537fcc6
--- /dev/null
+++ b/libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c
@@ -0,0 +1,323 @@
1#include "evas_engine.h"
2
3static Evas_GL_Wl_Window *_evas_gl_wl_window = NULL;
4
5static EGLContext context = EGL_NO_CONTEXT;
6
7// fixme: something is up/wrong here - dont know what tho...
8//#define NEWGL 1
9
10static int win_count = 0;
11
12Evas_GL_Wl_Window *
13eng_window_new(struct wl_display *disp, struct wl_surface *surface, int screen,
14 int depth, int w, int h, int indirect, int alpha, int rot)
15{
16 Evas_GL_Wl_Window *gw;
17 int context_attrs[3];
18 int config_attrs[40];
19 int major_version, minor_version;
20 int num_config, n = 0;
21 const GLubyte *vendor, *renderer, *version;
22
23 gw = calloc(1, sizeof(Evas_GL_Wl_Window));
24 if (!gw) return NULL;
25
26 win_count++;
27 gw->disp = disp;
28 gw->surface = surface;
29 gw->screen = screen;
30 gw->depth = depth;
31 gw->alpha = alpha;
32 gw->w = w;
33 gw->h = h;
34 gw->rot = rot;
35
36// EGL / GLES
37 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
38 context_attrs[1] = 2;
39 context_attrs[2] = EGL_NONE;
40
41#if defined(GLES_VARIETY_S3C6410)
42 if (gw->visualinfo->depth == 16) // 16bpp
43 {
44 config_attrs[n++] = EGL_SURFACE_TYPE;
45 config_attrs[n++] = EGL_WINDOW_BIT;
46 config_attrs[n++] = EGL_RENDERABLE_TYPE;
47 config_attrs[n++] = EGL_OPENGL_ES2_BIT;
48 config_attrs[n++] = EGL_RED_SIZE;
49 config_attrs[n++] = 5;
50 config_attrs[n++] = EGL_GREEN_SIZE;
51 config_attrs[n++] = 6;
52 config_attrs[n++] = EGL_BLUE_SIZE;
53 config_attrs[n++] = 5;
54 config_attrs[n++] = EGL_DEPTH_SIZE;
55 config_attrs[n++] = 0;
56 config_attrs[n++] = EGL_STENCIL_SIZE;
57 config_attrs[n++] = 0;
58 config_attrs[n++] = EGL_NONE;
59 }
60 else // 24/32bit. no one does 8bpp anymore. and 15bpp... dead
61 {
62 config_attrs[n++] = EGL_SURFACE_TYPE;
63 config_attrs[n++] = EGL_WINDOW_BIT;
64 config_attrs[n++] = EGL_RENDERABLE_TYPE;
65 config_attrs[n++] = EGL_OPENGL_ES2_BIT;
66 config_attrs[n++] = EGL_RED_SIZE;
67 config_attrs[n++] = 8;
68 config_attrs[n++] = EGL_GREEN_SIZE;
69 config_attrs[n++] = 8;
70 config_attrs[n++] = EGL_BLUE_SIZE;
71 config_attrs[n++] = 8;
72 config_attrs[n++] = EGL_DEPTH_SIZE;
73 config_attrs[n++] = 0;
74 config_attrs[n++] = EGL_STENCIL_SIZE;
75 config_attrs[n++] = 0;
76 config_attrs[n++] = EGL_NONE;
77 }
78#elif defined(GLES_VARIETY_SGX)
79 config_attrs[n++] = EGL_SURFACE_TYPE;
80 config_attrs[n++] = EGL_WINDOW_BIT;
81 config_attrs[n++] = EGL_RENDERABLE_TYPE;
82 config_attrs[n++] = EGL_OPENGL_ES2_BIT;
83# if 0
84// FIXME: n900 - omap3 sgx libs break here
85 config_attrs[n++] = EGL_RED_SIZE;
86 config_attrs[n++] = 1;
87 config_attrs[n++] = EGL_GREEN_SIZE;
88 config_attrs[n++] = 1;
89 config_attrs[n++] = EGL_BLUE_SIZE;
90 config_attrs[n++] = 1;
91// FIXME: end n900 breakage
92# endif
93 if (gw->alpha)
94 {
95 config_attrs[n++] = EGL_ALPHA_SIZE;
96 config_attrs[n++] = 1;
97 }
98 else
99 {
100 config_attrs[n++] = EGL_ALPHA_SIZE;
101 config_attrs[n++] = 0;
102 }
103 config_attrs[n++] = EGL_DEPTH_SIZE;
104 config_attrs[n++] = 0;
105 config_attrs[n++] = EGL_STENCIL_SIZE;
106 config_attrs[n++] = 0;
107 config_attrs[n++] = EGL_NONE;
108#endif
109
110 gw->egl_disp = eglGetDisplay((EGLNativeDisplayType)(gw->disp));
111 if (!gw->egl_disp)
112 {
113 ERR("eglGetDisplay() fail. code=%#x", eglGetError());
114 eng_window_free(gw);
115 return NULL;
116 }
117 if (!eglInitialize(gw->egl_disp, &major_version, &minor_version))
118 {
119 ERR("eglInitialize() fail. code=%#x", eglGetError());
120 eng_window_free(gw);
121 return NULL;
122 }
123 eglBindAPI(EGL_OPENGL_ES_API);
124 if (eglGetError() != EGL_SUCCESS)
125 {
126 ERR("eglBindAPI() fail. code=%#x", eglGetError());
127 eng_window_free(gw);
128 return NULL;
129 }
130
131 num_config = 0;
132 if (!eglChooseConfig(gw->egl_disp, config_attrs, &gw->egl_config,
133 1, &num_config) || (num_config != 1))
134 {
135 ERR("eglChooseConfig() fail. code=%#x", eglGetError());
136 eng_window_free(gw);
137 return NULL;
138 }
139
140 gw->win = wl_egl_window_create(gw->surface, gw->w, gw->h);
141
142 gw->egl_surface[0] = eglCreateWindowSurface(gw->egl_disp, gw->egl_config,
143 (EGLNativeWindowType)gw->win,
144 NULL);
145 if (gw->egl_surface[0] == EGL_NO_SURFACE)
146 {
147 ERR("eglCreateWindowSurface() fail for %#x. code=%#x",
148 (unsigned int)gw->win, eglGetError());
149 eng_window_free(gw);
150 return NULL;
151 }
152
153 if (context == EGL_NO_CONTEXT)
154 context = eglCreateContext(gw->egl_disp, gw->egl_config, NULL,
155 context_attrs);
156 gw->egl_context[0] = context;
157 if (gw->egl_context[0] == EGL_NO_CONTEXT)
158 {
159 ERR("eglCreateContext() fail. code=%#x", eglGetError());
160 eng_window_free(gw);
161 return NULL;
162 }
163
164 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0],
165 gw->egl_context[0]) == EGL_FALSE)
166 {
167 ERR("eglMakeCurrent() fail. code=%#x", eglGetError());
168 eng_window_free(gw);
169 return NULL;
170 }
171
172 vendor = glGetString(GL_VENDOR);
173 renderer = glGetString(GL_RENDERER);
174 version = glGetString(GL_VERSION);
175 if (!vendor) vendor = (unsigned char *)"-UNKNOWN-";
176 if (!renderer) renderer = (unsigned char *)"-UNKNOWN-";
177 if (!version) version = (unsigned char *)"-UNKNOWN-";
178 if (getenv("EVAS_GL_INFO"))
179 {
180 fprintf(stderr, "vendor: %s\n", vendor);
181 fprintf(stderr, "renderer: %s\n", renderer);
182 fprintf(stderr, "version: %s\n", version);
183 }
184
185 gw->gl_context = evas_gl_common_context_new();
186 if (!gw->gl_context)
187 {
188 eng_window_free(gw);
189 return NULL;
190 }
191 gw->gl_context->egldisp = gw->egl_disp;
192 eng_window_use(gw);
193 evas_gl_common_context_resize(gw->gl_context, w, h, rot);
194 gw->surf = 1;
195 return gw;
196 indirect = 0;
197}
198
199void
200eng_window_free(Evas_GL_Wl_Window *gw)
201{
202 int ref = 0;
203
204 win_count--;
205 eng_window_use(gw);
206 if (gw == _evas_gl_wl_window) _evas_gl_wl_window = NULL;
207// if (gw->win) wl_egl_window_destroy(gw->win);
208 if (gw->gl_context)
209 {
210 ref = gw->gl_context->references - 1;
211 evas_gl_common_context_free(gw->gl_context);
212 }
213 if (gw->egl_surface[0] != EGL_NO_SURFACE)
214 eglDestroySurface(gw->egl_disp, gw->egl_surface[0]);
215 eglMakeCurrent(gw->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
216 if (ref == 0)
217 {
218 if (context) eglDestroyContext(gw->egl_disp, context);
219 context = EGL_NO_CONTEXT;
220 eglTerminate(gw->egl_disp);
221 eglReleaseThread();
222 }
223 free(gw);
224}
225
226void
227eng_window_use(Evas_GL_Wl_Window *gw)
228{
229 Eina_Bool force_use = EINA_FALSE;
230
231 if (_evas_gl_wl_window)
232 {
233 if ((eglGetCurrentContext() !=
234 _evas_gl_wl_window->egl_context[0]) ||
235 (eglGetCurrentSurface(EGL_READ) !=
236 _evas_gl_wl_window->egl_surface[0]) ||
237 (eglGetCurrentSurface(EGL_DRAW) !=
238 _evas_gl_wl_window->egl_surface[0]))
239 force_use = EINA_TRUE;
240 }
241 if ((_evas_gl_wl_window != gw) || (force_use))
242 {
243 if (_evas_gl_wl_window)
244 {
245 evas_gl_common_context_use(_evas_gl_wl_window->gl_context);
246 evas_gl_common_context_flush(_evas_gl_wl_window->gl_context);
247 }
248 _evas_gl_wl_window = gw;
249 if (gw)
250 {
251 // EGL / GLES
252 if (gw->egl_surface[0] != EGL_NO_SURFACE)
253 {
254 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0],
255 gw->egl_surface[0],
256 gw->egl_context[0]) == EGL_FALSE)
257 {
258 ERR("eglMakeCurrent() failed!");
259 }
260 }
261 }
262 }
263 if (gw) evas_gl_common_context_use(gw->gl_context);
264}
265
266void
267eng_window_unsurf(Evas_GL_Wl_Window *gw)
268{
269 if (!gw->surf) return;
270 if (!getenv("EVAS_GL_WIN_RESURF")) return;
271 if (getenv("EVAS_GL_INFO")) printf("unsurf %p\n", gw);
272
273 if (_evas_gl_wl_window)
274 evas_gl_common_context_flush(_evas_gl_wl_window->gl_context);
275 if (_evas_gl_wl_window == gw)
276 {
277 eglMakeCurrent(gw->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
278 if (gw->egl_surface[0] != EGL_NO_SURFACE)
279 eglDestroySurface(gw->egl_disp, gw->egl_surface[0]);
280 gw->egl_surface[0] = EGL_NO_SURFACE;
281 _evas_gl_wl_window = NULL;
282 }
283 gw->surf = 0;
284}
285
286void
287eng_window_resurf(Evas_GL_Wl_Window *gw)
288{
289 if (gw->surf) return;
290 if (getenv("EVAS_GL_INFO")) printf("resurf %p\n", gw);
291
292 gw->egl_surface[0] =
293 eglCreateWindowSurface(gw->egl_disp, gw->egl_config,
294 (EGLNativeWindowType)gw->win, NULL);
295
296 if (gw->egl_surface[0] == EGL_NO_SURFACE)
297 {
298 ERR("eglCreateWindowSurface() fail for %#x. code=%#x",
299 (unsigned int)gw->win, eglGetError());
300 return;
301 }
302 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0],
303 gw->egl_context[0]) == EGL_FALSE)
304 {
305 ERR("eglMakeCurrent() failed!");
306 }
307 gw->surf = 1;
308}
309
310int
311eng_best_depth_get(Evas_Engine_Info_Wayland_Egl *einfo)
312{
313 if (!einfo) return 0;
314 if (!einfo->info.display) return 0;
315 return 32;
316 /* if (!_evas_gl_x11_vi) eng_best_visual_get(einfo); */
317 /* if (!_evas_gl_x11_vi) return 0; */
318 /* if (einfo->info.destination_alpha) */
319 /* { */
320 /* if (_evas_gl_x11_rgba_vi) return _evas_gl_x11_rgba_vi->depth; */
321 /* } */
322 /* return _evas_gl_x11_vi->depth; */
323}