st/egl: Make config optional for create_pixmap_surface.
authorChia-I Wu <olv@lunarg.com>
Wed, 22 Dec 2010 04:14:44 +0000 (12:14 +0800)
committerChia-I Wu <olv@lunarg.com>
Wed, 22 Dec 2010 05:22:36 +0000 (13:22 +0800)
eglCopyBuffers or EGL_KHR_image_pixmap require creating a pixmap surface
without a config.  Make it just work without relying on
is_pixmap_supported.

src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_ximage.c

index 3886ca20562b0ae25a3a33a8294821d55a843fc6..a66e81def6f0463b8fa62feb9a62a5e66a0dece3 100644 (file)
@@ -185,7 +185,9 @@ struct native_display {
                                                    const struct native_config *nconf);
 
    /**
-    * Create a pixmap surface.  Required unless no config has pixmap_bit set.
+    * Create a pixmap surface.  The native config may be NULL.  In that case, a
+    * "best config" will be picked.  Required unless no config has pixmap_bit
+    * set.
     */
    struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
                                                    EGLNativePixmapType pix,
index 8108ce45865021dfcd6a2554eb6d7d456560b333..92203e1176c85f583a796e2b0458c130a18b9c7b 100644 (file)
 
 #ifdef GLX_DIRECT_RENDERING
 
