All of 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 '-r'.
Date: Thu, 26 Jul 2012 14:23:36 +0800	[thread overview]
Message-ID: <1343283816-5176-1-git-send-email-yi.sun@intel.com> (raw)

With the option '-r', the testdisplay could paint a 2-D bar code(QR bar code) on the screen. The word "pass" is hiden in the bar code image.
Further more, with this option, testdisplay will wait until a system signal 'SIGUSR1' coming after each mode setting. This function is for another program to control testdisplay.

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

diff --git a/lib/drmtest.c b/lib/drmtest.c
index 34db126..2101f6a 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -774,5 +774,6 @@ void kmstest_dump_mode(drmModeModeInfo *mode)
 	       mode->flags,
 	       mode->type,
 	       mode->clock);
+	fflush(stdout);
 }
 
diff --git a/tests/pass.png b/tests/pass.png
new file mode 100644
index 0000000000000000000000000000000000000000..5928d5ca109b7db33640851ceb352f9da742ff7b
GIT binary patch
literal 376
zcmV-;0f+vHP)<h;3K|Lk000e1NJLTq007<q007<r00000dK`lq00009a7bBm000XT
z000XT0n*)m`~Uy}DoI2^R9J=Wm(dNwAPht;F#sd6IwLUvl53w0P1CgB_W?SQ){l=E
z9mWy;GvvSnd7=1dMSE)a|H2CWIhyfM87+gHaEJ$d4q*v9e2X8NH73LkVH2~nh8{db
z1oH@vt%vi;17nnJ>K&qlmd8Y?m?=S>V};d!&JC-@c%hEGI?~i|G%bw#%`yn#2zFYS
z+0-7gg|{O}1!wg<q~?C}LtVEqB(o|lRCr`J5x)I`I3=`z)d}<Rt{K;Mk`1O)KFXWY
z!nic_THZ#Zg>I00c~fPDf?c;Hvckz~B`9IOHyYm1SA#|bqn!+nJepLch5kgVzT3%I
zOA6OV+pcX-Uvy+}b(EP0H?%ow8?F&4v@mQk8p>PG2rCR<_!R9VEK^wF&vD>^r0@l&
W)>)U}2&Hxa0000<MNUMnLSTY*+nlZd

literal 0
HcmV?d00001

diff --git a/tests/testdisplay.c b/tests/testdisplay.c
index 5b99269..2bb60e1 100644
--- a/tests/testdisplay.c
+++ b/tests/testdisplay.c
@@ -62,12 +62,16 @@
 #include "drmtest.h"
 #include "testdisplay.h"
 
+#include <stdlib.h>
+#include <signal.h>
+
 drmModeRes *resources;
 int drm_fd, modes;
 int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
 	test_plane, enable_tiling;
 int sleep_between_modes = 5;
 uint32_t depth = 24, stride, bpp;
+int qr_code = 0;
 
 drmModeModeInfo force_timing;
 
@@ -334,6 +338,40 @@ paint_color_key(void)
 		}
 }
 
+static void paint_image(cairo_t *cr, const char *file)
+{
+	int img_x, img_y, img_w, img_h, img_w_o, img_h_o;
+	double img_w_scale, img_h_scale;
+
+	cairo_surface_t *image;
+
+	img_y = height * (0.10 );
+	img_h = height * 0.08 * 4;
+	img_w = img_h;
+
+	img_x = (width / 2) - (img_w / 2);
+
+	image = cairo_image_surface_create_from_png(file);
+
+	img_w_o = cairo_image_surface_get_width(image);
+	img_h_o = cairo_image_surface_get_height(image);
+
+	cairo_translate(cr, img_x, img_y);
+
+	fprintf(stderr, "drew %dx%d image at %d,%d\n", img_w, img_h,
+		img_x, img_y);
+
+	img_w_scale = (double)img_w / (double)img_w_o;
+	img_h_scale = (double)img_h / (double)img_h_o;
+	cairo_scale(cr, img_w_scale, img_h_scale);
+
+	cairo_set_source_surface(cr, image, 0, 0);
+	cairo_scale(cr, 1, 1);
+
+	cairo_paint(cr);
+	cairo_surface_destroy(image);
+}
+
 static void
 paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 {
@@ -419,6 +457,26 @@ paint_output_info(cairo_t *cr, int l_width, int l_height, void *priv)
 		cairo_set_source_rgb(cr, 1, 1, 1);
 		cairo_fill(cr);
 	}
+
+	if (qr_code)
+		paint_image(cr, "./pass.png");
+}
+
+static void sighandler(int signo)
+{
+	return;
+}
+
+static void set_single(void)
+{
+	int sigs[] = { SIGUSR1 };
+	struct sigaction sa;
+	sa.sa_handler = sighandler;
+
+	sigemptyset(&sa.sa_mask);
+
+	if (sigaction(sigs[0], &sa, NULL) == -1)
+		perror("Could not set signal handler");
 }
 
 static void
@@ -480,9 +538,14 @@ set_mode(struct connector *c)
 			continue;
 		}
 
-		if (sleep_between_modes && test_all_modes)
+		if (sleep_between_modes && test_all_modes && !qr_code)
 			sleep(sleep_between_modes);
 
+		if (qr_code){
+			set_single();
+			pause();
+		}
+
 	}
 
 	if(test_all_modes){
@@ -536,7 +599,7 @@ int update_display(void)
 	return 1;
 }
 
-static char optstr[] = "hiaf:s:d:p:mt";
+static char optstr[] = "hiaf:s:d:p:mrt";
 
 static void usage(char *name)
 {
@@ -548,6 +611,7 @@ static void usage(char *name)
 	fprintf(stderr, "\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n");
 	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-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");
@@ -558,7 +622,7 @@ static void usage(char *name)
 #define dump_resource(res) if (res) dump_##res()
 
 static gboolean input_event(GIOChannel *source, GIOCondition condition,
-			    gpointer data)
+				gpointer data)
 {
 	gchar buf[2];
 	gsize count;
@@ -571,6 +635,24 @@ static gboolean input_event(GIOChannel *source, GIOCondition condition,
 	return TRUE;
 }
 
+void enter_exec_path( char **argv )
+{
+	char *exec_path = NULL;
+	char *pos = NULL;
+	short len_path = 0;
+
+	len_path = strlen( argv[0] );
+	exec_path = (char*) malloc(len_path);
+
+	memcpy(exec_path, argv[0], len_path);
+	pos = strrchr(exec_path, '/');
+	if (pos != NULL)
+		*(pos+1) = '\0';
+
+	chdir(exec_path);
+	free(exec_path);
+}
+
 int main(int argc, char **argv)
 {
 	int c;
@@ -579,6 +661,8 @@ int main(int argc, char **argv)
 	GMainLoop *mainloop;
 	float force_clock;
 
+	enter_exec_path( argv );
+
 	opterr = 0;
 	while ((c = getopt(argc, argv, optstr)) != -1) {
 		switch (c) {
@@ -617,6 +701,9 @@ int main(int argc, char **argv)
 		case 't':
 			enable_tiling = 1;
 			break;
+		case 'r':
+			qr_code = 1;
+			break;
 		default:
 			fprintf(stderr, "unknown option %c\n", c);
 			/* fall through */
-- 
1.7.6.4

             reply	other threads:[~2012-07-26  6:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26  6:23 Yi Sun [this message]
2012-07-26 13:01 ` [PATCH] tests/testdisplay.c: Add a option '-r' Daniel Vetter
2012-07-26 13:33   ` 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=1343283816-5176-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.