Skip to content

Commit

Permalink
Merge pull request #90 from rust-mobile/release-0.4.2
Browse files Browse the repository at this point in the history
Release 0.4.2
  • Loading branch information
rib authored Jun 27, 2023
2 parents 1ad3abd + 9a713c8 commit 0f00a58
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 21 deletions.
6 changes: 6 additions & 0 deletions android-activity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]


## [0.4.2] - 2022-02-16
### Changed
- The `Activity.finish()` method is now called when `android_main` returns so the `Activity` will be destroyed ([#67](https://github.com/rust-mobile/android-activity/issues/67))
- The `native-activity` backend now propagates `NativeWindow` redraw/resize and `ContentRectChanged` callbacks to main loop ([#70](https://github.com/rust-mobile/android-activity/pull/70))
- The `game-activity` implementation of `pointer_index()` was fixed to not always return `0` ([#80](https://github.com/rust-mobile/android-activity/pull/84))
- Added `panic` guards around application's `android_main()` and native code that could potentially unwind across a Java FFI boundary ([#68](https://github.com/rust-mobile/android-activity/pull/68))

## [0.4.1] - 2022-02-16
### Added
Expand Down
2 changes: 1 addition & 1 deletion android-activity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "android-activity"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
keywords = ["android", "ndk"]
readme = "../README.md"
Expand Down
2 changes: 2 additions & 0 deletions examples/agdk-mainloop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2021"
log = "0.4"
android_logger = "0.11.0"
android-activity = { path="../../android-activity", features = ["game-activity"] }
ndk-sys = "0.4"
ndk = "0.7"

[lib]
name="main"
Expand Down
2 changes: 2 additions & 0 deletions examples/agdk-mainloop/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

android {
ndkVersion "25.2.9519653"
compileSdk 31

defaultConfig {
Expand Down Expand Up @@ -32,6 +33,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'co.realfit.agdkmainloop'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions examples/agdk-mainloop/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.realfit.agdkmainloop">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
4 changes: 2 additions & 2 deletions examples/agdk-mainloop/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
}

task clean(type: Delete) {
Expand Down
4 changes: 3 additions & 1 deletion examples/agdk-mainloop/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 02 15:39:12 BST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
31 changes: 27 additions & 4 deletions examples/agdk-mainloop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn android_main(app: AndroidApp) {

let mut quit = false;
let mut redraw_pending = true;
let mut render_state: Option<()> = Default::default();
let mut native_window: Option<ndk::native_window::NativeWindow> = None;

while !quit {
app.poll_events(
Expand Down Expand Up @@ -37,11 +37,11 @@ fn android_main(app: AndroidApp) {
}
}
MainEvent::InitWindow { .. } => {
render_state = Some(());
native_window = app.native_window();
redraw_pending = true;
}
MainEvent::TerminateWindow { .. } => {
render_state = None;
native_window = None;
}
MainEvent::WindowResized { .. } => {
redraw_pending = true;
Expand All @@ -65,7 +65,7 @@ fn android_main(app: AndroidApp) {
}

if redraw_pending {
if let Some(_rs) = render_state {
if let Some(native_window) = &native_window {
redraw_pending = false;

// Handle input
Expand All @@ -75,9 +75,32 @@ fn android_main(app: AndroidApp) {
});

info!("Render...");
dummy_render(native_window);
}
}
},
);
}
}

/// Post a NOP frame to the window
///
/// Since this is a bare minimum test app we don't depend
/// on any GPU graphics APIs but we do need to at least
/// convince Android that we're drawing something and are
/// responsive, otherwise it will stop delivering input
/// events to us.
fn dummy_render(native_window: &ndk::native_window::NativeWindow) {
unsafe {
let mut buf: ndk_sys::ANativeWindow_Buffer = std::mem::zeroed();
let mut rect: ndk_sys::ARect = std::mem::zeroed();
ndk_sys::ANativeWindow_lock(
native_window.ptr().as_ptr() as _,
&mut buf as _,
&mut rect as _,
);
// Note: we don't try and touch the buffer since that
// also requires us to handle various buffer formats
ndk_sys::ANativeWindow_unlockAndPost(native_window.ptr().as_ptr() as _);
}
}
2 changes: 2 additions & 0 deletions examples/na-mainloop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2021"
log = "0.4"
android_logger = "0.11.0"
android-activity = { path="../../android-activity", features = [ "native-activity" ] }
ndk-sys = "0.4"
ndk = "0.7"

[lib]
#name="na_mainloop"
Expand Down
2 changes: 2 additions & 0 deletions examples/na-mainloop/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

android {
ndkVersion "25.2.9519653"
compileSdk 31

defaultConfig {
Expand Down Expand Up @@ -32,6 +33,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'co.realfit.namainloop'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions examples/na-mainloop/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.realfit.namainloop">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
4 changes: 2 additions & 2 deletions examples/na-mainloop/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'com.android.application' version '8.0.0' apply false
id 'com.android.library' version '8.0.0' apply false
}

task clean(type: Delete) {
Expand Down
4 changes: 3 additions & 1 deletion examples/na-mainloop/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ android.useAndroidX=true
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 02 15:39:12 BST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
31 changes: 27 additions & 4 deletions examples/na-mainloop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn android_main(app: AndroidApp) {

let mut quit = false;
let mut redraw_pending = true;
let mut render_state: Option<()> = Default::default();
let mut native_window: Option<ndk::native_window::NativeWindow> = None;

while !quit {
app.poll_events(
Expand Down Expand Up @@ -37,11 +37,11 @@ fn android_main(app: AndroidApp) {
}
}
MainEvent::InitWindow { .. } => {
render_state = Some(());
native_window = app.native_window();
redraw_pending = true;
}
MainEvent::TerminateWindow { .. } => {
render_state = None;
native_window = None;
}
MainEvent::WindowResized { .. } => {
redraw_pending = true;
Expand All @@ -65,7 +65,7 @@ fn android_main(app: AndroidApp) {
}

if redraw_pending {
if let Some(_rs) = render_state {
if let Some(native_window) = &native_window {
redraw_pending = false;

// Handle input
Expand All @@ -75,9 +75,32 @@ fn android_main(app: AndroidApp) {
});

info!("Render...");
dummy_render(native_window);
}
}
},
);
}
}

/// Post a NOP frame to the window
///
/// Since this is a bare minimum test app we don't depend
/// on any GPU graphics APIs but we do need to at least
/// convince Android that we're drawing something and are
/// responsive, otherwise it will stop delivering input
/// events to us.
fn dummy_render(native_window: &ndk::native_window::NativeWindow) {
unsafe {
let mut buf: ndk_sys::ANativeWindow_Buffer = std::mem::zeroed();
let mut rect: ndk_sys::ARect = std::mem::zeroed();
ndk_sys::ANativeWindow_lock(
native_window.ptr().as_ptr() as _,
&mut buf as _,
&mut rect as _,
);
// Note: we don't try and touch the buffer since that
// also requires us to handle various buffer formats
ndk_sys::ANativeWindow_unlockAndPost(native_window.ptr().as_ptr() as _);
}
}

0 comments on commit 0f00a58

Please sign in to comment.