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

[WIP] Android support #1313

Closed
wants to merge 4 commits into from
Closed

Conversation

katyo
Copy link

@katyo katyo commented Jul 7, 2020

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • 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

Linked issues: #1307

@katyo
Copy link
Author

katyo commented Jul 8, 2020

According to current winit's event handling implementation details there is no way directly hook Android's pause/resume events which can be used to create/destroy surface.

@katyo
Copy link
Author

katyo commented Jul 10, 2020

To get it work we need solve at least two issues.

  1. Create context after window actually created.
    This happens when we get WindowCreated event from ndk-glue.
    In winit this event corresponds to Resumed event.
  2. Manage creating and destroying rendering surface.
    This should be done when we get Resume/Suspend events from ndk-glue.
    Winit currently missing corresponding events.

For now I see the next possible solutions:

  1. Change winit API by introducing additional event: WindowEvent::Created related to corresponding event from ndk-glue.
    This event should be place for actual context initialization. On other platforms this event can be triggered synchronous when window created. In this case Resume/Suspend events may corresponds to Android`s one and can be used to manage rendering surface.
  2. Override needed (low-level) callbacks directly in NativeActivity at runtime.
    In that case the main function should be called after WindowCreated event actually received (which requires ndk-glue changes or additional wrapper for it). This solution does not require winit API changes but looks too dirty for me and possibly may have less obvious flaws.

cc @dvc94ch, @goddessfreya, @VZout, @francesca64

@Kaiser1989
Copy link

Here we go, some running example based on your changes:

https://github.com/Kaiser1989/rust-android-example

@dvc94ch
Copy link
Member

dvc94ch commented Jul 12, 2020

Change winit API by introducing additional event: WindowEvent::Created related to corresponding event from ndk-glue.
This event should be place for actual context initialization. On other platforms this event can be triggered synchronous when window created. In this case Resume/Suspend events may corresponds to Android`s one and can be used to manage rendering surface.

Those were removed because @goddessfreya and me came to the conclusion that glutin didn't need to know about those after the improvements to glutin 0.23. I'd still like to see those happen as it makes integrating with for example libflutter_engine.so in flutter-rs much more natural and less error prone. But it looks like no one is willing to update the macos/windows backends :/

Also I don't have the time to work on this stuff at the moment, as due to instability of flutter-rs/winit on desktop platforms and lack of support for mobile platforms we decided to go with "regular" flutter and are using ffi to integrate our rust code into the ui.

PureTryOut added a commit to Lea-fish/Leafish that referenced this pull request Sep 8, 2021
Currently this fails because of an Android incompatibility in glutin:
rust-windowing/glutin#1307
rust-windowing/glutin#1313
PureTryOut added a commit to Lea-fish/Leafish that referenced this pull request Jul 1, 2022
Currently this fails because of an Android incompatibility in glutin:
rust-windowing/glutin#1307
rust-windowing/glutin#1313
PureTryOut added a commit to Lea-fish/Leafish that referenced this pull request Jul 1, 2022
Currently this fails because of an Android incompatibility in glutin:
rust-windowing/glutin#1307
rust-windowing/glutin#1313
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.

4 participants