diff options
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r-- | src/gallium/state_trackers/egl/common/native.h | 4 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/x11/native_dri2.c | 42 | ||||
-rw-r--r-- | src/gallium/state_trackers/egl/x11/native_ximage.c | 79 |
3 files changed, 79 insertions, 46 deletions
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 3886ca20562..a66e81def6f 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -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, diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c index 8108ce45865..92203e1176c 100644 --- a/src/gallium/state_trackers/egl/x11/native_dri2.c +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c @@ -40,11 +40,6 @@ #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; } diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c index 84811fb6e14..3c32f379a2f 100644 --- a/src/gallium/state_trackers/egl/x11/native_ximage.c +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -38,11 +38,6 @@ #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); } |