From: Matt Roper <matthew.d.roper@intel.com>
To: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org, chandra.konduru@intel.com
Subject: [PATCH libdrm] xf86drmMode: Add RGBA property helpers
Date: Thu, 22 Oct 2015 17:26:36 -0700 [thread overview]
Message-ID: <1445559996-17342-1-git-send-email-matthew.d.roper@intel.com> (raw)
In-Reply-To: <1445559935-17217-1-git-send-email-matthew.d.roper@intel.com>
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 <matthew.d.roper@intel.com>
---
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)
}
--
2.1.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-10-23 0:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-23 0:25 [PATCH 0/2] CRTC background color support for i915 Matt Roper
2015-10-23 0:25 ` [PATCH 1/2] drm: Add infrastructure for CRTC background color property Matt Roper
2015-10-23 1:26 ` kbuild test robot
2015-11-18 21:35 ` Bob Paauwe
2015-11-18 22:55 ` Matt Roper
2015-11-18 23:09 ` Emil Velikov
2015-10-23 0:25 ` [PATCH 2/2] drm/i915/skl: Add support for pipe background color Matt Roper
2015-10-23 0:39 ` [Intel-gfx] " kbuild test robot
2015-10-23 1:08 ` kbuild test robot
2015-11-18 21:43 ` Bob Paauwe
2015-10-23 0:26 ` Matt Roper [this message]
2015-10-23 0:27 ` [PATCH i-g-t 1/2] igt_kms: Set atomic capability bit Matt Roper
2015-10-23 0:27 ` [PATCH i-g-t 2/2] kms_crtc_background_color: Update to match kernel interface Matt Roper
2015-10-23 8:05 ` [PATCH i-g-t 1/2] igt_kms: Set atomic capability bit Daniel Vetter
2015-10-26 9:14 ` Daniel Stone
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=1445559996-17342-1-git-send-email-matthew.d.roper@intel.com \
--to=matthew.d.roper@intel.com \
--cc=chandra.konduru@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--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.