[PATCH i-g-t 3/6] lib/igt_fb: Add igt_cairo_image_surface_create_from_png()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>

Raw usage of cairo_image_surface_create_from_png() doesn't work
since it doesn't know about IGT_DATADIR and IGT_SRCDIR. Let's extract
the helper from igt_paint_image() that uses igt_fopen_data() +
cairo_image_surface_create_from_png_stream() and call it
igt_cairo_image_surface_create_from_png_file().

Signed-off-by: Ville Syrjälä <ville.syrjala@xxxxxxxxxxxxxxx>
---
 lib/igt_fb.c | 21 ++++++++++++++-------
 lib/igt_fb.h |  1 +
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 95434a699dcf..d4eaed71acef 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -583,6 +583,18 @@ stdio_read_func(void *closure, unsigned char* data, unsigned int size)
 	return CAIRO_STATUS_SUCCESS;
 }
 
+cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename)
+{
+	cairo_surface_t *image;
+	FILE *f;
+
+	f = igt_fopen_data(filename);
+	image = cairo_image_surface_create_from_png_stream(&stdio_read_func, f);
+	fclose(f);
+
+	return image;
+}
+
 /**
  * igt_paint_image:
  * @cr: cairo drawing context
@@ -601,11 +613,8 @@ void igt_paint_image(cairo_t *cr, const char *filename,
 	cairo_surface_t *image;
 	int img_width, img_height;
 	double scale_x, scale_y;
-	FILE* f;
-
-	f = igt_fopen_data(filename);
 
-	image = cairo_image_surface_create_from_png_stream(&stdio_read_func, f);
+	image = igt_cairo_image_surface_create_from_png(filename);
 	igt_assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
 
 	img_width = cairo_image_surface_get_width(image);
@@ -624,8 +633,6 @@ void igt_paint_image(cairo_t *cr, const char *filename,
 	cairo_surface_destroy(image);
 
 	cairo_restore(cr);
-
-	fclose(f);
 }
 
 /**
@@ -877,7 +884,7 @@ unsigned int igt_create_image_fb(int fd, int width, int height,
 	uint32_t fb_id;
 	cairo_t *cr;
 
-	image = cairo_image_surface_create_from_png(filename);
+	image = igt_cairo_image_surface_create_from_png(filename);
 	igt_assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
 	if (width == 0)
 		width = cairo_image_surface_get_width(image);
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index a193a1e7572d..3f549036abc5 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -136,6 +136,7 @@ uint64_t igt_fb_tiling_to_mod(uint64_t tiling);
 
 /* cairo-based painting */
 cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb);
+cairo_surface_t *igt_cairo_image_surface_create_from_png(const char *filename);
 cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb);
 void igt_paint_color(cairo_t *cr, int x, int y, int w, int h,
 			 double r, double g, double b);
-- 
2.13.5

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux