diff options
author | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2015-12-17 01:39:31 +0200 |
---|---|---|
committer | Ville Syrjälä <ville.syrjala@linux.intel.com> | 2016-01-08 15:01:59 +0200 |
commit | 5b113d323dde18ef3bbae2f57d613be4ab7eb267 (patch) | |
tree | cd2bc3a7b496e985bd856f2c341e553c3315ec71 /lib | |
parent | 7cb35109645e6495f67981b9930587c1ddfe4f90 (diff) |
lib: Extract some common fb create+fill methods into helpers
Several tests do one or more of the following:
* igt_create_fb() + igt_paint_test_pattern()
* igt_create_color_fb() + igt_paint_test_pattern()
* igt_create_fb() + igt_paint_image()
Extract them into new helpers: igt_create_pattern_fb(),
igt_create_color_pattern_fb(), igt_create_image_fb().
v2: Fix typos, and improve API docs (Thomas)
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/igt_fb.c | 128 | ||||
-rw-r--r-- | lib/igt_fb.h | 11 |
2 files changed, 138 insertions, 1 deletions
diff --git a/lib/igt_fb.c b/lib/igt_fb.c index 3ea9915c..c9858240 100644 --- a/lib/igt_fb.c +++ b/lib/igt_fb.c @@ -503,7 +503,7 @@ unsigned int igt_create_fb(int fd, int width, int height, uint32_t format, * @format: drm fourcc pixel format code * @tiling: tiling layout of the framebuffer * @r: red value to use as fill color - * @g: gree value to use as fill color + * @g: green value to use as fill color * @b: blue value to use as fill color * @fb: pointer to an #igt_fb structure * @@ -537,6 +537,132 @@ unsigned int igt_create_color_fb(int fd, int width, int height, return fb_id; } +/** + * igt_create_pattern_fb: + * @fd: open i915 drm file descriptor + * @width: width of the framebuffer in pixel + * @height: height of the framebuffer in pixel + * @format: drm fourcc pixel format code + * @tiling: tiling layout of the framebuffer + * @fb: pointer to an #igt_fb structure + * + * This function allocates a gem buffer object suitable to back a framebuffer + * with the requested properties and then wraps it up in a drm framebuffer + * object. All metadata is stored in @fb. + * + * Compared to igt_create_fb() this function also draws the standard test pattern + * into the framebuffer. + * + * Returns: + * The kms id of the created framebuffer on success or a negative error code on + * failure. + */ +unsigned int igt_create_pattern_fb(int fd, int width, int height, + uint32_t format, uint64_t tiling, + struct igt_fb *fb /* out */) +{ + unsigned int fb_id; + cairo_t *cr; + + fb_id = igt_create_fb(fd, width, height, format, tiling, fb); + igt_assert(fb_id); + + cr = igt_get_cairo_ctx(fd, fb); + igt_paint_test_pattern(cr, width, height); + igt_assert(cairo_status(cr) == 0); + cairo_destroy(cr); + + return fb_id; +} + +/** + * igt_create_color_pattern_fb: + * @fd: open i915 drm file descriptor + * @width: width of the framebuffer in pixel + * @height: height of the framebuffer in pixel + * @format: drm fourcc pixel format code + * @tiling: tiling layout of the framebuffer + * @r: red value to use as fill color + * @g: green value to use as fill color + * @b: blue value to use as fill color + * @fb: pointer to an #igt_fb structure + * + * This function allocates a gem buffer object suitable to back a framebuffer + * with the requested properties and then wraps it up in a drm framebuffer + * object. All metadata is stored in @fb. + * + * Compared to igt_create_fb() this function also fills the entire framebuffer + * with the given color, and then draws the standard test pattern into the + * framebuffer. + * + * Returns: + * The kms id of the created framebuffer on success or a negative error code on + * failure. + */ +unsigned int igt_create_color_pattern_fb(int fd, int width, int height, + uint32_t format, uint64_t tiling, + double r, double g, double b, + struct igt_fb *fb /* out */) +{ + unsigned int fb_id; + cairo_t *cr; + + fb_id = igt_create_fb(fd, width, height, format, tiling, fb); + igt_assert(fb_id); + + 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); + + return fb_id; +} + +/** + * igt_create_image_fb: + * @drm_fd: open i915 drm file descriptor + * @width: width of the framebuffer in pixel or 0 + * @height: height of the framebuffer in pixel or 0 + * @format: drm fourcc pixel format code + * @tiling: tiling layout of the framebuffer + * @filename: filename of the png image to draw + * @fb: pointer to an #igt_fb structure + * + * Create a framebuffer with the specified image. If @width is zero the + * image width will be used. If @height is zero the image height will be used. + * + * Returns: + * The kms id of the created framebuffer on success or a negative error code on + * failure. + */ +unsigned int igt_create_image_fb(int fd, int width, int height, + uint32_t format, uint64_t tiling, + const char *filename, + struct igt_fb *fb /* out */) +{ + cairo_surface_t *image; + uint32_t fb_id; + cairo_t *cr; + + image = 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); + if (height == 0) + height = cairo_image_surface_get_height(image); + cairo_surface_destroy(image); + + fb_id = igt_create_fb(fd, width, height, format, tiling, fb); + + 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); + + return fb_id; +} + struct box { int x, y, width, height; }; diff --git a/lib/igt_fb.h b/lib/igt_fb.h index 37892b50..5cc8644d 100644 --- a/lib/igt_fb.h +++ b/lib/igt_fb.h @@ -80,6 +80,17 @@ unsigned int igt_create_color_fb(int fd, int width, int height, uint32_t format, uint64_t tiling, double r, double g, double b, struct igt_fb *fb /* out */); +unsigned int igt_create_pattern_fb(int fd, int width, int height, + uint32_t format, uint64_t tiling, + struct igt_fb *fb /* out */); +unsigned int igt_create_color_pattern_fb(int fd, int width, int height, + uint32_t format, uint64_t tiling, + double r, double g, double b, + struct igt_fb *fb /* out */); +unsigned int igt_create_image_fb(int drm_fd, int width, int height, + uint32_t format, uint64_t tiling, + const char *filename, + struct igt_fb *fb /* out */); unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode, uint32_t format, uint64_t tiling); void igt_remove_fb(int fd, struct igt_fb *fb); |