[igt-dev] [CI 01/16] fb: Add buffer map/unmap functions
Arkadiusz Hiler
arkadiusz.hiler at intel.com
Mon Oct 8 14:04:18 UTC 2018
From: Maxime Ripard <maxime.ripard at bootlin.com>
The current code to manipulate the buffer has the assumption that we can
create an underlying cairo instance.
However, when it comes to supporting various formats, cairo is very limited
so we would need to decouple the buffer access from cairo surfaces.
Let's create a function that allows to map the underlying GEM buffer from
an igt_fb structure, which will then allow use to manipulate as we wish.
Reviewed-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Maxime Ripard <maxime.ripard at bootlin.com>
---
lib/igt_fb.c | 59 +++++++++++++++++++++++++++++++++++++++++++---------
lib/igt_fb.h | 2 ++
2 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index cba67f41..f1332169 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1336,18 +1336,23 @@ int igt_dirty_fb(int fd, struct igt_fb *fb)
return drmModeDirtyFB(fb->fd, fb->fb_id, NULL, 0);
}
+static void unmap_bo(struct igt_fb *fb, void *ptr)
+{
+ gem_munmap(ptr, fb->size);
+
+ if (fb->is_dumb)
+ igt_dirty_fb(fb->fd, fb);
+}
+
static void destroy_cairo_surface__gtt(void *arg)
{
struct igt_fb *fb = arg;
- gem_munmap(cairo_image_surface_get_data(fb->cairo_surface), fb->size);
+ unmap_bo(fb, cairo_image_surface_get_data(fb->cairo_surface));
fb->cairo_surface = NULL;
-
- if (fb->is_dumb)
- igt_dirty_fb(fb->fd, fb);
}
-static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
+static void *map_bo(int fd, struct igt_fb *fb)
{
void *ptr;
@@ -1361,6 +1366,13 @@ static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
ptr = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
PROT_READ | PROT_WRITE);
+ return ptr;
+}
+
+static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
+{
+ void *ptr = map_bo(fd, fb);
+
fb->cairo_surface =
cairo_image_surface_create_for_data(ptr,
drm_format_to_cairo(fb->drm_format),
@@ -1776,7 +1788,7 @@ static void destroy_cairo_surface__convert(void *arg)
if (blit->base.linear.fb.gem_handle)
free_linear_mapping(&blit->base);
else
- gem_munmap(blit->base.linear.map, fb->size);
+ unmap_bo(fb, blit->base.linear.map);
free(blit);
@@ -1800,10 +1812,7 @@ static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
setup_linear_mapping(fd, fb, &blit->base.linear);
} else {
blit->base.linear.fb.gem_handle = 0;
- gem_set_domain(fd, fb->gem_handle,
- I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
- blit->base.linear.map = gem_mmap__gtt(fd, fb->gem_handle, fb->size,
- PROT_READ | PROT_WRITE);
+ blit->base.linear.map = map_bo(fd, fb);
igt_assert(blit->base.linear.map);
blit->base.linear.fb.size = fb->size;
memcpy(blit->base.linear.fb.strides, fb->strides, sizeof(fb->strides));
@@ -1837,6 +1846,36 @@ static void create_cairo_surface__convert(int fd, struct igt_fb *fb)
blit, destroy_cairo_surface__convert);
}
+/**
+ * igt_fb_map_buffer:
+ * @fd: open drm file descriptor
+ * @fb: pointer to an #igt_fb structure
+ *
+ * This function will creating a new mapping of the buffer and return a pointer
+ * to the content of the supplied framebuffer's plane. This mapping needs to be
+ * deleted using igt_fb_unmap_buffer().
+ *
+ * Returns:
+ * A pointer to a buffer with the contents of the framebuffer
+ */
+void *igt_fb_map_buffer(int fd, struct igt_fb *fb)
+{
+ return map_bo(fd, fb);
+}
+
+/**
+ * igt_fb_unmap_buffer:
+ * @fb: pointer to the backing igt_fb structure
+ * @buffer: pointer to the buffer previously mappped
+ *
+ * This function will unmap a buffer mapped previously with
+ * igt_fb_map_buffer().
+ */
+void igt_fb_unmap_buffer(struct igt_fb *fb, void *buffer)
+{
+ return unmap_bo(fb, buffer);
+}
+
/**
* igt_get_cairo_surface:
* @fd: open drm file descriptor
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 35bf307a..758d4d0d 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -132,6 +132,8 @@ unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
uint32_t format, uint64_t tiling);
void igt_remove_fb(int fd, struct igt_fb *fb);
int igt_dirty_fb(int fd, struct igt_fb *fb);
+void *igt_fb_map_buffer(int fd, struct igt_fb *fb);
+void igt_fb_unmap_buffer(struct igt_fb *fb, void *buffer);
int igt_create_bo_with_dimensions(int fd, int width, int height, uint32_t format,
uint64_t modifier, unsigned stride,
--
2.17.1
More information about the igt-dev
mailing list