Skip to contentSkip to conversation

lib: Remove unused field from struct igt_fb

PATCH In review Damien Lespiau 1 participant 6 messages Jul 11, 2014 – Jul 29, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 lib: Remove unused field from struct igt_fb

---
 lib/igt_fb.h | 1 -
 1 file changed, 1 deletion(-)
lib/igt_fb.h +0 -1
index 6d030e6..f5110d4 100644
@@ -48,7 +48,6 @@ struct igt_fb {
 	uint32_t drm_format;
 	int width;
 	int height;
-	int depth;
 	unsigned stride;
 	unsigned tiling;
 	unsigned size;
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/5 lib: Split the GTT mapping out of get_cairo_surface()

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

---
 lib/igt_fb.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
lib/igt_fb.c +15 -11
index f43af93..39a1f62 100644
@@ -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);
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 3/5 lib: NULLify ->cairo_surface once unmapped

In reply to Damien Lespiau

Just a matter of not leaving dangling pointers around.

---
 lib/igt_fb.c | 2 ++
 1 file changed, 2 insertions(+)
lib/igt_fb.c +2 -0
index 39a1f62..83f4343 100644
@@ -521,7 +521,9 @@ static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 static void destroy_cairo_surface__gtt(void *arg)
 {
 	struct igt_fb *fb = arg;
+
 	munmap(cairo_image_surface_get_data(fb->cairo_surface), fb->size);
+	fb->cairo_surface = NULL;
 }
 
 static void create_cairo_surface__gtt(int fd, struct igt_fb *fb)
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 4/5 lib: Don't take a reference to the surface in get_cairo_surface()

In reply to Damien Lespiau

We don't need to keep a reference to the surface, the cairo context will keep a reference to it until we destroy it.

---
 lib/igt_fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/igt_fb.c +1 -1
index 83f4343..d07af0d 100644
@@ -547,7 +547,7 @@ static cairo_surface_t *get_cairo_surface(int fd, struct igt_fb *fb)
 		       I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
 
 	igt_assert(cairo_surface_status(fb->cairo_surface) == CAIRO_STATUS_SUCCESS);
-	return cairo_surface_reference(fb->cairo_surface);
+	return fb->cairo_surface;
 }
 
 /**
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 5/5 testdisplay: Destroy the cairo context once the fb is painted

In reply to Damien Lespiau
---
 tests/testdisplay.c | 2 ++
 1 file changed, 2 insertions(+)
tests/testdisplay.c +2 -0
index 6d8fe3a..887105d 100644
@@ -314,6 +314,8 @@ static void paint_output_info(struct connector *c, struct igt_fb *fb)
 		paint_image(cr, IGT_DATADIR"/pass.png");
 
 	igt_assert(!cairo_status(cr));
+
+	cairo_destroy(cr);
 }
 
 static void sighandler(int signo)
Signature · 1 line
1.8.3.1
#5 lore raw
In reply to Damien Lespiau

Pushed those, before I forget.

Signature · 1 line
Damien
Quoted 24 lines · Damien Lespiau
---
 lib/igt_fb.h | 1 -
 1 file changed, 1 deletion(-)
lib/igt_fb.h +0 -1
index 6d030e6..f5110d4 100644
@@ -48,7 +48,6 @@ struct igt_fb {
 	uint32_t drm_format;
 	int width;
 	int height;
-	int depth;
 	unsigned stride;
 	unsigned tiling;
 	unsigned size;
Signature · 6 lines
1.8.3.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx