Skip to content

Fix a window size regression on macOS #2374

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

Merged
merged 14 commits into from
Apr 6, 2023
Merged

Fix a window size regression on macOS #2374

merged 14 commits into from
Apr 6, 2023

Conversation

kcgen
Copy link
Member

@kcgen kcgen commented Apr 3, 2023

Tentatively fixes #2335

Suggest testing all eight permutations of:

[SDL]
fullscreen = on / off
output = texture / opengl / texturepp / openglpp
windowresolution = 960x720

For each permutation:

  1. Alt+Enter to toggle between full and window-mode
  2. Resizing and drag the window.
  3. Toggle back in and out of full screen
  4. Confirm your prior window size and position is retained.

Other things to look for:

  • Toggling should be as fast or faster than baseline
  • Toggling should have the same or less flickering or visual 'activity' between the transitions. This is because there is now only one call to SDL making the window change instead of 3 or more (depending on platform).

Ideally we can test all these permutations on Windows, Linux(es), and macOS(es).

I've done a fair bit of testing on Linux (Ubuntu 22.10) and macOS 11.x, but the more the better.

@kcgen kcgen added the regression We broke something 😊 label Apr 3, 2023
@kcgen kcgen self-assigned this Apr 3, 2023
kcgen added 2 commits April 2, 2023 22:04
On macOS, this extra resize callback action
conflicted with SDL's own ability to resize
the window back to it's last known state
prior to going fullscreen.
@kcgen kcgen force-pushed the kc/window-resize-2 branch from 0e60168 to 16c5093 Compare April 3, 2023 05:06
@johnnovak
Copy link
Member

johnnovak commented Apr 3, 2023

MacOS test results

Generally there is improvement; the original reported issue is gone! 🎉 There's also less flicker and the windowed/fullscreen switching it a bit faster in the OpenGL modes. In texture modes there's no difference as the flicker and slowness was only happening in the OpenGL modes.

Now, I noticed a couple of issues. I haven't cross-checked these against main to see whether they're regressions or pre-existing stuff. Anyway, here we go.

Will test on Windows tomorrow.

Case 1

[sdl]
fullscreen = off
output = texture | opengl
windowresolution = 960x720

Issue 1

  1. Resize & move window
  2. Switch to fullscreen & back
  3. Position is retained, but window size is not
  4. Resize & move window again
  5. Switch to fullscreen & back
  6. Both position & size are retained from the 2nd time onwards

Window position is retained doing the same test, just not the size.

Issue 2

  1. Switch to fullscreen & back
  2. Resize window to desktop width only horizontally
  3. Switch to fullscreen & back
  4. Note that window jumped back to its default size
  5. Resize window to desktop width only horizontally
  6. Switch to fullscreen & back
  7. Window size is retained from the 2nd time onwards

Case 2

[sdl]
fullscreen = on | off
output = openglpp
windowresolution = 960x720

Window position is always retained, resized window size is never retained.

Case 3

[sdl]
fullscreen = on
output = openglpp
windowresolution = 960x720
  1. Switch to windowed mode
  2. Note the window size is correct but the scaling factor is wrong; the contents of the window is way too small and there's a huge black border around it
  3. Switch to fullscreen & back
  4. Now the scaling factor is correct
  5. After this, we're back to the problem from Case 2 -- the window position is always retained, the resized window size is never retained.

Case 4

[sdl]
fullscreen = off
output = openglpp
windowresolution = 960x720

Same as Case 2.

@kcgen kcgen force-pushed the kc/window-resize-2 branch from 16c5093 to b91f861 Compare April 3, 2023 15:30
@kcgen
Copy link
Member Author

kcgen commented Apr 3, 2023

@johnnovak , thanks for the repro details. I think all should be addressed in the new commits - except I'm still not sure about:

the window size is correct but the scaling factor is wrong; the contents of the window is way too small and there's a huge black border around it

output = openglpp
windowresolution = 960x720

This is what I'm seeing (matching your description); I think it's correct given for a 960x720 window, pixel perfect cannot double the 640x400 text-mode up to the desired 1280+ width (with only a 960-wide window):

2023-04-03_09-20_1

DISPLAY: Text 640x400 16 color (mode 03h) at 70.087 Hz VFR,
         scaled to 640x400 with 1 pixel aspect ratio

But if I give it more room:

output = openglpp
windowresolution = 1280x960

2023-04-03_09-20

DISPLAY: Text 640x400 16 color (mode 03h) at 70.087 Hz VFR,
         scaled to 1280x800 with 1 pixel aspect ratio

That's on Linux, but it's similar for me on macOS because I have a normal DPI screen.

@kcgen
Copy link
Member Author

kcgen commented Apr 3, 2023

More on case 3:

@johnnovak, @GranMinigun helped look over the PR.

> <GranMinigun> 960 * 200% = 1920; 1920 / 640 = 3...

Captured some footage from the mac to re-check it using the current PR, and we both think (the updated commits) are now doing the right, but that's given my non-hi-DPI screen.

Video:
https://kcgen.duckdns.org/Screen%20Recording%202023-04-03%20at%202.29.00%20PM.mov

Curious what you see on your side w/ the latest commits.

@FeralChild64
Copy link
Collaborator

I did some tests using 1280x960 window resolution on my Gentoo Linux system - didn't notice any issues, but I haven't checked whether the pixel-perfect scaling modes really sets proper scaling.

@johnnovak
Copy link
Member

I can't test right now @kcgen , but if you do the test in Case as I described, the scaling is different between step 2 and 4. Both cannot be right.

The issue is not present with texturepp. So at the very least we are inconsistent.

What you wrote about the pixelperfect mode is logical, but I think there is another thing at play, namely thst we are forcing 640x480 min window size (I think).

This is another issue I did not flag because it seems unrelated but might be easy to fix. You can resize the window to say 100x100, and then do the fullscreen switch, then back to windowed. The window size jumps back to 640x480, and this defaulting to 640x480 min size screws up the pixelperfect stuff.

In fact, what I flagged as issue is the correct pp behaviour, you are right. Meaning everything else that I did not flag about it is wrong :)

I think the window min size should be perhaps set to 640x480 so the user cannot set it to a smaller size, or remove this altogether. I think I would keep it, but disallow the user from resizing the window below the min dimension of 640x480.

@kcgen
Copy link
Member Author

kcgen commented Apr 3, 2023

Thanks for the checks @FeralChild64. A simple way to check PP is to do a dragging resize. As the window grows, pixel-perfect will "step" the image size up in a stair-case manner (and pretty easy to visually see the multiplier in effect).

Thanks for the quick feedback @johnnovak; no rush on the ticket (want you kicking the tires on the latest revision so you can re-assess).

As for the minimum window size - yes; I'll check if SDL has some bounds we can give it, so it manages those for us.

(context: some of the functions calls this PR removes were used to "fight" with SDL by trying to manage the window size; and want to keep avoiding that approach).

This is going to get better too: @GranMinigun mentioned - "I think I'll be dropping window sizes from sdl struct in the future, as SDL itself tracks both window size and fullscreen display".

@johnnovak
Copy link
Member

johnnovak commented Apr 3, 2023

As for the minimum window size - yes; I'll check if SDL has some bounds we can give it, so it manages those for us.

This one should do the trick:
https://wiki.libsdl.org/SDL2/SDL_SetWindowMinimumSize

Care needs to be taken that it works with "logical pixels" on hiDPI screens in the expected way.

For the record, I'm a GLFW user myself, and GLFW has a similar function that just works (at least on Windows and macOS, I can't test on Linux):
https://www.glfw.org/docs/3.3/group__window.html#gac314fa6cec7d2d307be9963e2709cc90

(context: some of the functions calls this PR removes were used to "fight" with SDL by trying to manage the window size; and want to keep avoiding that approach).

This is going to get better too: @GranMinigun mentioned - "I think I'll be dropping window sizes from sdl struct in the future, as SDL itself tracks both window size and fullscreen display".

That's a very good idea to remove it; maintaining "shadow dimensions" ourselves is asking for trouble (talking from experience with GFLW). You can make it work, kinda, but it easily breaks on different OSes, OS versions, etc.

Thanks for the quick feedback @johnnovak; no rush on the ticket (want you kicking the tires on the latest revision so you can re-assess).

That's fine. I'll wait until you put in the minimum window size stuff, should be easy enough and it will spare me another time consuming full testing cycle. Just let me know when that's in and I'll retest everything on Windows & macOS!

@kcgen kcgen force-pushed the kc/window-resize-2 branch 3 times, most recently from 21d2877 to da9bf18 Compare April 4, 2023 07:12
@kcgen
Copy link
Member Author

kcgen commented Apr 4, 2023

I'll wait until you put in the minimum window size stuff, should be easy enough and it will spare me another time consuming full testing cycle.

👍 all set now. Tested as much as I could on my side; minimum bounds are being respected.

@johnnovak
Copy link
Member

johnnovak commented Apr 4, 2023

New results. There are improvements, but there are also regressions. I'll only test Windows once everything is perfect on macOS. OpenGL seems to be generally more difficult to get right, the texture backend is almost perfect.

Haven't listed all possible permutations explicitly because it's overwhelming; just read the descriptions carefully as I've included comments about the permutations/variations. That should be enough to fix the issues because 2-3 issues seem to affect all various combos.

macOS

Issue 1

fullscreen = off
output = opengl
windowresolution = 960x720
  1. Resize window only horizontally so there's black bars on the two sides.
  2. Switch to fullscreen and then back.
  3. The window size & position are retained, but the content is stretched to the window! Moving or resizing the window "snaps" it back to the correct aspect ratio.

Same thing happens with output = openglpp; the correct pixel-perfect ratio "snaps" in place only after moving the window or resizing it after exiting fullscreen.

Does not happen with output = texture.

image

Issue 2

fullscreen = off
output = opengl
windowresolution = 640x480
  1. The fullscreen image at start is much larger than it should be.
  2. When switching to windowed mode, the the correct 640x480 size is displayed.

