SDL  2.0
SDL_egl.c
Go to the documentation of this file.
1 /*
2  * Simple DirectMedia Layer
3  * Copyright (C) 1997-2020 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 #if SDL_VIDEO_DRIVER_ANDROID
29 #include <android/native_window.h>
30 #include "../core/android/SDL_android.h"
31 #endif
32 
33 #include "SDL_sysvideo.h"
34 #include "SDL_log.h"
35 #include "SDL_egl_c.h"
36 #include "SDL_loadso.h"
37 #include "SDL_hints.h"
38 
39 #ifdef EGL_KHR_create_context
40 /* EGL_OPENGL_ES3_BIT_KHR was added in version 13 of the extension. */
41 #ifndef EGL_OPENGL_ES3_BIT_KHR
42 #define EGL_OPENGL_ES3_BIT_KHR 0x00000040
43 #endif
44 #endif /* EGL_KHR_create_context */
45 
46 #if SDL_VIDEO_DRIVER_RPI
47 /* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
48 #define DEFAULT_EGL ( vc4 ? "libEGL.so.1" : "libbrcmEGL.so" )
49 #define DEFAULT_OGL_ES2 ( vc4 ? "libGLESv2.so.2" : "libbrcmGLESv2.so" )
50 #define ALT_EGL "libEGL.so"
51 #define ALT_OGL_ES2 "libGLESv2.so"
52 #define DEFAULT_OGL_ES_PVR ( vc4 ? "libGLES_CM.so.1" : "libbrcmGLESv2.so" )
53 #define DEFAULT_OGL_ES ( vc4 ? "libGLESv1_CM.so.1" : "libbrcmGLESv2.so" )
54 
55 #elif SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_VIVANTE
56 /* Android */
57 #define DEFAULT_EGL "libEGL.so"
58 #define DEFAULT_OGL_ES2 "libGLESv2.so"
59 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
60 #define DEFAULT_OGL_ES "libGLESv1_CM.so"
61 
62 #elif SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
63 /* EGL AND OpenGL ES support via ANGLE */
64 #define DEFAULT_EGL "libEGL.dll"
65 #define DEFAULT_OGL_ES2 "libGLESv2.dll"
66 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
67 #define DEFAULT_OGL_ES "libGLESv1_CM.dll"
68 
69 #elif SDL_VIDEO_DRIVER_COCOA
70 /* EGL AND OpenGL ES support via ANGLE */
71 #define DEFAULT_EGL "libEGL.dylib"
72 #define DEFAULT_OGL_ES2 "libGLESv2.dylib"
73 #define DEFAULT_OGL_ES_PVR "libGLES_CM.dylib" //???
74 #define DEFAULT_OGL_ES "libGLESv1_CM.dylib" //???
75 
76 #else
77 /* Desktop Linux */
78 #define DEFAULT_OGL "libGL.so.1"
79 #define DEFAULT_EGL "libEGL.so.1"
80 #define DEFAULT_OGL_ES2 "libGLESv2.so.2"
81 #define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
82 #define DEFAULT_OGL_ES "libGLESv1_CM.so.1"
83 #endif /* SDL_VIDEO_DRIVER_RPI */
84 
85 /** If we happen to not have this defined because of an older EGL version, just define it 0x0
86  as eglGetPlatformDisplayEXT will most likely be NULL if this is missing
87 */
88 #ifndef EGL_PLATFORM_DEVICE_EXT
89 #define EGL_PLATFORM_DEVICE_EXT 0x0
90 #endif
91 
92 #ifdef SDL_VIDEO_STATIC_ANGLE
93 #define LOAD_FUNC(NAME) \
94 _this->egl_data->NAME = (void *)NAME;
95 #else
96 #define LOAD_FUNC(NAME) \
97 _this->egl_data->NAME = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
98 if (!_this->egl_data->NAME) \
99 { \
100  return SDL_SetError("Could not retrieve EGL function " #NAME); \
101 }
102 #endif
103 
104 /* it is allowed to not have some of the EGL extensions on start - attempts to use them will fail later. */
105 #define LOAD_FUNC_EGLEXT(NAME) \
106  _this->egl_data->NAME = _this->egl_data->eglGetProcAddress(#NAME);
107 
108 
109 static const char * SDL_EGL_GetErrorName(EGLint eglErrorCode)
110 {
111 #define SDL_EGL_ERROR_TRANSLATE(e) case e: return #e;
112  switch (eglErrorCode) {
113  SDL_EGL_ERROR_TRANSLATE(EGL_SUCCESS);
114  SDL_EGL_ERROR_TRANSLATE(EGL_NOT_INITIALIZED);
115  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_ACCESS);
116  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_ALLOC);
117  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_ATTRIBUTE);
118  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_CONTEXT);
119  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_CONFIG);
120  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_CURRENT_SURFACE);
121  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_DISPLAY);
122  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_SURFACE);
123  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_MATCH);
124  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_PARAMETER);
125  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_NATIVE_PIXMAP);
126  SDL_EGL_ERROR_TRANSLATE(EGL_BAD_NATIVE_WINDOW);
127  SDL_EGL_ERROR_TRANSLATE(EGL_CONTEXT_LOST);
128  }
129  return "";
130 }
131 
132 int SDL_EGL_SetErrorEx(const char * message, const char * eglFunctionName, EGLint eglErrorCode)
133 {
134  const char * errorText = SDL_EGL_GetErrorName(eglErrorCode);
135  char altErrorText[32];
136  if (errorText[0] == '\0') {
137  /* An unknown-to-SDL error code was reported. Report its hexadecimal value, instead of its name. */
138  SDL_snprintf(altErrorText, SDL_arraysize(altErrorText), "0x%x", (unsigned int)eglErrorCode);
139  errorText = altErrorText;
140  }
141  return SDL_SetError("%s (call to %s failed, reporting an error of %s)", message, eglFunctionName, errorText);
142 }
143 
144 /* EGL implementation of SDL OpenGL ES support */
145 typedef enum {
146  SDL_EGL_DISPLAY_EXTENSION,
147  SDL_EGL_CLIENT_EXTENSION
148 } SDL_EGL_ExtensionType;
149 
150 static SDL_bool SDL_EGL_HasExtension(_THIS, SDL_EGL_ExtensionType type, const char *ext)
151 {
152  size_t ext_len;
153  const char *ext_override;
154  const char *egl_extstr;
155  const char *ext_start;
156 
157  /* Invalid extensions can be rejected early */
158  if (ext == NULL || *ext == 0 || SDL_strchr(ext, ' ') != NULL) {
159  /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "SDL_EGL_HasExtension: Invalid EGL extension"); */
160  return SDL_FALSE;
161  }
162 
163  /* Extensions can be masked with an environment variable.
164  * Unlike the OpenGL override, this will use the set bits of an integer
165  * to disable the extension.
166  * Bit Action
167  * 0 If set, the display extension is masked and not present to SDL.
168  * 1 If set, the client extension is masked and not present to SDL.
169  */
170  ext_override = SDL_getenv(ext);
171  if (ext_override != NULL) {
172  int disable_ext = SDL_atoi(ext_override);
173  if (disable_ext & 0x01 && type == SDL_EGL_DISPLAY_EXTENSION) {
174  return SDL_FALSE;
175  } else if (disable_ext & 0x02 && type == SDL_EGL_CLIENT_EXTENSION) {
176  return SDL_FALSE;
177  }
178  }
179 
180  ext_len = SDL_strlen(ext);
181  switch (type) {
182  case SDL_EGL_DISPLAY_EXTENSION:
183  egl_extstr = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_EXTENSIONS);
184  break;
185  case SDL_EGL_CLIENT_EXTENSION:
186  /* EGL_EXT_client_extensions modifies eglQueryString to return client extensions
187  * if EGL_NO_DISPLAY is passed. Implementations without it are required to return NULL.
188  * This behavior is included in EGL 1.5.
189  */
190  egl_extstr = _this->egl_data->eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
191  break;
192  default:
193  /* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "SDL_EGL_HasExtension: Invalid extension type"); */
194  return SDL_FALSE;
195  }
196 
197  if (egl_extstr != NULL) {
198  ext_start = egl_extstr;
199 
200  while (*ext_start) {
201  ext_start = SDL_strstr(ext_start, ext);
202  if (ext_start == NULL) {
203  return SDL_FALSE;
204  }
205  /* Check if the match is not just a substring of one of the extensions */
206  if (ext_start == egl_extstr || *(ext_start - 1) == ' ') {
207  if (ext_start[ext_len] == ' ' || ext_start[ext_len] == 0) {
208  return SDL_TRUE;
209  }
210  }
211  /* If the search stopped in the middle of an extension, skip to the end of it */
212  ext_start += ext_len;
213  while (*ext_start != ' ' && *ext_start != 0) {
214  ext_start++;
215  }
216  }
217  }
218 
219  return SDL_FALSE;
220 }
221 
222 void *
223 SDL_EGL_GetProcAddress(_THIS, const char *proc)
224 {
225  const Uint32 eglver = (((Uint32) _this->egl_data->egl_version_major) << 16) | ((Uint32) _this->egl_data->egl_version_minor);
226  const SDL_bool is_egl_15_or_later = eglver >= ((((Uint32) 1) << 16) | 5);
227  void *retval = NULL;
228 
229  /* EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points. */
230  if (!retval && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
231  retval = _this->egl_data->eglGetProcAddress(proc);
232  }
233 
234  /* Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5. */
235  if (!retval) {
236  static char procname[64];
237  retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
238  /* just in case you need an underscore prepended... */
239  if (!retval && (SDL_strlen(proc) < (sizeof (procname) - 1))) {
240  procname[0] = '_';
241  SDL_strlcpy(procname + 1, proc, sizeof (procname) - 1);
242  retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
243  }
244  }
245 
246  /* Try eglGetProcAddress if we on <= 1.4 and still searching... */
247  if (!retval && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
248  retval = _this->egl_data->eglGetProcAddress(proc);
249  if (retval) {
250  return retval;
251  }
252  }
253 
254  return retval;
255 }
256 
257 void
258 SDL_EGL_UnloadLibrary(_THIS)
259 {
260  if (_this->egl_data) {
261  if (_this->egl_data->egl_display) {
262  _this->egl_data->eglTerminate(_this->egl_data->egl_display);
263  _this->egl_data->egl_display = NULL;
264  }
265 
266  if (_this->egl_data->dll_handle) {
267  SDL_UnloadObject(_this->egl_data->dll_handle);
268  _this->egl_data->dll_handle = NULL;
269  }
270  if (_this->egl_data->egl_dll_handle) {
271  SDL_UnloadObject(_this->egl_data->egl_dll_handle);
272  _this->egl_data->egl_dll_handle = NULL;
273  }
274 
275  SDL_free(_this->egl_data);
276  _this->egl_data = NULL;
277  }
278 }
279 
280 int
281 SDL_EGL_LoadLibraryOnly(_THIS, const char *egl_path)
282 {
283  void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
284  const char *path = NULL;
285 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
286  const char *d3dcompiler;
287 #endif
288 #if SDL_VIDEO_DRIVER_RPI
289  SDL_bool vc4 = (0 == access("/sys/module/vc4/", F_OK));
290 #endif
291 
292  if (_this->egl_data) {
293  return SDL_SetError("EGL context already created");
294  }
295 
296  _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
297  if (!_this->egl_data) {
298  return SDL_OutOfMemory();
299  }
300 
301 #if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
303  if (d3dcompiler) {
304  if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
305  if (SDL_LoadObject(d3dcompiler) == NULL) {
306  SDL_ClearError();
307  }
308  }
309  } else {
311  /* Try the newer d3d compilers first */
312  const char *d3dcompiler_list[] = {
313  "d3dcompiler_47.dll", "d3dcompiler_46.dll",
314  };
315  int i;
316 
317  for (i = 0; i < SDL_arraysize(d3dcompiler_list); ++i) {
318  if (SDL_LoadObject(d3dcompiler_list[i]) != NULL) {
319  break;
320  }
321  SDL_ClearError();
322  }
323  } else {
324  if (SDL_LoadObject("d3dcompiler_43.dll") == NULL) {
325  SDL_ClearError();
326  }
327  }
328  }
329 #endif
330 
331 #ifndef SDL_VIDEO_STATIC_ANGLE
332  /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
333  path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
334  if (path != NULL) {
335  egl_dll_handle = SDL_LoadObject(path);
336  }
337 
338  if (egl_dll_handle == NULL) {
340  if (_this->gl_config.major_version > 1) {
341  path = DEFAULT_OGL_ES2;
342  egl_dll_handle = SDL_LoadObject(path);
343 #ifdef ALT_OGL_ES2
344  if (egl_dll_handle == NULL && !vc4) {
345  path = ALT_OGL_ES2;
346  egl_dll_handle = SDL_LoadObject(path);
347  }
348 #endif
349 
350  } else {
351  path = DEFAULT_OGL_ES;
352  egl_dll_handle = SDL_LoadObject(path);
353  if (egl_dll_handle == NULL) {
354  path = DEFAULT_OGL_ES_PVR;
355  egl_dll_handle = SDL_LoadObject(path);
356  }
357 #ifdef ALT_OGL_ES2
358  if (egl_dll_handle == NULL && !vc4) {
359  path = ALT_OGL_ES2;
360  egl_dll_handle = SDL_LoadObject(path);
361  }
362 #endif
363  }
364  }
365 #ifdef DEFAULT_OGL
366  else {
367  path = DEFAULT_OGL;
368  egl_dll_handle = SDL_LoadObject(path);
369  }
370 #endif
371  }
372  _this->egl_data->egl_dll_handle = egl_dll_handle;
373 
374  if (egl_dll_handle == NULL) {
375  return SDL_SetError("Could not initialize OpenGL / GLES library");
376  }
377 
378  /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
379  if (egl_path != NULL) {
380  dll_handle = SDL_LoadObject(egl_path);
381  }
382  /* Try loading a EGL symbol, if it does not work try the default library paths */
383  if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
384  if (dll_handle != NULL) {
385  SDL_UnloadObject(dll_handle);
386  }
387  path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
388  if (path == NULL) {
389  path = DEFAULT_EGL;
390  }
391  dll_handle = SDL_LoadObject(path);
392 
393 #ifdef ALT_EGL
394  if (dll_handle == NULL && !vc4) {
395  path = ALT_EGL;
396  dll_handle = SDL_LoadObject(path);
397  }
398 #endif
399 
400  if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
401  if (dll_handle != NULL) {
402  SDL_UnloadObject(dll_handle);
403  }
404  return SDL_SetError("Could not load EGL library");
405  }
406  SDL_ClearError();
407  }
408 #endif
409 
410  _this->egl_data->dll_handle = dll_handle;
411 
412  /* Load new function pointers */
413  LOAD_FUNC(eglGetDisplay);
414  LOAD_FUNC(eglInitialize);
415  LOAD_FUNC(eglTerminate);
416  LOAD_FUNC(eglGetProcAddress);
417  LOAD_FUNC(eglChooseConfig);
418  LOAD_FUNC(eglGetConfigAttrib);
419  LOAD_FUNC(eglCreateContext);
420  LOAD_FUNC(eglDestroyContext);
421  LOAD_FUNC(eglCreatePbufferSurface);
422  LOAD_FUNC(eglCreateWindowSurface);
423  LOAD_FUNC(eglDestroySurface);
424  LOAD_FUNC(eglMakeCurrent);
425  LOAD_FUNC(eglSwapBuffers);
426  LOAD_FUNC(eglSwapInterval);
427  LOAD_FUNC(eglWaitNative);
428  LOAD_FUNC(eglWaitGL);
429  LOAD_FUNC(eglBindAPI);
430  LOAD_FUNC(eglQueryAPI);
431  LOAD_FUNC(eglQueryString);
432  LOAD_FUNC(eglGetError);
433  LOAD_FUNC_EGLEXT(eglQueryDevicesEXT);
434  LOAD_FUNC_EGLEXT(eglGetPlatformDisplayEXT);
435 
437 
438  if (path) {
440  } else {
441  *_this->gl_config.driver_path = '\0';
442  }
443 
444  return 0;
445 }
446 
447 static void
448 SDL_EGL_GetVersion(_THIS) {
449  if (_this->egl_data->eglQueryString) {
450  const char *egl_version = _this->egl_data->eglQueryString(_this->egl_data->egl_display, EGL_VERSION);
451  if (egl_version) {
452  int major = 0, minor = 0;
453  if (SDL_sscanf(egl_version, "%d.%d", &major, &minor) == 2) {
454  _this->egl_data->egl_version_major = major;
455  _this->egl_data->egl_version_minor = minor;
456  } else {
457  SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not parse EGL version string: %s", egl_version);
458  }
459  }
460  }
461 }
462 
463 int
464 SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
465 {
466  int egl_version_major, egl_version_minor;
467  int library_load_retcode = SDL_EGL_LoadLibraryOnly(_this, egl_path);
468  if (library_load_retcode != 0) {
469  return library_load_retcode;
470  }
471 
472  /* EGL 1.5 allows querying for client version with EGL_NO_DISPLAY */
473  SDL_EGL_GetVersion(_this);
474 
475  egl_version_major = _this->egl_data->egl_version_major;
476  egl_version_minor = _this->egl_data->egl_version_minor;
477 
478  if (egl_version_major == 1 && egl_version_minor == 5) {
479  LOAD_FUNC(eglGetPlatformDisplay);
480  }
481 
482  _this->egl_data->egl_display = EGL_NO_DISPLAY;
483 #if !defined(__WINRT__)
484  if (platform) {
485  if (egl_version_major == 1 && egl_version_minor == 5) {
486  _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplay(platform, (void *)(size_t)native_display, NULL);
487  } else {
488  if (SDL_EGL_HasExtension(_this, SDL_EGL_CLIENT_EXTENSION, "EGL_EXT_platform_base")) {
489  _this->egl_data->eglGetPlatformDisplayEXT = SDL_EGL_GetProcAddress(_this, "eglGetPlatformDisplayEXT");
490  if (_this->egl_data->eglGetPlatformDisplayEXT) {
491  _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplayEXT(platform, (void *)(size_t)native_display, NULL);
492  }
493  }
494  }
495  }
496  /* Try the implementation-specific eglGetDisplay even if eglGetPlatformDisplay fails */
497  if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
498  _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
499  }
500  if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
502  *_this->gl_config.driver_path = '\0';
503  return SDL_SetError("Could not get EGL display");
504  }
505 
506  if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
508  *_this->gl_config.driver_path = '\0';
509  return SDL_SetError("Could not initialize EGL");
510  }
511 #endif
512 
513  /* Get the EGL version with a valid egl_display, for EGL <= 1.4 */
514  SDL_EGL_GetVersion(_this);
515 
516  _this->egl_data->is_offscreen = 0;
517 
518  return 0;
519 }
520 
521 /**
522  On multi GPU machines EGL device 0 is not always the first valid GPU.
523  Container environments can restrict access to some GPUs that are still listed in the EGL
524  device list. If the requested device is a restricted GPU and cannot be used
525  (eglInitialize() will fail) then attempt to automatically and silently select the next
526  valid available GPU for EGL to use.
527 */
528 
529 int
530 SDL_EGL_InitializeOffscreen(_THIS, int device)
531 {
532  void *egl_devices[SDL_EGL_MAX_DEVICES];
533  EGLint num_egl_devices = 0;
534  const char *egl_device_hint;
535 
536  if (_this->gl_config.driver_loaded != 1) {
537  return SDL_SetError("SDL_EGL_LoadLibraryOnly() has not been called or has failed.");
538  }
539 
540  /* Check for all extensions that are optional until used and fail if any is missing */
541  if (_this->egl_data->eglQueryDevicesEXT == NULL) {
542  return SDL_SetError("eglQueryDevicesEXT is missing (EXT_device_enumeration not supported by the drivers?)");
543  }
544 
545  if (_this->egl_data->eglGetPlatformDisplayEXT == NULL) {
546  return SDL_SetError("eglGetPlatformDisplayEXT is missing (EXT_platform_base not supported by the drivers?)");
547  }
548 
549  if (_this->egl_data->eglQueryDevicesEXT(SDL_EGL_MAX_DEVICES, egl_devices, &num_egl_devices) != EGL_TRUE) {
550  return SDL_SetError("eglQueryDevicesEXT() failed");
551  }
552 
553  egl_device_hint = SDL_GetHint("SDL_HINT_EGL_DEVICE");
554  if (egl_device_hint) {
555  device = SDL_atoi(egl_device_hint);
556 
557  if (device >= num_egl_devices) {
558  return SDL_SetError("Invalid EGL device is requested.");
559  }
560 
561  _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, egl_devices[device], NULL);
562 
563  if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
564  return SDL_SetError("eglGetPlatformDisplayEXT() failed.");
565  }
566 
567  if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
568  return SDL_SetError("Could not initialize EGL");
569  }
570  }
571  else {
572  int i;
573  SDL_bool found = SDL_FALSE;
574  EGLDisplay attempted_egl_display;
575 
576  /* If no hint is provided lets look for the first device/display that will allow us to eglInit */
577  for (i = 0; i < num_egl_devices; i++) {
578  attempted_egl_display = _this->egl_data->eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, egl_devices[i], NULL);
579 
580  if (attempted_egl_display == EGL_NO_DISPLAY) {
581  continue;
582  }
583 
584  if (_this->egl_data->eglInitialize(attempted_egl_display, NULL, NULL) != EGL_TRUE) {
585  _this->egl_data->eglTerminate(attempted_egl_display);
586  continue;
587  }
588 
589  /* We did not fail, we'll pick this one! */
590  _this->egl_data->egl_display = attempted_egl_display;
591  found = SDL_TRUE;
592 
593  break;
594  }
595 
596  if (!found) {
597  return SDL_SetError("Could not find a valid EGL device to initialize");
598  }
599  }
600 
601  /* Get the EGL version with a valid egl_display, for EGL <= 1.4 */
602  SDL_EGL_GetVersion(_this);
603 
604  _this->egl_data->is_offscreen = 1;
605 
606  return 0;
607 }
608 
609 void
610 SDL_EGL_SetRequiredVisualId(_THIS, int visual_id)
611 {
612  _this->egl_data->egl_required_visual_id=visual_id;
613 }
614 
615 #ifdef DUMP_EGL_CONFIG
616 
617 #define ATTRIBUTE(_attr) { _attr, #_attr }
618 
619 typedef struct {
621  char const* name;
622 } Attribute;
623 
624 Attribute attributes[] = {
625  ATTRIBUTE( EGL_BUFFER_SIZE ),
626  ATTRIBUTE( EGL_ALPHA_SIZE ),
627  ATTRIBUTE( EGL_BLUE_SIZE ),
628  ATTRIBUTE( EGL_GREEN_SIZE ),
629  ATTRIBUTE( EGL_RED_SIZE ),
630  ATTRIBUTE( EGL_DEPTH_SIZE ),
631  ATTRIBUTE( EGL_STENCIL_SIZE ),
632  ATTRIBUTE( EGL_CONFIG_CAVEAT ),
633  ATTRIBUTE( EGL_CONFIG_ID ),
634  ATTRIBUTE( EGL_LEVEL ),
635  ATTRIBUTE( EGL_MAX_PBUFFER_HEIGHT ),
636  ATTRIBUTE( EGL_MAX_PBUFFER_WIDTH ),
637  ATTRIBUTE( EGL_MAX_PBUFFER_PIXELS ),
638  ATTRIBUTE( EGL_NATIVE_RENDERABLE ),
639  ATTRIBUTE( EGL_NATIVE_VISUAL_ID ),
640  ATTRIBUTE( EGL_NATIVE_VISUAL_TYPE ),
641  ATTRIBUTE( EGL_SAMPLES ),
642  ATTRIBUTE( EGL_SAMPLE_BUFFERS ),
643  ATTRIBUTE( EGL_SURFACE_TYPE ),
644  ATTRIBUTE( EGL_TRANSPARENT_TYPE ),
645  ATTRIBUTE( EGL_TRANSPARENT_BLUE_VALUE ),
646  ATTRIBUTE( EGL_TRANSPARENT_GREEN_VALUE ),
647  ATTRIBUTE( EGL_TRANSPARENT_RED_VALUE ),
648  ATTRIBUTE( EGL_BIND_TO_TEXTURE_RGB ),
649  ATTRIBUTE( EGL_BIND_TO_TEXTURE_RGBA ),
650  ATTRIBUTE( EGL_MIN_SWAP_INTERVAL ),
651  ATTRIBUTE( EGL_MAX_SWAP_INTERVAL ),
652  ATTRIBUTE( EGL_LUMINANCE_SIZE ),
653  ATTRIBUTE( EGL_ALPHA_MASK_SIZE ),
654  ATTRIBUTE( EGL_COLOR_BUFFER_TYPE ),
655  ATTRIBUTE( EGL_RENDERABLE_TYPE ),
656  ATTRIBUTE( EGL_MATCH_NATIVE_PIXMAP ),
657  ATTRIBUTE( EGL_CONFORMANT ),
658 };
659 
660 
661 static void dumpconfig(_THIS, EGLConfig config)
662 {
663  int attr;
664  for (attr = 0 ; attr<sizeof(attributes)/sizeof(Attribute) ; attr++) {
665  EGLint value;
666  _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, config, attributes[attr].attribute, &value);
667  SDL_Log("\t%-32s: %10d (0x%08x)\n", attributes[attr].name, value, value);
668  }
669 }
670 
671 #endif /* DUMP_EGL_CONFIG */
672 
673 int
674 SDL_EGL_ChooseConfig(_THIS)
675 {
676 /* 64 seems nice. */
677  EGLint attribs[64];
678  EGLint found_configs = 0, value;
679  /* 128 seems even nicer here */
680  EGLConfig configs[128];
681  int i, j, best_bitdiff = -1, bitdiff;
682 
683  if (!_this->egl_data) {
684  /* The EGL library wasn't loaded, SDL_GetError() should have info */
685  return -1;
686  }
687 
688  /* Get a valid EGL configuration */
689  i = 0;
690  attribs[i++] = EGL_RED_SIZE;
692  attribs[i++] = EGL_GREEN_SIZE;
694  attribs[i++] = EGL_BLUE_SIZE;
696 
697  if (_this->gl_config.alpha_size) {
698  attribs[i++] = EGL_ALPHA_SIZE;
700  }
701 
702  if (_this->gl_config.buffer_size) {
705  }
706 
707  attribs[i++] = EGL_DEPTH_SIZE;
709 
713  }
714 
718  }
719 
721  attribs[i++] = EGL_SAMPLES;
723  }
724 
725  if (_this->egl_data->is_offscreen) {
728  }
729 
732 #ifdef EGL_KHR_create_context
733  if (_this->gl_config.major_version >= 3 &&
734  SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context")) {
736  } else
737 #endif
738  if (_this->gl_config.major_version >= 2) {
740  } else {
742  }
743  _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
744  } else {
745  attribs[i++] = EGL_OPENGL_BIT;
746  _this->egl_data->eglBindAPI(EGL_OPENGL_API);
747  }
748 
749  if (_this->egl_data->egl_surfacetype) {
751  attribs[i++] = _this->egl_data->egl_surfacetype;
752  }
753 
754  attribs[i++] = EGL_NONE;
755 
756  if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
757  attribs,
758  configs, SDL_arraysize(configs),
759  &found_configs) == EGL_FALSE ||
760  found_configs == 0) {
761  return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig");
762  }
763 
764  /* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
765  /* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
766 
767  for (i = 0; i < found_configs; i++ ) {
768  if (_this->egl_data->egl_required_visual_id)
769  {
770  EGLint format;
771  _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
772  configs[i],
774  if (_this->egl_data->egl_required_visual_id != format)
775  continue;
776  }
777 
778  bitdiff = 0;
779  for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
780  if (attribs[j] == EGL_NONE) {
781  break;
782  }
783 
784  if ( attribs[j+1] != EGL_DONT_CARE && (
785  attribs[j] == EGL_RED_SIZE ||
786  attribs[j] == EGL_GREEN_SIZE ||
787  attribs[j] == EGL_BLUE_SIZE ||
788  attribs[j] == EGL_ALPHA_SIZE ||
789  attribs[j] == EGL_DEPTH_SIZE ||
790  attribs[j] == EGL_STENCIL_SIZE)) {
791  _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
792  bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
793  }
794  }
795 
796  if (bitdiff < best_bitdiff || best_bitdiff == -1) {
797  _this->egl_data->egl_config = configs[i];
798 
799  best_bitdiff = bitdiff;
800  }
801 
802  if (bitdiff == 0) {
803  break; /* we found an exact match! */
804  }
805  }
806 
807 #ifdef DUMP_EGL_CONFIG
808  dumpconfig(_this, _this->egl_data->egl_config);
809 #endif
810 
811  return 0;
812 }
813 
815 SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
816 {
817  /* max 14 values plus terminator. */
818  EGLint attribs[15];
819  int attr = 0;
820 
821  EGLContext egl_context, share_context = EGL_NO_CONTEXT;
822  EGLint profile_mask = _this->gl_config.profile_mask;
823  EGLint major_version = _this->gl_config.major_version;
824  EGLint minor_version = _this->gl_config.minor_version;
825  SDL_bool profile_es = (profile_mask == SDL_GL_CONTEXT_PROFILE_ES);
826 
827  if (!_this->egl_data) {
828  /* The EGL library wasn't loaded, SDL_GetError() should have info */
829  return NULL;
830  }
831 
833  share_context = (EGLContext)SDL_GL_GetCurrentContext();
834  }
835 
836 #if SDL_VIDEO_DRIVER_ANDROID
838  /* If SDL_GL_CONTEXT_DEBUG_FLAG is set but EGL_KHR_debug unsupported, unset.
839  * This is required because some Android devices like to complain about it
840  * by "silently" failing, logging a hint which could be easily overlooked:
841  * E/libEGL (26984): validate_display:255 error 3008 (EGL_BAD_DISPLAY)
842  * The following explicitly checks for EGL_KHR_debug before EGL 1.5
843  */
844  int egl_version_major = _this->egl_data->egl_version_major;
845  int egl_version_minor = _this->egl_data->egl_version_minor;
846  if (((egl_version_major < 1) || (egl_version_major == 1 && egl_version_minor < 5)) &&
847  !SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_debug")) {
848  /* SDL profile bits match EGL profile bits. */
850  }
851  }
852 #endif
853 
854  /* Set the context version and other attributes. */
855  if ((major_version < 3 || (minor_version == 0 && profile_es)) &&
856  _this->gl_config.flags == 0 &&
857  (profile_mask == 0 || profile_es)) {
858  /* Create a context without using EGL_KHR_create_context attribs.
859  * When creating a GLES context without EGL_KHR_create_context we can
860  * only specify the major version. When creating a desktop GL context
861  * we can't specify any version, so we only try in that case when the
862  * version is less than 3.0 (matches SDL's GLX/WGL behavior.)
863  */
864  if (profile_es) {
866  attribs[attr++] = SDL_max(major_version, 1);
867  }
868  } else {
869 #ifdef EGL_KHR_create_context
870  /* The Major/minor version, context profiles, and context flags can
871  * only be specified when this extension is available.
872  */
873  if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context")) {
875  attribs[attr++] = major_version;
877  attribs[attr++] = minor_version;
878 
879  /* SDL profile bits match EGL profile bits. */
880  if (profile_mask != 0 && profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
882  attribs[attr++] = profile_mask;
883  }
884 
885  /* SDL flags match EGL flags. */
886  if (_this->gl_config.flags != 0) {
887  attribs[attr++] = EGL_CONTEXT_FLAGS_KHR;
888  attribs[attr++] = _this->gl_config.flags;
889  }
890  } else
891 #endif /* EGL_KHR_create_context */
892  {
893  SDL_SetError("Could not create EGL context (context attributes are not supported)");
894  return NULL;
895  }
896  }
897 
898  if (_this->gl_config.no_error) {
899 #ifdef EGL_KHR_create_context_no_error
900  if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_create_context_no_error")) {
902  attribs[attr++] = _this->gl_config.no_error;
903  } else
904 #endif
905  {
906  SDL_SetError("EGL implementation does not support no_error contexts");
907  return NULL;
908  }
909  }
910 
911  attribs[attr++] = EGL_NONE;
912 
913  /* Bind the API */
914  if (profile_es) {
915  _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
916  } else {
917  _this->egl_data->eglBindAPI(EGL_OPENGL_API);
918  }
919 
920  egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
921  _this->egl_data->egl_config,
922  share_context, attribs);
923 
924  if (egl_context == EGL_NO_CONTEXT) {
925  SDL_EGL_SetError("Could not create EGL context", "eglCreateContext");
926  return NULL;
927  }
928 
929  _this->egl_data->egl_swapinterval = 0;
930 
931  if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) {
932  /* Save the SDL error set by SDL_EGL_MakeCurrent */
933  char errorText[1024];
934  SDL_strlcpy(errorText, SDL_GetError(), SDL_arraysize(errorText));
935 
936  /* Delete the context, which may alter the value returned by SDL_GetError() */
937  SDL_EGL_DeleteContext(_this, egl_context);
938 
939  /* Restore the SDL error */
940  SDL_SetError("%s", errorText);
941 
942  return NULL;
943  }
944 
945  return (SDL_GLContext) egl_context;
946 }
947 
948 int
949 SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context)
950 {
951  EGLContext egl_context = (EGLContext) context;
952 
953  if (!_this->egl_data) {
954  return SDL_SetError("OpenGL not initialized");
955  }
956 
957  /* The android emulator crashes badly if you try to eglMakeCurrent
958  * with a valid context and invalid surface, so we have to check for both here.
959  */
960  if (!egl_context || !egl_surface) {
961  _this->egl_data->eglMakeCurrent(_this->egl_data->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
962  } else {
963  if (!_this->egl_data->eglMakeCurrent(_this->egl_data->egl_display,
964  egl_surface, egl_surface, egl_context)) {
965  return SDL_EGL_SetError("Unable to make EGL context current", "eglMakeCurrent");
966  }
967  }
968 
969  return 0;
970 }
971 
972 int
973 SDL_EGL_SetSwapInterval(_THIS, int interval)
974 {
975  EGLBoolean status;
976 
977  if (!_this->egl_data) {
978  return SDL_SetError("EGL not initialized");
979  }
980 
981  status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
982  if (status == EGL_TRUE) {
983  _this->egl_data->egl_swapinterval = interval;
984  return 0;
985  }
986 
987  return SDL_EGL_SetError("Unable to set the EGL swap interval", "eglSwapInterval");
988 }
989 
990 int
991 SDL_EGL_GetSwapInterval(_THIS)
992 {
993  if (!_this->egl_data) {
994  SDL_SetError("EGL not initialized");
995  return 0;
996  }
997 
998  return _this->egl_data->egl_swapinterval;
999 }
1000 
1001 int
1002 SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface)
1003 {
1004  if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) {
1005  return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers");
1006  }
1007  return 0;
1008 }
1009 
1010 void
1011 SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
1012 {
1013  EGLContext egl_context = (EGLContext) context;
1014 
1015  /* Clean up GLES and EGL */
1016  if (!_this->egl_data) {
1017  return;
1018  }
1019 
1020  if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
1021  _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
1022  }
1023 
1024 }
1025 
1026 EGLSurface *
1027 SDL_EGL_CreateSurface(_THIS, NativeWindowType nw)
1028 {
1029  /* max 2 values plus terminator. */
1030  EGLint attribs[3];
1031  int attr = 0;
1032 
1033  EGLSurface * surface;
1034 
1035  if (SDL_EGL_ChooseConfig(_this) != 0) {
1036  return EGL_NO_SURFACE;
1037  }
1038 
1039 #if SDL_VIDEO_DRIVER_ANDROID
1040  {
1041  /* Android docs recommend doing this!
1042  * Ref: http://developer.android.com/reference/android/app/NativeActivity.html
1043  */
1044  EGLint format;
1045  _this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display,
1046  _this->egl_data->egl_config,
1048 
1049  ANativeWindow_setBuffersGeometry(nw, 0, 0, format);
1050 
1051  /* Update SurfaceView holder format.
1052  * May triggers a sequence surfaceDestroyed(), surfaceCreated(), surfaceChanged(). */
1054  }
1055 #endif
1057 #ifdef EGL_KHR_gl_colorspace
1058  if (SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_KHR_gl_colorspace")) {
1059  attribs[attr++] = EGL_GL_COLORSPACE_KHR;
1061  } else
1062 #endif
1063  {
1064  SDL_SetError("EGL implementation does not support sRGB system framebuffers");
1065  return EGL_NO_SURFACE;
1066  }
1067  }
1068 
1069  attribs[attr++] = EGL_NONE;
1070 
1071  surface = _this->egl_data->eglCreateWindowSurface(
1072  _this->egl_data->egl_display,
1073  _this->egl_data->egl_config,
1074  nw, &attribs[0]);
1075  if (surface == EGL_NO_SURFACE) {
1076  SDL_EGL_SetError("unable to create an EGL window surface", "eglCreateWindowSurface");
1077  }
1078  return surface;
1079 }
1080 
1081 EGLSurface
1082 SDL_EGL_CreateOffscreenSurface(_THIS, int width, int height)
1083 {
1084  EGLint attributes[] = {
1085  EGL_WIDTH, width,
1086  EGL_HEIGHT, height,
1087  EGL_NONE
1088  };
1089 
1090  if (SDL_EGL_ChooseConfig(_this) != 0) {
1091  return EGL_NO_SURFACE;
1092  }
1093 
1094  return _this->egl_data->eglCreatePbufferSurface(
1095  _this->egl_data->egl_display,
1096  _this->egl_data->egl_config,
1097  attributes);
1098 }
1099 
1100 void
1101 SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface)
1102 {
1103  if (!_this->egl_data) {
1104  return;
1105  }
1106 
1107  if (egl_surface != EGL_NO_SURFACE) {
1108  _this->egl_data->eglDestroySurface(_this->egl_data->egl_display, egl_surface);
1109  }
1110 }
1111 
1112 #endif /* SDL_VIDEO_OPENGL_EGL */
1113 
1114 /* vi: set ts=4 sw=4 expandtab: */
1115 
EGL_CONFORMANT
#define EGL_CONFORMANT
Definition: egl.h:211
EGL_NATIVE_VISUAL_TYPE
#define EGL_NATIVE_VISUAL_TYPE
Definition: egl.h:94
format
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: SDL_opengl.h:1572
eglGetDisplay
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
EGL_OPENGL_ES_BIT
#define EGL_OPENGL_ES_BIT
Definition: egl.h:189
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
EGLContext
void * EGLContext
Definition: egl.h:60
SDL_strlcpy
#define SDL_strlcpy
Definition: SDL_dynapi_overrides.h:394
EGL_PBUFFER_BIT
#define EGL_PBUFFER_BIT
Definition: egl.h:101
EGL_MAX_PBUFFER_WIDTH
#define EGL_MAX_PBUFFER_WIDTH
Definition: egl.h:91
WIN_IsWindowsVistaOrGreater
BOOL WIN_IsWindowsVistaOrGreater(void)
eglMakeCurrent
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
SDL_ClearError
#define SDL_ClearError
Definition: SDL_dynapi_overrides.h:114
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR
#define EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR
Definition: eglext.h:92
eglSwapBuffers
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
EGL_OPENGL_ES2_BIT
#define EGL_OPENGL_ES2_BIT
Definition: egl.h:214
eglInitialize
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
eglWaitNative
EGLAPI EGLBoolean EGLAPIENTRY eglWaitNative(EGLint engine)
NULL
#define NULL
Definition: begin_code.h:167
surface
EGLSurface surface
Definition: eglext.h:248
SDL_VideoDevice::buffer_size
int buffer_size
Definition: SDL_sysvideo.h:340
attribs
const GLint * attribs
Definition: SDL_opengl_glext.h:9691
width
GLint GLint GLsizei width
Definition: SDL_opengl.h:1572
SDL_VideoDevice::multisamplesamples
int multisamplesamples
Definition: SDL_sysvideo.h:349
message
GLuint GLsizei const GLchar * message
Definition: SDL_opengl_glext.h:2486
SDL_VideoDevice::blue_size
int blue_size
Definition: SDL_sysvideo.h:337
access
GLuint GLint GLboolean GLint GLenum access
Definition: SDL_opengl_glext.h:2165
eglQueryString
EGLAPI const char *EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name)
EGL_BAD_MATCH
#define EGL_BAD_MATCH
Definition: egl.h:70
NativeWindowType
EGLNativeWindowType NativeWindowType
Definition: eglplatform.h:112
SDL_log.h
EGL_CONFIG_CAVEAT
#define EGL_CONFIG_CAVEAT
Definition: egl.h:77
eglDestroySurface
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
EGL_OPENGL_API
#define EGL_OPENGL_API
Definition: egl.h:232
EGL_MIN_SWAP_INTERVAL
#define EGL_MIN_SWAP_INTERVAL
Definition: egl.h:153
SDL_VideoDevice::driver_path
char driver_path[256]
Definition: SDL_sysvideo.h:362
SDL_VideoDevice::major_version
int major_version
Definition: SDL_sysvideo.h:351
EGLenum
unsigned int EGLenum
Definition: egl.h:171
EGL_SURFACE_TYPE
#define EGL_SURFACE_TYPE
Definition: egl.h:110
Android_JNI_SetSurfaceViewFormat
void Android_JNI_SetSurfaceViewFormat(int format)
EGL_BAD_PARAMETER
#define EGL_BAD_PARAMETER
Definition: egl.h:73
EGL_RENDERABLE_TYPE
#define EGL_RENDERABLE_TYPE
Definition: egl.h:195
SDL_UnloadObject
#define SDL_UnloadObject
Definition: SDL_dynapi_overrides.h:234
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_VideoDevice::profile_mask
int profile_mask
Definition: SDL_sysvideo.h:354
EGL_OPENGL_BIT
#define EGL_OPENGL_BIT
Definition: egl.h:233
path
GLsizei const GLchar *const * path
Definition: SDL_opengl_glext.h:3733
SDL_VideoDevice::depth_size
int depth_size
Definition: SDL_sysvideo.h:339
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:191
EGL_TRUE
#define EGL_TRUE
Definition: egl.h:116
EGL_GL_COLORSPACE_KHR
#define EGL_GL_COLORSPACE_KHR
Definition: eglext.h:171
EGL_NATIVE_VISUAL_ID
#define EGL_NATIVE_VISUAL_ID
Definition: egl.h:93
eglGetPlatformDisplay
EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplay(EGLenum platform, void *native_display, const EGLAttrib *attrib_list)
eglGetProcAddress
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress(const char *procname)
SDL_LoadObject
#define SDL_LoadObject
Definition: SDL_dynapi_overrides.h:232
EGL_TRANSPARENT_BLUE_VALUE
#define EGL_TRANSPARENT_BLUE_VALUE
Definition: egl.h:111
SDL_VideoDevice::red_size
int red_size
Definition: SDL_sysvideo.h:335
EGL_NO_CONTEXT
#define EGL_NO_CONTEXT
Definition: egl.h:98
EGL_BAD_ALLOC
#define EGL_BAD_ALLOC
Definition: egl.h:64
EGL_GREEN_SIZE
#define EGL_GREEN_SIZE
Definition: egl.h:85
SDL_HINT_VIDEO_WIN_D3DCOMPILER
#define SDL_HINT_VIDEO_WIN_D3DCOMPILER
A variable specifying which shader compiler to preload when using the Chrome ANGLE binaries.
Definition: SDL_hints.h:760
SDL_strcasecmp
#define SDL_strcasecmp
Definition: SDL_dynapi_overrides.h:419
eglBindAPI
EGLAPI EGLBoolean EGLAPIENTRY eglBindAPI(EGLenum api)
SDL_egl_c.h
EGL_MAX_PBUFFER_PIXELS
#define EGL_MAX_PBUFFER_PIXELS
Definition: egl.h:90
EGL_NATIVE_RENDERABLE
#define EGL_NATIVE_RENDERABLE
Definition: egl.h:92
EGL_OPENGL_ES3_BIT_KHR
#define EGL_OPENGL_ES3_BIT_KHR
Definition: eglext.h:101
SDL_GLContext
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:192
SDL_VideoDevice::gl_config
struct SDL_VideoDevice::@255 gl_config
SDL_GL_CONTEXT_DEBUG_FLAG
@ SDL_GL_CONTEXT_DEBUG_FLAG
Definition: SDL_video.h:237
EGL_NO_DISPLAY
#define EGL_NO_DISPLAY
Definition: egl.h:99
EGL_MAX_SWAP_INTERVAL
#define EGL_MAX_SWAP_INTERVAL
Definition: egl.h:154
context
static screen_context_t context
Definition: video.c:25
SDL_strchr
#define SDL_strchr
Definition: SDL_dynapi_overrides.h:401
EGL_NOT_INITIALIZED
#define EGL_NOT_INITIALIZED
Definition: egl.h:97
EGLDisplay
void * EGLDisplay
Definition: egl.h:55
EGL_BLUE_SIZE
#define EGL_BLUE_SIZE
Definition: egl.h:75
eglChooseConfig
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
NativeDisplayType
EGLNativeDisplayType NativeDisplayType
Definition: eglplatform.h:110
EGL_TRANSPARENT_TYPE
#define EGL_TRANSPARENT_TYPE
Definition: egl.h:115
retval
SDL_bool retval
Definition: testgamecontroller.c:65
EGLConfig
void * EGLConfig
Definition: egl.h:58
EGL_ALPHA_MASK_SIZE
#define EGL_ALPHA_MASK_SIZE
Definition: egl.h:176
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:31
EGL_NO_SURFACE
#define EGL_NO_SURFACE
Definition: egl.h:100
EGL_SUCCESS
#define EGL_SUCCESS
Definition: egl.h:109
EGL_RED_SIZE
#define EGL_RED_SIZE
Definition: egl.h:104
EGL_OPENGL_ES_API
#define EGL_OPENGL_ES_API
Definition: egl.h:191
EGL_WIDTH
#define EGL_WIDTH
Definition: egl.h:119
EGL_EXTENSIONS
#define EGL_EXTENSIONS
Definition: egl.h:83
EGL_GL_COLORSPACE_SRGB_KHR
#define EGL_GL_COLORSPACE_SRGB_KHR
Definition: eglext.h:172
config
EGLConfig config
Definition: eglext.h:433
EGL_VERSION
#define EGL_VERSION
Definition: egl.h:118
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
EGL_BAD_CURRENT_SURFACE
#define EGL_BAD_CURRENT_SURFACE
Definition: egl.h:68
EGL_CONTEXT_OPENGL_NO_ERROR_KHR
#define EGL_CONTEXT_OPENGL_NO_ERROR_KHR
Definition: eglext.h:106
height
GLint GLint GLsizei GLsizei height
Definition: SDL_opengl.h:1572
SDL_max
#define SDL_max(x, y)
Definition: SDL_stdinc.h:407
EGL_BUFFER_SIZE
#define EGL_BUFFER_SIZE
Definition: egl.h:76
EGL_BAD_NATIVE_WINDOW
#define EGL_BAD_NATIVE_WINDOW
Definition: egl.h:72
SDL_VideoDevice::driver_loaded
int driver_loaded
Definition: SDL_sysvideo.h:361
EGL_DEPTH_SIZE
#define EGL_DEPTH_SIZE
Definition: egl.h:80
eglDestroyContext
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
EGL_SAMPLE_BUFFERS
#define EGL_SAMPLE_BUFFERS
Definition: egl.h:106
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:663
EGL_STENCIL_SIZE
#define EGL_STENCIL_SIZE
Definition: egl.h:108
EGL_BAD_SURFACE
#define EGL_BAD_SURFACE
Definition: egl.h:74
SDL_VideoDevice::multisamplebuffers
int multisamplebuffers
Definition: SDL_sysvideo.h:348
EGL_LUMINANCE_SIZE
#define EGL_LUMINANCE_SIZE
Definition: egl.h:188
SDL_GL_CONTEXT_PROFILE_ES
@ SDL_GL_CONTEXT_PROFILE_ES
Definition: SDL_video.h:232
SDL_VideoDevice::share_with_current_context
int share_with_current_context
Definition: SDL_sysvideo.h:355
EGL_LEVEL
#define EGL_LEVEL
Definition: egl.h:88
SDL_VideoDevice::green_size
int green_size
Definition: SDL_sysvideo.h:336
eglCreateContext
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
EGL_TRANSPARENT_RED_VALUE
#define EGL_TRANSPARENT_RED_VALUE
Definition: egl.h:113
EGL_BAD_ATTRIBUTE
#define EGL_BAD_ATTRIBUTE
Definition: egl.h:65
EGL_ALPHA_SIZE
#define EGL_ALPHA_SIZE
Definition: egl.h:62
eglGetError
EGLAPI EGLint EGLAPIENTRY eglGetError(void)
SDL_VideoDevice::no_error
int no_error
Definition: SDL_sysvideo.h:359
eglCreateWindowSurface
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
EGL_SAMPLES
#define EGL_SAMPLES
Definition: egl.h:105
EGL_COLOR_BUFFER_TYPE
#define EGL_COLOR_BUFFER_TYPE
Definition: egl.h:183
SDL_VideoDevice::dll_handle
void * dll_handle
Definition: SDL_sysvideo.h:363
SDL_GL_GetCurrentContext
#define SDL_GL_GetCurrentContext
Definition: SDL_dynapi_overrides.h:562
SDL_sscanf
#define SDL_sscanf
Definition: SDL_dynapi_overrides.h:39
EGL_MATCH_NATIVE_PIXMAP
#define EGL_MATCH_NATIVE_PIXMAP
Definition: egl.h:213
EGLBoolean
unsigned int EGLBoolean
Definition: egl.h:54
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_VideoDevice::flags
int flags
Definition: SDL_sysvideo.h:353
EGL_NONE
#define EGL_NONE
Definition: egl.h:95
eglSwapInterval
EGLAPI EGLBoolean EGLAPIENTRY eglSwapInterval(EGLDisplay dpy, EGLint interval)
EGL_MAX_PBUFFER_HEIGHT
#define EGL_MAX_PBUFFER_HEIGHT
Definition: egl.h:89
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_calloc
#define SDL_calloc
Definition: SDL_dynapi_overrides.h:375
SDL_atoi
#define SDL_atoi
Definition: SDL_dynapi_overrides.h:410
EGL_TRANSPARENT_GREEN_VALUE
#define EGL_TRANSPARENT_GREEN_VALUE
Definition: egl.h:112
EGL_HEIGHT
#define EGL_HEIGHT
Definition: egl.h:86
SDL_getenv
#define SDL_getenv
Definition: SDL_dynapi_overrides.h:378
native_display
void * native_display
Definition: eglext.h:789
attribute
EGLSurface EGLint attribute
Definition: eglext.h:263
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:701
EGLint
khronos_int32_t EGLint
Definition: eglplatform.h:122
EGL_CONTEXT_CLIENT_VERSION
#define EGL_CONTEXT_CLIENT_VERSION
Definition: egl.h:212
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
EGL_BAD_NATIVE_PIXMAP
#define EGL_BAD_NATIVE_PIXMAP
Definition: egl.h:71
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:40
SDL_LoadFunction
void * SDL_LoadFunction(void *handle, const char *name)
eglCreatePbufferSurface
EGLAPI EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
EGL_CONTEXT_MAJOR_VERSION_KHR
#define EGL_CONTEXT_MAJOR_VERSION_KHR
Definition: eglext.h:89
EGL_CONTEXT_FLAGS_KHR
#define EGL_CONTEXT_FLAGS_KHR
Definition: eglext.h:91
SDL_hints.h
eglTerminate
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
EGL_CONTEXT_LOST
#define EGL_CONTEXT_LOST
Definition: egl.h:152
SDL_VideoDevice::framebuffer_srgb_capable
int framebuffer_srgb_capable
Definition: SDL_sysvideo.h:358
EGL_BAD_ACCESS
#define EGL_BAD_ACCESS
Definition: egl.h:63
SDL_VideoDevice::alpha_size
int alpha_size
Definition: SDL_sysvideo.h:338
EGL_DONT_CARE
#define EGL_DONT_CARE
Definition: egl.h:81
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:393
EGL_BAD_CONFIG
#define EGL_BAD_CONFIG
Definition: egl.h:66
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
eglQueryAPI
EGLAPI EGLenum EGLAPIENTRY eglQueryAPI(void)
eglWaitGL
EGLAPI EGLBoolean EGLAPIENTRY eglWaitGL(void)
j
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
EGLSurface
void * EGLSurface
Definition: egl.h:59
EGL_CONFIG_ID
#define EGL_CONFIG_ID
Definition: egl.h:78
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_sysvideo.h
SDL_VideoDevice::stencil_size
int stencil_size
Definition: SDL_sysvideo.h:341
SDL_strstr
#define SDL_strstr
Definition: SDL_dynapi_overrides.h:403
SDL_VideoDevice::minor_version
int minor_version
Definition: SDL_sysvideo.h:352
device
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_LogWarn
#define SDL_LogWarn
Definition: SDL_dynapi_overrides.h:35
EGL_CONTEXT_MINOR_VERSION_KHR
#define EGL_CONTEXT_MINOR_VERSION_KHR
Definition: eglext.h:90
SDL_loadso.h
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
EGL_BIND_TO_TEXTURE_RGB
#define EGL_BIND_TO_TEXTURE_RGB
Definition: egl.h:150
EGL_BAD_DISPLAY
#define EGL_BAD_DISPLAY
Definition: egl.h:69
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
EGL_BIND_TO_TEXTURE_RGBA
#define EGL_BIND_TO_TEXTURE_RGBA
Definition: egl.h:151
EGL_FALSE
#define EGL_FALSE
Definition: egl.h:84
eglGetConfigAttrib
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
EGL_BAD_CONTEXT
#define EGL_BAD_CONTEXT
Definition: egl.h:67
EGL_PLATFORM_DEVICE_EXT
#define EGL_PLATFORM_DEVICE_EXT
Definition: eglext.h:801
SDL_LOG_CATEGORY_VIDEO
@ SDL_LOG_CATEGORY_VIDEO
Definition: SDL_log.h:71