[Intel-gfx] [PATCH i-g-t 02/13] lib: Extract igt_buf_write_to_png() from gem_render_copy
Tvrtko Ursulin
tvrtko.ursulin at linux.intel.com
Tue Mar 3 06:10:55 PST 2015
From: Damien Lespiau <damien.lespiau at intel.com>
Now that the Android build has cairo, we can put cairo-dependant code
back into lib/
v2: Document image format. (Daniel Vetter)
Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
lib/intel_batchbuffer.c | 26 ++++++++++++++++++++++++++
lib/intel_batchbuffer.h | 2 ++
tests/gem_render_copy.c | 24 +++---------------------
3 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index c70f6d8..d3efc1e 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -31,6 +31,8 @@
#include <string.h>
#include <assert.h>
+#include <cairo.h>
+
#include "drm.h"
#include "drmtest.h"
#include "intel_batchbuffer.h"
@@ -458,6 +460,30 @@ unsigned igt_buf_height(struct igt_buf *buf)
}
/**
+ * igt_buf_write_to_png:
+ * @buf: an i-g-t buffer object
+ *
+ * Writes the content of @buf as a PNG file.
+ * Buffer is interpreted as in RGBX format.
+ */
+void igt_buf_write_to_png(struct igt_buf *buf, const char *filename)
+{
+ cairo_surface_t *surface;
+ cairo_status_t ret;
+
+ drm_intel_bo_map(buf->bo, 0);
+ surface = cairo_image_surface_create_for_data(buf->bo->virtual,
+ CAIRO_FORMAT_RGB24,
+ igt_buf_width(buf),
+ igt_buf_height(buf),
+ buf->stride);
+ ret = cairo_surface_write_to_png(surface, filename);
+ igt_assert(ret == CAIRO_STATUS_SUCCESS);
+ cairo_surface_destroy(surface);
+ drm_intel_bo_unmap(buf->bo);
+}
+
+/**
* igt_get_render_copyfunc:
* @devid: pci device id
*
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 12f7be1..e2afc3b 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -210,6 +210,8 @@ struct igt_buf {
unsigned igt_buf_width(struct igt_buf *buf);
unsigned igt_buf_height(struct igt_buf *buf);
+void igt_buf_write_to_png(struct igt_buf *buf, const char *filename);
+
/**
* igt_render_copyfunc_t:
* @batch: batchbuffer object
diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index df1ac88..76f8c63 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -31,7 +31,6 @@
#include <stdbool.h>
#include <unistd.h>
-#include <cairo.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <stdio.h>
@@ -71,23 +70,6 @@ typedef struct {
static int opt_dump_png = false;
static int check_all_pixels = false;
-static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename)
-{
- cairo_surface_t *surface;
- cairo_status_t ret;
-
- drm_intel_bo_map(buf->bo, 0);
- surface = cairo_image_surface_create_for_data(buf->bo->virtual,
- CAIRO_FORMAT_RGB24,
- igt_buf_width(buf),
- igt_buf_height(buf),
- buf->stride);
- ret = cairo_surface_write_to_png(surface, filename);
- igt_assert(ret == CAIRO_STATUS_SUCCESS);
- cairo_surface_destroy(surface);
- drm_intel_bo_unmap(buf->bo);
-}
-
static void scratch_buf_init(data_t *data, struct igt_buf *buf,
int width, int height, int stride, uint32_t color)
{
@@ -165,8 +147,8 @@ int main(int argc, char **argv)
scratch_buf_check(&data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR);
if (opt_dump_png) {
- scratch_buf_write_to_png(&src, "source.png");
- scratch_buf_write_to_png(&dst, "destination.png");
+ igt_buf_write_to_png(&src, "source.png");
+ igt_buf_write_to_png(&dst, "destination.png");
}
if (opt_dump_aub) {
@@ -188,7 +170,7 @@ int main(int argc, char **argv)
&dst, WIDTH / 2, HEIGHT / 2);
if (opt_dump_png)
- scratch_buf_write_to_png(&dst, "result.png");
+ igt_buf_write_to_png(&dst, "result.png");
if (opt_dump_aub) {
drm_intel_gem_bo_aub_dump_bmp(dst.bo,
--
2.3.0
More information about the Intel-gfx
mailing list