Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the "Auto Adjust Window Size" option respect the current game's aspect ratio. #4739

Merged

Conversation

AdmiralCurtiss
Copy link
Contributor

A friend asked me if it was possible to make Dolphin auto-resize the window in windowed mode in a way that hides all the black bars and just displays the game. I told him that, yeah, you can do that, it's a checkbox in the graphics settings. But, as it turns out, there are some big issues with this! Most pressingly, if you play a widescreen game, you get big letterboxes.

At first, I thought the option just always assumed a 4:3 aspect ratio, but as I dug into the code, there's actually more going on here.

The window size is set by Renderer::SetWindowSize(), which gets the current framebuffer size, scales it according to internal resolution, then requests the host window to resize itself to the result. This sounds reasonable at first glance, but is not quite right. The framebuffer size is not yet stretched to the proper aspect ratio. This results in the situation that every game whose internal framebuffer aspect ratio is different from the final display aspect ratio gets unnecessarily letter- or pillarboxed, and sometimes even scaled down in both directions.

The solution to this is mostly straightforward: Instead of requesting the window size to be the framebuffer size, first scale the width or height so that it matches the desired display aspect ratio. If the Crop option is selected, additionally reduce the requested width or height to match a standard 4:3 or 16:9.

There's a minor problem with this approach though. Renderer::UpdateDrawRectangle() attempts to scale and translate the rendered image so that it fits into the window's framebuffer without cutting off anything. But since our width and height has to be in pixels rather than a real number, the calculation can end up ever so slightly scaling the image trying to fit it into the already correctly sized window, which results in a couple pixel rows (or columns I guess, but I've only seen rows) of black. This is not nice. I've tried to work around it by checking if the aspect ratio difference between the window aspect ratio and the game aspect ratio is very small, and if so not doing any scaling, but I'm not super happy with that approach. If anyone can think of a better way to detect that feel free to suggest something.

This fixes issue 7706.

Some comparison shots:

Before, without the 'Crop' option:

img img img

Before, with the 'Crop' option:

img img img

With this PR, without the 'Crop' option:

img img img

With this PR, with the 'Crop' option:

img img img

@JMC47
Copy link
Contributor

JMC47 commented Jan 23, 2017

This is something I've wanted for a while. I'm worried it could be confusing to users and/or titles that use really weird resolutions (240i in Zelda Collector's Edition that renders super thin with auto-aspect ratio.)

@@ -94,6 +94,8 @@ class Renderer

static const TargetRectangle& GetTargetRectangle() { return target_rc; }
static float CalculateDrawAspectRatio(int target_width, int target_height);
static void ScaleToDisplayAspectRatio(const int width, const int height, float* scaledWidth,

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -476,6 +476,26 @@ float Renderer::CalculateDrawAspectRatio(int target_width, int target_height)
}
}

void Renderer::ScaleToDisplayAspectRatio(const int width, const int height, float* scaledWidth,

This comment was marked as off-topic.

This comment was marked as off-topic.

@JMC47
Copy link
Contributor

JMC47 commented Jan 24, 2017

Seems to work fine in that situation (240i), where as it was broken before. Nice. LGTM.

@Parlane
Copy link
Member

Parlane commented Jan 25, 2017

@lioncash merge when happy \o/

@AdmiralCurtiss
Copy link
Contributor Author

Is there anything holding this up?

@Parlane
Copy link
Member

Parlane commented Jan 28, 2017

Just need @lioncash to OK changes :/

// Preserve horizontal resolution, scale vertically.
return std::make_tuple(static_cast<float>(width), static_cast<float>(height) * ratio);
}
else

This comment was marked as off-topic.

This comment was marked as off-topic.

@AdmiralCurtiss
Copy link
Contributor Author

Okay, should be good now.

@degasus degasus merged commit 3405f0b into dolphin-emu:master Jan 28, 2017
@AdmiralCurtiss AdmiralCurtiss deleted the auto-adjust-window-size-16-9 branch January 28, 2017 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants