[i-g-t,v3,13/21] lib/igt_kms: Add helpers to count and iterate planes from pipe

Submitted by Paul Kocialkowski on Jan. 11, 2019, 9:05 a.m.

Details

Message ID 20190111090532.19235-14-paul.kocialkowski@bootlin.com
State New
Series "Chamelium VC4 plane fuzzy testing, with SAND and T-tiled mode"
Headers show

Commit Message

Paul Kocialkowski Jan. 11, 2019, 9:05 a.m.
This introduces helpers that allow counting how many planes of a given
type are present from a pipe and getting the n-th plane of a given type.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 lib/igt_kms.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  3 +++
 2 files changed, 51 insertions(+)

Patch hide | download patch | download mbox

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 684a599ca674..e5c4ee72884a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -2276,6 +2276,54 @@  igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type)
 	return &pipe->planes[plane_idx];
 }
 
+/**
+ * igt_pipe_count_plane_type:
+ * @pipe: Target pipe
+ * @plane_type: Cursor, primary or an overlay plane
+ *
+ * Counts the number of planes of type @plane_type for the provided @pipe.
+ *
+ * Returns: The number of planes that match the requested plane type
+ */
+int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type)
+{
+	int i, count = 0;
+
+	for(i = 0; i < pipe->n_planes; i++)
+		if (pipe->planes[i].type == plane_type)
+			count++;
+
+	return count;
+}
+
+/**
+ * igt_pipe_get_plane_type_index:
+ * @pipe: Target pipe
+ * @plane_type: Cursor, primary or an overlay plane
+ * @index: the index of the plane among planes of the same type
+ *
+ * Get the @index th plane of type @plane_type for the provided @pipe.
+ *
+ * Returns: The @index th plane that matches the requested plane type
+ */
+igt_plane_t *igt_pipe_get_plane_type_index(igt_pipe_t *pipe, int plane_type,
+					   int index)
+{
+	int i, type_index = 0;
+
+	for(i = 0; i < pipe->n_planes; i++) {
+		if (pipe->planes[i].type != plane_type)
+			continue;
+
+		if (type_index == index)
+			return &pipe->planes[i];
+
+		type_index++;
+	}
+
+	return NULL;
+}
+
 static bool output_is_internal_panel(igt_output_t *output)
 {
 	switch (output->config.connector->connector_type) {
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 4a7c3c97957f..0f99535e2c6e 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -405,6 +405,9 @@  igt_output_t *igt_output_from_connector(igt_display_t *display,
     drmModeConnector *connector);
 
 igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type);
+int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type);
+igt_plane_t *igt_pipe_get_plane_type_index(igt_pipe_t *pipe, int plane_type,
+					   int index);
 igt_output_t *igt_get_single_output_for_pipe(igt_display_t *display, enum pipe pipe);
 
 void igt_pipe_request_out_fence(igt_pipe_t *pipe);

Comments

Maxime Ripard Jan. 11, 2019, 3:11 p.m.
On Fri, Jan 11, 2019 at 10:05:24AM +0100, Paul Kocialkowski wrote:
> This introduces helpers that allow counting how many planes of a given
> type are present from a pipe and getting the n-th plane of a given type.
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>

Reviewed-by: Maxime Ripard <maxime.ripard@bootlin.com>

Maxime
Lyude Paul Jan. 15, 2019, 9:57 p.m.
Reviewed-by: Lyude Paul <lyude@redhat.com>

On Fri, 2019-01-11 at 10:05 +0100, Paul Kocialkowski wrote:
> This introduces helpers that allow counting how many planes of a given
> type are present from a pipe and getting the n-th plane of a given type.
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  lib/igt_kms.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_kms.h |  3 +++
>  2 files changed, 51 insertions(+)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 684a599ca674..e5c4ee72884a 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -2276,6 +2276,54 @@ igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t
> *pipe, int plane_type)
>  	return &pipe->planes[plane_idx];
>  }
>  
> +/**
> + * igt_pipe_count_plane_type:
> + * @pipe: Target pipe
> + * @plane_type: Cursor, primary or an overlay plane
> + *
> + * Counts the number of planes of type @plane_type for the provided @pipe.
> + *
> + * Returns: The number of planes that match the requested plane type
> + */
> +int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type)
> +{
> +	int i, count = 0;
> +
> +	for(i = 0; i < pipe->n_planes; i++)
> +		if (pipe->planes[i].type == plane_type)
> +			count++;
> +
> +	return count;
> +}
> +
> +/**
> + * igt_pipe_get_plane_type_index:
> + * @pipe: Target pipe
> + * @plane_type: Cursor, primary or an overlay plane
> + * @index: the index of the plane among planes of the same type
> + *
> + * Get the @index th plane of type @plane_type for the provided @pipe.
> + *
> + * Returns: The @index th plane that matches the requested plane type
> + */
> +igt_plane_t *igt_pipe_get_plane_type_index(igt_pipe_t *pipe, int
> plane_type,
> +					   int index)
> +{
> +	int i, type_index = 0;
> +
> +	for(i = 0; i < pipe->n_planes; i++) {
> +		if (pipe->planes[i].type != plane_type)
> +			continue;
> +
> +		if (type_index == index)
> +			return &pipe->planes[i];
> +
> +		type_index++;
> +	}
> +
> +	return NULL;
> +}
> +
>  static bool output_is_internal_panel(igt_output_t *output)
>  {
>  	switch (output->config.connector->connector_type) {
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 4a7c3c97957f..0f99535e2c6e 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -405,6 +405,9 @@ igt_output_t *igt_output_from_connector(igt_display_t
> *display,
>      drmModeConnector *connector);
>  
>  igt_plane_t *igt_pipe_get_plane_type(igt_pipe_t *pipe, int plane_type);
> +int igt_pipe_count_plane_type(igt_pipe_t *pipe, int plane_type);
> +igt_plane_t *igt_pipe_get_plane_type_index(igt_pipe_t *pipe, int
> plane_type,
> +					   int index);
>  igt_output_t *igt_get_single_output_for_pipe(igt_display_t *display, enum
> pipe pipe);
>  
>  void igt_pipe_request_out_fence(igt_pipe_t *pipe);