clients/simple-dmabuf-*: Use gbm_bo_create_with_modifiers2

It is used in Mesa. Lets switch to it as well in order to provide
good examples and encourage proper API usage.

Signed-off-by: Robert Mader <robert.mader@collabora.com>
dev
Robert Mader 3 years ago committed by Robert Mader
parent 46a6b5b448
commit 572ad2d8a9
  1. 4
      clients/meson.build
  2. 10
      clients/simple-dmabuf-egl.c
  3. 23
      clients/simple-dmabuf-feedback.c

@ -35,6 +35,10 @@ dep_toytoolkit = declare_dependency(
link_with: lib_toytoolkit, link_with: lib_toytoolkit,
dependencies: deps_toytoolkit, dependencies: deps_toytoolkit,
) )
dep_gbm = dependency('gbm', required: false)
if dep_gbm.found() and dep_gbm.version().version_compare('>= 21.3')
config_h.set('HAVE_GBM_BO_CREATE_WITH_MODIFIERS2', '1')
endif
simple_clients_enabled = get_option('simple-clients') simple_clients_enabled = get_option('simple-clients')
simple_build_all = simple_clients_enabled.contains('all') simple_build_all = simple_clients_enabled.contains('all')

@ -343,12 +343,22 @@ create_dmabuf_buffer(struct display *display, struct buffer *buffer,
#ifdef HAVE_GBM_MODIFIERS #ifdef HAVE_GBM_MODIFIERS
if (display->modifiers_count > 0) { if (display->modifiers_count > 0) {
#ifdef HAVE_GBM_BO_CREATE_WITH_MODIFIERS2
buffer->bo = gbm_bo_create_with_modifiers2(display->gbm.device,
buffer->width,
buffer->height,
buffer->format,
display->modifiers,
display->modifiers_count,
GBM_BO_USE_RENDERING);
#else
buffer->bo = gbm_bo_create_with_modifiers(display->gbm.device, buffer->bo = gbm_bo_create_with_modifiers(display->gbm.device,
buffer->width, buffer->width,
buffer->height, buffer->height,
buffer->format, buffer->format,
display->modifiers, display->modifiers,
display->modifiers_count); display->modifiers_count);
#endif
if (buffer->bo) if (buffer->bo)
buffer->modifier = gbm_bo_get_modifier(buffer->bo); buffer->modifier = gbm_bo_get_modifier(buffer->bo);
} }

@ -180,6 +180,7 @@ struct window {
struct dmabuf_feedback dmabuf_feedback, pending_dmabuf_feedback; struct dmabuf_feedback dmabuf_feedback, pending_dmabuf_feedback;
int card_fd; int card_fd;
struct drm_format format; struct drm_format format;
uint32_t bo_flags;
struct buffer buffers[NUM_BUFFERS]; struct buffer buffers[NUM_BUFFERS];
}; };
@ -461,7 +462,7 @@ buffer_free(struct buffer *buf)
static void static void
create_dmabuf_buffer(struct window *window, struct buffer *buf, uint32_t width, create_dmabuf_buffer(struct window *window, struct buffer *buf, uint32_t width,
uint32_t height, uint32_t format, unsigned int count_modifiers, uint32_t height, uint32_t format, unsigned int count_modifiers,
uint64_t *modifiers); uint64_t *modifiers, uint32_t bo_flags);
static void static void
buffer_recreate(struct buffer *buf) buffer_recreate(struct buffer *buf)
@ -474,7 +475,7 @@ buffer_recreate(struct buffer *buf)
create_dmabuf_buffer(window, buf, width, height, create_dmabuf_buffer(window, buf, width, height,
window->format.format, window->format.format,
window->format.modifiers.size / sizeof(uint64_t), window->format.modifiers.size / sizeof(uint64_t),
window->format.modifiers.data); window->format.modifiers.data, window->bo_flags);
buf->recreate = false; buf->recreate = false;
} }
@ -524,7 +525,7 @@ static const struct zwp_linux_buffer_params_v1_listener params_listener = {
static void static void
create_dmabuf_buffer(struct window *window, struct buffer *buf, uint32_t width, create_dmabuf_buffer(struct window *window, struct buffer *buf, uint32_t width,
uint32_t height, uint32_t format, unsigned int count_modifiers, uint32_t height, uint32_t format, unsigned int count_modifiers,
uint64_t *modifiers) uint64_t *modifiers, uint32_t bo_flags)
{ {
struct display *display = window->display; struct display *display = window->display;
static uint32_t flags = 0; static uint32_t flags = 0;
@ -539,10 +540,18 @@ create_dmabuf_buffer(struct window *window, struct buffer *buf, uint32_t width,
#ifdef HAVE_GBM_MODIFIERS #ifdef HAVE_GBM_MODIFIERS
if (count_modifiers > 0) { if (count_modifiers > 0) {
#ifdef HAVE_GBM_BO_CREATE_WITH_MODIFIERS2
buf->bo = gbm_bo_create_with_modifiers2(display->gbm_device,
buf->width, buf->height,
format, modifiers,
count_modifiers,
bo_flags);
#else
buf->bo = gbm_bo_create_with_modifiers(display->gbm_device, buf->bo = gbm_bo_create_with_modifiers(display->gbm_device,
buf->width, buf->height, buf->width, buf->height,
format, modifiers, format, modifiers,
count_modifiers); count_modifiers);
#endif
if (buf->bo) if (buf->bo)
buf->modifier = gbm_bo_get_modifier(buf->bo); buf->modifier = gbm_bo_get_modifier(buf->bo);
} }
@ -551,7 +560,7 @@ create_dmabuf_buffer(struct window *window, struct buffer *buf, uint32_t width,
if (!buf->bo) { if (!buf->bo) {
buf->bo = gbm_bo_create(display->gbm_device, buf->width, buf->bo = gbm_bo_create(display->gbm_device, buf->width,
buf->height, buf->format, buf->height, buf->format,
GBM_BO_USE_RENDERING); bo_flags);
buf->modifier = DRM_FORMAT_MOD_INVALID; buf->modifier = DRM_FORMAT_MOD_INVALID;
} }
@ -938,7 +947,7 @@ create_window(struct display *display)
create_dmabuf_buffer(window, &window->buffers[i], width, height, create_dmabuf_buffer(window, &window->buffers[i], width, height,
window->format.format, window->format.format,
window->format.modifiers.size / sizeof(uint64_t), window->format.modifiers.size / sizeof(uint64_t),
window->format.modifiers.data); window->format.modifiers.data, window->bo_flags);
window->xdg_surface = xdg_wm_base_get_xdg_surface(display->wm_base, window->xdg_surface = xdg_wm_base_get_xdg_surface(display->wm_base,
@ -1237,6 +1246,8 @@ pick_initial_format_from_renderer_tranche(struct window *window,
window->format.format = fmt->format; window->format.format = fmt->format;
wl_array_copy(&window->format.modifiers, &fmt->modifiers); wl_array_copy(&window->format.modifiers, &fmt->modifiers);
window->bo_flags = GBM_BO_USE_RENDERING;
return true; return true;
} }
return false; return false;
@ -1267,6 +1278,8 @@ pick_format_from_scanout_tranche(struct window *window,
window->format.format = fmt->format; window->format.format = fmt->format;
wl_array_copy(&window->format.modifiers, &fmt->modifiers); wl_array_copy(&window->format.modifiers, &fmt->modifiers);
window->bo_flags = GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT;
return true; return true;
} }
return false; return false;

Loading…
Cancel
Save