Skip to content

Commit 933baca

Browse files
committed
Smart integer scaling fixup
1 parent f189ed5 commit 933baca

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

gfx/video_driver.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,9 +2525,6 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
25252525
* crop overscan and fills more of the screen. */
25262526
unsigned overscale_h = underscale_h + 1;
25272527
unsigned max_scale_h = underscale_h;
2528-
float width_utilization;
2529-
float height_utilization;
2530-
25312528
/* This is the minimum amount content that must be shown in order
25322529
* for overscan to be used.
25332530
*
@@ -2553,29 +2550,6 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
25532550
if (height / overscale_h >= overscale_min_height)
25542551
max_scale_h = overscale_h;
25552552
max_scale = MIN(max_scale_w, max_scale_h);
2556-
2557-
/* Final step: check if the underscaling margins are too large.
2558-
*
2559-
* Sometimes there's no reasonable integer scale that can be used,
2560-
* such as when scaling 480p to 720p. Overscaling would crop 25% of
2561-
* the content height, but underscaling would only use 2/3 of the
2562-
* display's height.
2563-
*
2564-
* A threshold of 88% utilization (i.e. 12% margin) captures the
2565-
* majority of underscaling scenarios for HD resolutions while
2566-
* keeping the margins relatively small. Noteworthy use cases that
2567-
* straddle this cutoff include: GBA scaled to 720p; Nintendo DS
2568-
* scaled to 1080p; and 480p content scaled to 1080p. Past this,
2569-
* noticeable jumps in margin size would be needed to capture a
2570-
* relatively small number of additional use cases.
2571-
* TODO: Make this threshold configurable. */
2572-
width_utilization = (float)content_width * max_scale / width;
2573-
height_utilization = (float)content_height * max_scale / height;
2574-
if (MAX(height_utilization, width_utilization) < 0.88)
2575-
{
2576-
video_viewport_get_scaled_aspect(vp, width, height, y_down);
2577-
return;
2578-
}
25792553
}
25802554
else if (scaling == VIDEO_SCALE_INTEGER_SCALING_OVERSCALE)
25812555
max_scale = MIN((width / content_width) + !!(width % content_width),
@@ -2718,6 +2692,32 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp,
27182692
padding_x = width - content_width * (max_scale_w + (half_w * 0.5f));
27192693
padding_y = height - content_height * (max_scale_h + (half_h * 0.5f));
27202694

2695+
if (scaling == VIDEO_SCALE_INTEGER_SCALING_SMART)
2696+
{
2697+
/* Final step: check if the underscaling margins are too large.
2698+
*
2699+
* Sometimes there's no reasonable integer scale that can be used,
2700+
* such as when scaling 480p to 720p. Overscaling would crop 25% of
2701+
* the content height, but underscaling would only use 2/3 of the
2702+
* display's height.
2703+
*
2704+
* A threshold of 88% utilization (i.e. 12% margin) captures the
2705+
* majority of underscaling scenarios for HD resolutions while
2706+
* keeping the margins relatively small. Noteworthy use cases that
2707+
* straddle this cutoff include: GBA scaled to 720p; Nintendo DS
2708+
* scaled to 1080p; and 480p content scaled to 1080p. Past this,
2709+
* noticeable jumps in margin size would be needed to capture a
2710+
* relatively small number of additional use cases.
2711+
* TODO: Make this threshold configurable. */
2712+
float width_utilization = (float)(width - padding_x) / width;
2713+
float height_utilization = (float)(height - padding_y) / height;
2714+
if (MAX(height_utilization, width_utilization) < 0.88)
2715+
{
2716+
video_viewport_get_scaled_aspect(vp, width, height, y_down);
2717+
return;
2718+
}
2719+
}
2720+
27212721
/* Use regular scaling if overscale is unreasonable */
27222722
if ( padding_x <= (int)-video_st->av_info.geometry.base_width
27232723
|| padding_y <= (int)-video_st->av_info.geometry.base_height)

0 commit comments

Comments
 (0)