@@ -62,6 +62,7 @@
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
+#include <math.h>
#include "xf86drm.h"
#include "xf86drmMode.h"
@@ -75,7 +76,7 @@ struct udev_monitor *uevent_monitor;
drmModeRes *resources;
int fd, modes;
int dump_info = 0, test_all_modes =0, test_preferred_mode = 0, force_mode = 0,
- test_plane, enable_tiling;
+ test_plane, enable_tiling, test_gamma=0;
int sleep_between_modes = 5;
uint32_t depth = 24;
@@ -88,6 +89,13 @@ int force_vdisplay;
int force_vsync_start;
int force_vsync_end;
int force_vtotal;
+uint16_t red[256], green[256], blue[256];
+float gamma_red, gamma_green, gamma_blue;
+
+static inline double dmin (double x, double y)
+{
+ return x < y ? x : y;
+}
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
@@ -237,7 +245,6 @@ static void dump_crtcs(void)
crtc->x, crtc->y,
crtc->width, crtc->height);
dump_mode(&crtc->mode);
-
drmModeFreeCrtc(crtc);
}
printf("\n");
@@ -784,7 +791,6 @@ set_mode(struct connector *c)
char buf[128];
int j, test_mode_num;
uint32_t bpp = 32;
-
if (depth <= 8)
bpp = 8;
else if (depth > 8 && depth <= 16)
@@ -881,7 +887,33 @@ set_mode(struct connector *c)
strerror(errno));
continue;
}
-
+ if (test_gamma) {
+ int size = 256;
+ float brightness = 1.0;
+ for (int i = 0; i < size; i++) {
+ if (gamma_red == 1.0 && brightness == 1.0)
+ red[i] = (i << 8) + i;
+ else
+ red[i] = dmin(pow((double)i/(double)(size - 1),
+ gamma_red) * brightness,
+ 1.0) * 65535.0;
+
+ if (gamma_green == 1.0 && brightness == 1.0)
+ green[i] = (i << 8) + i;
+ else
+ green[i] = dmin(pow((double)i/(double)(size - 1),
+ gamma_green) * brightness,
+ 1.0) * 65535.0;
+
+ if (gamma_blue == 1.0 && brightness == 1.0)
+ blue[i] = (i << 8) + i;
+ else
+ blue[i] = dmin(pow((double)i/(double)(size - 1),
+ gamma_blue) * brightness,
+ 1.0) * 65535.0;
+ }
+ drmModeCrtcSetGamma(fd, c->crtc, 256, red, green, blue);
+ }
if (test_plane)
enable_plane(c);
@@ -939,11 +971,11 @@ static void update_display(void)
extern char *optarg;
extern int optind, opterr, optopt;
-static char optstr[] = "hiaf:s:d:pt";
+static char optstr[] = "hiaf:s:d:ptg:s";
static void usage(char *name)
{
- fprintf(stderr, "usage: %s [-hiafs]\n", name);
+ fprintf(stderr, "usage: %s [-hiafsgpt]\n", name);
fprintf(stderr, "\t-i\tdump info\n");
fprintf(stderr, "\t-a\ttest all modes\n");
fprintf(stderr, "\t-s\t<duration>\tsleep between each mode test\n");
@@ -953,6 +985,7 @@ static void usage(char *name)
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");
+ fprintf(stderr, "\t-g\t<red>,<green>,<blue> test gamma\n");
fprintf(stderr, "\tDefault is to test the preferred mode.\n");
exit(0);
}
@@ -1039,6 +1072,11 @@ int main(int argc, char **argv)
case 't':
enable_tiling = 1;
break;
+ case 'g':
+ test_gamma = 1;
+ if(sscanf(optarg,"%f,%f,%f",&gamma_red,&gamma_green,&gamma_blue)!= 3)
+ usage(argv[0]);
+ break;
default:
fprintf(stderr, "unknown option %c\n", c);
/* fall through */
Signed-off-by: Hai Lan <hai.lan@intel.com> --- tests/testdisplay.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 44 insertions(+), 6 deletions(-)