Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yi Sun <yi.sun@intel.com>
To: daniel.vetter@ffwll.ch
Cc: intel-gfx@lists.freedesktop.org
Subject: [PATCH] tests/testdisplay.c: Add a option '-g' to save images which intended to paint on screen during each mode setting.
Date: Wed,  1 Aug 2012 09:51:46 +0800	[thread overview]
Message-ID: <1343785906-31256-1-git-send-email-yi.sun@intel.com> (raw)

That option will save all the images which are created and intended to paint on screen.
The images will be saved in folder "saveimages" with PNG format.

Signed-off-by: Yi Sun <yi.sun@intel.com>

diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 4430d07..2d1fdb0 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -64,6 +64,7 @@
 
 #include <stdlib.h>
 #include <signal.h>
+#include <sys/stat.h>
 
 drmModeRes *resources;
 int drm_fd, modes;
@@ -72,6 +73,7 @@ int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
 int sleep_between_modes = 5;
 uint32_t depth = 24, stride, bpp;
 int qr_code = 0;
+int save_image = 0;
 
 drmModeModeInfo force_timing;
 
@@ -379,6 +381,8 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 	cairo_text_extents_t name_extents, mode_extents;
 	char name_buf[128], mode_buf[128];
 	int i, x, y, modes_x, modes_y;
+	static int count = 0;
+	count++;
 
 	/* Get text extents for each string */
 	snprintf(name_buf, sizeof name_buf, "%s",
@@ -460,6 +464,25 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 
 	if (qr_code)
 		paint_image(cr, "./pass.png");
+
+	if (save_image){
+		char pngname[256];
+		char *pos;
+
+		readlink("/proc/self/exe", pngname, sizeof(pngname));
+		pos = strrchr(pngname, '/');
+		*(pos + 1) = '\0';
+
+		strcat(pngname, "saveimages");
+
+		//judge whether folder mkdir existed, if not create it.
+		if(access(pngname,0) == -1)
+			if (mkdir( pngname,0777))
+				fprintf (stderr, "error %d, %s\n", errno, strerror (errno));
+
+		sprintf(pngname, "%s/%d_%s@%d.png", pngname, count, c->mode.name, c->mode.vrefresh);
+		cairo_surface_write_to_png( cairo_get_target(cr), pngname );
+	}
 }
 
 static void sighandler(int signo)
@@ -599,7 +622,7 @@ int update_display(void)
 	return 1;
 }
 
-static char optstr[] = "hiaf:s:d:p:mrt";
+static char optstr[] = "hiaf:s:d:p:mrtg";
 
 static void usage(char *name)
 {
@@ -612,6 +635,7 @@ static void usage(char *name)
 	fprintf(stderr, "\t-m\ttest the preferred mode\n");
 	fprintf(stderr, "\t-t\tuse a tiled framebuffer\n");
 	fprintf(stderr, "\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n");
+	fprintf(stderr, "\t-g\tsave images which is intended to paint on the screen as png files in folder \"saveimages\"\n");
 	fprintf(stderr, "\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n");
 	fprintf(stderr, "\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n");
 	fprintf(stderr, "\t\ttest force mode\n");
@@ -704,6 +728,9 @@ int main(int argc, char **argv)
 		case 'r':
 			qr_code = 1;
 			break;
+		case 'g':
+			save_image = 1;
+			break;
 		default:
 			fprintf(stderr, "unknown option %c\n", c);
 			/* fall through */
-- 
1.7.6.4

             reply	other threads:[~2012-08-01  1:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-01  1:51 Yi Sun [this message]
2012-08-01  3:21 ` [PATCH] tests/testdisplay.c: Add a option '-g' to save images which intended to paint on screen during each mode setting Ben Widawsky
2012-08-06  7:09 ` Daniel Vetter
2012-08-06  7:47   ` Sun, Yi
2012-08-06  8:33     ` Daniel Vetter
2012-08-08  6:49       ` Sun, Yi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343785906-31256-1-git-send-email-yi.sun@intel.com \
    --to=yi.sun@intel.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox