#include <stdlib.h>
#include <string.h>
#include "c11/threads.h"
+#include "util/u_atomic.h"
#include "eglcontext.h"
#include "eglcurrent.h"
/**
- * Map --with-egl-platforms names to platform types.
+ * Map --with-platforms names to platform types.
*/
static const struct {
_EGLPlatformType platform;
_EGLPlatformType
_eglGetNativePlatform(void *nativeDisplay)
{
- static _EGLPlatformType native_platform;
- char *detection_method;
+ static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
+ _EGLPlatformType detected_platform = native_platform;
- native_platform = _eglGetNativePlatformFromEnv();
- detection_method = "environment overwrite";
+ if (detected_platform == _EGL_INVALID_PLATFORM) {
+ const char *detection_method;
- if (native_platform == _EGL_INVALID_PLATFORM) {
- native_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
- detection_method = "autodetected";
- }
+ detected_platform = _eglGetNativePlatformFromEnv();
+ detection_method = "environment overwrite";
- if (native_platform == _EGL_INVALID_PLATFORM) {
- native_platform = _EGL_NATIVE_PLATFORM;
- detection_method = "build-time configuration";
- }
+ if (detected_platform == _EGL_INVALID_PLATFORM) {
+ detected_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
+ detection_method = "autodetected";
+ }
- _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
- egl_platforms[native_platform].name, detection_method);
+ if (detected_platform == _EGL_INVALID_PLATFORM) {
+ detected_platform = _EGL_NATIVE_PLATFORM;
+ detection_method = "build-time configuration";
+ }
+
+ _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
+ egl_platforms[detected_platform].name, detection_method);
+
+ p_atomic_cmpxchg(&native_platform, _EGL_INVALID_PLATFORM,
+ detected_platform);
+ }
return native_platform;
}
/* EGL_EXT_platform_x11 recognizes exactly one attribute,
* EGL_PLATFORM_X11_SCREEN_EXT, which is optional.
*/
- if (attrib == EGL_PLATFORM_X11_SCREEN_EXT) {
- display->Options.Platform = (void *)value;
- } else {
- _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
- return EGL_FALSE;
- }
+ if (attrib != EGL_PLATFORM_X11_SCREEN_EXT)
+ return _eglError(EGL_BAD_ATTRIBUTE, "eglGetPlatformDisplay");
+
+ display->Options.Platform = (void *)(uintptr_t)value;
}
return EGL_TRUE;
_EGLDisplay *display = _eglFindDisplay(_EGL_PLATFORM_X11,
native_display);
- if (!display)
+ if (!display) {
_eglError(EGL_BAD_ALLOC, "eglGetPlatformDisplay");
+ return NULL;
+ }
if (!_eglParseX11DisplayAttribList(display, attrib_list)) {
return NULL;