summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom St Denis <tom.stdenis@amd.com>2015-11-11 15:46:50 +0900
committerMichel Dänzer <michel@daenzer.net>2015-11-12 11:27:04 +0900
commitd88fa0dd5d37604de8efb05853738cfaca6a3166 (patch)
treed3051cb1054a5cb726a4f6d445c7a6e097d03992
parentdbbcd75b3c80aba77673904d46bca97779fd8a8d (diff)
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 <tom.stdenis@amd.com> (ported from amdgpu commit 3055724aef76a624718f26d5f0f9e9d567ffbcfb) Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--src/radeon_video.c54
1 files 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;
}