Skip to contentSkip to conversation

igt_fb: Close the image file when we are done with it

PATCH In review Tvrtko Ursulin 2 participants 3 messages Apr 30, 2015 – May 1, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 igt_fb: Close the image file when we are done with it

From: Tvrtko Ursulin <[email protected]>

---
 lib/igt_fb.c | 2 ++
 1 file changed, 2 insertions(+)
lib/igt_fb.c +2 -0
index 6dc22bb..eed5405 100644
@@ -388,6 +388,8 @@ void igt_paint_image(cairo_t *cr, const char *filename,
 	cairo_surface_destroy(image);
 
 	cairo_restore(cr);
+
+	fclose(f);
 }
 
 /**
Signature · 6 lines
2.3.5

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

PATCH 2/2 kms_plane_scaling: Find the image regardless how the test is run

From: Tvrtko Ursulin <[email protected]>

As it stands running the test like "sudo tests/kms_plane_scaling" does not work.

Fix it by using the same method igt_paint_image uses.

---
 tests/kms_plane_scaling.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tests/kms_plane_scaling.c +15 -2
index 00db5cb..8ff154f 100644
@@ -202,6 +202,15 @@ static void iterate_plane_scaling(data_t *d, drmModeModeInfo *mode)
 	}
 }
 
+static cairo_status_t
+stdio_read_func(void *closure, unsigned char* data, unsigned int size)
+{
+	if (fread(data, 1, size, (FILE*)closure) != size)
+		return CAIRO_STATUS_READ_ERROR;
+
+	return CAIRO_STATUS_SUCCESS;
+}
+
 static void test_plane_scaling(data_t *d)
 {
 	igt_display_t *display = &d->display;
@@ -210,6 +219,7 @@ static void test_plane_scaling(data_t *d)
 	enum pipe pipe;
 	int valid_tests = 0;
 	int primary_plane_scaling = 0; /* For now */
+	FILE* f;
 
 	igt_require(d->display.has_universal_planes);
 	igt_require(d->num_scalers);
@@ -223,11 +233,15 @@ static void test_plane_scaling(data_t *d)
 		mode = igt_output_get_mode(output);
 
 		/* allocate fb2 with image size */
-		image = cairo_image_surface_create_from_png(FILE_NAME);
+
+		f = igt_fopen_data(FILE_NAME);
+		image = cairo_image_surface_create_from_png_stream(
+							&stdio_read_func, f);
 		igt_assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
 		d->image_w = cairo_image_surface_get_width(image);
 		d->image_h = cairo_image_surface_get_height(image);
 		cairo_surface_destroy(image);
+		fclose(f);
 
 		d->fb_id2 = igt_create_fb(d->drm_fd,
 				d->image_w, d->image_h,
@@ -355,7 +369,6 @@ igt_simple_main
 
 	igt_skip_on_simulation();
 
-
 	data.drm_fd = drm_open_any();
 	igt_require_pipe_crc();
 	igt_display_init(&data.display, data.drm_fd);
Signature · 6 lines
2.3.5

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

Re: [PATCH i-g-t 2/2] kms_plane_scaling: Find the image regardless how the test is run

Quoted 6 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

As it stands running the test like "sudo tests/kms_plane_scaling" does not work.

Fix it by using the same method igt_paint_image uses.

Adding a new function to igt_kms would avoid duplicating stdio_read_func and may be useful to other tests in the future.

There is also an unrelated whitespace change to remove at the end of the patch.

Quoted 63 lines
---
 tests/kms_plane_scaling.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tests/kms_plane_scaling.c +15 -3
index 00db5cb..8ff154f 100644
@@ -202,6 +202,15 @@ static void iterate_plane_scaling(data_t *d, drmModeModeInfo *mode)
        }
 }
 
+static cairo_status_t
+stdio_read_func(void *closure, unsigned char* data, unsigned int size)
+{
+       if (fread(data, 1, size, (FILE*)closure) != size)
+               return CAIRO_STATUS_READ_ERROR;
+
+       return CAIRO_STATUS_SUCCESS;
+}
+
 static void test_plane_scaling(data_t *d)
 {
        igt_display_t *display = &d->display;
@@ -210,6 +219,7 @@ static void test_plane_scaling(data_t *d)
        enum pipe pipe;
        int valid_tests = 0;
        int primary_plane_scaling = 0; /* For now */
+       FILE* f;
 
        igt_require(d->display.has_universal_planes);
        igt_require(d->num_scalers);
@@ -223,11 +233,15 @@ static void test_plane_scaling(data_t *d)
                mode = igt_output_get_mode(output);
 
                /* allocate fb2 with image size */
-               image = cairo_image_surface_create_from_png(FILE_NAME);
+
+               f = igt_fopen_data(FILE_NAME);
+               image = cairo_image_surface_create_from_png_stream(
+                                                       &stdio_read_func, f);
                igt_assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
                d->image_w = cairo_image_surface_get_width(image);
                d->image_h = cairo_image_surface_get_height(image);
                cairo_surface_destroy(image);
+               fclose(f);
 
                d->fb_id2 = igt_create_fb(d->drm_fd,
                                d->image_w, d->image_h,
@@ -355,7 +369,6 @@ igt_simple_main
 
        igt_skip_on_simulation();
 
-
        data.drm_fd = drm_open_any();
        igt_require_pipe_crc();
        igt_display_init(&data.display, data.drm_fd);
--

2.3.5

Quoted 4 lines

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

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