Skip to contentSkip to conversation

drm/plane-helper: Add a drm_plane_helper_atomic_check() helper

PATCH Superseded Javier Martinez Canillas 3 participants 5 messages Sep 13, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Javier Martinez Canillas

author maintainer
#0 lore raw

PATCH v2 1/1 drm/plane-helper: Add a drm_plane_helper_atomic_check() helper

Provides a default plane state check handler for primary planes that are a fullscreen scanout buffer and whose state scale and position can't change.

There are some drivers that duplicate this logic in their helpers, such as simpledrm and ssd130x. Factor out this common code into a plane helper and make drivers use it.

---

Changes in v2:
- Fix new_state field comment (Ville Syrjälä).
- Rename new_state to just state (Ville Syrjälä).

 drivers/gpu/drm/drm_plane_helper.c | 28 ++++++++++++++++++++++++++++
 drivers/gpu/drm/solomon/ssd130x.c  | 18 +-----------------
 drivers/gpu/drm/tiny/simpledrm.c   | 25 +------------------------
 include/drm/drm_plane_helper.h     |  1 +
 4 files changed, 31 insertions(+), 41 deletions(-)
drivers/gpu/drm/drm_plane_helper.c +28 -0
index c7785967f5bf..2165390863f4 100644
@@ -278,3 +278,31 @@ void drm_plane_helper_destroy(struct drm_plane *plane)
 	kfree(plane);
 }
 EXPORT_SYMBOL(drm_plane_helper_destroy);
+
+/**
+ * drm_plane_helper_atomic_check() - Helper to check primary planes states
+ * @plane: plane to check
+ * @state: atomic state object
+ *
+ * Provides a default plane state check handler for primary planes whose atomic
+ * state scale and position is not expected to change because the primary plane
+ * is always a fullscreen scanout buffer.
+ *
+ * RETURNS:
+ * Zero on success, or an errno code otherwise.
+ */
+int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+	struct drm_crtc *new_crtc = new_plane_state->crtc;
+	struct drm_crtc_state *new_crtc_state = NULL;
+
+	if (new_crtc)
+		new_crtc_state = drm_atomic_get_new_crtc_state(state, new_crtc);
+
+	return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
+						   DRM_PLANE_NO_SCALING,
+						   DRM_PLANE_NO_SCALING,
+						   false, false);
+}
+EXPORT_SYMBOL(drm_plane_helper_atomic_check);
drivers/gpu/drm/solomon/ssd130x.c +1 -17
index 79e8e2017c68..28cf9c87f86d 100644
@@ -565,22 +565,6 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m
 	return ret;
 }
 
-static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane,
-						     struct drm_atomic_state *new_state)
-{
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane);
-	struct drm_crtc *new_crtc = new_plane_state->crtc;
-	struct drm_crtc_state *new_crtc_state = NULL;
-
-	if (new_crtc)
-		new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc);
-
-	return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
-						   DRM_PLANE_NO_SCALING,
-						   DRM_PLANE_NO_SCALING,
-						   false, false);
-}
-
 static void ssd130x_primary_plane_helper_atomic_update(struct drm_plane *plane,
 						       struct drm_atomic_state *old_state)
 {
@@ -623,7 +607,7 @@ static void ssd130x_primary_plane_helper_atomic_disable(struct drm_plane *plane,
 
 static const struct drm_plane_helper_funcs ssd130x_primary_plane_helper_funcs = {
 	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
-	.atomic_check = ssd130x_primary_plane_helper_atomic_check,
+	.atomic_check = drm_plane_helper_atomic_check,
 	.atomic_update = ssd130x_primary_plane_helper_atomic_update,
 	.atomic_disable = ssd130x_primary_plane_helper_atomic_disable,
 };
drivers/gpu/drm/tiny/simpledrm.c +1 -24
index 777ccd250871..ea5b3239a659 100644
@@ -469,29 +469,6 @@ static const uint64_t simpledrm_primary_plane_format_modifiers[] = {
 	DRM_FORMAT_MOD_INVALID
 };
 
-static int simpledrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
-						       struct drm_atomic_state *new_state)
-{
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane);
-	struct drm_crtc *new_crtc = new_plane_state->crtc;
-	struct drm_crtc_state *new_crtc_state = NULL;
-	int ret;
-
-	if (new_crtc)
-		new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc);
-
-	ret = drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
-						  DRM_PLANE_NO_SCALING,
-						  DRM_PLANE_NO_SCALING,
-						  false, false);
-	if (ret)
-		return ret;
-	else if (!new_plane_state->visible)
-		return 0;
-
-	return 0;
-}
-
 static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane,
 							 struct drm_atomic_state *old_state)
 {
@@ -543,7 +520,7 @@ static void simpledrm_primary_plane_helper_atomic_disable(struct drm_plane *plan
 
 static const struct drm_plane_helper_funcs simpledrm_primary_plane_helper_funcs = {
 	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
-	.atomic_check = simpledrm_primary_plane_helper_atomic_check,
+	.atomic_check = drm_plane_helper_atomic_check,
 	.atomic_update = simpledrm_primary_plane_helper_atomic_update,
 	.atomic_disable = simpledrm_primary_plane_helper_atomic_disable,
 };
include/drm/drm_plane_helper.h +1 -0
index 1781fab24dd6..7760b27b0323 100644
@@ -41,5 +41,6 @@ int drm_plane_helper_update_primary(struct drm_plane *plane, struct drm_crtc *cr
 int drm_plane_helper_disable_primary(struct drm_plane *plane,
 				     struct drm_modeset_acquire_ctx *ctx);
 void drm_plane_helper_destroy(struct drm_plane *plane);
+int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state);
 
 #endif
Signature · 1 line
2.37.1
#1 lore raw
Quoted 3 lines · Javier Martinez Canillas

Provides a default plane state check handler for primary planes that are a fullscreen scanout buffer and whose state scale and position can't change.

Even though this might be how some drivers are handling the primary plane this assumption is not universal. For example, on ChromeOS when the (default) underlay strategy is selected the compositor will position the video plane as the bottom-most plane and mark it as primary, while the desktop plane is marked as overlay and will contain an alpha cutout to show the underlying video.

In this case the video plane (primary) won't span the screen and is regularly panned and resized.

No objections to this change as it helps share code between drivers, but maybe specify that this behavior is a unique requirement of these drivers.

Harry

Quoted 144 lines

There are some drivers that duplicate this logic in their helpers, such as simpledrm and ssd130x. Factor out this common code into a plane helper and make drivers use it.

---

Changes in v2:
- Fix new_state field comment (Ville Syrjälä).
- Rename new_state to just state (Ville Syrjälä).

 drivers/gpu/drm/drm_plane_helper.c | 28 ++++++++++++++++++++++++++++
 drivers/gpu/drm/solomon/ssd130x.c  | 18 +-----------------
 drivers/gpu/drm/tiny/simpledrm.c   | 25 +------------------------
 include/drm/drm_plane_helper.h     |  1 +
 4 files changed, 31 insertions(+), 41 deletions(-)
drivers/gpu/drm/drm_plane_helper.c +28 -0
index c7785967f5bf..2165390863f4 100644
@@ -278,3 +278,31 @@ void drm_plane_helper_destroy(struct drm_plane *plane)
 	kfree(plane);
 }
 EXPORT_SYMBOL(drm_plane_helper_destroy);
+
+/**
+ * drm_plane_helper_atomic_check() - Helper to check primary planes states
+ * @plane: plane to check
+ * @state: atomic state object
+ *
+ * Provides a default plane state check handler for primary planes whose atomic
+ * state scale and position is not expected to change because the primary plane
+ * is always a fullscreen scanout buffer.
+ *
+ * RETURNS:
+ * Zero on success, or an errno code otherwise.
+ */
+int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+	struct drm_crtc *new_crtc = new_plane_state->crtc;
+	struct drm_crtc_state *new_crtc_state = NULL;
+
+	if (new_crtc)
+		new_crtc_state = drm_atomic_get_new_crtc_state(state, new_crtc);
+
+	return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
+						   DRM_PLANE_NO_SCALING,
+						   DRM_PLANE_NO_SCALING,
+						   false, false);
+}
+EXPORT_SYMBOL(drm_plane_helper_atomic_check);
drivers/gpu/drm/solomon/ssd130x.c +1 -17
index 79e8e2017c68..28cf9c87f86d 100644
@@ -565,22 +565,6 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m
 	return ret;
 }
 
-static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane,
-						     struct drm_atomic_state *new_state)
-{
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane);
-	struct drm_crtc *new_crtc = new_plane_state->crtc;
-	struct drm_crtc_state *new_crtc_state = NULL;
-
-	if (new_crtc)
-		new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc);
-
-	return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
-						   DRM_PLANE_NO_SCALING,
-						   DRM_PLANE_NO_SCALING,
-						   false, false);
-}
-
 static void ssd130x_primary_plane_helper_atomic_update(struct drm_plane *plane,
 						       struct drm_atomic_state *old_state)
 {
@@ -623,7 +607,7 @@ static void ssd130x_primary_plane_helper_atomic_disable(struct drm_plane *plane,
 
 static const struct drm_plane_helper_funcs ssd130x_primary_plane_helper_funcs = {
 	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
-	.atomic_check = ssd130x_primary_plane_helper_atomic_check,
+	.atomic_check = drm_plane_helper_atomic_check,
 	.atomic_update = ssd130x_primary_plane_helper_atomic_update,
 	.atomic_disable = ssd130x_primary_plane_helper_atomic_disable,
 };
drivers/gpu/drm/tiny/simpledrm.c +1 -24
index 777ccd250871..ea5b3239a659 100644
@@ -469,29 +469,6 @@ static const uint64_t simpledrm_primary_plane_format_modifiers[] = {
 	DRM_FORMAT_MOD_INVALID
 };
 
-static int simpledrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
-						       struct drm_atomic_state *new_state)
-{
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane);
-	struct drm_crtc *new_crtc = new_plane_state->crtc;
-	struct drm_crtc_state *new_crtc_state = NULL;
-	int ret;
-
-	if (new_crtc)
-		new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc);
-
-	ret = drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
-						  DRM_PLANE_NO_SCALING,
-						  DRM_PLANE_NO_SCALING,
-						  false, false);
-	if (ret)
-		return ret;
-	else if (!new_plane_state->visible)
-		return 0;
-
-	return 0;
-}
-
 static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane,
 							 struct drm_atomic_state *old_state)
 {
@@ -543,7 +520,7 @@ static void simpledrm_primary_plane_helper_atomic_disable(struct drm_plane *plan
 
 static const struct drm_plane_helper_funcs simpledrm_primary_plane_helper_funcs = {
 	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
-	.atomic_check = simpledrm_primary_plane_helper_atomic_check,
+	.atomic_check = drm_plane_helper_atomic_check,
 	.atomic_update = simpledrm_primary_plane_helper_atomic_update,
 	.atomic_disable = simpledrm_primary_plane_helper_atomic_disable,
 };
include/drm/drm_plane_helper.h +1 -0
index 1781fab24dd6..7760b27b0323 100644
@@ -41,5 +41,6 @@ int drm_plane_helper_update_primary(struct drm_plane *plane, struct drm_crtc *cr
 int drm_plane_helper_disable_primary(struct drm_plane *plane,
 				     struct drm_modeset_acquire_ctx *ctx);
 void drm_plane_helper_destroy(struct drm_plane *plane);
+int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state);
 
 #endif
author maintainer
#2 lore raw
Quoted 14 lines · Harry Wentland
Quoted 3 lines · Javier Martinez Canillas

Provides a default plane state check handler for primary planes that are a fullscreen scanout buffer and whose state scale and position can't change.

Even though this might be how some drivers are handling the primary plane this assumption is not universal. For example, on ChromeOS when the (default) underlay strategy is selected the compositor will position the video plane as the bottom-most plane and mark it as primary, while the desktop plane is marked as overlay and will contain an alpha cutout to show the underlying video.

Quoted 3 lines

In this case the video plane (primary) won't span the screen and is regularly panned and resized.

I see. Interesting.

Quoted 4 lines

No objections to this change as it helps share code between drivers, but maybe specify that this behavior is a unique requirement of these drivers.

I tried to make it clear in the comment by mentioning that this helper is applicable for drivers whose primary plane is always fullscreen and can't scale or change position.

Any suggestions of what's missing in the helper kernel-doc comment to be more clear ?

Quoted 2 lines

Harry

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#3 lore raw
Quoted 26 lines · Javier Martinez Canillas
Quoted 14 lines · Harry Wentland
Quoted 3 lines · Javier Martinez Canillas

Provides a default plane state check handler for primary planes that are a fullscreen scanout buffer and whose state scale and position can't change.

Even though this might be how some drivers are handling the primary plane this assumption is not universal. For example, on ChromeOS when the (default) underlay strategy is selected the compositor will position the video plane as the bottom-most plane and mark it as primary, while the desktop plane is marked as overlay and will contain an alpha cutout to show the underlying video.

Quoted 3 lines

In this case the video plane (primary) won't span the screen and is regularly panned and resized.

I see. Interesting.

Quoted 4 lines

No objections to this change as it helps share code between drivers, but maybe specify that this behavior is a unique requirement of these drivers.

Quoted 7 lines

I tried to make it clear in the comment by mentioning that this helper is applicable for drivers whose primary plane is always fullscreen and can't scale or change position.

Any suggestions of what's missing in the helper kernel-doc comment to be more clear ?

After re-reading I see what you mean.

A sentence to the effect of "Some drivers require the primary plane to be a fullscreen scanout buffer..." or similar might help clarify that this isn't universal but helpful for drivers who require this constraint.

Harry

Quoted 3 lines
Quoted 2 lines

Harry

maintainer Reviewed-by
#4 lore raw
In reply to Harry Wentland

Hi

Am 13.09.22 um 15:49 schrieb Harry Wentland:

Quoted 41 lines · Javier Martinez Canillas
Quoted 3 lines

Provides a default plane state check handler for primary planes that are a fullscreen scanout buffer and whose state scale and position can't change.

Even though this might be how some drivers are handling the primary plane this assumption is not universal. For example, on ChromeOS when the (default) underlay strategy is selected the compositor will position the video plane as the bottom-most plane and mark it as primary, while the desktop plane is marked as overlay and will contain an alpha cutout to show the underlying video.

In this case the video plane (primary) won't span the screen and is regularly panned and resized.

No objections to this change as it helps share code between drivers, but maybe specify that this behavior is a unique requirement of these drivers.

Harry

Quoted 18 lines

There are some drivers that duplicate this logic in their helpers, such as simpledrm and ssd130x. Factor out this common code into a plane helper and make drivers use it.

---

Changes in v2:
- Fix new_state field comment (Ville Syrjälä).
- Rename new_state to just state (Ville Syrjälä).

  drivers/gpu/drm/drm_plane_helper.c | 28 ++++++++++++++++++++++++++++
  drivers/gpu/drm/solomon/ssd130x.c  | 18 +-----------------
  drivers/gpu/drm/tiny/simpledrm.c   | 25 +------------------------
  include/drm/drm_plane_helper.h     |  1 +
  4 files changed, 31 insertions(+), 41 deletions(-)
Quoted 15 lines
Quoted 5 lines
drivers/gpu/drm/drm_plane_helper.c +0 -0
index c7785967f5bf..2165390863f4 100644

drivers/gpu/drm/drm_plane_helper.c void drm_plane_helper_destroy(struct drm_plane *plane) · line 287

Quoted 10 lines
drivers/gpu/drm/drm_plane_helper.c +7 -0
@@ -278,3 +278,31 @@ void drm_plane_helper_destroy(struct drm_plane *plane)
  	kfree(plane);
  }
  EXPORT_SYMBOL(drm_plane_helper_destroy);
+
+/**
+ * drm_plane_helper_atomic_check() - Helper to check primary planes states
+ * @plane: plane to check
+ * @state: atomic state object
+ *
+ * Provides a default plane state check handler for primary planes whose atomic

'plane-state'

'atomic-state scale and positioning properties are not expected to change'

Quoted 2 lines

drivers/gpu/drm/drm_plane_helper.c void drm_plane_helper_destroy(struct drm_plane *plane) · line 289

Quoted 2 lines
drivers/gpu/drm/drm_plane_helper.c +2 -0
+ * state scale and position is not expected to change because the primary plane
+ * is always a fullscreen scanout buffer.

AFAICT the docs clearly state the purpose of the helper. Maybe say 'plane' instead of 'primary plane' in the docs and add a sentence like 'This is often the case for the primary plane of simple framebuffers.'

Best regards
Thomas

Quoted 110 lines
Quoted 109 lines
drivers/gpu/drm/drm_plane_helper.c +19 -0
+ *
+ * RETURNS:
+ * Zero on success, or an errno code otherwise.
+ */
+int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state)
+{
+	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+	struct drm_crtc *new_crtc = new_plane_state->crtc;
+	struct drm_crtc_state *new_crtc_state = NULL;
+
+	if (new_crtc)
+		new_crtc_state = drm_atomic_get_new_crtc_state(state, new_crtc);
+
+	return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
+						   DRM_PLANE_NO_SCALING,
+						   DRM_PLANE_NO_SCALING,
+						   false, false);
+}
+EXPORT_SYMBOL(drm_plane_helper_atomic_check);
drivers/gpu/drm/solomon/ssd130x.c +1 -17
index 79e8e2017c68..28cf9c87f86d 100644
@@ -565,22 +565,6 @@ static int ssd130x_fb_blit_rect(struct drm_framebuffer *fb, const struct iosys_m
  	return ret;
  }
 
