@@ -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;
+}
+
@@ -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)
}
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(+)