[PATCH 2/8] Simplify pick best crtc to fold two loops into one

Michel Dänzer michel at daenzer.net
Tue Nov 10 23:16:00 PST 2015


From: Tom St Denis <tom.stdenis at amd.com>

This patch folds the two for loops from radeon_pick_best_crtc() into
one to reduce the LOC and make the routine easier to read.

Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
(ported from amdgpu commit 3055724aef76a624718f26d5f0f9e9d567ffbcfb)

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/radeon_video.c | 54 +++++++++++++++++++++++-------------------------------
 1 file changed, 23 insertions(+), 31 deletions(-)

diff --git a/src/radeon_video.c b/src/radeon_video.c
index 9b714e9..7abc2f6 100644
--- a/src/radeon_video.c
+++ b/src/radeon_video.c
@@ -79,7 +79,7 @@ radeon_pick_best_crtc(ScrnInfoPtr pScrn, Bool consider_disabled,
 		      int x1, int x2, int y1, int y2)
 {
     xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-    int			coverage, best_coverage, c;
+    int			coverage, best_coverage, c, cd;
     BoxRec		box, crtc_box, cover_box;
     RROutputPtr         primary_output = NULL;
     xf86CrtcPtr         best_crtc = NULL, primary_crtc = NULL;
@@ -103,38 +103,30 @@ radeon_pick_best_crtc(ScrnInfoPtr pScrn, Bool consider_disabled,
     if (primary_output && primary_output->crtc)
 	primary_crtc = primary_output->crtc->devPrivate;
 
-    /* first consider only enabled CRTCs */
-    for (c = 0; c < xf86_config->num_crtc; c++) {
-	xf86CrtcPtr crtc = xf86_config->crtc[c];
-
-	if (!radeon_crtc_is_enabled(crtc))
-	    continue;
-
-	radeon_crtc_box(crtc, &crtc_box);
-	radeon_box_intersect(&cover_box, &crtc_box, &box);
-	coverage = radeon_box_area(&cover_box);
-	if (coverage > best_coverage ||
-	    (coverage == best_coverage && crtc == primary_crtc)) {
-	    best_crtc = crtc;
-	    best_coverage = coverage;
-	}
-    }
-    if (best_crtc || !consider_disabled)
-	return best_crtc;
-
-    /* if we found nothing, repeat the search including disabled CRTCs */
-    for (c = 0; c < xf86_config->num_crtc; c++) {
-	xf86CrtcPtr crtc = xf86_config->crtc[c];
-
-	radeon_crtc_box(crtc, &crtc_box);
-	radeon_box_intersect(&cover_box, &crtc_box, &box);
-	coverage = radeon_box_area(&cover_box);
-	if (coverage > best_coverage ||
-	    (coverage == best_coverage && crtc == primary_crtc)) {
-	    best_crtc = crtc;
-	    best_coverage = coverage;
+    /* first consider only enabled CRTCs
+     * then on second pass consider disabled ones
+     */
+    for (cd = 0; cd < (consider_disabled ? 2 : 1); cd++) {
+	for (c = 0; c < xf86_config->num_crtc; c++) {
+	    xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	    if (!cd && !radeon_crtc_is_enabled(crtc))
+		continue;
+
+	    radeon_crtc_box(crtc, &crtc_box);
+	    radeon_box_intersect(&cover_box, &crtc_box, &box);
+	    coverage = radeon_box_area(&cover_box);
+	    if (coverage > best_coverage ||
+		(coverage == best_coverage &&
+		 crtc == primary_crtc)) {
+		best_crtc = crtc;
+		best_coverage = coverage;
+	    }
 	}
+	if (best_crtc)
+	    break;
     }
+
     return best_crtc;
 }
 
-- 
2.6.2



More information about the xorg-driver-ati mailing list