Don't cast the return value of malloc/realloc
[mesa.git] / src / egl / main / egldisplay.c
index 2849dd96c6431169d516d370cb3600bd20bd5c96..985e781b0b5556ad715af59a446798f1958d1d2a 100644 (file)
 #endif
 
 
+/**
+ * Map --with-egl-platforms names to platform types.
+ */
+static const struct {
+   _EGLPlatformType platform;
+   const char *name;
+} egl_platforms[_EGL_NUM_PLATFORMS] = {
+   { _EGL_PLATFORM_WINDOWS, "gdi" },
+   { _EGL_PLATFORM_X11, "x11" },
+   { _EGL_PLATFORM_WAYLAND, "wayland" },
+   { _EGL_PLATFORM_DRM, "drm" },
+   { _EGL_PLATFORM_FBDEV, "fbdev" },
+   { _EGL_PLATFORM_NULL, "null" },
+   { _EGL_PLATFORM_ANDROID, "android" }
+};
+
+
 /**
  * Return the native platform by parsing EGL_PLATFORM.
  */
 static _EGLPlatformType
 _eglGetNativePlatformFromEnv(void)
 {
-   /* map --with-egl-platforms names to platform types */
-   static const struct {
-      _EGLPlatformType platform;
-      const char *name;
-   } egl_platforms[_EGL_NUM_PLATFORMS] = {
-      { _EGL_PLATFORM_WINDOWS, "gdi" },
-      { _EGL_PLATFORM_X11, "x11" },
-      { _EGL_PLATFORM_WAYLAND, "wayland" },
-      { _EGL_PLATFORM_DRM, "drm" },
-      { _EGL_PLATFORM_FBDEV, "fbdev" }
-   };
    _EGLPlatformType plat = _EGL_INVALID_PLATFORM;
    const char *plat_name;
    EGLint i;
@@ -151,6 +157,8 @@ _eglNativePlatformDetectNativeDisplay(EGLNativeDisplayType nativeDisplay)
    if (_eglPointerIsDereferencable(nativeDisplay)) {
       void *first_pointer = *(void **) nativeDisplay;
 
+      (void) first_pointer; /* silence unused var warning */
+
 #ifdef HAVE_WAYLAND_PLATFORM
       /* wl_display is a wl_proxy, which is a wl_object.
        * wl_object's first element points to the interfacetype. */
@@ -181,16 +189,25 @@ _EGLPlatformType
 _eglGetNativePlatform(EGLNativeDisplayType nativeDisplay)
 {
    static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
+   char *detection_method = NULL;
 
    if (native_platform == _EGL_INVALID_PLATFORM) {
       native_platform = _eglGetNativePlatformFromEnv();
+      detection_method = "environment overwrite";
       if (native_platform == _EGL_INVALID_PLATFORM) {
          native_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
-         if (native_platform == _EGL_INVALID_PLATFORM)
+         detection_method = "autodetected";
+         if (native_platform == _EGL_INVALID_PLATFORM) {
             native_platform = _EGL_NATIVE_PLATFORM;
+            detection_method = "build-time configuration";
+         }
       }
    }
 
+   if (detection_method != NULL)
+      _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
+              egl_platforms[native_platform].name, detection_method);
+
    return native_platform;
 }
 
@@ -249,7 +266,7 @@ _eglFindDisplay(_EGLPlatformType plat, void *plat_dpy)
 
    /* create a new display */
    if (!dpy) {
-      dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
+      dpy = calloc(1, sizeof(_EGLDisplay));
       if (dpy) {
          _eglInitMutex(&dpy->Mutex);
          dpy->Platform = plat;