diff options
author | Jonas Ådahl <jadahl@gmail.com> | 2023-03-08 16:53:32 +0100 |
---|---|---|
committer | Jonas Ådahl <jadahl@gmail.com> | 2023-03-08 16:53:32 +0100 |
commit | af255b16513bab34bfc527cae139eb09c3fdbf82 (patch) | |
tree | d2840e35e8e6d9bca4b51cb4497ec9b93aff1f40 /hw/xwayland | |
parent | 08b0ea09de120a64c498238cc15b6cc04276ca22 (diff) |
xwayland/glamor/gbm: Initialize explicit buffer params in helper
This is preparing for cleaning up the macro mess.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Diffstat (limited to 'hw/xwayland')
-rw-r--r-- | hw/xwayland/xwayland-glamor-gbm.c | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/hw/xwayland/xwayland-glamor-gbm.c b/hw/xwayland/xwayland-glamor-gbm.c index 82d9e7880..2e1a4bfd5 100644 --- a/hw/xwayland/xwayland-glamor-gbm.c +++ b/hw/xwayland/xwayland-glamor-gbm.c @@ -347,42 +347,24 @@ static const struct wl_buffer_listener xwl_glamor_gbm_buffer_listener = { xwl_pixmap_buffer_release_cb, }; -static struct wl_buffer * -xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap) +#ifdef GBM_BO_WITH_MODIFIERS +static Bool +init_buffer_params_with_modifiers(struct xwl_pixmap *xwl_pixmap, + uint64_t *modifier, + int *num_planes, + int *prime_fds, + uint32_t *strides, + uint32_t *offsets) { - struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen); - struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap); - struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen); - unsigned short width = pixmap->drawable.width; - unsigned short height = pixmap->drawable.height; - uint32_t format; - int num_planes; - int prime_fds[4]; - uint32_t strides[4]; - uint32_t offsets[4]; - uint64_t modifier; - int i; #ifndef GBM_BO_FD_FOR_PLANE int32_t first_handle; #endif + int i; - if (xwl_pixmap == NULL) - return NULL; - - if (xwl_pixmap->buffer) { - /* Buffer already exists. */ - return xwl_pixmap->buffer; - } - - if (!xwl_pixmap->bo) - return NULL; - - format = wl_drm_format_for_depth(pixmap->drawable.depth); + *num_planes = gbm_bo_get_plane_count(xwl_pixmap->bo); + *modifier = gbm_bo_get_modifier(xwl_pixmap->bo); -#ifdef GBM_BO_WITH_MODIFIERS - num_planes = gbm_bo_get_plane_count(xwl_pixmap->bo); - modifier = gbm_bo_get_modifier(xwl_pixmap->bo); - for (i = 0; i < num_planes; i++) { + for (i = 0; i < *num_planes; i++) { #ifdef GBM_BO_FD_FOR_PLANE prime_fds[i] = gbm_bo_get_fd_for_plane(xwl_pixmap->bo, i); #else @@ -405,11 +387,53 @@ xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap) if (prime_fds[i] == -1) { while (--i >= 0) close(prime_fds[i]); - return NULL; + return FALSE; } strides[i] = gbm_bo_get_stride_for_plane(xwl_pixmap->bo, i); offsets[i] = gbm_bo_get_offset(xwl_pixmap->bo, i); } + + return TRUE; +} +#endif + +static struct wl_buffer * +xwl_glamor_gbm_get_wl_buffer_for_pixmap(PixmapPtr pixmap) +{ + struct xwl_screen *xwl_screen = xwl_screen_get(pixmap->drawable.pScreen); + struct xwl_pixmap *xwl_pixmap = xwl_pixmap_get(pixmap); + struct xwl_gbm_private *xwl_gbm = xwl_gbm_get(xwl_screen); + unsigned short width = pixmap->drawable.width; + unsigned short height = pixmap->drawable.height; + uint32_t format; + int num_planes; + int prime_fds[4]; + uint32_t strides[4]; + uint32_t offsets[4]; + uint64_t modifier; + int i; + + if (xwl_pixmap == NULL) + return NULL; + + if (xwl_pixmap->buffer) { + /* Buffer already exists. */ + return xwl_pixmap->buffer; + } + + if (!xwl_pixmap->bo) + return NULL; + + format = wl_drm_format_for_depth(pixmap->drawable.depth); + +#ifdef GBM_BO_WITH_MODIFIERS + if (!init_buffer_params_with_modifiers(xwl_pixmap, + &modifier, + &num_planes, + prime_fds, + strides, + offsets)) + return NULL; #else num_planes = 1; modifier = DRM_FORMAT_MOD_INVALID; |