X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fegl%2Fdrivers%2Fdri2%2Fplatform_x11_dri3.c;h=f230fcabb5b65a1cf132ba5b7cf21c056e35b785;hb=4dc322c4c6720733cce793846e4fb140c1b4403f;hp=1e326984dd113f3e347c5a8fb4a8999d191e1359;hpb=13c23b19d0b3b965d666498eb759e63fc4a625d9;p=mesa.git diff --git a/src/egl/drivers/dri2/platform_x11_dri3.c b/src/egl/drivers/dri2/platform_x11_dri3.c index 1e326984dd1..f230fcabb5b 100644 --- a/src/egl/drivers/dri2/platform_x11_dri3.c +++ b/src/egl/drivers/dri2/platform_x11_dri3.c @@ -33,7 +33,6 @@ #include "util/macros.h" #include "egl_dri2.h" -#include "egl_dri2_fallbacks.h" #include "platform_x11_dri3.h" #include "loader.h" @@ -51,8 +50,8 @@ egl_dri3_set_drawable_size(struct loader_dri3_drawable *draw, { struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw); - dri3_surf->base.Width = width; - dri3_surf->base.Height = height; + dri3_surf->surf.base.Width = width; + dri3_surf->surf.base.Height = height; } static bool @@ -61,7 +60,7 @@ egl_dri3_in_current_context(struct loader_dri3_drawable *draw) struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw); _EGLContext *ctx = _eglGetCurrentContext(); - return ctx->Resource.Display == dri3_surf->base.Resource.Display; + return ctx->Resource.Display == dri3_surf->surf.base.Resource.Display; } static __DRIcontext * @@ -75,19 +74,31 @@ egl_dri3_get_dri_context(struct loader_dri3_drawable *draw) return dri2_ctx->dri_context; } +static __DRIscreen * +egl_dri3_get_dri_screen(void) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + struct dri2_egl_context *dri2_ctx; + if (!ctx) + return NULL; + dri2_ctx = dri2_egl_context(ctx); + return dri2_egl_display(dri2_ctx->base.Resource.Display)->dri_screen; +} + static void egl_dri3_flush_drawable(struct loader_dri3_drawable *draw, unsigned flags) { struct dri3_egl_surface *dri3_surf = loader_drawable_to_egl_surface(draw); - _EGLDisplay *disp = dri3_surf->base.Resource.Display; + _EGLDisplay *disp = dri3_surf->surf.base.Resource.Display; - dri2_flush_drawable_for_swapbuffers(disp, &dri3_surf->base); + dri2_flush_drawable_for_swapbuffers(disp, &dri3_surf->surf.base); } static const struct loader_dri3_vtable egl_dri3_vtable = { .set_drawable_size = egl_dri3_set_drawable_size, .in_current_context = egl_dri3_in_current_context, .get_dri_context = egl_dri3_get_dri_context, + .get_dri_screen = egl_dri3_get_dri_screen, .flush_drawable = egl_dri3_flush_drawable, .show_fps = NULL, }; @@ -95,12 +106,17 @@ static const struct loader_dri3_vtable egl_dri3_vtable = { static EGLBoolean dri3_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) { + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf); + xcb_drawable_t drawable = dri3_surf->loader_drawable.drawable; (void) drv; loader_dri3_drawable_fini(&dri3_surf->loader_drawable); + if (surf->Type == EGL_PBUFFER_BIT) + xcb_free_pixmap (dri2_dpy->conn, drawable); + dri2_fini_surface(surf); free(surf); @@ -113,7 +129,7 @@ dri3_set_swap_interval(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf); - dri3_surf->base.SwapInterval = interval; + dri3_surf->surf.base.SwapInterval = interval; loader_dri3_set_swap_interval(&dri3_surf->loader_drawable, interval); return EGL_TRUE; @@ -138,25 +154,33 @@ dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, return NULL; } - if (!dri2_init_surface(&dri3_surf->base, disp, type, conf, attrib_list, false)) + if (!dri2_init_surface(&dri3_surf->surf.base, disp, type, conf, + attrib_list, false, native_surface)) goto cleanup_surf; if (type == EGL_PBUFFER_BIT) { drawable = xcb_generate_id(dri2_dpy->conn); xcb_create_pixmap(dri2_dpy->conn, conf->BufferSize, drawable, dri2_dpy->screen->root, - dri3_surf->base.Width, dri3_surf->base.Height); + dri3_surf->surf.base.Width, dri3_surf->surf.base.Height); } else { STATIC_ASSERT(sizeof(uintptr_t) == sizeof(native_surface)); drawable = (uintptr_t) native_surface; } dri_config = dri2_get_dri_config(dri2_conf, type, - dri3_surf->base.GLColorspace); + dri3_surf->surf.base.GLColorspace); + + if (!dri_config) { + _eglError(EGL_BAD_MATCH, "Unsupported surfacetype/colorspace configuration"); + goto cleanup_pixmap; + } if (loader_dri3_drawable_init(dri2_dpy->conn, drawable, dri2_dpy->dri_screen, - dri2_dpy->is_different_gpu, dri_config, + dri2_dpy->is_different_gpu, + dri2_dpy->multibuffers_available, + dri_config, &dri2_dpy->loader_dri3_ext, &egl_dri3_vtable, &dri3_surf->loader_drawable)) { @@ -164,7 +188,7 @@ dri3_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type, goto cleanup_pixmap; } - return &dri3_surf->base; + return &dri3_surf->surf.base; cleanup_pixmap: if (type == EGL_PBUFFER_BIT) @@ -262,17 +286,8 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, return NULL; } - switch (bp_reply->depth) { - case 16: - format = __DRI_IMAGE_FORMAT_RGB565; - break; - case 24: - format = __DRI_IMAGE_FORMAT_XRGB8888; - break; - case 32: - format = __DRI_IMAGE_FORMAT_ARGB8888; - break; - default: + format = dri2_format_for_depth(dri2_dpy, bp_reply->depth); + if (format == __DRI_IMAGE_FORMAT_NONE) { _eglError(EGL_BAD_PARAMETER, "dri3_create_image_khr: unsupported pixmap depth"); free(bp_reply); @@ -282,6 +297,7 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, dri2_img = malloc(sizeof *dri2_img); if (!dri2_img) { _eglError(EGL_BAD_ALLOC, "dri3_create_image_khr"); + free(bp_reply); return EGL_NO_IMAGE_KHR; } @@ -299,15 +315,80 @@ dri3_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx, return &dri2_img->base; } +#ifdef HAVE_DRI3_MODIFIERS +static _EGLImage * +dri3_create_image_khr_pixmap_from_buffers(_EGLDisplay *disp, _EGLContext *ctx, + EGLClientBuffer buffer, + const EGLint *attr_list) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_image *dri2_img; + xcb_dri3_buffers_from_pixmap_cookie_t bp_cookie; + xcb_dri3_buffers_from_pixmap_reply_t *bp_reply; + xcb_drawable_t drawable; + unsigned int format; + + drawable = (xcb_drawable_t) (uintptr_t) buffer; + bp_cookie = xcb_dri3_buffers_from_pixmap(dri2_dpy->conn, drawable); + bp_reply = xcb_dri3_buffers_from_pixmap_reply(dri2_dpy->conn, + bp_cookie, NULL); + + if (!bp_reply) { + _eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr"); + return EGL_NO_IMAGE_KHR; + } + + format = dri2_format_for_depth(dri2_dpy, bp_reply->depth); + if (format == __DRI_IMAGE_FORMAT_NONE) { + _eglError(EGL_BAD_PARAMETER, + "dri3_create_image_khr: unsupported pixmap depth"); + free(bp_reply); + return EGL_NO_IMAGE_KHR; + } + + dri2_img = malloc(sizeof *dri2_img); + if (!dri2_img) { + _eglError(EGL_BAD_ALLOC, "dri3_create_image_khr"); + free(bp_reply); + return EGL_NO_IMAGE_KHR; + } + + _eglInitImage(&dri2_img->base, disp); + + dri2_img->dri_image = loader_dri3_create_image_from_buffers(dri2_dpy->conn, + bp_reply, + format, + dri2_dpy->dri_screen, + dri2_dpy->image, + dri2_img); + free(bp_reply); + + if (!dri2_img->dri_image) { + _eglError(EGL_BAD_ATTRIBUTE, "dri3_create_image_khr"); + free(dri2_img); + return EGL_NO_IMAGE_KHR; + } + + return &dri2_img->base; +} +#endif + static _EGLImage * dri3_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list) { - (void) drv; +#ifdef HAVE_DRI3_MODIFIERS + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); +#endif switch (target) { case EGL_NATIVE_PIXMAP_KHR: +#ifdef HAVE_DRI3_MODIFIERS + if (dri2_dpy->multibuffers_available) + return dri3_create_image_khr_pixmap_from_buffers(disp, ctx, buffer, + attr_list); +#endif return dri3_create_image_khr_pixmap(disp, ctx, buffer, attr_list); default: return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list); @@ -321,13 +402,15 @@ dri3_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp, static void dri3_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate) { + struct loader_dri3_drawable *draw = loaderPrivate; + (void) driDrawable; + /* There does not seem to be any kind of consensus on whether we should * support front-buffer rendering or not: * http://lists.freedesktop.org/archives/mesa-dev/2013-June/040129.html */ - _eglLog(_EGL_WARNING, "FIXME: egl/x11 doesn't support front buffer rendering."); - (void) driDrawable; - (void) loaderPrivate; + if (!draw->is_pixmap) + _eglLog(_EGL_WARNING, "FIXME: egl/x11 doesn't support front buffer rendering."); } const __DRIimageLoaderExtension dri3_image_loader_extension = { @@ -342,10 +425,6 @@ dri3_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(draw); - /* No-op for a pixmap or pbuffer surface */ - if (draw->Type == EGL_PIXMAP_BIT || draw->Type == EGL_PBUFFER_BIT) - return EGL_FALSE; - return loader_dri3_swap_buffers_msc(&dri3_surf->loader_drawable, 0, 0, 0, 0, draw->SwapBehavior == EGL_BUFFER_PRESERVED) != -1; @@ -368,7 +447,7 @@ dri3_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, } static int -dri3_query_buffer_age(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) +dri3_query_buffer_age(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf) { struct dri3_egl_surface *dri3_surf = dri3_egl_surface(surf); @@ -376,7 +455,7 @@ dri3_query_buffer_age(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) } static EGLBoolean -dri3_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, +dri3_query_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint attribute, EGLint *value) { @@ -391,7 +470,7 @@ dri3_query_surface(_EGLDriver *drv, _EGLDisplay *dpy, break; } - return _eglQuerySurface(drv, dpy, surf, attribute, value); + return _eglQuerySurface(drv, disp, surf, attribute, value); } static __DRIdrawable * @@ -403,9 +482,9 @@ dri3_get_dri_drawable(_EGLSurface *surf) } static void -dri3_close_screen_notify(_EGLDisplay *dpy) +dri3_close_screen_notify(_EGLDisplay *disp) { - struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); loader_dri3_close_screen(dri2_dpy->dri_screen); } @@ -419,19 +498,26 @@ struct dri2_egl_display_vtbl dri3_x11_display_vtbl = { .create_image = dri3_create_image_khr, .swap_interval = dri3_set_swap_interval, .swap_buffers = dri3_swap_buffers, - .swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, - .swap_buffers_region = dri2_fallback_swap_buffers_region, - .set_damage_region = dri2_fallback_set_damage_region, - .post_sub_buffer = dri2_fallback_post_sub_buffer, .copy_buffers = dri3_copy_buffers, .query_buffer_age = dri3_query_buffer_age, .query_surface = dri3_query_surface, - .create_wayland_buffer_from_image = dri2_fallback_create_wayland_buffer_from_image, .get_sync_values = dri3_get_sync_values, .get_dri_drawable = dri3_get_dri_drawable, .close_screen_notify = dri3_close_screen_notify, }; +/* Only request versions of these protocols which we actually support. */ +#define DRI3_SUPPORTED_MAJOR 1 +#define PRESENT_SUPPORTED_MAJOR 1 + +#ifdef HAVE_DRI3_MODIFIERS +#define DRI3_SUPPORTED_MINOR 2 +#define PRESENT_SUPPORTED_MINOR 2 +#else +#define PRESENT_SUPPORTED_MINOR 0 +#define DRI3_SUPPORTED_MINOR 0 +#endif + EGLBoolean dri3_x11_connect(struct dri2_egl_display *dri2_dpy) { @@ -454,12 +540,12 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) return EGL_FALSE; dri3_query_cookie = xcb_dri3_query_version(dri2_dpy->conn, - XCB_DRI3_MAJOR_VERSION, - XCB_DRI3_MINOR_VERSION); + DRI3_SUPPORTED_MAJOR, + DRI3_SUPPORTED_MINOR); present_query_cookie = xcb_present_query_version(dri2_dpy->conn, - XCB_PRESENT_MAJOR_VERSION, - XCB_PRESENT_MINOR_VERSION); + PRESENT_SUPPORTED_MAJOR, + PRESENT_SUPPORTED_MINOR); dri3_query = xcb_dri3_query_version_reply(dri2_dpy->conn, dri3_query_cookie, &error); @@ -469,6 +555,9 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) free(error); return EGL_FALSE; } + + dri2_dpy->dri3_major_version = dri3_query->major_version; + dri2_dpy->dri3_minor_version = dri3_query->minor_version; free(dri3_query); present_query = @@ -480,6 +569,9 @@ dri3_x11_connect(struct dri2_egl_display *dri2_dpy) free(error); return EGL_FALSE; } + + dri2_dpy->present_major_version = present_query->major_version; + dri2_dpy->present_minor_version = present_query->minor_version; free(present_query); dri2_dpy->fd = loader_dri3_open(dri2_dpy->conn, dri2_dpy->screen->root, 0);