Cocoa: Fix MoltenVK layer scale out of sync

The contents scale of the hosted CAMetalLayer created for MoltenVK was
updated only after the GLFW content scale and framebuffer size events
were emitted, causing the layer to get out of sync with the monitor the
window was on.
master
Camilla Löwy ago%!(EXTRA string=4 years)
parent 836e709503
commit 076bfd55be
  1. 2
      README.md
  2. 21
      src/cocoa_window.m

@ -196,6 +196,8 @@ information on what to include when reporting a bug.
regained focus (#1648,#1802) regained focus (#1648,#1802)
- [Cocoa] Bugfix: Monitor name query could segfault on macOS 11 (#1809,#1833) - [Cocoa] Bugfix: Monitor name query could segfault on macOS 11 (#1809,#1833)
- [Cocoa] Bugfix: The install name of the installed dylib was relative (#1504) - [Cocoa] Bugfix: The install name of the installed dylib was relative (#1504)
- [Cocoa] Bugfix: The MoltenVK layer contents scale was updated only after
related events were emitted
- [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480)
- [X11] Bugfix: Key names were not updated when the keyboard layout changed - [X11] Bugfix: Key names were not updated when the keyboard layout changed
(#1462,#1528) (#1462,#1528)

@ -520,26 +520,25 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
{ {
const NSRect contentRect = [window->ns.view frame]; const NSRect contentRect = [window->ns.view frame];
const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect]; const NSRect fbRect = [window->ns.view convertRectToBacking:contentRect];
if (fbRect.size.width != window->ns.fbWidth ||
fbRect.size.height != window->ns.fbHeight)
{
window->ns.fbWidth = fbRect.size.width;
window->ns.fbHeight = fbRect.size.height;
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
}
const float xscale = fbRect.size.width / contentRect.size.width; const float xscale = fbRect.size.width / contentRect.size.width;
const float yscale = fbRect.size.height / contentRect.size.height; const float yscale = fbRect.size.height / contentRect.size.height;
if (xscale != window->ns.xscale || yscale != window->ns.yscale) if (xscale != window->ns.xscale || yscale != window->ns.yscale)
{ {
if (window->ns.retina && window->ns.layer)
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]];
window->ns.xscale = xscale; window->ns.xscale = xscale;
window->ns.yscale = yscale; window->ns.yscale = yscale;
_glfwInputWindowContentScale(window, xscale, yscale); _glfwInputWindowContentScale(window, xscale, yscale);
}
if (window->ns.retina && window->ns.layer) if (fbRect.size.width != window->ns.fbWidth ||
[window->ns.layer setContentsScale:[window->ns.object backingScaleFactor]]; fbRect.size.height != window->ns.fbHeight)
{
window->ns.fbWidth = fbRect.size.width;
window->ns.fbHeight = fbRect.size.height;
_glfwInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
} }
} }

Loading…
Cancel
Save