src/video/SDL_egl.c
author Gabriel Jacobo <gabomdq@gmail.com>
Thu, 03 Jul 2014 17:36:08 -0300
changeset 8971 c30e826412d1
parent 8966 5771ab3290d6
child 8976 1a5d959d7b32
permissions -rw-r--r--
Maybe fixes bug #2291 (red tinted screen on some Samsung Android devices)

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