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

Emit Suspended on every platform before LoopDestroyed for surface-cleanup feature parity? #3206

Open
MarijnS95 opened this issue Nov 1, 2023 · 4 comments
Labels
S - platform parity Unintended platform differences

Comments

@MarijnS95
Copy link
Member

As we have done in #2331 by emitting Resumed on every platform somewhere after the loop starts (for platforms that don't have an explicit point/callback where this should happen) to consistently implement surface creation, we should likely do the same with Suspended on loop shutdown for platforms that don't have an explicit callback here. This will allow implementers to perform surface destruction in a single consistent place too.

I'm currently improving a random winit sample to utilize these events, and the implementation becomes clumsy when having surface destruction in both LoopExiting and Suspended. It might even conflict with WindowEvent::Destroyed.

On Android I'm not yet sure if triggering a loop exit would terminate the Android app in such a way that surface destruction (== Suspended) is raised prior to LoopExiting anyway.


Side-note: Android supports multiple windows, and once the backend crates handle that properly perhaps Resumed needs to be moved to a WindowEvent, and Suspended will become Destroyed?

@MarijnS95 MarijnS95 added the S - platform parity Unintended platform differences label Nov 7, 2023
@MarijnS95
Copy link
Member Author

CC @rib @notgull @kchibisov, thoughts about this one?

@notgull
Copy link
Member

notgull commented Nov 7, 2023

I'm fine with this

@daxpedda
Copy link
Member

daxpedda commented Nov 9, 2023

This affects Web as well, I'm in favor of this!

Side-note: Android supports multiple windows, and once the backend crates handle that properly perhaps Resumed needs to be moved to a WindowEvent, and Suspended will become Destroyed?

Can't talk about other backends, but at least on Web this is weird because a Window doesn't represent an actual window, but just a canvas (see #696, which might attempt to change this, though I'm not sure how this affects the logic of all this for other backends, e.g. Android). So a single Window can't be independently suspended.

@MarijnS95
Copy link
Member Author

On Android a winit::Window should - theoretically when we fix everything - represent an Activity, which really is analogous to a desktop window. These typically have only one drawable surface for native apps/games 1.

When one goes out of view and is paused (because activities are mostly fullscreen) their backing surface could be Suspended, so that might not map to Web then. But we could still start with consistently emitting the event "somewhere" before LoopExit.

One thing I haven't really looked into, but which we'll need to is loop consistency. For example on Android, do we use the proper APIs to destroy the app and receive a NativeWindowDestroyed (resulting in winit::Event::Suspended) before exiting the loop, or should we emulate it if the window is still there?

Footnotes

  1. But you could definitely have more, i.e. one can create Surfaces in Android's "view root" that are all individual raw-"window"-handles that can be bound to GL/Vulkan Surfaces/Swapchains and rendered to, as individual buffer producers that are sent to the compositor.

@madsmtm madsmtm mentioned this issue May 27, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S - platform parity Unintended platform differences
Development

No branches or pull requests

3 participants