Repository navigation
Fix macOS HUD and dynamic-overlay-resize on Metal present thread #88
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
Open
actuallyitsnathaniel
wants to merge
2
commits into
ThatGuyMcd:main
Choose a base branch
from
actuallyitsnathaniel:fix/mac-hud-resize-reflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−20
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- a/plume_apple.mm | ||
| +++ b/plume_apple.mm | ||
| @@ -95,28 +95,20 @@ | ||
| } | ||
|
|
||
| void CocoaWindow::getWindowAttributes(CocoaWindowAttributes* attributes) const { | ||
| - if ([NSThread isMainThread]) { | ||
| - UIWindow *uiWindow = (__bridge UIWindow *)windowHandle; | ||
| - CGRect bounds = [uiWindow bounds]; | ||
| - CGFloat scaleFactor = getScaleFactor(uiWindow); | ||
| + // Always read live bounds. The present/resize path calls this off the | ||
| + // main thread; returning a stale cache (and only scheduling async refresh) | ||
| + // leaves the Metal swapchain and overlay target at the pre-resize size. | ||
| + UIWindow *uiWindow = (__bridge UIWindow *)windowHandle; | ||
| + CGRect bounds = [uiWindow bounds]; | ||
| + CGFloat scaleFactor = getScaleFactor(uiWindow); | ||
|
|
||
| - { | ||
| - std::lock_guard<std::mutex> lock(attributesMutex); | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.x = 0; | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.y = 0; | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.width = (int)round(bounds.size.width * scaleFactor); | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.height = (int)round(bounds.size.height * scaleFactor); | ||
| + std::lock_guard<std::mutex> lock(attributesMutex); | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.x = 0; | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.y = 0; | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.width = (int)round(bounds.size.width * scaleFactor); | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.height = (int)round(bounds.size.height * scaleFactor); | ||
|
|
||
| - *attributes = cachedAttributes; | ||
| - } | ||
| - } else { | ||
| - { | ||
| - std::lock_guard<std::mutex> lock(attributesMutex); | ||
| - *attributes = cachedAttributes; | ||
| - } | ||
| - | ||
| - const_cast<CocoaWindow*>(this)->updateWindowAttributesInternal(false); | ||
| - } | ||
| + *attributes = cachedAttributes; | ||
| } | ||
|
|
||
| int CocoaWindow::getRefreshRate() const { | ||
| @@ -257,28 +249,20 @@ | ||
| } | ||
|
|
||
| void CocoaWindow::getWindowAttributes(CocoaWindowAttributes* attributes) const { | ||
| - if ([NSThread isMainThread]) { | ||
| - NSWindow *nsWindow = (__bridge NSWindow *)windowHandle; | ||
| - NSRect contentFrame = [[nsWindow contentView] frame]; | ||
| - CGFloat scaleFactor = getScaleFactor(nsWindow); | ||
| + // Always read live content size. RT64's present thread calls needsResize | ||
| + // / resize off the main thread; a cached size plus async refresh leaves | ||
| + // the drawable and ImGui target stuck until something else refreshes. | ||
| + NSWindow *nsWindow = (__bridge NSWindow *)windowHandle; | ||
| + NSRect contentFrame = [[nsWindow contentView] frame]; | ||
| + CGFloat scaleFactor = getScaleFactor(nsWindow); | ||
|
|
||
| - { | ||
| - std::lock_guard<std::mutex> lock(attributesMutex); | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.x = (int)round(contentFrame.origin.x); | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.y = (int)round(contentFrame.origin.y); | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.width = (int)round(contentFrame.size.width * scaleFactor); | ||
| - const_cast<CocoaWindow*>(this)->cachedAttributes.height = (int)round(contentFrame.size.height * scaleFactor); | ||
| + std::lock_guard<std::mutex> lock(attributesMutex); | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.x = (int)round(contentFrame.origin.x); | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.y = (int)round(contentFrame.origin.y); | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.width = (int)round(contentFrame.size.width * scaleFactor); | ||
| + const_cast<CocoaWindow*>(this)->cachedAttributes.height = (int)round(contentFrame.size.height * scaleFactor); | ||
|
|
||
| - *attributes = cachedAttributes; | ||
| - } | ||
| - } else { | ||
| - { | ||
| - std::lock_guard<std::mutex> lock(attributesMutex); | ||
| - *attributes = cachedAttributes; | ||
| - } | ||
| - | ||
| - const_cast<CocoaWindow*>(this)->updateWindowAttributesInternal(false); | ||
| - } | ||
| + *attributes = cachedAttributes; | ||
| } | ||
|
|
||
| int CocoaWindow::getRefreshRate() const { | ||
|
|
||
| --- a/plume_apple.h | ||
| +++ b/plume_apple.h | ||
| @@ -31,7 +31,7 @@ | ||
| CocoaWindow(void* window); | ||
| ~CocoaWindow(); | ||
|
|
||
| - // Get cached window attributes, may trigger async update | ||
| + // Live window attributes (safe to call from the present thread) | ||
| void getWindowAttributes(CocoaWindowAttributes* attributes) const; | ||
|
|
||
| // Get cached refresh rate, may trigger async update | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-[NSView frame]andbackingScaleFactorare main-thread-only, which is why upstream caches here and refreshes on the main queue. Reading them from the present thread races live resize and Main Thread Checker will flag it. The UIKit half has the same problem, and iOS wasn't rebuilt.Maybe refresh the cache synchronously on the main thread from the SDL resize event instead (
updateWindowAttributesInternal(true)), and keep the present thread reading the cache?