modetest: add C8 support to generate SMPTE pattern

This includes logic to configure the LUT accordingly.

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
main
Ilia Mirkin 2017-11-17 23:52:46 -05:00
parent 557d1a2e6f
commit bfc469f241
2 changed files with 44 additions and 5 deletions

View File

@ -135,6 +135,7 @@ bo_create(int fd, unsigned int format,
int ret; int ret;
switch (format) { switch (format) {
case DRM_FORMAT_C8:
case DRM_FORMAT_NV12: case DRM_FORMAT_NV12:
case DRM_FORMAT_NV21: case DRM_FORMAT_NV21:
case DRM_FORMAT_NV16: case DRM_FORMAT_NV16:
@ -275,6 +276,7 @@ bo_create(int fd, unsigned int format,
planes[2] = virtual + offsets[2]; planes[2] = virtual + offsets[2];
break; break;
case DRM_FORMAT_C8:
case DRM_FORMAT_ARGB4444: case DRM_FORMAT_ARGB4444:
case DRM_FORMAT_XRGB4444: case DRM_FORMAT_XRGB4444:
case DRM_FORMAT_ABGR4444: case DRM_FORMAT_ABGR4444:

View File

@ -1089,6 +1089,42 @@ static bool add_property_optional(struct device *dev, uint32_t obj_id,
return set_property(dev, &p); return set_property(dev, &p);
} }
static void set_gamma(struct device *dev, unsigned crtc_id, unsigned fourcc)
{
unsigned blob_id = 0;
/* TODO: support 1024-sized LUTs, when the use-case arises */
struct drm_color_lut gamma_lut[256];
int i, ret;
if (fourcc == DRM_FORMAT_C8) {
/* TODO: Add C8 support for more patterns */
util_smpte_c8_gamma(256, gamma_lut);
drmModeCreatePropertyBlob(dev->fd, gamma_lut, sizeof(gamma_lut), &blob_id);
} else {
for (i = 0; i < 256; i++) {
gamma_lut[i].red =
gamma_lut[i].green =
gamma_lut[i].blue = i << 8;
}
}
add_property_optional(dev, crtc_id, "DEGAMMA_LUT", 0);
add_property_optional(dev, crtc_id, "CTM", 0);
if (!add_property_optional(dev, crtc_id, "GAMMA_LUT", blob_id)) {
uint16_t r[256], g[256], b[256];
for (i = 0; i < 256; i++) {
r[i] = gamma_lut[i].red;
g[i] = gamma_lut[i].green;
b[i] = gamma_lut[i].blue;
}
ret = drmModeCrtcSetGamma(dev->fd, crtc_id, 256, r, g, b);
if (ret)
fprintf(stderr, "failed to set gamma: %s\n", strerror(errno));
}
}
static int atomic_set_plane(struct device *dev, struct plane_arg *p, static int atomic_set_plane(struct device *dev, struct plane_arg *p,
int pattern, bool update) int pattern, bool update)
{ {
@ -1270,6 +1306,8 @@ static void atomic_set_planes(struct device *dev, struct plane_arg *p,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (i > 0) if (i > 0)
pattern = UTIL_PATTERN_TILES; pattern = UTIL_PATTERN_TILES;
else
set_gamma(dev, p[i].crtc_id, p[i].fourcc);
if (atomic_set_plane(dev, &p[i], pattern, update)) if (atomic_set_plane(dev, &p[i], pattern, update))
return; return;
@ -1454,6 +1492,8 @@ static void set_mode(struct device *dev, struct pipe_arg *pipes, unsigned int co
fprintf(stderr, "failed to set mode: %s\n", strerror(errno)); fprintf(stderr, "failed to set mode: %s\n", strerror(errno));
return; return;
} }
set_gamma(dev, pipe->crtc->crtc->crtc_id, pipe->fourcc);
} }
} }
@ -1728,11 +1768,8 @@ static int parse_plane(struct plane_arg *plane, const char *p)
} }
if (*end == '@') { if (*end == '@') {
p = end + 1; strncpy(plane->format_str, end + 1, 4);
if (strlen(p) != 4) plane->format_str[4] = '\0';
return -EINVAL;
strcpy(plane->format_str, p);
} else { } else {
strcpy(plane->format_str, "XR24"); strcpy(plane->format_str, "XR24");
} }