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

Basic android event loop 2.0 #2

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ jobs:
- { target: i686-pc-windows-gnu, os: windows-latest, host: -i686-pc-windows-gnu }
- { target: i686-unknown-linux-gnu, os: ubuntu-latest, }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, }
- { target: aarch64-linux-android, os: ubuntu-latest, cmd: 'apk --' }
- { target: x86_64-apple-darwin, os: macos-latest, }
- { target: x86_64-apple-ios, os: macos-latest, }
- { target: aarch64-apple-ios, os: macos-latest, }
# We're using Windows rather than Ubuntu to run the wasm tests because caching cargo-web
# doesn't currently work on Linux.
- { target: wasm32-unknown-unknown, os: windows-latest, features: stdweb, web: web }
- { target: wasm32-unknown-unknown, os: windows-latest, features: web-sys, web: web }
- { target: wasm32-unknown-unknown, os: windows-latest, features: stdweb, cmd: web }
- { target: wasm32-unknown-unknown, os: windows-latest, features: web-sys, cmd: web }

env:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-C debuginfo=0"
FEATURES: ${{ format(',{0}', matrix.platform.features ) }}
WEB: ${{ matrix.platform.web }}
CMD: ${{ matrix.platform.cmd }}

runs-on: ${{ matrix.platform.os }}
steps:
Expand Down Expand Up @@ -116,6 +117,9 @@ jobs:
- name: Install GCC Multilib
if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686')
run: sudo apt-get update && sudo apt-get install gcc-multilib
- name: Install cargo-apk
if: contains(matrix.platform.target, 'android')
run: cargo install cargo-apk
- name: Install cargo-web
continue-on-error: true
if: contains(matrix.platform.target, 'wasm32')
Expand All @@ -124,29 +128,35 @@ jobs:
- name: Check documentation
shell: bash
if: matrix.platform.target != 'wasm32-unknown-unknown'
run: cargo doc --no-deps --target ${{ matrix.platform.target }} --features $FEATURES
run: cargo $CMD doc --no-deps --target ${{ matrix.platform.target }} --features $FEATURES

- name: Build
shell: bash
run: cargo $WEB build --verbose --target ${{ matrix.platform.target }} --features $FEATURES
run: cargo $CMD build --verbose --target ${{ matrix.platform.target }} --features $FEATURES

- name: Build tests
shell: bash
run: cargo $WEB test --no-run --verbose --target ${{ matrix.platform.target }} --features $FEATURES
run: cargo $CMD test --no-run --verbose --target ${{ matrix.platform.target }} --features $FEATURES
- name: Run tests
shell: bash
if: (!contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'wasm32'))
run: cargo $WEB test --verbose --target ${{ matrix.platform.target }} --features $FEATURES
if: (
!contains(matrix.platform.target, 'android') &&
!contains(matrix.platform.target, 'ios') &&
!contains(matrix.platform.target, 'wasm32'))
run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} --features $FEATURES


- name: Build with serde enabled
shell: bash
run: cargo $WEB build --verbose --target ${{ matrix.platform.target }} --features serde_feature,$FEATURES
run: cargo $CMD build --verbose --target ${{ matrix.platform.target }} --features serde_feature,$FEATURES

- name: Build tests with serde enabled
shell: bash
run: cargo $WEB test --no-run --verbose --target ${{ matrix.platform.target }} --features serde_feature,$FEATURES
run: cargo $CMD test --no-run --verbose --target ${{ matrix.platform.target }} --features serde_feature,$FEATURES
- name: Run tests with serde enabled
shell: bash
if: (!contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'wasm32'))
run: cargo $WEB test --verbose --target ${{ matrix.platform.target }} --features serde_feature,$FEATURES
if: (
!contains(matrix.platform.target, 'android') &&
!contains(matrix.platform.target, 'ios') &&
!contains(matrix.platform.target, 'wasm32'))
run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} --features serde_feature,$FEATURES
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ image = "0.22.4"
simple_logger = "1.4.0"

[target.'cfg(target_os = "android")'.dependencies]
android_glue = "0.2.3"
ndk = { path = "../android-ndk-rs/ndk" }
ndk-glue = { path = "../android-ndk-rs/ndk-glue" }
ndk-sys = { path = "../android-ndk-rs/ndk-sys" }

[target.'cfg(target_os = "ios")'.dependencies]
objc = "0.2.7"
Expand Down
82 changes: 67 additions & 15 deletions src/platform/android.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,85 @@
#![cfg(any(target_os = "android"))]

use crate::{EventLoop, Window, WindowBuilder};
use std::os::raw::c_void;
use crate::event_loop::{EventLoop, EventLoopWindowTarget};
use crate::window::{Window, WindowBuilder};
use glutin_interface::{
AndroidWindowParts, NativeDisplay, NativeWindow, NativeWindowSource, RawDisplay, RawWindow,
Seal,
};
use ndk::configuration::Configuration;
use ndk_glue::Rect;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use winit_types::dpi::PhysicalSize;
use winit_types::error::Error;

/// Additional methods on `EventLoop` that are specific to Android.
pub trait EventLoopExtAndroid {
/// Makes it possible for glutin to register a callback when a suspend event happens on Android
fn set_suspend_callback(&self, cb: Option<Box<dyn Fn(bool) -> ()>>);
}
pub trait EventLoopExtAndroid {}

impl EventLoopExtAndroid for EventLoop {
fn set_suspend_callback(&self, cb: Option<Box<dyn Fn(bool) -> ()>>) {
self.event_loop.set_suspend_callback(cb);
}
}
impl<T> EventLoopExtAndroid for EventLoop<T> {}

/// Additional methods on `EventLoopWindowTarget` that are specific to Android.
pub trait EventLoopWindowTargetExtAndroid {}

/// Additional methods on `Window` that are specific to Android.
pub trait WindowExtAndroid {
fn native_window(&self) -> *const c_void;
fn content_rect(&self) -> Rect;

fn config(&self) -> Configuration;
}

impl WindowExtAndroid for Window {
#[inline]
fn native_window(&self) -> *const c_void {
self.window.native_window()
fn content_rect(&self) -> Rect {
self.window.content_rect()
}

fn config(&self) -> Configuration {
self.window.config()
}
}

/// Additional methods on `WindowBuilder` that are specific to Android.
pub trait WindowBuilderExtAndroid {}

impl WindowBuilderExtAndroid for WindowBuilder {}

impl NativeWindow for Window {
fn raw_window(&self) -> RawWindow {
if let RawWindowHandle::Android(handle) = self.raw_window_handle() {
RawWindow::Android {
a_native_window: handle.a_native_window,
_non_exhaustive_do_not_use: Seal,
}
} else {
unreachable!()
}
}

fn size(&self) -> PhysicalSize<u32> {
self.inner_size()
}

fn scale_factor(&self) -> f64 {
self.scale_factor()
}
}

impl<T> NativeDisplay for EventLoopWindowTarget<T> {
fn raw_display(&self) -> RawDisplay {
RawDisplay::Android {
_non_exhaustive_do_not_use: Seal,
}
}
}

impl<T> NativeWindowSource for EventLoopWindowTarget<T> {
type Window = Window;
type WindowBuilder = WindowBuilder;

fn build_android(
&self,
wb: Self::WindowBuilder,
_awp: AndroidWindowParts,
) -> Result<Self::Window, Error> {
wb.build(self)
}
}
122 changes: 0 additions & 122 deletions src/platform_impl/android/ffi.rs

This file was deleted.

Loading