diff options
author | Maarten Lankhorst <maarten.lankhorst@linux.intel.com> | 2018-02-01 12:48:45 +0100 |
---|---|---|
committer | Maarten Lankhorst <maarten.lankhorst@linux.intel.com> | 2018-02-01 13:18:31 +0100 |
commit | be2f6fc1cba25372837daed6cec19107d44d3eb5 (patch) | |
tree | c44bd208a21616c7575e96c4a5562a340a5baf61 /lib/igt_fb.c | |
parent | 6095e218e44578fc9bee1d01cebf7064f2fa0c27 (diff) |
lib/igt_fb: Add igt_put_cairo_ctx as counter to igt_get_cairo_ctx
This will allow support for NV12 in the future, where igt_get_cairo_ctx
will return a RGB image to draw with, which will be converted in
igt_put_cairo_ctx so tests don't have to add special support for NV12.
This is the same as cairo_destroy + checking for errors, but not all
tests use this correctly so it's better to have a single handler for it.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Diffstat (limited to 'lib/igt_fb.c')
-rw-r--r-- | lib/igt_fb.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/igt_fb.c b/lib/igt_fb.c index ded639e8..39a83bae 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -771,8 +771,7 @@ unsigned int igt_create_color_fb(int fd, int width, int height, cr = igt_get_cairo_ctx(fd, fb); igt_paint_color(cr, 0, 0, width, height, r, g, b); - igt_assert(cairo_status(cr) == 0); - cairo_destroy(cr); + igt_put_cairo_ctx(fd, fb, cr); return fb_id; } @@ -809,8 +808,7 @@ unsigned int igt_create_pattern_fb(int fd, int width, int height, cr = igt_get_cairo_ctx(fd, fb); igt_paint_test_pattern(cr, width, height); - igt_assert(cairo_status(cr) == 0); - cairo_destroy(cr); + igt_put_cairo_ctx(fd, fb, cr); return fb_id; } @@ -853,8 +851,7 @@ unsigned int igt_create_color_pattern_fb(int fd, int width, int height, cr = igt_get_cairo_ctx(fd, fb); igt_paint_color(cr, 0, 0, width, height, r, g, b); igt_paint_test_pattern(cr, width, height); - igt_assert(cairo_status(cr) == 0); - cairo_destroy(cr); + igt_put_cairo_ctx(fd, fb, cr); return fb_id; } @@ -897,8 +894,7 @@ unsigned int igt_create_image_fb(int fd, int width, int height, cr = igt_get_cairo_ctx(fd, fb); igt_paint_image(cr, filename, 0, 0, width, height); - igt_assert(cairo_status(cr) == 0); - cairo_destroy(cr); + igt_put_cairo_ctx(fd, fb, cr); return fb_id; } @@ -998,7 +994,7 @@ unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode, layout.right.x, layout.right.y, layout.right.width, layout.right.height); - cairo_destroy(cr); + igt_put_cairo_ctx(drm_fd, &fb, cr); return fb_id; } @@ -1206,7 +1202,7 @@ cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb) * * This initializes a cairo surface for @fb and then allocates a drawing context * for it. The return cairo drawing context should be released by calling - * cairo_destroy(). This also sets a default font for drawing text on + * igt_put_cairo_ctx(). This also sets a default font for drawing text on * framebuffers. * * Returns: @@ -1230,6 +1226,24 @@ cairo_t *igt_get_cairo_ctx(int fd, struct igt_fb *fb) } /** + * igt_put_cairo_ctx: + * @fd: open i915 drm file descriptor + * @fb: pointer to an #igt_fb structure + * @cr: the cairo context returned by igt_get_cairo_ctx. + * + * This releases the cairo surface @cr returned by igt_get_cairo_ctx() + * for @fb, and writes the changes out to the framebuffer if cairo doesn't + * have native support for the format. + */ +void igt_put_cairo_ctx(int fd, struct igt_fb *fb, cairo_t *cr) +{ + cairo_status_t ret = cairo_status(cr); + igt_assert_f(ret == CAIRO_STATUS_SUCCESS, "Cairo failed to draw with %s\n", cairo_status_to_string(ret)); + + cairo_destroy(cr); +} + +/** * igt_remove_fb: * @fd: open i915 drm file descriptor * @fb: pointer to an #igt_fb structure |