Skip to content

Commit

Permalink
Add wlr_{create,destroy}_dmabuffer functions in wlr_screencast_common.c
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Sep 13, 2020
1 parent 2122757 commit ccfa2c6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/wlr_screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ struct wl_buffer *wlr_create_shm_buffer(struct xdpw_screencast_instance *cast,
enum wl_shm_format fmt, int width, int height, int stride,
void **data_out);

struct wl_buffer *wlr_create_dmabuf_buffer(struct xdpw_screencast_instance *cast,
int width, int height, uint32_t fourcc, struct gbm_bo *bo);
void wlr_destroy_dmabuf_buffer(struct wl_buffer *buffer, struct gbm_bo *bo);

struct gbm_device *create_gbm_device();
void destroy_gbm_device(struct gbm_device *gbm);

Expand Down
50 changes: 50 additions & 0 deletions src/screencast/wlr_screencast_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "xdpw.h"
#include "logger.h"

#include "linux-dmabuf-unstable-v1-client-protocol.h"
#include<gdbm.h>
#include<xf86drm.h>
#include <bsd/string.h>
Expand Down Expand Up @@ -80,6 +81,55 @@ struct wl_buffer *wlr_create_shm_buffer(struct xdpw_screencast_instance *cast,
return buffer;
}

struct wl_buffer *wlr_create_dmabuf_buffer(struct xdpw_screencast_instance *cast,
int width, int height, uint32_t fourcc, struct gbm_bo *bo) {
bo = gbm_bo_create(cast->ctx->gbm, width, height, fourcc,
GBM_BO_USE_RENDERING);
if (bo) {
logprint(ERROR, "wlroots: failed to create gbm_do");
return NULL;
}

struct zwp_linux_buffer_params_v1* params;
params = zwp_linux_dmabuf_v1_create_params(cast->ctx->linux_dmabuf);
if (!params) {
logprint(ERROR, "wlroots: failed to create linux_buffer_params");
gbm_bo_destroy(bo);
return NULL;
}

uint32_t offset = gbm_bo_get_offset(bo, 0);
uint32_t stride = gbm_bo_get_stride(bo);
uint64_t mod = gbm_bo_get_modifier(bo);
int fd = gbm_bo_get_fd(bo);

if (fd < 0) {
logprint(ERROR, "wlroots: failed to get file descriptor");
zwp_linux_buffer_params_v1_destroy(params);
gbm_bo_destroy(bo);
return NULL;
}

zwp_linux_buffer_params_v1_add(params, fd, 0, offset, stride,
mod >> 32, mod & 0xffffffff);
struct wl_buffer *buffer = zwp_linux_buffer_params_v1_create_immed(params,
width, height, fourcc, /* flags */ 0);
zwp_linux_buffer_params_v1_destroy(params);
close(fd);

if (!buffer) {
logprint(ERROR, "wlroots: failed to create buffer");
gbm_bo_destroy(bo);
}

return buffer;
}

void wlr_destroy_dmabuf_buffer(struct wl_buffer *buffer, struct gbm_bo *bo) {
wl_buffer_destroy(buffer);
gbm_bo_destroy(bo);
}

static int gbm_find_render_node(char *node, size_t maxlen) {
bool r = -1;
drmDevice *devices[64];
Expand Down

0 comments on commit ccfa2c6

Please sign in to comment.