[Intel-gfx] [PATCH i-g-t 2/5] lib: Split the GTT mapping out of get_cairo_surface()

Damien Lespiau damien.lespiau at intel.com
Fri Jul 11 16:09:02 CEST 2014


This is preparation work for when we need a different way to get a
linear buffer we can use with cairo.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
 lib/igt_fb.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index f43af93..39a1f62 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -518,24 +518,28 @@ static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 	igt_fail(101);
 }
 
-static void __destroy_cairo_surface(void *arg)
+static void destroy_cairo_surface__gtt(void *arg)
 {
 	struct igt_fb *fb = arg;
 	munmap(cairo_image_surface_get_data(fb->cairo_surface), fb->size);
 }
 
+static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
+{
+	fb->cairo_surface =
+		cairo_image_surface_create_for_data(gem_mmap(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE),
+						    drm_format_to_cairo(fb->drm_format),
+						    fb->width, fb->height, fb->stride);
+
+	cairo_surface_set_user_data(fb->cairo_surface,
+				    (cairo_user_data_key_t *)create_cairo_surface__gtt,
+				    fb, destroy_cairo_surface__gtt);
+}
+
 static cairo_surface_t *get_cairo_surface(int fd, struct igt_fb *fb)
 {
-	if (fb->cairo_surface == NULL) {
-		fb->cairo_surface =
-			cairo_image_surface_create_for_data(gem_mmap(fd, fb->gem_handle, fb->size, PROT_READ | PROT_WRITE),
-							    drm_format_to_cairo(fb->drm_format),
-							    fb->width, fb->height, fb->stride);
-
-		cairo_surface_set_user_data(fb->cairo_surface,
-					    (cairo_user_data_key_t *)get_cairo_surface,
-					    fb, __destroy_cairo_surface);
-	}
+	if (fb->cairo_surface == NULL)
+		create_cairo_surface__gtt(fd, fb);
 
 	gem_set_domain(fd, fb->gem_handle,
 		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
-- 
1.8.3.1




More information about the Intel-gfx mailing list