347 Commits

Author SHA1 Message Date
Robert Bragg 14eb2f0a17 Merge pull request #49 from rust-mobile/demote-spam
native_activity: Demote spammy `info!`/`eprintln!` debug logs to `trace!`
2022-12-20 16:59:40 +00:00
Robert Bragg 8f68cb5db9 Merge pull request #47 from rust-mobile/remove-unneeded-backslash-escape
Remove backslash-escaping of quotes in raw string
2022-12-20 16:29:53 +00:00
Marijn Suijten b217ad546c Remove backslash-escaping of quotes in raw string
In a raw string [no escaping is processed] nor are these quotes treated
specially unless it was postfixed with `#`; the backslashes show up in
the compiler error displayed to the user instead.

For consistency the string this was likely copied from is now also
turned into a raw string literal, with backslashes equivalently removed.

[no escaping is processed]: https://doc.rust-lang.org/reference/tokens.html#raw-string-literals
2022-12-14 20:51:39 +01:00
Marijn Suijten bf251c63cd native_activity: Demote spammy info!/eprintln! debug logs to trace!
Ideally information - especially when spamming per `Looper` poll - used
for debugging `android-activity` doesn't show to the user unless they
use the `Trace` level (eventually for this specific crate/module).  This
is already adhered to in most places of the code but there were a few
high-volume cases still remaining.
2022-12-14 20:09:16 +01:00
Robert Bragg 1633f62d0d Merge pull request #39 from rib/release-0.4
Release 0.4
2022-11-14 16:06:52 +00:00
Robert Bragg 6ca4ea2e30 Release 0.4.0 v0.4.0 2022-11-13 15:15:24 +00:00
Robert Bragg 9640893477 Update README 2022-11-13 15:15:24 +00:00
Robert Bragg fab31d3408 Thin MotionEvent + KeyEvent types with lifetimes
This patch is addressing two notable issues:
1. MotionEvents with the GameActivity backend were extremely large and
   forced us to copy lots of redundant padding from the internal
   circular buffer of events when calling an apps `input_events()`
   callback.
2. MotionEvents + KeyEvents with the NativeActivity backend (re-exported
   from the ndk crate) simply wrapped a raw pointer but had no lifetime
   that would stop applications from keeping them too long and then
   potentially dereferencing an invalid pointer.

The common change is that `InputEvent` is now defined with a lifetime
parameter which makes it possible for Motion and Key events to hold
references that let them avoid copying large amounts of state.

The `Source` and `Class` enums were also moved out of the GameActivity
backend so they could be shared since there was some inconsistency
between the backends with these types.

Overall this doesn't, practically, affect the public API

GameActivity
============

On the GameActivity side the events will now point into the internal
circular buffer that is iterated during `input_events()` and so
the `MotionEvent` type is now a thin wrapper over a reference.

This removes the `Iterator` implementations we had internally for
iterating key/motion events because we effectively need a lending
iterator now. It's also noted that while our MSRV is 1.60 we can't use
GATs to implement the interation in terms of a LendingIterator trait.
(This is fine in practice because this iteration is a private
implementation detail and so we can have lending iteration without any
traits for now)

NativeActivity
==============

On the NativeActivity side we now have newtype wrappers around
MotionEvent and KeyEvent from the ndk crate. These newtypes add a
lifetime and implement all the same passthrough methods as the
corresponding GameActivity types.

This added more boilerplate to the NativeActivity backend but it
also improves consistency between the backends.

