From: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [CI 01/16] fb: Add buffer map/unmap functions
Date: Mon, 8 Oct 2018 17:04:18 +0300 [thread overview]
Message-ID: <20181008140433.32399-1-arkadiusz.hiler@intel.com> (raw)
From: Maxime Ripard <maxime.ripard@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@anholt.net>
Signed-off-by: Maxime Ripard <maxime.ripard@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
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next reply other threads:[~2018-10-08 14:04 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-08 14:04 Arkadiusz Hiler [this message]
2018-10-08 14:04 ` [igt-dev] [CI 02/16] fb: Only set the GEM domain on intel platforms Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 03/16] fb: Add RGB888 format Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 04/16] fb: Use an igt_fb for the cairo shadow buffer Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 05/16] fb: convert: Remove swizzle from the arguments Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 06/16] fb: Create common function to convert frame formats Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 07/16] fb: Add format conversion routine Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 08/16] igt: Make pixman mandatory Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 09/16] tests: kms_plane: Disable XBGR8888 Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 10/16] fb: Add support for conversions through pixman Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 11/16] fb: Add more formats Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 12/16] chamelium: Split CRC test function in two Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 13/16] chamelium: Change our pattern for a custom one if needed Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 14/16] chamelium: Add format support Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 15/16] chamelium: Add format subtests Arkadiusz Hiler
2018-10-08 14:04 ` [igt-dev] [CI 16/16] tests: Add chamelium formats subtests to vc4 test lists Arkadiusz Hiler
2018-10-08 14:56 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [CI,01/16] fb: Add buffer map/unmap functions Patchwork
2018-10-08 16:26 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181008140433.32399-1-arkadiusz.hiler@intel.com \
--to=arkadiusz.hiler@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox