diff mbox

[i-g-t,v2,02/33] lib/igt_kms: Avoid depencency on static plane count

Message ID 20170124233400.5053-3-robert.foss@collabora.com (mailing list archive)
State New, archived
Headers show

Commit Message

Robert Foss Jan. 24, 2017, 11:33 p.m. UTC
Rework kmstest_crtc and kmstest_plane structs and their usage
to not depend on a static plane count.

Signed-off-by: Robert Foss <robert.foss@collabora.com>
---
 lib/igt_kms.c | 47 ++++++++++++++++++++++++++++++-----------------
 lib/igt_kms.h |  4 ++--
 2 files changed, 32 insertions(+), 19 deletions(-)

Comments

Kahola, Mika Jan. 25, 2017, 8:52 a.m. UTC | #1
Reviewed-by: Mika Kahola <mika.kahola@intel.com>

On Tue, 2017-01-24 at 18:33 -0500, Robert Foss wrote:
> Rework kmstest_crtc and kmstest_plane structs and their usage
> to not depend on a static plane count.
> 
> Signed-off-by: Robert Foss <robert.foss@collabora.com>
> ---
>  lib/igt_kms.c | 47 ++++++++++++++++++++++++++++++-----------------
>  lib/igt_kms.h |  4 ++--
>  2 files changed, 32 insertions(+), 19 deletions(-)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index e1abcf0d..922bba63 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -1227,7 +1227,7 @@ static void get_plane(char *str, int type,
> struct kmstest_plane *plane)
>  	int ret;
>  	char buf[256];
>  
> -	plane->plane = type;
> +	plane->type = type;
>  	ret = sscanf(str + 12, "%d%*c %*s %[^n]s",
>  		     &plane->id,
>  		     buf);
> @@ -1240,31 +1240,36 @@ static void get_plane(char *str, int type,
> struct kmstest_plane *plane)
>  	igt_assert_eq(ret, 2);
>  }
>  
> -static int parse_planes(FILE *fid, struct kmstest_plane *plane)
> +static int parse_planes(FILE *fid, struct kmstest_plane *planes)
>  {
>  	char tmp[256];
> -	int nplanes;
> +	int n_planes;
>  
> -	nplanes = 0;
> +	n_planes = 0;
>  	while (fgets(tmp, 256, fid) != NULL) {
> -		igt_assert_neq(nplanes, IGT_MAX_PLANES);
>  		if (strstr(tmp, "type=PRI") != NULL) {
> -			get_plane(tmp, DRM_PLANE_TYPE_PRIMARY,
> &plane[nplanes]);
> -			plane[nplanes].index = nplanes;
> -			nplanes++;
> +			if (planes) {
> +				get_plane(tmp,
> DRM_PLANE_TYPE_PRIMARY, &planes[n_planes]);
> +				planes[n_planes].index = n_planes;
> +			}
> +			n_planes++;
>  		} else if (strstr(tmp, "type=OVL") != NULL) {
> -			get_plane(tmp, DRM_PLANE_TYPE_OVERLAY,
> &plane[nplanes]);
> -			plane[nplanes].index = nplanes;
> -			nplanes++;
> +			if (planes) {
> +				get_plane(tmp,
> DRM_PLANE_TYPE_OVERLAY, &planes[n_planes]);
> +				planes[n_planes].index = n_planes;
> +			}
> +			n_planes++;
>  		} else if (strstr(tmp, "type=CUR") != NULL) {
> -			get_plane(tmp, DRM_PLANE_TYPE_CURSOR,
> &plane[nplanes]);
> -			plane[nplanes].index = nplanes;
> -			nplanes++;
> +			if (planes) {
> +				get_plane(tmp,
> DRM_PLANE_TYPE_CURSOR, &planes[n_planes]);
> +				planes[n_planes].index = n_planes;
> +			}
> +			n_planes++;
>  			break;
>  		}
>  	}
>  
> -	return nplanes;
> +	return n_planes;
>  }
>  
>  static void parse_crtc(char *info, struct kmstest_crtc *crtc)
> @@ -1304,7 +1309,12 @@ void kmstest_get_crtc(enum pipe pipe, struct
> kmstest_crtc *crtc)
>  			if (strstr(tmp, "active=yes") != NULL) {
>  				crtc->active = true;
>  				parse_crtc(tmp, crtc);
> -				crtc->nplanes = parse_planes(fid,
> crtc->plane);
> +
> +				crtc->nplanes = parse_planes(fid,
> NULL);
> +				crtc->plane = calloc(crtc->nplanes,
> sizeof(*crtc->plane));
> +				fseek(fid, 0, SEEK_END);
> +				fseek(fid, 0, SEEK_SET);
> +				parse_planes(fid, crtc->plane);
>  
>  				if (crtc->pipe != pipe)
>  					crtc = NULL;
> @@ -1330,7 +1340,10 @@ void igt_assert_plane_visible(enum pipe pipe,
> bool visibility)
>  	kmstest_get_crtc(pipe, &crtc);
>  
>  	visible = true;
> -	for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
> +	for (i = 0; i < crtc.nplanes; i++) {
> +		if (crtc.plane[i].type == DRM_PLANE_TYPE_PRIMARY)
> +			continue;
> +
>  		if (crtc.plane[i].pos_x > crtc.width) {
>  			visible = false;
>  			break;
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 198174c2..5eb49ab3 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -135,8 +135,8 @@ struct kmstest_connector_config {
>  
>  struct kmstest_plane {
>  	int id;
> -	int plane;
>  	int index;
> +	int type;
>  	int pos_x;
>  	int pos_y;
>  	int width;
> @@ -150,7 +150,7 @@ struct kmstest_crtc {
>  	int width;
>  	int height;
>  	int nplanes;
> -	struct kmstest_plane plane[IGT_MAX_PLANES];
> +	struct kmstest_plane *plane;
>  };
>  
>  /**
diff mbox

Patch

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index e1abcf0d..922bba63 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1227,7 +1227,7 @@  static void get_plane(char *str, int type, struct kmstest_plane *plane)
 	int ret;
 	char buf[256];
 
-	plane->plane = type;
+	plane->type = type;
 	ret = sscanf(str + 12, "%d%*c %*s %[^n]s",
 		     &plane->id,
 		     buf);
@@ -1240,31 +1240,36 @@  static void get_plane(char *str, int type, struct kmstest_plane *plane)
 	igt_assert_eq(ret, 2);
 }
 
-static int parse_planes(FILE *fid, struct kmstest_plane *plane)
+static int parse_planes(FILE *fid, struct kmstest_plane *planes)
 {
 	char tmp[256];
-	int nplanes;
+	int n_planes;
 
-	nplanes = 0;
+	n_planes = 0;
 	while (fgets(tmp, 256, fid) != NULL) {
-		igt_assert_neq(nplanes, IGT_MAX_PLANES);
 		if (strstr(tmp, "type=PRI") != NULL) {
-			get_plane(tmp, DRM_PLANE_TYPE_PRIMARY, &plane[nplanes]);
-			plane[nplanes].index = nplanes;
-			nplanes++;
+			if (planes) {
+				get_plane(tmp, DRM_PLANE_TYPE_PRIMARY, &planes[n_planes]);
+				planes[n_planes].index = n_planes;
+			}
+			n_planes++;
 		} else if (strstr(tmp, "type=OVL") != NULL) {
-			get_plane(tmp, DRM_PLANE_TYPE_OVERLAY, &plane[nplanes]);
-			plane[nplanes].index = nplanes;
-			nplanes++;
+			if (planes) {
+				get_plane(tmp, DRM_PLANE_TYPE_OVERLAY, &planes[n_planes]);
+				planes[n_planes].index = n_planes;
+			}
+			n_planes++;
 		} else if (strstr(tmp, "type=CUR") != NULL) {
-			get_plane(tmp, DRM_PLANE_TYPE_CURSOR, &plane[nplanes]);
-			plane[nplanes].index = nplanes;
-			nplanes++;
+			if (planes) {
+				get_plane(tmp, DRM_PLANE_TYPE_CURSOR, &planes[n_planes]);
+				planes[n_planes].index = n_planes;
+			}
+			n_planes++;
 			break;
 		}
 	}
 
-	return nplanes;
+	return n_planes;
 }
 
 static void parse_crtc(char *info, struct kmstest_crtc *crtc)
@@ -1304,7 +1309,12 @@  void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
 			if (strstr(tmp, "active=yes") != NULL) {
 				crtc->active = true;
 				parse_crtc(tmp, crtc);
-				crtc->nplanes = parse_planes(fid, crtc->plane);
+
+				crtc->nplanes = parse_planes(fid, NULL);
+				crtc->plane = calloc(crtc->nplanes, sizeof(*crtc->plane));
+				fseek(fid, 0, SEEK_END);
+				fseek(fid, 0, SEEK_SET);
+				parse_planes(fid, crtc->plane);
 
 				if (crtc->pipe != pipe)
 					crtc = NULL;
@@ -1330,7 +1340,10 @@  void igt_assert_plane_visible(enum pipe pipe, bool visibility)
 	kmstest_get_crtc(pipe, &crtc);
 
 	visible = true;
-	for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
+	for (i = 0; i < crtc.nplanes; i++) {
+		if (crtc.plane[i].type == DRM_PLANE_TYPE_PRIMARY)
+			continue;
+
 		if (crtc.plane[i].pos_x > crtc.width) {
 			visible = false;
 			break;
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 198174c2..5eb49ab3 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -135,8 +135,8 @@  struct kmstest_connector_config {
 
 struct kmstest_plane {
 	int id;
-	int plane;
 	int index;
+	int type;
 	int pos_x;
 	int pos_y;
 	int width;
@@ -150,7 +150,7 @@  struct kmstest_crtc {
 	int width;
 	int height;
 	int nplanes;
-	struct kmstest_plane plane[IGT_MAX_PLANES];
+	struct kmstest_plane *plane;
 };
 
 /**