summaryrefslogtreecommitdiff
path: root/src/amdgpu_video.c
diff options
context:
space:
mode:
authorTom St Denis <tom.stdenis@amd.com>2015-09-24 13:08:31 -0400
committerMichel Dänzer <michel.daenzer@amd.com>2015-10-05 15:56:21 +0900
commit3055724aef76a624718f26d5f0f9e9d567ffbcfb (patch)
tree3ad7369e62a374301a4a9221d6263f79ac192577 /src/amdgpu_video.c
parent9945b4ae1664ab815b39ff07e7b66cfa7f942dfa (diff)
Simplify pick best crtc to fold two loops into one
This patch folds the two for loops from amdgpu_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> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Diffstat (limited to 'src/amdgpu_video.c')
-rw-r--r--src/amdgpu_video.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/amdgpu_video.c b/src/amdgpu_video.c
index 95a75e9..74e7c84 100644
--- a/src/amdgpu_video.c
+++ b/src/amdgpu_video.c
@@ -75,7 +75,7 @@ amdgpu_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;
@@ -99,38 +99,30 @@ amdgpu_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 (!amdgpu_crtc_is_enabled(crtc))
- continue;
-
- amdgpu_crtc_box(crtc, &crtc_box);
- amdgpu_box_intersect(&cover_box, &crtc_box, &box);
- coverage = amdgpu_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];
-
- amdgpu_crtc_box(crtc, &crtc_box);
- amdgpu_box_intersect(&cover_box, &crtc_box, &box);
- coverage = amdgpu_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 && !amdgpu_crtc_is_enabled(crtc))
+ continue;
+
+ amdgpu_crtc_box(crtc, &crtc_box);
+ amdgpu_box_intersect(&cover_box, &crtc_box, &box);
+ coverage = amdgpu_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;
}