1 #include "evas_engine.h"
3 static Evas_GL_Wl_Window *_evas_gl_wl_window = NULL;
5 static EGLContext share_context = EGL_NO_CONTEXT;
7 // fixme: something is up/wrong here - dont know what tho...
10 static int win_count = 0;
13 eng_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)
16 Evas_GL_Wl_Window *gw;
19 int major_version, minor_version;
20 int num_config, n = 0;
21 const GLubyte *vendor, *renderer, *version;
23 gw = calloc(1, sizeof(Evas_GL_Wl_Window));
28 gw->surface = surface;
37 context_attrs[0] = EGL_CONTEXT_CLIENT_VERSION;
39 context_attrs[2] = EGL_NONE;
41 #if defined(GLES_VARIETY_S3C6410)
42 if (gw->depth == 16) // 16bpp
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;
60 else // 24/32bit. no one does 8bpp anymore. and 15bpp... dead
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;
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;
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
95 config_attrs[n++] = EGL_ALPHA_SIZE;
96 config_attrs[n++] = 1;
100 config_attrs[n++] = EGL_ALPHA_SIZE;
101 config_attrs[n++] = 0;
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;
110 gw->egl_disp = eglGetDisplay((EGLNativeDisplayType)(gw->disp));
113 ERR("eglGetDisplay() fail. code=%#x", eglGetError());
117 if (!eglInitialize(gw->egl_disp, &major_version, &minor_version))
119 ERR("eglInitialize() fail. code=%#x", eglGetError());
123 eglBindAPI(EGL_OPENGL_ES_API);
124 if (eglGetError() != EGL_SUCCESS)
126 ERR("eglBindAPI() fail. code=%#x", eglGetError());
132 if (!eglChooseConfig(gw->egl_disp, config_attrs, &gw->egl_config,
133 1, &num_config) || (num_config != 1))
135 ERR("eglChooseConfig() fail. code=%#x", eglGetError());
140 if ((gw->rot == 0) || (gw->rot == 180))
141 gw->win = wl_egl_window_create(gw->surface, gw->w, gw->h);
142 else if ((gw->rot == 90) || (gw->rot == 270))
143 gw->win = wl_egl_window_create(gw->surface, gw->h, gw->w);
145 gw->egl_surface[0] = eglCreateWindowSurface(gw->egl_disp, gw->egl_config,
146 (EGLNativeWindowType)gw->win,
148 if (gw->egl_surface[0] == EGL_NO_SURFACE)
150 ERR("eglCreateWindowSurface() fail for %p. code=%#x",
151 gw->win, eglGetError());
157 eglCreateContext(gw->egl_disp, gw->egl_config, share_context,
160 if (gw->egl_context[0] == EGL_NO_CONTEXT)
162 ERR("eglCreateContext() fail. code=%#x", eglGetError());
167 if (share_context == EGL_NO_CONTEXT)
168 share_context = gw->egl_context[0];
170 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0],
171 gw->egl_context[0]) == EGL_FALSE)
173 ERR("eglMakeCurrent() fail. code=%#x", eglGetError());
178 vendor = glGetString(GL_VENDOR);
179 renderer = glGetString(GL_RENDERER);
180 version = glGetString(GL_VERSION);
181 if (!vendor) vendor = (unsigned char *)"-UNKNOWN-";
182 if (!renderer) renderer = (unsigned char *)"-UNKNOWN-";
183 if (!version) version = (unsigned char *)"-UNKNOWN-";
184 if (getenv("EVAS_GL_INFO"))
186 fprintf(stderr, "vendor: %s\n", vendor);
187 fprintf(stderr, "renderer: %s\n", renderer);
188 fprintf(stderr, "version: %s\n", version);
191 gw->gl_context = evas_gl_common_context_new();
197 gw->gl_context->egldisp = gw->egl_disp;
199 evas_gl_common_context_resize(gw->gl_context, w, h, rot);
206 eng_window_free(Evas_GL_Wl_Window *gw)
212 if (gw == _evas_gl_wl_window) _evas_gl_wl_window = NULL;
213 // if (gw->win) wl_egl_window_destroy(gw->win);
216 ref = gw->gl_context->references - 1;
217 evas_gl_common_context_free(gw->gl_context);
219 if (gw->egl_surface[0] != EGL_NO_SURFACE)
220 eglDestroySurface(gw->egl_disp, gw->egl_surface[0]);
221 eglMakeCurrent(gw->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
223 if (gw->egl_context[0] != EGL_NO_CONTEXT && gw->egl_context[0] != share_context)
224 eglDestroyContext(gw->egl_disp, gw->egl_context[0]);
228 /* NB: This is causing an unknown hang when we run elm apps as
229 * wayland clients inside the weston compositor */
230 /* eglTerminate(gw->egl_disp); */
237 eng_window_use(Evas_GL_Wl_Window *gw)
239 Eina_Bool force_use = EINA_FALSE;
241 if (_evas_gl_wl_window)
243 if ((eglGetCurrentContext() !=
244 _evas_gl_wl_window->egl_context[0]) ||
245 (eglGetCurrentSurface(EGL_READ) !=
246 _evas_gl_wl_window->egl_surface[0]) ||
247 (eglGetCurrentSurface(EGL_DRAW) !=
248 _evas_gl_wl_window->egl_surface[0]))
249 force_use = EINA_TRUE;
251 if ((_evas_gl_wl_window != gw) || (force_use))
253 if (_evas_gl_wl_window)
255 evas_gl_common_context_use(_evas_gl_wl_window->gl_context);
256 evas_gl_common_context_flush(_evas_gl_wl_window->gl_context);
258 _evas_gl_wl_window = gw;
262 if (gw->egl_surface[0] != EGL_NO_SURFACE)
264 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0],
266 gw->egl_context[0]) == EGL_FALSE)
268 ERR("eglMakeCurrent() failed!");
273 if (gw) evas_gl_common_context_use(gw->gl_context);
277 eng_window_unsurf(Evas_GL_Wl_Window *gw)
279 if (!gw->surf) return;
280 if (!getenv("EVAS_GL_WIN_RESURF")) return;
281 if (getenv("EVAS_GL_INFO")) printf("unsurf %p\n", gw);
283 if (_evas_gl_wl_window)
284 evas_gl_common_context_flush(_evas_gl_wl_window->gl_context);
285 if (_evas_gl_wl_window == gw)
287 eglMakeCurrent(gw->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
288 if (gw->egl_surface[0] != EGL_NO_SURFACE)
289 eglDestroySurface(gw->egl_disp, gw->egl_surface[0]);
290 gw->egl_surface[0] = EGL_NO_SURFACE;
291 _evas_gl_wl_window = NULL;
297 eng_window_resurf(Evas_GL_Wl_Window *gw)
299 if (gw->surf) return;
300 if (getenv("EVAS_GL_INFO")) printf("resurf %p\n", gw);
303 eglCreateWindowSurface(gw->egl_disp, gw->egl_config,
304 (EGLNativeWindowType)gw->win, NULL);
306 if (gw->egl_surface[0] == EGL_NO_SURFACE)
308 ERR("eglCreateWindowSurface() fail for %p. code=%#x",
309 gw->win, eglGetError());
312 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0],
313 gw->egl_context[0]) == EGL_FALSE)
315 ERR("eglMakeCurrent() failed!");
321 eng_best_depth_get(Evas_Engine_Info_Wayland_Egl *einfo)
323 if (!einfo) return 0;
324 if (!einfo->info.display) return 0;
325 return (einfo->info.depth ? einfo->info.depth : 32);