[Intel-gfx] [PATCH libdrm] xf86drmMode: Add RGBA property helpers
Matt Roper
matthew.d.roper at intel.com
Thu Oct 22 17:26:36 PDT 2015
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 at lists.freedesktop.org
Signed-off-by: Matt Roper <matthew.d.roper at 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
More information about the Intel-gfx
mailing list