Conversation
… representation `ANativeWindow` is the C counterpart to the `android.view.Surface` object in Java, and has these functions available to convert between the C and Java (JNI representation) variant of it.
|
Looks good, haven't tested this though |
|
I'll quickly try my luck to get this working :) Hold my coffee! :D |
| /// `surface` is a valid pointer to an [`android.view.Surface`]. | ||
| /// | ||
| /// [`android.view.Surface`]: https://developer.android.com/reference/android/view/Surface | ||
| pub unsafe fn from_surface(env: *mut JNIEnv, surface: jobject) -> Option<Self> { |
There was a problem hiding this comment.
Do we somehow need to release this surface? (ANativeWindow_release)
There was a problem hiding this comment.
Nope! You'll get a NativeWindow here which already implements acquire/release semantics in clone() and drop(), respectively.
There was a problem hiding this comment.
I don't know if you need to retain the life of the surface JNI object (in Java land), though - https://developer.android.com/ndk/reference/group/native-activity#anativewindow_fromsurface doesn't specify 😞
All I know is that to_surface gives you a Java Surface which internally keeps the NativeWindow alive, so you don't need to do that at least.
`winit` provides a `raw-window-handle` specifically for crates to process window pointers/references in a crate-agnostic way. `glutin` can use it too, to get rid of its `ndk-glue` dependency which otherwise has a hard versioning dependency as it should be updated in sync with `winit`. Over time this should be worked into the other backends, in turn removing `winit` from the `new_windowed()` function signature and replacing it with `impl HasRawWindowHandle` or `dyn HasRawWindowHandle`. This will also allow Android users to pass generic `Surface`s (first converted to a so-called `NativeWindow` in the NDK through [#272], then passed as `RawWindowHandle` thanks to [#274]) created in Java / Kotlin / Flutter to render to individual UI elements instead of the entire screen with a `NativeActivity` (`ndk-glue`). It'll in turn make the code more generic, too, as `raw-window-handle` has a variant for every platform / windowing system currently supported by glutin. [#272]: rust-mobile/ndk#272 [#274]: rust-mobile/ndk#274
`winit` provides a `raw-window-handle` specifically for crates to process window pointers/references in a crate-agnostic way. `glutin` can use it too, to get rid of its `ndk-glue` dependency which otherwise has a hard versioning dependency as it should be updated in sync with `winit`. Over time this should be worked into the other backends, in turn removing `winit` from the `new_windowed()` function signature and replacing it with `impl HasRawWindowHandle` or `dyn HasRawWindowHandle`. This will also allow Android users to pass generic `Surface`s (first converted to a so-called `NativeWindow` in the NDK through [#272], then passed as `RawWindowHandle` thanks to [#274]) created in Java / Kotlin / Flutter to render to individual UI elements instead of the entire screen with a `NativeActivity` (`ndk-glue`). It'll in turn make the code more generic, too, as `raw-window-handle` has a variant for every platform / windowing system currently supported by glutin. [#272]: rust-mobile/ndk#272 [#274]: rust-mobile/ndk#274

ANativeWindowis the C counterpart to theandroid.view.Surfaceobject in Java, and has these functions available to convert between the C and Java (JNI representation) variant of it.