From dc84e7d6ada3c4dbf07a5cfafdbdd597ab03c635 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 2 Mar 2016 13:39:44 +0100 Subject: lib: Add wrapper for DRM_IOCTL_MODE_CREATE_DUMB In order to test drivers that don't have support for proper buffer objects, add a wrapper for creating dumb buffer objects that will be called from the lib code for those subtests that don't need to care. Signed-off-by: Tomeu Vizoso Reviewed-by: Daniel Stone Acked-by: Daniel Vetter --- lib/igt_kms.c | 36 ++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 3 +++ 2 files changed, 39 insertions(+) (limited to 'lib') diff --git a/lib/igt_kms.c b/lib/igt_kms.c index b63a59d6..a013a05f 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -426,6 +426,42 @@ uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res, igt_assert(false); } +/** + * kmstest_dumb_create: + * @fd: open drm file descriptor + * @width: width of the buffer in pixels + * @height: height of the buffer in pixels + * @bpp: bytes per pixel of the buffer + * + * This wraps the CREATE_DUMB ioctl, which allocates a new dumb buffer object + * for the specified dimensions. + * + * Returns: The file-private handle of the created buffer object + */ +uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp, + unsigned *stride, unsigned *size) +{ + struct drm_mode_create_dumb create; + + memset(&create, 0, sizeof(create)); + create.width = width; + create.height = height; + create.bpp = bpp; + + create.handle = 0; + do_ioctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &create); + igt_assert(create.handle); + igt_assert(create.size >= width * height * bpp / 8); + + if (stride) + *stride = create.pitch; + + if (size) + *size = create.size; + + return create.handle; +} + /* * Returns: the previous mode, or KD_GRAPHICS if no /dev/tty0 was * found and nothing was done. diff --git a/lib/igt_kms.h b/lib/igt_kms.h index b7631203..7bf51b15 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -175,6 +175,9 @@ uint32_t kmstest_find_crtc_for_connector(int fd, drmModeRes *res, drmModeConnector *connector, uint32_t crtc_blacklist_idx_mask); +uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp, + unsigned *stride, unsigned *size); + /* * A small modeset API */ -- cgit v1.2.3