modetest: use dumb buffer helpers

Signed-off-by: Simon Ser <contact@emersion.fr>
main
Simon Ser 2022-10-27 19:13:06 +02:00
parent ce22377778
commit e832f5b0b8
1 changed files with 7 additions and 21 deletions

View File

@ -37,6 +37,7 @@
#include "libdrm_macros.h" #include "libdrm_macros.h"
#include "xf86drm.h" #include "xf86drm.h"
#include "xf86drmMode.h"
#include "buffers.h" #include "buffers.h"
@ -56,7 +57,6 @@ struct bo
static struct bo * static struct bo *
bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bpp) bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bpp)
{ {
struct drm_mode_create_dumb arg;
struct bo *bo; struct bo *bo;
int ret; int ret;
@ -66,12 +66,8 @@ bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bpp
return NULL; return NULL;
} }
memset(&arg, 0, sizeof(arg)); ret = drmModeCreateDumbBuffer(fd, width, height, bpp, 0, &bo->handle,
arg.bpp = bpp; &bo->pitch, &bo->size);
arg.width = width;
arg.height = height;
ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
if (ret) { if (ret) {
fprintf(stderr, "failed to create dumb buffer: %s\n", fprintf(stderr, "failed to create dumb buffer: %s\n",
strerror(errno)); strerror(errno));
@ -80,28 +76,22 @@ bo_create_dumb(int fd, unsigned int width, unsigned int height, unsigned int bpp
} }
bo->fd = fd; bo->fd = fd;
bo->handle = arg.handle;
bo->size = arg.size;
bo->pitch = arg.pitch;
return bo; return bo;
} }
static int bo_map(struct bo *bo, void **out) static int bo_map(struct bo *bo, void **out)
{ {
struct drm_mode_map_dumb arg;
void *map; void *map;
int ret; int ret;
uint64_t offset;
memset(&arg, 0, sizeof(arg)); ret = drmModeMapDumbBuffer(bo->fd, bo->handle, &offset);
arg.handle = bo->handle;
ret = drmIoctl(bo->fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
if (ret) if (ret)
return ret; return ret;
map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
bo->fd, arg.offset); bo->fd, offset);
if (map == MAP_FAILED) if (map == MAP_FAILED)
return -EINVAL; return -EINVAL;
@ -339,13 +329,9 @@ bo_create(int fd, unsigned int format,
void bo_destroy(struct bo *bo) void bo_destroy(struct bo *bo)
{ {
struct drm_mode_destroy_dumb arg;
int ret; int ret;
memset(&arg, 0, sizeof(arg)); ret = drmModeDestroyDumbBuffer(bo->fd, bo->handle);
arg.handle = bo->handle;
ret = drmIoctl(bo->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
if (ret) if (ret)
fprintf(stderr, "failed to destroy dumb buffer: %s\n", fprintf(stderr, "failed to destroy dumb buffer: %s\n",
strerror(errno)); strerror(errno));