-static int ssd130x_primary_plane_helper_atomic_check(struct drm_plane *plane,
-						     struct drm_atomic_state *new_state)
-{
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane);
-	struct drm_crtc *new_crtc = new_plane_state->crtc;
-	struct drm_crtc_state *new_crtc_state = NULL;
-
-	if (new_crtc)
-		new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc);
-
-	return drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
-						   DRM_PLANE_NO_SCALING,
-						   DRM_PLANE_NO_SCALING,
-						   false, false);
-}
-
  static void ssd130x_primary_plane_helper_atomic_update(struct drm_plane *plane,
  						       struct drm_atomic_state *old_state)
  {
@@ -623,7 +607,7 @@ static void ssd130x_primary_plane_helper_atomic_disable(struct drm_plane *plane,
 
  static const struct drm_plane_helper_funcs ssd130x_primary_plane_helper_funcs = {
  	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
-	.atomic_check = ssd130x_primary_plane_helper_atomic_check,
+	.atomic_check = drm_plane_helper_atomic_check,
  	.atomic_update = ssd130x_primary_plane_helper_atomic_update,
  	.atomic_disable = ssd130x_primary_plane_helper_atomic_disable,
  };
drivers/gpu/drm/tiny/simpledrm.c +1 -24
index 777ccd250871..ea5b3239a659 100644
@@ -469,29 +469,6 @@ static const uint64_t simpledrm_primary_plane_format_modifiers[] = {
  	DRM_FORMAT_MOD_INVALID
  };
 
-static int simpledrm_primary_plane_helper_atomic_check(struct drm_plane *plane,
-						       struct drm_atomic_state *new_state)
-{
-	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(new_state, plane);
-	struct drm_crtc *new_crtc = new_plane_state->crtc;
-	struct drm_crtc_state *new_crtc_state = NULL;
-	int ret;
-
-	if (new_crtc)
-		new_crtc_state = drm_atomic_get_new_crtc_state(new_state, new_crtc);
-
-	ret = drm_atomic_helper_check_plane_state(new_plane_state, new_crtc_state,
-						  DRM_PLANE_NO_SCALING,
-						  DRM_PLANE_NO_SCALING,
-						  false, false);
-	if (ret)
-		return ret;
-	else if (!new_plane_state->visible)
-		return 0;
-
-	return 0;
-}
-
  static void simpledrm_primary_plane_helper_atomic_update(struct drm_plane *plane,
  							 struct drm_atomic_state *old_state)
  {
@@ -543,7 +520,7 @@ static void simpledrm_primary_plane_helper_atomic_disable(struct drm_plane *plan
 
  static const struct drm_plane_helper_funcs simpledrm_primary_plane_helper_funcs = {
  	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
-	.atomic_check = simpledrm_primary_plane_helper_atomic_check,
+	.atomic_check = drm_plane_helper_atomic_check,
  	.atomic_update = simpledrm_primary_plane_helper_atomic_update,
  	.atomic_disable = simpledrm_primary_plane_helper_atomic_disable,
  };
include/drm/drm_plane_helper.h +1 -0
index 1781fab24dd6..7760b27b0323 100644
@@ -41,5 +41,6 @@ int drm_plane_helper_update_primary(struct drm_plane *plane, struct drm_crtc *cr
  int drm_plane_helper_disable_primary(struct drm_plane *plane,
  				     struct drm_modeset_acquire_ctx *ctx);
  void drm_plane_helper_destroy(struct drm_plane *plane);
+int drm_plane_helper_atomic_check(struct drm_plane *plane, struct drm_atomic_state *state);
 
  #endif
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev