Support drawing on iOS in examples
Softbuffer v0.4.6 added support for iOS.
This commit is contained in:
parent
b674d20edf
commit
dfea49f488
2 changed files with 15 additions and 15 deletions
|
|
@ -91,8 +91,8 @@ image = { version = "0.25.0", default-features = false, features = ["png"] }
|
||||||
tracing = { version = "0.1.40", default-features = false, features = ["log"] }
|
tracing = { version = "0.1.40", default-features = false, features = ["log"] }
|
||||||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
|
|
||||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dev-dependencies]
|
[target.'cfg(not(target_os = "android"))'.dev-dependencies]
|
||||||
softbuffer = { version = "0.4.0", default-features = false, features = [
|
softbuffer = { version = "0.4.6", default-features = false, features = [
|
||||||
"x11",
|
"x11",
|
||||||
"x11-dlopen",
|
"x11-dlopen",
|
||||||
"wayland",
|
"wayland",
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -11,9 +11,9 @@ use std::{fmt, mem};
|
||||||
|
|
||||||
use ::tracing::{error, info};
|
use ::tracing::{error, info};
|
||||||
use cursor_icon::CursorIcon;
|
use cursor_icon::CursorIcon;
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
use rwh_06::{DisplayHandle, HasDisplayHandle};
|
use rwh_06::{DisplayHandle, HasDisplayHandle};
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
use softbuffer::{Context, Surface};
|
use softbuffer::{Context, Surface};
|
||||||
use winit::application::ApplicationHandler;
|
use winit::application::ApplicationHandler;
|
||||||
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
|
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
|
||||||
|
|
@ -83,14 +83,14 @@ struct Application {
|
||||||
/// Drawing context.
|
/// Drawing context.
|
||||||
///
|
///
|
||||||
/// With OpenGL it could be EGLDisplay.
|
/// With OpenGL it could be EGLDisplay.
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
context: Option<Context<DisplayHandle<'static>>>,
|
context: Option<Context<DisplayHandle<'static>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application {
|
impl Application {
|
||||||
fn new(event_loop: &EventLoop, receiver: Receiver<Action>, sender: Sender<Action>) -> Self {
|
fn new(event_loop: &EventLoop, receiver: Receiver<Action>, sender: Sender<Action>) -> Self {
|
||||||
// SAFETY: we drop the context right before the event loop is stopped, thus making it safe.
|
// SAFETY: we drop the context right before the event loop is stopped, thus making it safe.
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
let context = Some(
|
let context = Some(
|
||||||
Context::new(unsafe {
|
Context::new(unsafe {
|
||||||
std::mem::transmute::<DisplayHandle<'_>, DisplayHandle<'static>>(
|
std::mem::transmute::<DisplayHandle<'_>, DisplayHandle<'static>>(
|
||||||
|
|
@ -119,7 +119,7 @@ impl Application {
|
||||||
Self {
|
Self {
|
||||||
receiver,
|
receiver,
|
||||||
sender,
|
sender,
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
context,
|
context,
|
||||||
custom_cursors,
|
custom_cursors,
|
||||||
icon,
|
icon,
|
||||||
|
|
@ -545,7 +545,7 @@ impl ApplicationHandler for Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
fn exiting(&mut self, _event_loop: &dyn ActiveEventLoop) {
|
fn exiting(&mut self, _event_loop: &dyn ActiveEventLoop) {
|
||||||
// We must drop the context here.
|
// We must drop the context here.
|
||||||
self.context = None;
|
self.context = None;
|
||||||
|
|
@ -559,7 +559,7 @@ struct WindowState {
|
||||||
/// Render surface.
|
/// Render surface.
|
||||||
///
|
///
|
||||||
/// NOTE: This surface must be dropped before the `Window`.
|
/// NOTE: This surface must be dropped before the `Window`.
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
surface: Surface<DisplayHandle<'static>, Arc<dyn Window>>,
|
surface: Surface<DisplayHandle<'static>, Arc<dyn Window>>,
|
||||||
/// The actual winit Window.
|
/// The actual winit Window.
|
||||||
window: Arc<dyn Window>,
|
window: Arc<dyn Window>,
|
||||||
|
|
@ -595,7 +595,7 @@ impl WindowState {
|
||||||
|
|
||||||
// SAFETY: the surface is dropped before the `window` which provided it with handle, thus
|
// SAFETY: the surface is dropped before the `window` which provided it with handle, thus
|
||||||
// it doesn't outlive it.
|
// it doesn't outlive it.
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
let surface = Surface::new(app.context.as_ref().unwrap(), Arc::clone(&window))?;
|
let surface = Surface::new(app.context.as_ref().unwrap(), Arc::clone(&window))?;
|
||||||
|
|
||||||
let theme = window.theme().unwrap_or(Theme::Dark);
|
let theme = window.theme().unwrap_or(Theme::Dark);
|
||||||
|
|
@ -614,7 +614,7 @@ impl WindowState {
|
||||||
custom_idx: app.custom_cursors.as_ref().map(Vec::len).unwrap_or(1) - 1,
|
custom_idx: app.custom_cursors.as_ref().map(Vec::len).unwrap_or(1) - 1,
|
||||||
cursor_grab: CursorGrabMode::None,
|
cursor_grab: CursorGrabMode::None,
|
||||||
named_idx,
|
named_idx,
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
surface,
|
surface,
|
||||||
window,
|
window,
|
||||||
theme,
|
theme,
|
||||||
|
|
@ -796,7 +796,7 @@ impl WindowState {
|
||||||
/// Resize the surface to the new size.
|
/// Resize the surface to the new size.
|
||||||
fn resize(&mut self, size: PhysicalSize<u32>) {
|
fn resize(&mut self, size: PhysicalSize<u32>) {
|
||||||
info!("Surface resized to {size:?}");
|
info!("Surface resized to {size:?}");
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
{
|
{
|
||||||
let (width, height) = match (NonZeroU32::new(size.width), NonZeroU32::new(size.height))
|
let (width, height) = match (NonZeroU32::new(size.width), NonZeroU32::new(size.height))
|
||||||
{
|
{
|
||||||
|
|
@ -889,7 +889,7 @@ impl WindowState {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the window contents.
|
/// Draw the window contents.
|
||||||
#[cfg(not(any(android_platform, ios_platform)))]
|
#[cfg(not(android_platform))]
|
||||||
fn draw(&mut self) -> Result<(), Box<dyn Error>> {
|
fn draw(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
if self.occluded {
|
if self.occluded {
|
||||||
info!("Skipping drawing occluded window={:?}", self.window.id());
|
info!("Skipping drawing occluded window={:?}", self.window.id());
|
||||||
|
|
@ -911,7 +911,7 @@ impl WindowState {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(android_platform, ios_platform))]
|
#[cfg(android_platform)]
|
||||||
fn draw(&mut self) -> Result<(), Box<dyn Error>> {
|
fn draw(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
info!("Drawing but without rendering...");
|
info!("Drawing but without rendering...");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue