Commit 4c684596 authored by Cristian Ciocaltea's avatar Cristian Ciocaltea Committed by Daniel Stone
Browse files

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: default avatarMatt Roper <matthew.d.roper@intel.com>
Signed-off-by: default avatarMatt Roper <matthew.d.roper@intel.com>
Reviewed-by: default avatarNícolas F. R. A. Prado <nfraprado@collabora.com>
Tested-by: default avatarDiederik de Haas <diederik@cknow-tech.com>
Signed-off-by: default avatarCristian Ciocaltea <cristian.ciocaltea@collabora.com>
Link: https://patch.msgid.link/20260303-rk3588-bgcolor-v8-2-fee377037ad1@collabora.com


Signed-off-by: default avatarDaniel Stone <daniels@collabora.com>
parent de9e2b3d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -475,6 +475,7 @@ static void drm_atomic_crtc_print_state(struct drm_printer *p,
	drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
	drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
	drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
	drm_printf(p, "\tbackground_color=%llx\n", state->background_color);

	if (crtc->funcs->atomic_print_state)
		crtc->funcs->atomic_print_state(p, state);
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ __drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state,
				     struct drm_crtc *crtc)
{
	crtc_state->crtc = crtc;
	crtc_state->background_color = DRM_ARGB64_PREP(0xffff, 0, 0, 0);
}
EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset);

+4 −0
Original line number Diff line number Diff line
@@ -454,6 +454,8 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
					&replaced);
		state->color_mgmt_changed |= replaced;
		return ret;
	} else if (property == config->background_color_property) {
		state->background_color = val;
	} else if (property == config->prop_out_fence_ptr) {
		s32 __user *fence_ptr = u64_to_user_ptr(val);

@@ -501,6 +503,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
		*val = (state->ctm) ? state->ctm->base.id : 0;
	else if (property == config->gamma_lut_property)
		*val = (state->gamma_lut) ? state->gamma_lut->base.id : 0;
	else if (property == config->background_color_property)
		*val = state->background_color;
	else if (property == config->prop_out_fence_ptr)
		*val = 0;
	else if (property == crtc->scaling_filter_property)
+35 −4
Original line number Diff line number Diff line
@@ -191,10 +191,6 @@
 *		 plane does not expose the "alpha" property, then this is
 *		 assumed to be 1.0
 *
 * Note that all the property extensions described here apply either to the
 * plane or the CRTC (e.g. for the background color, which currently is not
 * exposed and assumed to be black).
 *
 * SCALING_FILTER:
 *     Indicates scaling filter to be used for plane scaler
 *
@@ -207,6 +203,25 @@
 *
 * Drivers can set up this property for a plane by calling
 * drm_plane_create_scaling_filter_property
 *
 * The property extensions described above all apply to the plane.  Drivers
 * may also expose the following crtc property extension:
 *
 * BACKGROUND_COLOR:
 *	Background color is set up with drm_crtc_attach_background_color_property(),
 *	and expects a 64-bit ARGB value following DRM_FORMAT_ARGB16161616, as
 *	generated by the DRM_ARGB64_PREP*() helpers. It controls the color of a
 *	full-screen layer that exists below all planes. This color will be used
 *	for pixels not covered by any plane and may also be blended with plane
 *	contents as allowed by a plane's alpha values.
 *	The background color defaults to black, and is assumed to be black for
 *	drivers that do not expose this property. Although background color
 *	isn't a plane, it is assumed that the color provided here undergoes the
 *	CRTC degamma/CSC/gamma transformations applied after the planes blending.
 *	Note that the color value includes an alpha channel, hence non-opaque
 *	background color values are allowed, but since physically transparent
 *	monitors do not (yet) exists, the final alpha value may not reach the
 *	video sink or it may simply ignore it.
 */

/**
@@ -621,3 +636,19 @@ int drm_plane_create_blend_mode_property(struct drm_plane *plane,
	return 0;
}
EXPORT_SYMBOL(drm_plane_create_blend_mode_property);

/**
 * drm_crtc_attach_background_color_property - attach background color property
 * @crtc: drm crtc
 *
 * Attaches the background color property to @crtc.  The property defaults to
 * solid black and will accept 64-bit ARGB values in the format generated by
 * DRM_ARGB64_PREP*() helpers.
 */
void drm_crtc_attach_background_color_property(struct drm_crtc *crtc)
{
	drm_object_attach_property(&crtc->base,
				   crtc->dev->mode_config.background_color_property,
				   DRM_ARGB64_PREP(0xffff, 0, 0, 0));
}
EXPORT_SYMBOL(drm_crtc_attach_background_color_property);
+6 −0
Original line number Diff line number Diff line
@@ -380,6 +380,12 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
		return -ENOMEM;
	dev->mode_config.gamma_lut_size_property = prop;

	prop = drm_property_create_range(dev, 0,
					 "BACKGROUND_COLOR", 0, U64_MAX);
	if (!prop)
		return -ENOMEM;
	dev->mode_config.background_color_property = prop;

	prop = drm_property_create(dev,
				   DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB,
				   "IN_FORMATS", 0);
Loading