Make sure to view the images at "actual pixels" magnification to appreciate the difference.

The issue is the same when fullscreen = on is used; the fullscreen and windowed image sizes are different.

Same issue happens with output = texture too.

image

image

Issue 3

[sdl]
fullscreen = off
output = openglpp
windowresolution = 1500x720

Content gets stretched to the window (1st image), then "snaps" to the correct size after moving or resizing the window slightly (2nd image).

Same thing when using fullscreen = on and exiting fullscreen mode.

texturepp works fine.

image

image

@kcgen kcgen force-pushed the kc/window-resize-2 branch 2 times, most recently from 3add408 to 63d733e Compare April 4, 2023 15:37
Fixes a handful of PVS-Studio-flagged issues.
@kcgen kcgen force-pushed the kc/window-resize-2 branch from 63d733e to 54c8cc7 Compare April 4, 2023 15:47
kcgen added 3 commits April 4, 2023 09:17
Care is taken to not rely on the SDL struct members or globals,
so it's easily re-usable when refactoring.
This provides a single point where all subsequent things affected
by DPI (like the minimum window size) can be set.  Without a
single call-point like this, the DPI-affected-things will need
to be duplicated at every point the DPI is saved (duplicating a
lot of code, and adding even more things to keep track of).
We ultimately want all our minimum sizes to be linked - for example
the minimum window size should match the minimum logical drawing
size, because if they're not the same then window would be allowed
to obscure and hide the content (or vice-versa).
@kcgen
Copy link
Member Author

kcgen commented Apr 4, 2023

Thanks for the second round, @johnnovak.

The new window-size-minimum wasn't in lock-step with the minimum content size (leading the the window being able to "cover" the content when resized down). So the next round of updates bring them into lock-step.

Another change is that it moves the "point of change" into a single function, so extra book-keeping isn't needed at every possible change point (suggest reviewing the new commits one-by-one).

Also, I noticed that the these new minimum bounds were scaled up by the DPI factor - leading to a pretty huge window (and yes, with the window size now guanrateed no-smaller-than the minimum, I was blocked from manually dragging the window smaller - with a big DPI value, this felt very overbearing as it forced quite a huge window on me).

So I relaxed the minimum size boundaries by dividing out the DPI's influence, which allows a more generous smaller window - of course, not too small as to risk the user shrinking it away to a pin-point, but small enough that it can be put in the corner of their desktop if they're listening to music or something like that.

Hopefully third try does the trick!

@kcgen kcgen force-pushed the kc/window-resize-2 branch from dd9d065 to f0a6851 Compare April 4, 2023 18:53
@johnnovak
Copy link
Member

Great progress @kcgen , it's almost there now! 🎉 All previous issues are gone on macOS and everything works as expected, except for a single case.

I'll start Windows testing once this works too.

fullscreen = off
output = opengl | openglpp
windowresolution = 1500x720

The image appears fitted to the window, ignoring the correct aspect ratio. Moving/resizing and switches to fullscreen & back fixes it.

image

@kcgen
Copy link
Member Author

kcgen commented Apr 5, 2023

All previous issues are gone on macOS and everything works as expected, except for a single case.

Repro'd and got it. Confirmed all tests are working OK on the Linux side. Hopefully not much left w/ Windows!

@ThomasEricB
Copy link
Contributor

ThomasEricB commented Apr 5, 2023

Repro'd and got it. Confirmed all tests are working OK on the Linux side. Hopefully not much left w/ Windows!

Good news, it seems that Windows is working fine! See results below. Tested on all 8 different settings:

Desktop.05-04-2023.14-37-41-1.mp4

Fullscreen Pixel Perfect:

dosbox_PYV8TpXMqp

Grabbed this build from actions to test!

@ThomasEricB ThomasEricB self-requested a review April 6, 2023 02:39
Copy link
Contributor

@ThomasEricB ThomasEricB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my end, Windows 10, all looks good!

@johnnovak
Copy link
Member

Works 100% correctly on macOS now @kcgen, great job! 🎉 Will test on Win10 later today.

@kcgen
Copy link
Member Author

kcgen commented Apr 6, 2023

@ThomasEricB's confirmed all 8 permutations are running good on Windows; will merge as this is a good baseline (Not meaning cut your follow up testing short, @johnnovak !) -- teamwork in action. Thanks guys.

@kcgen kcgen merged commit d9ac217 into main Apr 6, 2023
@ThomasEricB
Copy link
Contributor

ThomasEricB commented Apr 6, 2023

@ThomasEricB's confirmed all 8 permutations are running good on Windows; will merge as this is a good baseline (Not meaning cut your follow up testing short, @johnnovak !) -- teamwork in action. Thanks guys.

I actually even went beyond and tested it swapping between texture_renderer = direct3d11 | opengl | software . Everything seemed normal on BLOOD.

@johnnovak
Copy link
Member

Everything is fine on Windows 10 on my end too @kcgen 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression We broke something 😊 video Graphics and video related issues
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Window resolution is ignored when fullscreen is turned on
5 participants