Skip to content

Commit f8e51a3

Browse files
cristiccchewitt
authored andcommitted
FROMLIST(v3): 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. Co-developed-by: Matt Roper <matthew.d.roper@intel.com> Signed-off-by: Matt Roper <matthew.d.roper@intel.com> Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
1 parent 75bc581 commit f8e51a3

File tree

8 files changed

+133
-5
lines changed

8 files changed

+133
-5
lines changed

drivers/gpu/drm/drm_atomic_state_helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ __drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,
7575
struct drm_crtc *crtc)
7676
{
7777
crtc_state->crtc = crtc;
78+
crtc_state->background_color = DRM_ARGB64_PREP(0xffff, 0, 0, 0);
7879
}
7980
EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);
8081

drivers/gpu/drm/drm_atomic_uapi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
407407
&replaced);
408408
state->color_mgmt_changed |= replaced;
409409
return ret;
410+
} else if (property == config->background_color_property) {
411+
state->background_color = val;
410412
} else if (property == config->prop_out_fence_ptr) {
411413
s32 __user *fence_ptr = u64_to_user_ptr(val);
412414

@@ -452,6 +454,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
452454
*val = (state->ctm) ? state->ctm->base.id : 0;
453455
else if (property == config->gamma_lut_property)
454456
*val = (state->gamma_lut) ? state->gamma_lut->base.id : 0;
457+
else if (property == config->background_color_property)
458+
*val = state->background_color;
455459
else if (property == config->prop_out_fence_ptr)
456460
*val = 0;
457461
else if (property == crtc->scaling_filter_property)

drivers/gpu/drm/drm_blend.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,6 @@
191191
* plane does not expose the "alpha" property, then this is
192192
* assumed to be 1.0
193193
*
194-
* Note that all the property extensions described here apply either to the
195-
* plane or the CRTC (e.g. for the background color, which currently is not
196-
* exposed and assumed to be black).
197-
*
198194
* SCALING_FILTER:
199195
* Indicates scaling filter to be used for plane scaler
200196
*
@@ -207,6 +203,25 @@
207203
*
208204
* Drivers can set up this property for a plane by calling
209205
* drm_plane_create_scaling_filter_property
206+
*
207+
* The property extensions described above all apply to the plane. Drivers
208+
* may also expose the following crtc property extension:
209+
*
210+
* BACKGROUND_COLOR:
211+
* Background color is set up with drm_crtc_attach_background_color_property(),
212+
* and expects a 64-bit ARGB value following DRM_FORMAT_ARGB16161616, as
213+
* generated by the DRM_ARGB64_PREP*() helpers. It controls the color of a
214+
* full-screen layer that exists below all planes. This color will be used
215+
* for pixels not covered by any plane and may also be blended with plane
216+
* contents as allowed by a plane's alpha values.
217+
* The background color defaults to black, and is assumed to be black for
218+
* drivers that do not expose this property. Although background color
219+
* isn't a plane, it is assumed that the color provided here undergoes the
220+
* CRTC degamma/CSC/gamma transformations applied after the planes blending.
221+
* Note that the color value includes an alpha channel, hence non-opaque
222+
* background color values are allowed, but since physically transparent
223+
* monitors do not (yet) exists, the final alpha value may not reach the
224+
* video sink or it may simply ignore it.
210225
*/
211226

212227
/**
@@ -621,3 +636,19 @@ int drm_plane_create_blend_mode_property(struct drm_plane *plane,
621636
return 0;
622637
}
623638
EXPORT_SYMBOL(drm_plane_create_blend_mode_property);
639+
640+
/**
641+
* drm_crtc_attach_background_color_property - attach background color property
642+
* @crtc: drm crtc
643+
*
644+
* Attaches the background color property to @crtc. The property defaults to
645+
* solid black and will accept 64-bit ARGB values in the format generated by
646+
* DRM_ARGB64_PREP*() helpers.
647+
*/
648+
void drm_crtc_attach_background_color_property(struct drm_crtc *crtc)
649+
{
650+
drm_object_attach_property(&crtc->base,
651+
crtc->dev->mode_config.background_color_property,
652+
DRM_ARGB64_PREP(0xffff, 0, 0, 0));
653+
}
654+
EXPORT_SYMBOL(drm_crtc_attach_background_color_property);

drivers/gpu/drm/drm_mode_config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
375375
return -ENOMEM;
376376
dev->mode_config.gamma_lut_size_property = prop;
377377

378+
prop = drm_property_create_range(dev, 0,
379+
"BACKGROUND_COLOR", 0, U64_MAX);
380+
if (!prop)
381+
return -ENOMEM;
382+
dev->mode_config.background_color_property = prop;
383+
378384
prop = drm_property_create(dev,
379385
DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB,
380386
"IN_FORMATS", 0);

include/drm/drm_blend.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
#define DRM_MODE_BLEND_COVERAGE 1
3232
#define DRM_MODE_BLEND_PIXEL_NONE 2
3333

34-
struct drm_device;
3534
struct drm_atomic_state;
35+
struct drm_crtc;
36+
struct drm_device;
3637
struct drm_plane;
3738

3839
static inline bool drm_rotation_90_or_270(unsigned int rotation)
@@ -58,4 +59,5 @@ int drm_atomic_normalize_zpos(struct drm_device *dev,
5859
struct drm_atomic_state *state);
5960
int drm_plane_create_blend_mode_property(struct drm_plane *plane,
6061
unsigned int supported_modes);
62+
void drm_crtc_attach_background_color_property(struct drm_crtc *crtc);
6163
#endif

include/drm/drm_crtc.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,18 @@ struct drm_crtc_state {
274274
*/
275275
struct drm_property_blob *gamma_lut;
276276

277+
/**
278+
* @background_color:
279+
*
280+
* RGB value representing the pipe's background color. The background
281+
* color (aka "canvas color") of a pipe is the color that will be used
282+
* for pixels not covered by a plane, or covered by transparent pixels
283+
* of a plane. The value here should be built using DRM_ARGB64_PREP*()
284+
* helpers, while the individual color components can be extracted with
285+
* desired precision via the DRM_ARGB64_GET*() macros.
286+
*/
287+
u64 background_color;
288+
277289
/**
278290
* @target_vblank:
279291
*

include/drm/drm_mode_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,11 @@ struct drm_mode_config {
814814
* gamma LUT as supported by the driver (read-only).
815815
*/
816816
struct drm_property *gamma_lut_size_property;
817+
/**
818+
* @background_color_property: Optional CRTC property to set the
819+
* background color.
820+
*/
821+
struct drm_property *background_color_property;
817822

818823
/**
819824
* @suggested_x_property: Optional connector property with a hint for

include/uapi/drm/drm_mode.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#ifndef _DRM_MODE_H
2828
#define _DRM_MODE_H
2929

30+
#include <linux/const.h>
31+
3032
#include "drm.h"
3133

3234
#if defined(__cplusplus)
@@ -1363,6 +1365,71 @@ struct drm_mode_closefb {
13631365
__u32 pad;
13641366
};
13651367

1368+
/*
1369+
* Put 16-bit ARGB values into a standard 64-bit representation that can be
1370+
* used for ioctl parameters, inter-driver communication, etc.
1371+
*
1372+
* If the component values being provided contain less than 16 bits of
1373+
* precision, use a conversion ratio to get a better color approximation.
1374+
* The ratio is computed as (2^16 - 1) / (2^bpc - 1), where bpc and 16 are
1375+
* the input and output precision, respectively.
1376+
*/
1377+
#define __DRM_ARGB64_PREP(c, shift) \
1378+
(((__u64)(c) & 0xffffU) << (shift))
1379+
1380+
#define __DRM_ARGB64_PREP_BPC(c, shift, bpc)( \
1381+
{ \
1382+
__u16 mask = (1U << (bpc)) - 1; \
1383+
__u16 conv = __KERNEL_DIV_ROUND_CLOSEST((mask & (c)) * \
1384+
0xffffU, mask); \
1385+
__DRM_ARGB64_PREP(conv, shift); \
1386+
} \
1387+
)
1388+
1389+
#define DRM_ARGB64_PREP_BPC(alpha, red, green, blue, bpc)( \
1390+
{ \
1391+
__typeof__(bpc) __bpc = bpc; \
1392+
__DRM_ARGB64_PREP_BPC(alpha, 48, __bpc) | \
1393+
__DRM_ARGB64_PREP_BPC(red, 32, __bpc) | \
1394+
__DRM_ARGB64_PREP_BPC(green, 16, __bpc) | \
1395+
__DRM_ARGB64_PREP_BPC(blue, 0, __bpc); \
1396+
} \
1397+
)
1398+
1399+
#define DRM_ARGB64_PREP(alpha, red, green, blue) \
1400+
(__DRM_ARGB64_PREP(alpha, 48) | \
1401+
__DRM_ARGB64_PREP(red, 32) | \
1402+
__DRM_ARGB64_PREP(green, 16) | \
1403+
__DRM_ARGB64_PREP(blue, 0))
1404+
1405+
/*
1406+
* Extract the specified color component from a standard 64-bit ARGB value.
1407+
*
1408+
* If the requested precision is less than 16 bits, make use of a conversion
1409+
* ratio calculated as (2^bpc - 1) / (2^16 - 1), where bpc and 16 are the
1410+
* output and input precision, respectively.
1411+
*/
1412+
#define __DRM_ARGB64_GET(c, shift) \
1413+
((__u16)(((__u64)(c) >> (shift)) & 0xffffU))
1414+
1415+
#define __DRM_ARGB64_GET_BPC(c, shift, bpc)( \
1416+
{ \
1417+
__u16 comp = __DRM_ARGB64_GET(c, shift); \
1418+
__KERNEL_DIV_ROUND_CLOSEST(comp * ((1U << (bpc)) - 1), \
1419+
0xffffU); \
1420+
} \
1421+
)
1422+
1423+
#define DRM_ARGB64_GETA_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 48, bpc)
1424+
#define DRM_ARGB64_GETR_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 32, bpc)
1425+
#define DRM_ARGB64_GETG_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 16, bpc)
1426+
#define DRM_ARGB64_GETB_BPC(c, bpc) __DRM_ARGB64_GET_BPC(c, 0, bpc)
1427+
1428+
#define DRM_ARGB64_GETA(c) __DRM_ARGB64_GET(c, 48)
1429+
#define DRM_ARGB64_GETR(c) __DRM_ARGB64_GET(c, 32)
1430+
#define DRM_ARGB64_GETG(c) __DRM_ARGB64_GET(c, 16)
1431+
#define DRM_ARGB64_GETB(c) __DRM_ARGB64_GET(c, 0)
1432+
13661433
#if defined(__cplusplus)
13671434
}
13681435
#endif

0 commit comments

Comments
 (0)