Fixes: #40
Fixes: #41
2022-11-11 20:44:19 +00:00
Robert Bragg 38554d98db Clippy fixes 2022-11-11 20:44:19 +00:00
Robert Bragg aa5fcc53bb Improve docs
This removes the indirection of the `StateSaver` and `StateLoader`
type aliases (which resulted in no documentation for these interfaces)
and we now simply re-export the types from the backend implementation.
2022-11-11 20:44:18 +00:00
Robert Bragg 4669508823 examples/*-winit-wgpu: make less verbose
This updates the *-winit-wgpu examples to use `log::info!` instead of `trace!`
and sets the log level to `Info`

The examples now also print info about and Winit Window events.

This makes them more practical to use to see how Winit events
are delivered without lots of tracing spam from dependency crates.
2022-11-11 20:44:18 +00:00
Robert Bragg 649b65c0c0 Update examples
- Updates deps
- Some README updates considering the Winit backend based on
  android-activity has been merged upstream
- runs cargo fmt over examples
- Top-level Cargo.toml simply excludes "examples" instead of
  listing each sub-directory separately
2022-11-10 19:28:01 +00:00
Robert Bragg c75f33a81e game_activity/input: support Pointer::tool_type()
This maintains compatibility with the `ndk` crate's `Pointer` API

Ref: https://github.com/rust-windowing/android-ndk-rs/pull/323

This will also be required for enabling pen pressure support to
Winit, re: https://github.com/rust-windowing/winit/pull/2396
2022-10-23 01:36:56 +01:00
Robert Bragg bd8cc86ec7 Adds a minimal na-winit-glutin example
This example shows how to draw a triangle with GL[ES via the Glutin
crate (the app works on desktop and Android) and on Android it
demonstrates how to re-create the applications surface state when
it is paused and resumed.

The Renderer code and some utilities are from the upstream Glutin example.
2022-10-23 00:51:32 +01:00
Robert Bragg e8ae198653 Update example deps + update for latest winit branch
The winit based examples no longer have an explicit dependency on
android-activity and they instead consume the `android-activity` API via
the Winit crate so there's no need to keep the versions synchronized.
2022-10-22 21:51:27 +01:00
Robert Bragg 1ece2ad87d Update README.md
Update example (copy from na-mainloop)
2022-10-18 19:38:22 +01:00
Robert Bragg 8077a4b0da Update Winit-based examples for Release 0.4.0-beta.1 2022-10-11 20:19:15 +01:00
Robert Bragg 364dffb2f7 Release 0.4.0-beta.1 2022-10-11 19:44:18 +01:00
Robert Bragg 0590bf601a Merge pull request #35 from rib/pure-rust-native-activity
Pure-Rust native activity backend
2022-10-11 19:12:40 +01:00
Robert Bragg c3d115fd7b CHANGELOG: note that native-activity backend is pure-Rust now 2022-10-11 18:50:11 +01:00
Robert Bragg 1ed7d383e0 native-activity: track saved state as a Vec<u8>
This simplifies the tracking of saved state by simply using a Vec and
only copying into a `malloc()` allocation when passing the saved state
to `ANativeActivity`.

This also ensures saved state persists (in Rust) between a
`MainEvent::SaveState` event and a `Resume` event - otherwise the saved
state would only be restored in the situation where `onCreate` is called
again for a new process.
2022-10-11 18:50:05 +01:00
Robert Bragg 2e25e2ebed native-activity: fix 1.60.0 compilation - don't derive Default for enum 2022-10-11 17:57:18 +01:00
Robert Bragg 949386ea4e native-activity: fix Weak ref from_raw + upgrade + into_raw handling for callbacks
This adds a common `try_with_waitable_activity_ref` utility that handles
upgrading the Weak reference associated with `ANativeActivity` whenever
we get an activity callback.

Previously we weren't converting the Weak reference back to a pointer
before returning from the callback which would result in us dropping the
Weak reference after the first callback.
2022-10-11 17:14:04 +01:00
Robert Bragg 879d7cac5a native-activity: use eprintln for early logging (before app sets up logging) 2022-10-11 17:10:15 +01:00
Robert Bragg cd32b4a064 native-activity: re-work ported glue code into idiomatic Rust
This is a fairly thorough re-working of all the code that was initially
naively ported from android_native_app_glue.c to be more idiomatic Rust
code (though by it's nature it still involves a lot of unsafe code)

Most of the glue code now lives in src/native_activity/glue.rs as part
of a NativeActivityGlue API

The design as far as the threading model, IPC and synchronization goes
is unchanged.
2022-10-08 14:39:21 +01:00
Robert Bragg 2870a84fbe native-activity: rename ported android_app state to be more idiomatic 2022-10-08 14:39:21 +01:00
Robert Bragg 3de1433f82 native-activity: complete (first-pass) port of C code to Rust
At this point the C code has been fully ported to Rust but it's not yet
well integrated with the pre-existing Rust code and the port is not yet
particularly idiomatic Rust code.
2022-10-08 14:39:21 +01:00
Robert Bragg 1507b37425 native-activity: port android_app_entry (mainloop init) from C to Rust 2022-10-08 14:39:21 +01:00
Robert Bragg 1314210be4 native-activity: complete port of sender/java-side C code to Rust 2022-10-08 14:39:21 +01:00
Robert Bragg a65729400b native-activity: Port android_app_create/free from C to Rust
A literal port for now, with the intention of re-working into more
idiomatic Rust code once we have a port of all the C code.
2022-10-08 14:39:21 +01:00
Robert Bragg 2d44950d14 native-activity: Migrate ANativeActivity callbacks to Rust
A first step towards replacing the android_native_app_glue code with a
pure Rust implementation.
2022-10-08 14:39:21 +01:00
Robert Bragg b13a53f182 Update Winit-based examples for Release 0.4.0-beta 2022-09-20 03:43:34 +01:00
Marijn Suijten b717c03dda Update README.md 2022-09-20 03:24:00 +01:00
Robert Bragg 42d6a7247e Merge pull request #33 from rib/v0.4
Release 0.4.0-beta
2022-09-20 03:21:10 +01:00
Robert Bragg 47afecda36 Release 0.4.0-beta 2022-09-20 02:56:05 +01:00
Robert Bragg 17f0c674c0 Don't ignore Cargo.lock files for examples 2022-09-20 00:41:21 +01:00
Robert Bragg 8ae1059aec na-openxr-wgpu: don't depend on specific version of android-activity 2022-09-20 00:32:09 +01:00
Robert Bragg 7cdb77eca4 Let applications report if they handled input events
The callback given to `AndroidApp::input_events()` is now expected to return
`InputStatus::Handled` or `InputStatus::Unhandled`.

When running with NativeActivity then if we know an input event hasn't been
handled we can notify the InputQueue which may result in fallback
handling.

Although the status is currently ignored with the GameActivity backend.

Since this is a breaking change that also affects the current Winit
backend this updates the winit based examples to stick with the 0.3
release of android-activity for now.

Fixes: #31
2022-09-20 00:14:38 +01:00
Robert Bragg 6245866228 Add 0.3 changes to Changelog 2022-09-19 23:12:34 +01:00
Robert Bragg 5c876308c1 examples: update deps (including bump to cpal 0.14) 2022-09-19 15:02:26 +01:00
Robert Bragg 351d0e9ddb Merge pull request #29 from msiglreith/na-winit-wgpu
update na-winit-wgpu example
2022-09-18 16:58:07 +01:00
msiglreith e689461580 na-winit-wgpu: update shader and use native-activity instead of game-activity 2022-09-18 16:10:07 +02:00
Robert Bragg ac46815956 Merge pull request #28 from rib/v0.3
Release 0.3
2022-09-17 18:09:01 +01:00
Robert Bragg bc177292d2 Release 0.3 v0.3.0 2022-09-16 14:07:06 +01:00
Robert Bragg 8d30454c8d native-activity: InputEvent forward compatibility
When building with native-activity then we no longer directly use
the `ndk::InputEvent` type and instead have our own extensible,
`#[non_exhaustive]` enum that ensures we will be able to add an
event for Ime state changes without necessarily needing a semver
bump.

Addresses: #18
2022-09-15 17:12:08 +01:00
Robert Bragg feff63ae78 Add show/hide_soft_input methods
This adds `AndroidApp::show/hide_soft_input` APIs for showing or
hiding the user's on-screen keyboard. (supported for NativeActivity
and GameActivity)

Addresses: #18
2022-09-15 17:12:08 +01:00
Robert Bragg 48993acf58 Support changing window manager params
This enables support for changing the various WindowManager
parameters documented here:
https://developer.android.com/reference/android/view/WindowManager.LayoutParams

either via NativeActivity_setWindowFlags or GameActivity_setWindowFlags

Fixes: #25
2022-09-15 16:48:37 +01:00
Robert Bragg 7d73e57364 Extend compiler_error for missing feature to warn of duplicate implementations 2022-09-15 16:48:37 +01:00
Robert Bragg 781e1fd658 ci: string in expressions should use single quotes 2022-09-01 14:48:03 +01:00
Robert Bragg 16391c4956 ci: add missing quotes 2022-09-01 14:43:08 +01:00