-enum dri2_surface_type {
-   DRI2_SURFACE_TYPE_WINDOW,
-   DRI2_SURFACE_TYPE_PIXMAP,
-};
-
 struct dri2_display {
    struct native_display base;
    Display *dpy;
@@ -66,7 +61,6 @@ struct dri2_display {
 struct dri2_surface {
    struct native_surface base;
    Drawable drawable;
-   enum dri2_surface_type type;
    enum pipe_format color_format;
    struct dri2_display *dri2dpy;
 
@@ -439,12 +433,10 @@ dri2_surface_destroy(struct native_surface *nsurf)
 
 static struct dri2_surface *
 dri2_display_create_surface(struct native_display *ndpy,
-                            enum dri2_surface_type type,
                             Drawable drawable,
-                            const struct native_config *nconf)
+                            enum pipe_format color_format)
 {
    struct dri2_display *dri2dpy = dri2_display(ndpy);
-   struct dri2_config *dri2conf = dri2_config(nconf);
    struct dri2_surface *dri2surf;
 
    dri2surf = CALLOC_STRUCT(dri2_surface);
@@ -452,9 +444,8 @@ dri2_display_create_surface(struct native_display *ndpy,
       return NULL;
 
    dri2surf->dri2dpy = dri2dpy;
-   dri2surf->type = type;
    dri2surf->drawable = drawable;
-   dri2surf->color_format = dri2conf->base.color_format;
+   dri2surf->color_format = color_format;
 
    dri2surf->base.destroy = dri2_surface_destroy;
    dri2surf->base.present = dri2_surface_present;
@@ -480,8 +471,8 @@ dri2_display_create_window_surface(struct native_display *ndpy,
 {
    struct dri2_surface *dri2surf;
 
-   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_WINDOW,
-         (Drawable) win, nconf);
+   dri2surf = dri2_display_create_surface(ndpy,
+         (Drawable) win, nconf->color_format);
    return (dri2surf) ? &dri2surf->base : NULL;
 }
 
@@ -492,8 +483,29 @@ dri2_display_create_pixmap_surface(struct native_display *ndpy,
 {
    struct dri2_surface *dri2surf;
 
-   dri2surf = dri2_display_create_surface(ndpy, DRI2_SURFACE_TYPE_PIXMAP,
-         (Drawable) pix, nconf);
+   if (!nconf) {
+      struct dri2_display *dri2dpy = dri2_display(ndpy);
+      uint depth, nconf_depth;
+      int i;
+
+      depth = x11_drawable_get_depth(dri2dpy->xscr, (Drawable) pix);
+      for (i = 0; i < dri2dpy->num_configs; i++) {
+         nconf_depth = util_format_get_blocksizebits(
+               dri2dpy->configs[i].base.color_format);
+         /* simple depth match for now */
+         if (depth == nconf_depth ||
+             (depth == 24 && depth + 8 == nconf_depth)) {
+            nconf = &dri2dpy->configs[i].base;
+            break;
+         }
+      }
+
+      if (!nconf)
+         return NULL;
+   }
+
+   dri2surf = dri2_display_create_surface(ndpy,
+         (Drawable) pix, nconf->color_format);
    return (dri2surf) ? &dri2surf->base : NULL;
 }
 
index 84811fb6e147b4e5cc908ac3192a313461ffdeda..3c32f379a2f527368633e45bc4ca5934f46ca85d 100644 (file)
 #include "native_x11.h"
 #include "x11_screen.h"
 
-enum ximage_surface_type {
-   XIMAGE_SURFACE_TYPE_WINDOW,
-   XIMAGE_SURFACE_TYPE_PIXMAP,
-};
-
 struct ximage_display {
    struct native_display base;
    Display *dpy;
@@ -60,7 +55,6 @@ struct ximage_display {
 struct ximage_surface {
    struct native_surface base;
    Drawable drawable;
-   enum ximage_surface_type type;
    enum pipe_format color_format;
    XVisualInfo visual;
    struct ximage_display *xdpy;
@@ -245,7 +239,6 @@ ximage_surface_destroy(struct native_surface *nsurf)
 
 static struct ximage_surface *
 ximage_display_create_surface(struct native_display *ndpy,
-                              enum ximage_surface_type type,
                               Drawable drawable,
                               const struct native_config *nconf)
 {
@@ -258,7 +251,6 @@ ximage_display_create_surface(struct native_display *ndpy,
       return NULL;
 
    xsurf->xdpy = xdpy;
-   xsurf->type = type;
    xsurf->color_format = xconf->base.color_format;
    xsurf->drawable = drawable;
 
@@ -297,11 +289,37 @@ ximage_display_create_window_surface(struct native_display *ndpy,
 {
    struct ximage_surface *xsurf;
 
-   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_WINDOW,
-         (Drawable) win, nconf);
+   xsurf = ximage_display_create_surface(ndpy, (Drawable) win, nconf);
    return (xsurf) ? &xsurf->base : NULL;
 }
 
+static enum pipe_format
+get_pixmap_format(struct native_display *ndpy, EGLNativePixmapType pix)
+{
+   struct ximage_display *xdpy = ximage_display(ndpy);
+   enum pipe_format fmt;
+   uint depth;
+
+   depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix);
+
+   switch (depth) {
+   case 32:
+      fmt = PIPE_FORMAT_B8G8R8A8_UNORM;
+      break;
+   case 24:
+      fmt = PIPE_FORMAT_B8G8R8X8_UNORM;
+      break;
+   case 16:
+      fmt = PIPE_FORMAT_B5G6R5_UNORM;
+      break;
+   default:
+      fmt = PIPE_FORMAT_NONE;
+      break;
+   }
+
+   return fmt;
+}
+
 static struct native_surface *
 ximage_display_create_pixmap_surface(struct native_display *ndpy,
                                      EGLNativePixmapType pix,
@@ -309,8 +327,26 @@ ximage_display_create_pixmap_surface(struct native_display *ndpy,
 {
    struct ximage_surface *xsurf;
 
-   xsurf = ximage_display_create_surface(ndpy, XIMAGE_SURFACE_TYPE_PIXMAP,
-         (Drawable) pix, nconf);
+   /* find the config */
+   if (!nconf) {
+      struct ximage_display *xdpy = ximage_display(ndpy);
+      enum pipe_format fmt = get_pixmap_format(&xdpy->base, pix);
+      int i;
+
+      if (fmt != PIPE_FORMAT_NONE) {
+         for (i = 0; i < xdpy->num_configs; i++) {
+            if (xdpy->configs[i].base.color_format == fmt) {
+               nconf = &xdpy->configs[i].base;
+               break;
+            }
+         }
+      }
+
+      if (!nconf)
+         return NULL;
+   }
+
+   xsurf = ximage_display_create_surface(ndpy, (Drawable) pix, nconf);
    return (xsurf) ? &xsurf->base : NULL;
 }
 
@@ -408,24 +444,7 @@ ximage_display_is_pixmap_supported(struct native_display *ndpy,
                                    const struct native_config *nconf)
 {
    struct ximage_display *xdpy = ximage_display(ndpy);
-   enum pipe_format fmt;
-   uint depth;
-
-   depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix);
-   switch (depth) {
-   case 32:
-      fmt = PIPE_FORMAT_B8G8R8A8_UNORM;
-      break;
-   case 24:
-      fmt = PIPE_FORMAT_B8G8R8X8_UNORM;
-      break;
-   case 16:
-      fmt = PIPE_FORMAT_B5G6R5_UNORM;
-      break;
-   default:
-      fmt = PIPE_FORMAT_NONE;
-      break;
-   }
+   enum pipe_format fmt = get_pixmap_format(&xdpy->base, pix);
 
    return (fmt == nconf->color_format);
 }