Skip to content

Commit

Permalink
dmabuf: recreate buffer on format change
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Mar 12, 2024
1 parent 4ca3f83 commit e989c6c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <atomic>
#include <getopt.h>

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -122,6 +121,7 @@ const zxdg_output_v1_listener xdg_output_implementation = {
struct wf_buffer : public buffer_pool_buf
{
struct gbm_bo *bo = nullptr;
zwp_linux_buffer_params_v1 *params = nullptr;
struct wl_buffer *wl_buffer = nullptr;
void *data = nullptr;
size_t size = 0;
Expand Down Expand Up @@ -332,12 +332,22 @@ static void frame_handle_linux_dmabuf(void *, struct zwlr_screencopy_frame_v1 *f

auto& buffer = buffers.capture();

auto old_format = buffer.format;
buffer.format = drm_to_wl_shm_format(format);
buffer.drm_format = format;
buffer.width = width;
buffer.height = height;

if (!buffer.wl_buffer) {
if (!buffer.wl_buffer || (old_format != buffer.format)) {
if (buffer.bo) {
if (buffer.wl_buffer) {
wl_buffer_destroy(buffer.wl_buffer);
}

zwp_linux_buffer_params_v1_destroy(buffer.params);
gbm_bo_destroy(buffer.bo);
}

const uint64_t modifier = 0; // DRM_FORMAT_MOD_LINEAR
buffer.bo = gbm_bo_create_with_modifiers(gbm_device, buffer.width,
buffer.height, format, &modifier, 1);
Expand All @@ -355,18 +365,17 @@ static void frame_handle_linux_dmabuf(void *, struct zwlr_screencopy_frame_v1 *f

buffer.stride = gbm_bo_get_stride(buffer.bo);

struct zwp_linux_buffer_params_v1 *params =
zwp_linux_dmabuf_v1_create_params(dmabuf);
buffer.params = zwp_linux_dmabuf_v1_create_params(dmabuf);

uint64_t mod = gbm_bo_get_modifier(buffer.bo);
zwp_linux_buffer_params_v1_add(params,
zwp_linux_buffer_params_v1_add(buffer.params,
gbm_bo_get_fd(buffer.bo), 0,
gbm_bo_get_offset(buffer.bo, 0),
gbm_bo_get_stride(buffer.bo),
mod >> 32, mod & 0xffffffff);

zwp_linux_buffer_params_v1_add_listener(params, &params_listener, frame);
zwp_linux_buffer_params_v1_create(params, buffer.width,
zwp_linux_buffer_params_v1_add_listener(buffer.params, &params_listener, frame);
zwp_linux_buffer_params_v1_create(buffer.params, buffer.width,
buffer.height, format, 0);
} else {
if (use_damage) {
Expand Down

0 comments on commit e989c6c

Please sign in to comment.