From patchwork Fri Oct 23 00:26:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 7468811 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1070C9F30B for ; Fri, 23 Oct 2015 00:27:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 108A720813 for ; Fri, 23 Oct 2015 00:27:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 382592080E for ; Fri, 23 Oct 2015 00:27:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0133F6E37C; Thu, 22 Oct 2015 17:27:33 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id EBA046E37C; Thu, 22 Oct 2015 17:27:31 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP; 22 Oct 2015 17:27:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,185,1444719600"; d="scan'208";a="586332879" Received: from mdroper-hswdev.fm.intel.com (HELO mdroper-hswdev) ([10.1.134.215]) by FMSMGA003.fm.intel.com with ESMTP; 22 Oct 2015 17:26:45 -0700 Received: from mattrope by mdroper-hswdev with local (Exim 4.84) (envelope-from ) id 1ZpQBx-0004WK-G5; Thu, 22 Oct 2015 17:26:45 -0700 From: Matt Roper To: intel-gfx@lists.freedesktop.org Subject: [PATCH libdrm] xf86drmMode: Add RGBA property helpers Date: Thu, 22 Oct 2015 17:26:36 -0700 Message-Id: <1445559996-17342-1-git-send-email-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1445559935-17217-1-git-send-email-matthew.d.roper@intel.com> References: <1445559935-17217-1-git-send-email-matthew.d.roper@intel.com> Cc: dri-devel@lists.freedesktop.org, chandra.konduru@intel.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we've added an RGBA property type to the kernel that handles RGBA values with a specific bit layout, let's add a userspace helper to allow userspace to easily build values in the proper format. Cc: dri-devel@lists.freedesktop.org Signed-off-by: Matt Roper --- xf86drmMode.c | 36 ++++++++++++++++++++++++++++++++++++ xf86drmMode.h | 7 +++++++ 2 files changed, 43 insertions(+) diff --git a/xf86drmMode.c b/xf86drmMode.c index ab6b519..4bfd419 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -1445,3 +1445,39 @@ drmModeDestroyPropertyBlob(int fd, uint32_t id) destroy.blob_id = id; return DRM_IOCTL(fd, DRM_IOCTL_MODE_DESTROYPROPBLOB, &destroy); } + +/* + * Builds an RGBA 16bpc color value with bits laid out in the format expected + * by DRM RGBA properties. @bpc is the number of bits per component value + * being provided as parameters. + */ +uint64_t +drmModeRGBA(unsigned bpc, + uint16_t red, + uint16_t green, + uint16_t blue, + uint16_t alpha) +{ + int shift; + uint64_t val; + + if (bpc > 16) + return -ERANGE; + + /* + * If we were provided with fewer than 16 bpc, shift the value we + * received into the most significant bits. + */ + shift = 16 - bpc; + + val = red << shift; + val <<= 16; + val |= green << shift; + val <<= 16; + val |= blue << shift; + val <<= 16; + val |= alpha << shift; + + return val; +} + diff --git a/xf86drmMode.h b/xf86drmMode.h index 4de7bbb..4aa4917 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -507,6 +507,13 @@ extern int drmModeCreatePropertyBlob(int fd, const void *data, size_t size, uint32_t *id); extern int drmModeDestroyPropertyBlob(int fd, uint32_t id); +extern uint64_t drmModeRGBA(unsigned bpc, + uint16_t red, + uint16_t green, + uint16_t blue, + uint16_t alpha); +#define DRM_RGBA8888(r, g, b, a) drmModeRGBA(8, r, g, b, a) +#define DRM_RGBA16161616(r, g, b, a) drmModeRGBA(16, r, g, b, a) #if defined(__cplusplus) }