History

drm: Add CRTC background color property

Some display controllers can be hardware programmed to show non-black colors for pixels that are either not covered by any plane or are exposed through transparent regions of higher planes. This feature can help reduce memory bandwidth usage, e.g. in compositors managing a UI with a solid background color while using smaller planes to render the remaining content. To support this capability, introduce the BACKGROUND_COLOR standard DRM mode property, which can be attached to a CRTC through the drm_crtc_attach_background_color_property() helper function. Additionally, define a 64-bit ARGB format value to be built with the help of a couple of dedicated DRM_ARGB64_PREP*() helpers. Individual color components can be extracted with desired precision using the corresponding DRM_ARGB64_GET*() macros.

Cristian Ciocaltea committed 8 months ago

Commit 4c684591 parent de9e2b39 files · +147 −5Browse files

Showing the changes to include/uapi (1 of 9 files). Show all

Unified · Split

include/uapi/drm/drm_mode.h+80−0
@@ -27,6 +27,9 @@ · 26 unmodified lines
27#ifndef _DRM_MODE_H27#ifndef _DRM_MODE_H
28#define _DRM_MODE_H28#define _DRM_MODE_H
29 29
30#include <linux/bits.h>
31#include <linux/const.h>
32
30#include "drm.h"33#include "drm.h"
31 34
32#if defined(__cplusplus)35#if defined(__cplusplus)
@@ -1549,6 +1552,83 @@ struct drm_mode_closefb { · 1516 unmodified lines
1549 __u32 pad;1552 __u32 pad;
1550};1553};
1551 1554
1555/*
1556 * Put 16-bit ARGB values into a standard 64-bit representation that can be
1557 * used for ioctl parameters, inter-driver communication, etc.
1558 *
1559 * If the component values being provided contain less than 16 bits of
1560 * precision, use a conversion ratio to get a better color approximation.
1561 * The ratio is computed as (2^16 - 1) / (2^bpc - 1), where bpc and 16 are
1562 * the input and output precision, respectively.
1563 * Also note bpc must be greater than 0.
1564 */
1565#define __DRM_ARGB64_PREP(c, shift) \
1566 (((__u64)(c) & __GENMASK(15, 0)) << (shift))
1567
1568#define __DRM_ARGB64_PREP_BPC(c, shift, bpc) \
1569({ \
1570 __u16 mask = __GENMASK((bpc) - 1, 0); \
1571 __u16 conv = __KERNEL_DIV_ROUND_CLOSEST((mask & (c)) * \
1572 __GENMASK(15, 0), mask);\
1573 __DRM_ARGB64_PREP(conv, shift); \
1574})
1575
1576#define DRM_ARGB64_PREP(alpha, red, green, blue) \
1577( \
1578 __DRM_ARGB64_PREP(alpha, 48) | \
1579 __DRM_ARGB64_PREP(red, 32) | \
1580 __DRM_ARGB64_PREP(green, 16) | \
1581 __DRM_ARGB64_PREP(blue, 0) \
1582)
1583
1584#define DRM_ARGB64_PREP_BPC(alpha, red, green, blue, bpc) \
1585({ \
1586 __typeof__(bpc) __bpc = bpc; \
1587 __DRM_ARGB64_PREP_BPC(alpha, 48, __bpc) | \
1588 __DRM_ARGB64_PREP_BPC(red, 32, __bpc) | \
1589 __DRM_ARGB64_PREP_BPC(green, 16, __bpc) | \
1590 __DRM_ARGB64_PREP_BPC(blue, 0, __bpc); \
1591})
1592
1593/*
1594 * Extract the specified color component from a standard 64-bit ARGB value.
1595 *
1596 * If the requested precision is less than 16 bits, make use of a conversion
1597 * ratio calculated as (2^bpc - 1) / (2^16 - 1), where bpc and 16 are the
1598 * output and input precision, respectively.
1599 *
1600 * If speed is more important than accuracy, use DRM_ARGB64_GET*_BPCS()
1601 * instead of DRM_ARGB64_GET*_BPC() in order to replace the expensive
1602 * division with a simple bit right-shift operation.
1603 */
1604#define __DRM_ARGB64_GET(c, shift) \
1605 ((__u16)(((__u64)(c) >> (shift)) & __GENMASK(15, 0)))
1606
1607#define __DRM_ARGB64_GET_BPC(c, shift, bpc) \
1608({ \
1609 __u16 comp = __DRM_ARGB64_GET(c, shift); \
1610 __KERNEL_DIV_ROUND_CLOSEST(comp * __GENMASK((bpc) - 1, 0), \
1611 __GENMASK(15, 0)); \
1612})
1613
1614#define __DRM_ARGB64_GET_BPCS(c, shift, bpc) \
1615 (__DRM_ARGB64_GET(c, shift) >> (16 - (bpc)))
1616
1617#define DRM_ARGB64_GETA(c) __DRM_ARGB64_GET(c, 48)
1618#define DRM_ARGB64_GETR(c) __DRM_ARGB64_GET(c, 32)
1619#define DRM_ARGB64_GETG(c) __DRM_ARGB64_GET(c, 16)
1620#define DRM_ARGB64_GETB(c) __DRM_ARGB64_GET(c, 0)
1621
1622#define DRM_ARGB64_GETA_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 48, bpc)
1623#define DRM_ARGB64_GETR_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 32, bpc)
1624#define DRM_ARGB64_GETG_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 16, bpc)
1625#define DRM_ARGB64_GETB_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 0, bpc)
1626
1627#define DRM_ARGB64_GETA_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 48, bpc)
1628#define DRM_ARGB64_GETR_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 32, bpc)
1629#define DRM_ARGB64_GETG_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 16, bpc)
1630#define DRM_ARGB64_GETB_BPCS(c, bpc) __DRM_ARGB64_GET_BPCS(c, 0, bpc)
1631
1552#if defined(__cplusplus)1632#if defined(__cplusplus)
1553}1633}
1554#endif1634#endif