From d88fa0dd5d37604de8efb05853738cfaca6a3166 Mon Sep 17 00:00:00 2001 From: Tom St Denis Date: Wed, 11 Nov 2015 15:46:50 +0900 Subject: Simplify pick best crtc to fold two loops into one 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 (ported from amdgpu commit 3055724aef76a624718f26d5f0f9e9d567ffbcfb) Reviewed-by: Alex Deucher --- 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 9b714e97..7abc2f66 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; } -- cgit v1.2.3