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

Update to new raw-window-handle strategy #3126

Merged
merged 12 commits into from
Oct 15, 2023
Merged

Update to new raw-window-handle strategy #3126

merged 12 commits into from
Oct 15, 2023

Conversation

notgull
Copy link
Member

@notgull notgull commented Oct 1, 2023

  • Tested on all platforms changed
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

Essentially a combination of #3075 and #2943. This PR adds explicit support for raw-window-handle v0.6 through the rwh_06 feature, which is enabled by default. It also adds optional support for raw-window-handle v0.5 and raw-window-handle v0.4, which is exposed through features that are not exposed by default.

This also adds a lifetime to WindowAttributes.

Copy link
Member

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

Web is LGTM.

Copy link
Member

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Thanks for following up on this @notgull!

macOS and iOS impl approved, have opened some discussion on the API though that I would like to see resolved.

src/window.rs Outdated Show resolved Hide resolved
Comment on lines 1560 to 1557
/// Returns a [`raw_window_handle::RawDisplayHandle`] used by the [`EventLoop`] that
/// created a window.
///
/// [`EventLoop`]: crate::event_loop::EventLoop
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This documentation is also relevant for v0.6

Copy link
Contributor

Choose a reason for hiding this comment

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

you mean, that this should also be added to the implementation of HasDisplayHandle for v0.6?

Copy link
Member

Choose a reason for hiding this comment

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

Yup

src/lib.rs Outdated Show resolved Hide resolved
examples/child_window.rs Outdated Show resolved Hide resolved
src/platform/windows.rs Outdated Show resolved Hide resolved
src/platform_impl/ios/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
src/platform_impl/macos/window.rs Outdated Show resolved Hide resolved
Copy link
Member

@kchibisov kchibisov left a comment

Choose a reason for hiding this comment

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

Could you expect instead of doing unchecked? I'd rather not have more unsafe and have an actual assert that it got a Null for whatever reason.

It'll basically never happen, but the cost of checking null in a function you rarely call is non-existent.

Cargo.toml Show resolved Hide resolved
examples/util/fill.rs Outdated Show resolved Hide resolved
@TornaxO7
Copy link
Contributor

TornaxO7 commented Oct 4, 2023

@notgull maybe not needed, but just in case, I fixed the CI build in this PR

@TornaxO7
Copy link
Contributor

TornaxO7 commented Oct 6, 2023

Could you expect instead of doing unchecked? I'd rather not have more unsafe and have an actual assert that it got a Null for whatever reason.

It'll basically never happen, but the cost of checking null in a function you rarely call is non-existent.

may I ask which unchecked places you mean?
rg -trust "unchecked" returns no entries, if I'm seeing it correctly, related with the HasDisplayHandle and HasWindowHandle.

@kchibisov
Copy link
Member

@TornaxO7 comments are getting resolved over time. This particular one was removed. See 9e15334

if let Some(native_window) = self.app.native_window().as_ref() {
let handle = rwh_06::AndroidNdkWindowHandle::new(native_window.ptr().cast());
Ok(rwh_06::RawWindowHandle::AndroidNdk(handle))
} else {
Copy link
Member

Choose a reason for hiding this comment

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

I'm implementing this in the NDK, as part of version bumps.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

May I ask what that means? Does anything has to do be done here or can this be marked as resolved?

Copy link
Member

Choose a reason for hiding this comment

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

This means that once I publish ndk 0.8.0, winit should upgrade to it (it's on -beta.0 now) and reuse the traits provided there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does this block this PR? I think that this should be merged in its current state and then we can upgrade to the latest ndk later.

Copy link
Member

Choose a reason for hiding this comment

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

It does not and I can patch this when submitting the final ndk bump inside winit.

}

#[cfg(feature = "rwh_06")]
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
Copy link
Member

Choose a reason for hiding this comment

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

Question while implementing the ndk portion for this: implementing the Has**RAW**WindowHandle trait is deprecated and there are blanket implementations when HasWindowHandle is implemented. Should this function also return a non-raw handle (in terms of that implementation when it is released)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered this, but it would add an additional unsafe { WIndowHandle::borrow_raw } call for each backend. I could go either way.

Copy link
Member

Choose a reason for hiding this comment

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

Right. At least for Android I'm willing to have that unsafe { borrow_raw() } inside the ndk with appropriate // SAFETY docs, so you could call through to that. But it'd have to be consistent across all the backends...

Copy link
Member

Choose a reason for hiding this comment

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

Did you consider whether or not the safe borrow handles should be implemented by winit?

Copy link
Member Author

Choose a reason for hiding this comment

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

For the time being it leads to a lot more unsafe throughout the codebase. So I think that we shouldn't for now.

MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 7, 2023
…0.5)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.6` behind a
corresponding `rwh_06` feature.  Implement the new non-raw trait and
**lifetimed** type for `0.6` (where `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types).

