mirror of
https://github.com/rust-mobile/android-activity.git
synced 2026-07-04 05:47:26 +00:00
Update na-mainloop
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -3,6 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
ndkVersion "25.2.9519653"
|
||||
compileSdk 31
|
||||
|
||||
defaultConfig {
|
||||
@@ -32,6 +33,7 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
namespace 'co.realfit.namainloop'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
@@ -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;
|
||||
@@ -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
|
||||
@@ -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 _);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user