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.c325
1 files changed, 0 insertions, 325 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
deleted file mode 100644
index 60a2371..0000000
--- a/libraries/evas/src/modules/engines/wayland_egl/evas_wl_main.c
+++ /dev/null
@@ -1,325 +0,0 @@
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 /* NB: This is causing an unknown hang when we run elm apps as
221 * wayland clients inside the weston compositor */
222 /* eglTerminate(gw->egl_disp); */
223 eglReleaseThread();
224 }
225 free(gw);
226}
227
228void
229eng_window_use(Evas_GL_Wl_Window *gw)
230{
231 Eina_Bool force_use = EINA_FALSE;
232
233 if (_evas_gl_wl_window)
234 {
235 if ((eglGetCurrentContext() !=
236 _evas_gl_wl_window->egl_context[0]) ||
237 (eglGetCurrentSurface(EGL_READ) !=
238 _evas_gl_wl_window->egl_surface[0]) ||
239 (eglGetCurrentSurface(EGL_DRAW) !=
240 _evas_gl_wl_window->egl_surface[0]))
241 force_use = EINA_TRUE;
242 }
243 if ((_evas_gl_wl_window != gw) || (force_use))
244 {
245 if (_evas_gl_wl_window)
246 {
247 evas_gl_common_context_use(_evas_gl_wl_window->gl_context);
248 evas_gl_common_context_flush(_evas_gl_wl_window->gl_context);
249 }
250 _evas_gl_wl_window = gw;
251 if (gw)
252 {
253 // EGL / GLES
254 if (gw->egl_surface[0] != EGL_NO_SURFACE)
255 {
256 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0],
257 gw->egl_surface[0],
258 gw->egl_context[0]) == EGL_FALSE)
259 {
260 ERR("eglMakeCurrent() failed!");
261 }
262 }
263 }
264 }
265 if (gw) evas_gl_common_context_use(gw->gl_context);
266}
267
268void
269eng_window_unsurf(Evas_GL_Wl_Window *gw)
270{
271 if (!gw->surf) return;
272 if (!getenv("EVAS_GL_WIN_RESURF")) return;
273 if (getenv("EVAS_GL_INFO")) printf("unsurf %p\n", gw);
274
275 if (_evas_gl_wl_window)
276 evas_gl_common_context_flush(_evas_gl_wl_window->gl_context);
277 if (_evas_gl_wl_window == gw)
278 {
279 eglMakeCurrent(gw->egl_disp, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
280 if (gw->egl_surface[0] != EGL_NO_SURFACE)
281 eglDestroySurface(gw->egl_disp, gw->egl_surface[0]);
282 gw->egl_surface[0] = EGL_NO_SURFACE;
283 _evas_gl_wl_window = NULL;
284 }
285 gw->surf = 0;
286}
287
288void
289eng_window_resurf(Evas_GL_Wl_Window *gw)
290{
291 if (gw->surf) return;
292 if (getenv("EVAS_GL_INFO")) printf("resurf %p\n", gw);
293
294 gw->egl_surface[0] =
295 eglCreateWindowSurface(gw->egl_disp, gw->egl_config,
296 (EGLNativeWindowType)gw->win, NULL);
297
298 if (gw->egl_surface[0] == EGL_NO_SURFACE)
299 {
300 ERR("eglCreateWindowSurface() fail for %#x. code=%#x",
301 (unsigned int)gw->win, eglGetError());
302 return;
303 }
304 if (eglMakeCurrent(gw->egl_disp, gw->egl_surface[0], gw->egl_surface[0],
305 gw->egl_context[0]) == EGL_FALSE)
306 {
307 ERR("eglMakeCurrent() failed!");
308 }
309 gw->surf = 1;
310}
311
312int
313eng_best_depth_get(Evas_Engine_Info_Wayland_Egl *einfo)
314{
315 if (!einfo) return 0;
316 if (!einfo->info.display) return 0;
317 return 32;
318 /* if (!_evas_gl_x11_vi) eng_best_visual_get(einfo); */
319 /* if (!_evas_gl_x11_vi) return 0; */
320 /* if (einfo->info.destination_alpha) */
321 /* { */
322 /* if (_evas_gl_x11_rgba_vi) return _evas_gl_x11_rgba_vi->depth; */
323 /* } */
324 /* return _evas_gl_x11_vi->depth; */
325}