egl: dereference XCB drawable pointers
authorJeffrey Knockel <jeff@jeffreyknockel.com>
Mon, 2 May 2022 01:15:32 +0000 (21:15 -0400)
committerMarge Bot <emma+marge@anholt.net>
Sat, 21 May 2022 14:42:06 +0000 (14:42 +0000)
eglCreatePlatformWindowSurface[EXT] and
eglCreatePlatformPixmapSurface[EXT] should be passed (xcb_window_t *)
and (xcb_pixmap_t *), so we must dereference these types before using
them as drawables.  We already do something similar with X11 drawable
pointers.

Signed-off-by: Jeffrey Knockel <jeff@jeffreyknockel.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16269>

src/egl/main/eglapi.c

index d0238fe..97f5b6a 100644 (file)
@@ -1031,6 +1031,15 @@ _fixupNativeWindow(_EGLDisplay *disp, void *native_window)
       return (void *)(* (Window*) native_window);
    }
 #endif
+#ifdef HAVE_XCB_PLATFORM
+   if (disp && disp->Platform == _EGL_PLATFORM_XCB && native_window != NULL) {
+      /* Similar to with X11, we need to convert (xcb_window_t *)
+       * (i.e., uint32_t *) to xcb_window_t. We have to do an intermediate cast
+       * to uintptr_t, since uint32_t may be smaller than a pointer.
+       */
+      return (void *)(uintptr_t) (* (uint32_t*) native_window);
+   }
+#endif
    return native_window;
 }
 
@@ -1085,6 +1094,15 @@ _fixupNativePixmap(_EGLDisplay *disp, void *native_pixmap)
    if (disp && disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL)
       return (void *)(* (Pixmap*) native_pixmap);
 #endif
+#ifdef HAVE_XCB_PLATFORM
+   if (disp && disp->Platform == _EGL_PLATFORM_XCB && native_pixmap != NULL) {
+      /* Similar to with X11, we need to convert (xcb_pixmap_t *)
+       * (i.e., uint32_t *) to xcb_pixmap_t. We have to do an intermediate cast
+       * to uintptr_t, since uint32_t may be smaller than a pointer.
+       */
+      return (void *)(uintptr_t) (* (uint32_t*) native_pixmap);
+   }
+#endif
    return native_pixmap;
 }