summaryrefslogtreecommitdiff
path: root/lib/drmtest.c
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2013-08-23 16:46:45 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2013-09-30 18:04:21 +0100
commitbde7060e3c30eba807295c6831e10d7e4365a33b (patch)
treea2aaa34d5a44e5c22017113013e8b02bce5d6406 /lib/drmtest.c
parent30e0710ca374eb937806ad79e20f53a222cab54a (diff)
lib: Add a helper to paint a PNG using cairo
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'lib/drmtest.c')
-rw-r--r--lib/drmtest.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 7f89fd1f..d9749d7e 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -1475,6 +1475,34 @@ void kmstest_paint_test_pattern(cairo_t *cr, int width, int height)
assert(!cairo_status(cr));
}
+void kmstest_paint_image(cairo_t *cr, const char *filename,
+ int dst_x, int dst_y, int dst_width, int dst_height)
+{
+ cairo_surface_t *image;
+ int img_width, img_height;
+ double scale_x, scale_y;
+
+ image = cairo_image_surface_create_from_png(filename);
+ assert(cairo_surface_status(image) == CAIRO_STATUS_SUCCESS);
+
+ img_width = cairo_image_surface_get_width(image);
+ img_height = cairo_image_surface_get_height(image);
+
+ scale_x = (double)dst_width / img_width;
+ scale_y = (double)dst_height / img_height;
+
+ cairo_save(cr);
+
+ cairo_translate(cr, dst_x, dst_y);
+ cairo_scale(cr, scale_x, scale_y);
+ cairo_set_source_surface(cr, image, 0, 0);
+ cairo_paint(cr);
+
+ cairo_surface_destroy(image);
+
+ cairo_restore(cr);
+}
+
#define DF(did, cid, _bpp, _depth) \
{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, _bpp, _depth }
static struct format_desc_struct {