[the same strategy in winit]: rust-windowing/winit#3126
MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 7, 2023
…0.5)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.6` behind a
corresponding `rwh_06` feature.  Implement the new non-raw trait and
**lifetimed** type for `0.6` (where `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types).

[the same strategy in winit]: rust-windowing/winit#3126
MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 8, 2023
…0.5)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.6` behind a
corresponding `rwh_06` feature.  Implement the new non-raw trait and
**lifetimed** type for `0.6` (where `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types).

[the same strategy in winit]: rust-windowing/winit#3126
MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 8, 2023
…aintain 0.5)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.4` and the newly
released `raw-window-handle 0.6` behind a corresponding `rwh04`/`rwh_06`
feature.  The new **non-raw** trait and **lifetimed** type since `0.6`
have been implemented instead, as `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types.

[the same strategy in winit]: rust-windowing/winit#3126
MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 8, 2023
…aintain 0.5)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.4` and the newly
released `raw-window-handle 0.6` behind a corresponding `rwh04`/`rwh_06`
feature.  The new **non-raw** trait and **lifetimed** type since `0.6`
have been implemented instead, as `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types.

[the same strategy in winit]: rust-windowing/winit#3126
MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 8, 2023
…aintain 0.5)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.4` and the newly
released `raw-window-handle 0.6` behind a corresponding `rwh04`/`rwh_06`
feature.  The new **non-raw** trait and **lifetimed** type since `0.6`
have been implemented instead, as `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types.

[the same strategy in winit]: rust-windowing/winit#3126
MarijnS95 added a commit to rust-mobile/ndk that referenced this pull request Oct 8, 2023
…aintain 0.5) (#434)

Following [the same strategy in winit], move `raw-window-handle 0.5`
behind a `rwh_05` feature and add `raw-window-handle 0.4` and the newly
released `raw-window-handle 0.6` behind a corresponding `rwh04`/`rwh_06`
feature.  The new **non-raw** trait and **lifetimed** type since `0.6`
have been implemented instead, as `raw-window-handle` provides blanket
implementations to coerce/convert back to `Raw*` types.

[the same strategy in winit]: rust-windowing/winit#3126
@madsmtm madsmtm mentioned this pull request Oct 13, 2023
3 tasks
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
notgull and others added 10 commits October 14, 2023 09:12
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
Co-Authored-By: TornaxO7 <tornax@proton.me>
Signed-off-by: John Nunley <dev@notgull.net>
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Approving the android changes, but still have a question about borrowed handles.

@kchibisov kchibisov merged commit e41fac8 into master Oct 15, 2023
50 checks passed
@kchibisov kchibisov deleted the notgull/rwh06 branch October 15, 2023 02:07
nicopap added a commit to nicopap/accesskit that referenced this pull request Dec 14, 2023
This allows using accesskit with current versions of wgpu.

Winit has a similar system to widden its support. See

rust-windowing/winit#3126
nicopap added a commit to nicopap/accesskit that referenced this pull request Dec 14, 2023
This allows using accesskit with current versions of wgpu.

Winit has a similar system to widden its support. See

rust-windowing/winit#3126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants