-
Notifications
You must be signed in to change notification settings - Fork 111
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
ndk/native_window: Add bindings to convert to and from Java Surface
representation
#272
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 |
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.
/// `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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we somehow need to release this surface? (ANativeWindow_release
)
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ANativeWindow
is the C counterpart to theandroid.view.Surface
object in Java, and has these functions available to convert between the C and Java (JNI representation) variant of it.