• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Simple DirectMedia Layer
3  *  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4  *
5  *  This software is provided 'as-is', without any express or implied
6  *  warranty.  In no event will the authors be held liable for any damages
7  *  arising from the use of this software.
8  *
9  *  Permission is granted to anyone to use this software for any purpose,
10  *  including commercial applications, and to alter it and redistribute it
11  *  freely, subject to the following restrictions:
12  *
13  *  1. The origin of this software must not be misrepresented; you must not
14  *     claim that you wrote the original software. If you use this software
15  *     in a product, an acknowledgment in the product documentation would be
16  *     appreciated but is not required.
17  *  2. Altered source versions must be plainly marked as such, and must not be
18  *     misrepresented as being the original software.
19  *  3. This notice may not be removed or altered from any source distribution.
20  */
21 #include "../SDL_internal.h"
22 
23 #if SDL_VIDEO_OPENGL_EGL
24 
25 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
26 #include "../core/windows/SDL_windows.h"
27 #endif
28 
29 #include "SDL_sysvideo.h"
30 #include "SDL_egl_c.h"
31 #include "SDL_loadso.h"
32 #include "SDL_hints.h"
33 
34 #ifdef EGL_KHR_create_context
35 /* EGL_OPENGL_ES3_BIT_KHR was added in version 13 of the extension. */
36 #ifndef EGL_OPENGL_ES3_BIT_KHR
37 #define EGL_OPENGL_ES3_BIT_KHR 0x00000040
38 #endif
39 #endif /* EGL_KHR_create_context */
40 
41 #if SDL_VIDEO_DRIVER_RPI
42 /* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
43 #define DEFAULT_EGL "/opt/vc/lib/libEGL.so"
44 #define DEFAULT_OGL_ES2 "/opt/vc/lib/libGLESv2.so"
45 #define DEFAULT_OGL_ES_PVR "/opt/vc/lib/libGLES_CM.so"
46 #define DEFAULT_OGL_ES "/opt/vc/lib/libGLESv1_CM.so"
47 
48 #elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE
49 /* Android */
50 #define DEFAULT_EGL "libEGL.so"
51 #define DEFAULT_OGL_ES2 "libGLESv2.so"
52 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
53 #define DEFAULT_OGL_ES "libGLESv1_CM.so"
54 
55 #elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
56 /* EGL AND OpenGL ES support via ANGLE */
57 #define DEFAULT_EGL "libEGL.dll"
58 #define DEFAULT_OGL_ES2 "libGLESv2.dll"
59 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
60 #define DEFAULT_OGL_ES "libGLESv1_CM.dll"
61 
62 #else
63 /* Desktop Linux */
64 #define DEFAULT_OGL "libGL.so.1"
65 #define DEFAULT_EGL "libEGL.so.1"
66 #define DEFAULT_OGL_ES2 "libGLESv2.so.2"
67 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
68 #define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
69 #endif /* SDL_VIDEO_DRIVER_RPI */
70 
71 #define LOAD_FUNC(NAME) \
72 _this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
73 if (!_this->egl_data->NAME) \
74 { \
75     return SDL_SetError("Could not retrieve EGL function " #NAME); \
76 }
77 
78 /* EGL implementation of SDL OpenGL ES support */
79 #ifdef EGL_KHR_create_context
SDL_EGL_HasExtension(_THIS,const char * ext)80 static int SDL_EGL_HasExtension(_THIS, const char *ext)
81 {
82     int i;
83     int len = 0;
84     size_t ext_len;
85     const char *exts;
86     const char *ext_word;
87 
88     ext_len = SDL_strlen(ext);
89     exts = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
90 
91     if (exts) {
92         ext_word = exts;
93 
94         for (i = 0; exts[i] != 0; i++) {
95             if (exts[i] == ' ') {
96                 if (ext_len == len && !SDL_strncmp(ext_word, ext, len)) {
97                     return 1;
98                 }
99 
100                 len = 0;
101                 ext_word = &exts[i + 1];
102             } else {
103                 len++;
104             }
105         }
106     }
107 
108     return 0;
109 }
110 #endif /* EGL_KHR_create_context */
111 
112 void *
SDL_EGL_GetProcAddress(_THIS,const char * proc)113 SDL_EGL_GetProcAddress(_THIS, const char *proc)
114 {
115     static char procname[1024];
116     void *retval;
117 
118     /* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
119 #if !defined(SDL_VIDEO_DRIVER_ANDROID) && !defined(SDL_VIDEO_DRIVER_MIR)
120     if (_this->egl_data->eglGetProcAddress) {
121         retval = _this->egl_data->eglGetProcAddress(proc);
122         if (retval) {
123             return retval;
124         }
125     }
126 #endif
127 
128     retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
129     if (!retval && SDL_strlen(proc) <= 1022) {
130         procname[0] = '_';
131         SDL_strlcpy(procname + 1, proc, 1022);
132         retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
133     }
134     return retval;
135 }
136 
137 void
SDL_EGL_UnloadLibrary(_THIS)138 SDL_EGL_UnloadLibrary(_THIS)
139 {
140     if (_this->egl_data) {
141         if (_this->egl_data->egl_display) {
142             _this->egl_data->eglTerminate(_this->egl_data->egl_display);
143             _this->egl_data->egl_display = NULL;
144         }
145 
146         if (_this->egl_data->dll_handle) {
147             SDL_UnloadObject(_this->egl_data->dll_handle);
148             _this->egl_data->dll_handle = NULL;
149         }
150         if (_this->egl_data->egl_dll_handle) {
151             SDL_UnloadObject(_this->egl_data->egl_dll_handle);
152             _this->egl_data->egl_dll_handle = NULL;
153         }
154 
155         SDL_free(_this->egl_data);
156         _this->egl_data = NULL;
157     }
158 }
159 
160 int
SDL_EGL_LoadLibrary(_THIS,const char * egl_path,NativeDisplayType native_display)161 SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display)
162 {
163     void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
164     const char *path = NULL;
165 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
166     const char *d3dcompiler;
167 #endif
168 
169     if (_this->egl_data) {
170         return SDL_SetError("OpenGL ES context already created");
171     }
172 
173     _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
174     if (!_this->egl_data) {
175         return SDL_OutOfMemory();
176     }
177 
178 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
179     d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
180     if (!d3dcompiler) {
181         if (WIN_IsWindowsVistaOrGreater()) {
182             d3dcompiler = "d3dcompiler_46.dll";
183         } else {
184             d3dcompiler = "d3dcompiler_43.dll";
185         }
186     }
187     if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
188         SDL_LoadObject(d3dcompiler);
189     }
190 #endif
191 
192     /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
193     path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
194     if (path != NULL) {
195         egl_dll_handle = SDL_LoadObject(path);
196     }
197 
198     if (egl_dll_handle == NULL) {
199         if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
200             if (_this->gl_config.major_version > 1) {
201                 path = DEFAULT_OGL_ES2;
202                 egl_dll_handle = SDL_LoadObject(path);
203             } else {
204                 path = DEFAULT_OGL_ES;
205                 egl_dll_handle = SDL_LoadObject(path);
206                 if (egl_dll_handle == NULL) {
207                     path = DEFAULT_OGL_ES_PVR;
208                     egl_dll_handle = SDL_LoadObject(path);
209                 }
210             }
211         }
212 #ifdef DEFAULT_OGL
213         else {
214             path = DEFAULT_OGL;
215             egl_dll_handle = SDL_LoadObject(path);
216         }
217 #endif
218     }
219     _this->egl_data->egl_dll_handle = egl_dll_handle;
220 
221     if (egl_dll_handle == NULL) {
222         return SDL_SetError("Could not initialize OpenGL / GLES library");
223     }
224 
225     /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
226     if (egl_path != NULL) {
227         dll_handle = SDL_LoadObject(egl_path);
228     }
229     /* Try loading a EGL symbol, if it does not work try the default library paths */
230     if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
231         if (dll_handle != NULL) {
232             SDL_UnloadObject(dll_handle);
233         }
234         path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
235         if (path == NULL) {
236             path = DEFAULT_EGL;
237         }
238         dll_handle = SDL_LoadObject(path);
239         if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
240             if (dll_handle != NULL) {
241                 SDL_UnloadObject(dll_handle);
242             }
243             return SDL_SetError("Could not load EGL library");
244         }
245         SDL_ClearError();
246     }
247 
248     _this->egl_data->dll_handle = dll_handle;
249 
250     /* Load new function pointers */
251     LOAD_FUNC(eglGetDisplay);
252     LOAD_FUNC(eglInitialize);
253     LOAD_FUNC(eglTerminate);
254     LOAD_FUNC(eglGetProcAddress);
255     LOAD_FUNC(eglChooseConfig);
256     LOAD_FUNC(eglGetConfigAttrib);
257     LOAD_FUNC(eglCreateContext);
258     LOAD_FUNC(eglDestroyContext);
259     LOAD_FUNC(eglCreateWindowSurface);
260     LOAD_FUNC(eglDestroySurface);
261     LOAD_FUNC(eglMakeCurrent);
262     LOAD_FUNC(eglSwapBuffers);
263     LOAD_FUNC(eglSwapInterval);
264     LOAD_FUNC(eglWaitNative);
265     LOAD_FUNC(eglWaitGL);
266     LOAD_FUNC(eglBindAPI);
267     LOAD_FUNC(eglQueryString);
268 
269 #if !defined(__WINRT__)
270     _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
271     if (!_this->egl_data->egl_display) {
272         return SDL_SetError("Could not get EGL display");
273     }
274 
275     if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
276         return SDL_SetError("Could not initialize EGL");
277     }
278 #endif
279 
280     _this->gl_config.driver_loaded = 1;
281 
282     if (path) {
283         SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
284     } else {
285         *_this->gl_config.driver_path = '\0';
286     }
287 
288     return 0;
289 }
290 
291 int
SDL_EGL_ChooseConfig(_THIS)292 SDL_EGL_ChooseConfig(_THIS)
293 {
294     /* 64 seems nice. */
295     EGLint attribs[64];
296     EGLint found_configs = 0, value;
297     /* 128 seems even nicer here */
298     EGLConfig configs[128];
299     int i, j, best_bitdiff = -1, bitdiff;
300 
301     if (!_this->egl_data) {
302         /* The EGL library wasn't loaded, SDL_GetError() should have info */
303         return -1;
304     }
305 
306     /* Get a valid EGL configuration */
307     i = 0;
308     attribs[i++] = EGL_RED_SIZE;
309     attribs[i++] = _this->gl_config.red_size;
310     attribs[i++] = EGL_GREEN_SIZE;
311     attribs[i++] = _this->gl_config.green_size;
312     attribs[i++] = EGL_BLUE_SIZE;
313     attribs[i++] = _this->gl_config.blue_size;
314 
315     if (_this->gl_config.alpha_size) {
316         attribs[i++] = EGL_ALPHA_SIZE;
317         attribs[i++] = _this->gl_config.alpha_size;
318     }
319 
320     if (_this->gl_config.buffer_size) {
321         attribs[i++] = EGL_BUFFER_SIZE;
322         attribs[i++] = _this->gl_config.buffer_size;
323     }
324 
325     attribs[i++] = EGL_DEPTH_SIZE;
326     attribs[i++] = _this->gl_config.depth_size;
327 
328     if (_this->gl_config.stencil_size) {
329         attribs[i++] = EGL_STENCIL_SIZE;
330         attribs[i++] = _this->gl_config.stencil_size;
331     }
332 
333     if (_this->gl_config.multisamplebuffers) {
334         attribs[i++] = EGL_SAMPLE_BUFFERS;
335         attribs[i++] = _this->gl_config.multisamplebuffers;
336     }
337 
338     if (_this->gl_config.multisamplesamples) {
339         attribs[i++] = EGL_SAMPLES;
340         attribs[i++] = _this->gl_config.multisamplesamples;
341     }
342 
343     if (_this->gl_config.framebuffer_srgb_capable) {
344 #ifdef EGL_KHR_gl_colorspace
345         if (SDL_EGL_HasExtension(_this, "EGL_KHR_gl_colorspace")) {
346             attribs[i++] = EGL_GL_COLORSPACE_KHR;
347             attribs[i++] = EGL_GL_COLORSPACE_SRGB_KHR;
348         } else
349 #endif
350         {
351             return SDL_SetError("EGL implementation does not support sRGB system framebuffers");
352         }
353     }
354 
355     attribs[i++] = EGL_RENDERABLE_TYPE;
356     if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
357 #ifdef EGL_KHR_create_context
358         if (_this->gl_config.major_version >= 3 &&
359             SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
360             attribs[i++] = EGL_OPENGL_ES3_BIT_KHR;
361         } else
362 #endif
363         if (_this->gl_config.major_version >= 2) {
364             attribs[i++] = EGL_OPENGL_ES2_BIT;
365         } else {
366             attribs[i++] = EGL_OPENGL_ES_BIT;
367         }
368         _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
369     } else {
370         attribs[i++] = EGL_OPENGL_BIT;
371         _this->egl_data->eglBindAPI(EGL_OPENGL_API);
372     }
373 
374     attribs[i++] = EGL_NONE;
375 
376     if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
377         attribs,
378         configs, SDL_arraysize(configs),
379         &found_configs) == EGL_FALSE ||
380         found_configs == 0) {
381         return SDL_SetError("Couldn't find matching EGL config");
382     }
383 
384     /* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
385     /* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
386 
387     for (i = 0; i < found_configs; i++ ) {
388         bitdiff = 0;
389         for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
390             if (attribs[j] == EGL_NONE) {
391                break;
392             }
393 
394             if ( attribs[j+1] != EGL_DONT_CARE && (
395                 attribs[j] == EGL_RED_SIZE ||
396                 attribs[j] == EGL_GREEN_SIZE ||
397                 attribs[j] == EGL_BLUE_SIZE ||
398                 attribs[j] == EGL_ALPHA_SIZE ||
399                 attribs[j] == EGL_DEPTH_SIZE ||
400                 attribs[j] == EGL_STENCIL_SIZE)) {
401                 _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
402                 bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
403             }
404         }
405 
406         if (bitdiff < best_bitdiff || best_bitdiff == -1) {
407             _this->egl_data->egl_config = configs[i];
408 
409             best_bitdiff = bitdiff;
410         }
411 
412         if (bitdiff == 0) {
413             break; /* we found an exact match! */
414         }
415     }
416 
417     return 0;
418 }
419 
420 SDL_GLContext
SDL_EGL_CreateContext(_THIS,EGLSurface egl_surface)421 SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
422 {
423     /* max 14 values plus terminator. */
424     EGLint attribs[15];
425     int attr = 0;
426 
427     EGLContext egl_context, share_context = EGL_NO_CONTEXT;
428     EGLint profile_mask = _this->gl_config.profile_mask;
429     EGLint major_version = _this->gl_config.major_version;
430     EGLint minor_version = _this->gl_config.minor_version;
431     SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
432 
433     if (!_this->egl_data) {
434         /* The EGL library wasn't loaded, SDL_GetError() should have info */
435         return NULL;
436     }
437 
438     if (_this->gl_config.share_with_current_context) {
439         share_context = (EGLContext)SDL_GL_GetCurrentContext();
440     }
441 
442     /* Set the context version and other attributes. */
443     if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
444         _this->gl_config.flags == 0 &&
445         (profile_mask == 0 || profile_es)) {
446         /* Create a context without using EGL_KHR_create_context attribs.
447          * When creating a GLES context without EGL_KHR_create_context we can
448          * only specify the major version. When creating a desktop GL context
449          * we can't specify any version, so we only try in that case when the
450          * version is less than 3.0 (matches SDL's GLX/WGL behavior.)
451          */
452         if (profile_es) {
453             attribs[attr++] = EGL_CONTEXT_CLIENT_VERSION;
454             attribs[attr++] = SDL_max(major_version, 1);
455         }
456     } else {
457 #ifdef EGL_KHR_create_context
458         /* The Major/minor version, context profiles, and context flags can
459          * only be specified when this extension is available.
460          */
461         if (SDL_EGL_HasExtension(_this, "EGL_KHR_create_context")) {
462             attribs[attr++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
463             attribs[attr++] = major_version;
464             attribs[attr++] = EGL_CONTEXT_MINOR_VERSION_KHR;
465             attribs[attr++] = minor_version;
466 
467             /* SDL profile bits match EGL profile bits. */
468             if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
469                 attribs[attr++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
470                 attribs[attr++] = profile_mask;
471             }
472 
473             /* SDL flags match EGL flags. */
474             if (_this->gl_config.flags != 0) {
475                 attribs[attr++] = EGL_CONTEXT_FLAGS_KHR;
476                 attribs[attr++] = _this->gl_config.flags;
477             }
478         } else
479 #endif /* EGL_KHR_create_context */
480         {
481             SDL_SetError("Could not create EGL context (context attributes are not supported)");
482             return NULL;
483         }
484     }
485 
486     attribs[attr++] = EGL_NONE;
487 
488     /* Bind the API */
489     if (profile_es) {
490         _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
491     } else {
492         _this->egl_data->eglBindAPI(EGL_OPENGL_API);
493     }
494 
495     egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
496                                       _this->egl_data->egl_config,
497                                       share_context, attribs);
498 
499     if (egl_context == EGL_NO_CONTEXT) {
500         SDL_SetError("Could not create EGL context");
501         return NULL;
502     }
503 
504     _this->egl_data->egl_swapinterval = 0;
505 
506     if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) {
507         SDL_EGL_DeleteContext(_this, egl_context);
508         SDL_SetError("Could not make EGL context current");
509         return NULL;
510     }
511 
512     return (SDL_GLContext) egl_context;
513 }
514 
515 int
SDL_EGL_MakeCurrent(_THIS,EGLSurface egl_surface,SDL_GLContext context)516 SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
517 {
518     EGLContext egl_context = (EGLContext) context;
519 
520     if (!_this->egl_data) {
521         return SDL_SetError("OpenGL not initialized");
522     }
523 
524     /* The android emulator crashes badly if you try to eglMakeCurrent
525      * with a valid context and invalid surface, so we have to check for both here.
526      */
527     if (!egl_context || !egl_surface) {
528          _this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
529     } else {
530         if (!_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display,
531             egl_surface, egl_surface, egl_context)) {
532             return SDL_SetError("Unable to make EGL context current");
533         }
534     }
535 
536     return 0;
537 }
538 
539 int
SDL_EGL_SetSwapInterval(_THIS,int interval)540 SDL_EGL_SetSwapInterval(_THIS, int interval)
541 {
542     EGLBoolean status;
543 
544     if (!_this->egl_data) {
545         return SDL_SetError("EGL not initialized");
546     }
547 
548     status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
549     if (status == EGL_TRUE) {
550         _this->egl_data->egl_swapinterval = interval;
551         return 0;
552     }
553 
554     return SDL_SetError("Unable to set the EGL swap interval");
555 }
556 
557 int
SDL_EGL_GetSwapInterval(_THIS)558 SDL_EGL_GetSwapInterval(_THIS)
559 {
560     if (!_this->egl_data) {
561         SDL_SetError("EGL not initialized");
562         return 0;
563     }
564 
565     return _this->egl_data->egl_swapinterval;
566 }
567 
568 void
SDL_EGL_SwapBuffers(_THIS,EGLSurface egl_surface)569 SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
570 {
571     _this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface);
572 }
573 
574 void
SDL_EGL_DeleteContext(_THIS,SDL_GLContext context)575 SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
576 {
577     EGLContext egl_context = (EGLContext) context;
578 
579     /* Clean up GLES and EGL */
580     if (!_this->egl_data) {
581         return;
582     }
583 
584     if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
585         SDL_EGL_MakeCurrent(_this, NULL, NULL);
586         _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
587     }
588 
589 }
590 
591 EGLSurface *
SDL_EGL_CreateSurface(_THIS,NativeWindowType nw)592 SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
593 {
594     if (SDL_EGL_ChooseConfig(_this) != 0) {
595         return EGL_NO_SURFACE;
596     }
597 
598 #if __ANDROID__
599     {
600         /* Android docs recommend doing this!
601          * Ref: http://developer.android.com/reference/android/app/NativeActivity.html
602          */
603         EGLint format;
604         _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
605                                             _this->egl_data->egl_config,
606                                             EGL_NATIVE_VISUAL_ID, &format);
607 
608         ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
609     }
610 #endif
611 
612     return _this->egl_data->eglCreateWindowSurface(
613             _this->egl_data->egl_display,
614             _this->egl_data->egl_config,
615             nw, NULL);
616 }
617 
618 void
SDL_EGL_DestroySurface(_THIS,EGLSurface egl_surface)619 SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
620 {
621     if (!_this->egl_data) {
622         return;
623     }
624 
625     if (egl_surface != EGL_NO_SURFACE) {
626         _this->egl_data->eglDestroySurface(_this->egl_data->egl_display, egl_surface);
627     }
628 }
629 
630 #endif /* SDL_VIDEO_OPENGL_EGL */
631 
632 /* vi: set ts=4 sw=4 expandtab: */
633 
634