From patchwork Mon Jun 3 00:40:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia Mirkin X-Patchwork-Id: 10972061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34F3F14C0 for ; Mon, 3 Jun 2019 00:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2521C28800 for ; Mon, 3 Jun 2019 00:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 195C52883A; Mon, 3 Jun 2019 00:40:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9755A28800 for ; Mon, 3 Jun 2019 00:40:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9AA1E89146; Mon, 3 Jun 2019 00:40:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by gabe.freedesktop.org (Postfix) with ESMTPS id B1AFF897D4 for ; Mon, 3 Jun 2019 00:40:29 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id z24so375398qtj.10 for ; Sun, 02 Jun 2019 17:40:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Jl08X09J5WaG5rButew5EplcjqlT6CYTrRnJ2xlwRL0=; b=Kjo7QlGxL2BGB03P8SNOgWBxwIxnhRlEGwhARBIAhbalBfP6JEnG7Yyq8ywyowm1To zEaH7T00tgoeP2xVHv1/S7V08STGcw17MD2xv/K9HwW+FUgAOlNeVNStY9AzaWuyjL95 EEdGloGnRMF2NSrq0IooD4H/fbRL4rUVFCYZZeh164R19CO3iJJZah+JjyWixZLZpYVA MotBjdz1WLjHT6kyfPd64kJkM+sYpzIW4SkrwLJK+pd7Sjsg1pzvq36ft5Ar2W97iMFk Asm5cgk/Z3zDPYgFad9/GNx4u2YH2bk7y7ZsJvOip/ufL5qhhwy8f3Xau2Ng31+aVGqq mcaA== X-Gm-Message-State: APjAAAUYCUjd5kKH/av6APYBOPpUqOBrhiGLO/5Joh2qaMON3E6HZWDz ZRE8u6dKRFjipFN2jOjUbj7C2dbnPsQ= X-Google-Smtp-Source: APXvYqyZCCKILabXXc3/sZpwxd0fCIKDf05qvdNZx25q9O0yecRA+lfmcnf64Rl9V9XrnPHyeFvnxg== X-Received: by 2002:a0c:f68e:: with SMTP id p14mr7754142qvn.172.1559522428698; Sun, 02 Jun 2019 17:40:28 -0700 (PDT) Received: from athos.fios-router.home (pool-173-68-20-215.nycmny.fios.verizon.net. [173.68.20.215]) by smtp.gmail.com with ESMTPSA id t8sm1432609qtc.80.2019.06.02.17.40.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Jun 2019 17:40:27 -0700 (PDT) From: Ilia Mirkin To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm 03/10] util: add gradient pattern Date: Sun, 2 Jun 2019 20:40:11 -0400 Message-Id: <20190603004017.7114-4-imirkin@alum.mit.edu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190603004017.7114-1-imirkin@alum.mit.edu> References: <20190603004017.7114-1-imirkin@alum.mit.edu> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jl08X09J5WaG5rButew5EplcjqlT6CYTrRnJ2xlwRL0=; b=oL4f8Nu5iZ3AadDSgsbeE94jg0yuaLfAqilnGk4KyNE70BQdCrRiJEPsjw3AVVcBRY acAI9+NH/9KQaeMWbWmULxEWhuKP+WQg0HxP8KAERajAR8qXDz6toic4TqG/75eETmw2 /aFPO84I2rYslA2DJvdec+uax0pmU3wMyXQYqzovtWvZ5sAJxMdJX8USHKVSbvG7I+Nl oOe/6McRNv36OGqyezRL+1OLZsNxmMyNnouUkN76LDg0mg6gV0DxU0SBc9neMLJJRnht XVzqoTatJnUE8PJY9CHlRK22wGLaSnYaFAVjx0m7FfeGsGuB+qGv3PrE/xzQzatgOUMs xV+g== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The idea is to have a horizontal pattern split into two with the top and bottom halves having different precision. This allows one to see whether 10bpc support is working properly or not, as there are many pieces to the puzzle beyond the basic format support (gamma ramps, bpc encodings, etc). This is really only useful on 10bpc formats, but we also add support for 8bpc formats to ease testing. In the future, this could be applied to 16bpc formats as well. Signed-off-by: Ilia Mirkin --- tests/util/pattern.c | 113 +++++++++++++++++++++++++++++++++++++++++-- tests/util/pattern.h | 1 + 2 files changed, 109 insertions(+), 5 deletions(-) diff --git a/tests/util/pattern.c b/tests/util/pattern.c index 8bdebd2c..ff110fd7 100644 --- a/tests/util/pattern.c +++ b/tests/util/pattern.c @@ -60,9 +60,11 @@ struct color_yuv { .u = MAKE_YUV_601_U(r, g, b), \ .v = MAKE_YUV_601_V(r, g, b) } -static inline uint32_t shiftcolor(const struct util_color_component *comp, +/* This function takes 8-bit color values */ +static inline uint32_t shiftcolor8(const struct util_color_component *comp, uint32_t value) { + value &= 0xff; /* Fill the low bits with the high bits. */ value = (value << 8) | value; /* Shift down to remove unwanted low bits */ @@ -71,11 +73,30 @@ static inline uint32_t shiftcolor(const struct util_color_component *comp, return value << comp->offset; } +/* This function takes 10-bit color values */ +static inline uint32_t shiftcolor10(const struct util_color_component *comp, + uint32_t value) +{ + value &= 0x3ff; + /* Fill the low bits with the high bits. */ + value = (value << 6) | (value >> 4); + /* Shift down to remove unwanted low bits */ + value = value >> (16 - comp->length); + /* Shift back up to where the value should be */ + return value << comp->offset; +} + +#define MAKE_RGBA10(rgb, r, g, b, a) \ + (shiftcolor10(&(rgb)->red, (r)) | \ + shiftcolor10(&(rgb)->green, (g)) | \ + shiftcolor10(&(rgb)->blue, (b)) | \ + shiftcolor10(&(rgb)->alpha, (a))) + #define MAKE_RGBA(rgb, r, g, b, a) \ - (shiftcolor(&(rgb)->red, (r)) | \ - shiftcolor(&(rgb)->green, (g)) | \ - shiftcolor(&(rgb)->blue, (b)) | \ - shiftcolor(&(rgb)->alpha, (a))) + (shiftcolor8(&(rgb)->red, (r)) | \ + shiftcolor8(&(rgb)->green, (g)) | \ + shiftcolor8(&(rgb)->blue, (b)) | \ + shiftcolor8(&(rgb)->alpha, (a))) #define MAKE_RGB24(rgb, r, g, b) \ { .value = MAKE_RGBA(rgb, r, g, b, 0) } @@ -912,6 +933,85 @@ static void fill_plain(void *planes[3], memset(planes[0], 0x77, stride * height); } +static void fill_gradient_rgb32(const struct util_rgb_info *rgb, + void *mem, + unsigned int width, unsigned int height, + unsigned int stride) +{ + int i, j; + + for (i = 0; i < height / 2; i++) { + uint32_t *row = mem; + + for (j = 0; j < width / 2; j++) { + uint32_t value = MAKE_RGBA10(rgb, j & 0x3ff, j & 0x3ff, j & 0x3ff, 0); + row[2*j] = row[2*j+1] = value; + } + mem += stride; + } + + for (; i < height; i++) { + uint32_t *row = mem; + + for (j = 0; j < width / 2; j++) { + uint32_t value = MAKE_RGBA10(rgb, j & 0x3fc, j & 0x3fc, j & 0x3fc, 0); + row[2*j] = row[2*j+1] = value; + } + mem += stride; + } +} + +/* The gradient pattern creates two horizontal gray gradients, split + * into two halves. The top half has 10bpc precision, the bottom half + * has 8bpc precision. When using with a 10bpc fb format, there are 3 + * possible outcomes: + * + * - Pixel data is encoded as 8bpc to the display, no dithering. This + * would lead to the top and bottom halves looking identical. + * + * - Pixel data is encoded as 8bpc to the display, with dithering. This + * would lead to there being a visible difference between the two halves, + * but the top half would look a little speck-y due to the dithering. + * + * - Pixel data is encoded at 10bpc+ to the display (which implies + * the display is able to show this level of depth). This should + * lead to the top half being a very clean gradient, and visibly different + * from the bottom half. + * + * Once we support additional fb formats, this approach could be extended + * to distinguish even higher bpc precisions. + * + * Note that due to practical size considerations, for the screens + * where this matters, the pattern actually emits stripes 2-pixels + * wide for each gradient color. Otherwise the difference may be a bit + * hard to notice. + */ +static void fill_gradient(const struct util_format_info *info, void *planes[3], + unsigned int width, unsigned int height, + unsigned int stride) +{ + switch (info->format) { + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ABGR8888: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_RGBA8888: + case DRM_FORMAT_RGBX8888: + case DRM_FORMAT_BGRA8888: + case DRM_FORMAT_BGRX8888: + case DRM_FORMAT_ARGB2101010: + case DRM_FORMAT_XRGB2101010: + case DRM_FORMAT_ABGR2101010: + case DRM_FORMAT_XBGR2101010: + case DRM_FORMAT_RGBA1010102: + case DRM_FORMAT_RGBX1010102: + case DRM_FORMAT_BGRA1010102: + case DRM_FORMAT_BGRX1010102: + return fill_gradient_rgb32(&info->rgb, planes[0], + width, height, stride); + } +} + /* * util_fill_pattern - Fill a buffer with a test pattern * @format: Pixel format @@ -944,6 +1044,9 @@ void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern, case UTIL_PATTERN_PLAIN: return fill_plain(planes, height, stride); + case UTIL_PATTERN_GRADIENT: + return fill_gradient(info, planes, width, height, stride); + default: printf("Error: unsupported test pattern %u.\n", pattern); break; diff --git a/tests/util/pattern.h b/tests/util/pattern.h index c8708d02..feac903a 100644 --- a/tests/util/pattern.h +++ b/tests/util/pattern.h @@ -32,6 +32,7 @@ enum util_fill_pattern { UTIL_PATTERN_TILES, UTIL_PATTERN_PLAIN, UTIL_PATTERN_SMPTE, + UTIL_PATTERN_GRADIENT, }; void util_fill_pattern(uint32_t format, enum util_fill_pattern pattern,