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

Update wgpu to 0.19, glyphon to 0.5, softbuffer to 0.4, window-clipboard to 0.4, and raw-window-handle to 0.6 #2191

Merged
merged 16 commits into from
Jan 19, 2024
Merged
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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bytemuck = { version = "1.0", features = ["derive"] }
cosmic-text = "0.10"
futures = "0.3"
glam = "0.24"
glyphon = "0.4"
glyphon = "0.5"
guillotiere = "0.6"
half = "2.2"
image = "0.24"
Expand All @@ -140,12 +140,12 @@ once_cell = "1.0"
ouroboros = "0.17"
palette = "0.7"
qrcode = { version = "0.12", default-features = false }
raw-window-handle = "0.5"
raw-window-handle = "0.6"
resvg = "0.36"
rustc-hash = "1.0"
smol = "1.0"
smol_str = "0.2"
softbuffer = "0.2"
softbuffer = "0.4"
syntect = "5.1"
sysinfo = "0.28"
thiserror = "1.0"
Expand All @@ -158,7 +158,7 @@ wasm-bindgen-futures = "0.4"
wasm-timer = "0.2"
web-sys = "0.3"
web-time = "0.2"
wgpu = "0.18"
wgpu = "0.19"
winapi = "0.3"
window_clipboard = "0.3"
winit = { git = "https://github.com/iced-rs/winit.git", rev = "b91e39ece2c0d378c3b80da7f3ab50e17bb798a5", features = ["rwh_05"] }
window_clipboard = "0.4"
winit = { git = "https://github.com/iced-rs/winit.git", rev = "b91e39ece2c0d378c3b80da7f3ab50e17bb798a5" }
3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ palette.workspace = true
palette.optional = true

[target.'cfg(windows)'.dependencies]
# TODO: Use `workspace` dependency once `wgpu` upgrades `raw-window-handle`
raw-window-handle = "0.6"
raw-window-handle.workspace = true

[dev-dependencies]
approx = "0.5"
2 changes: 2 additions & 0 deletions examples/custom_shader/src/scene/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl Pipeline {
usage: wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
},
wgpu::util::TextureDataOrder::LayerMajor,
&normal_map_data,
);

Expand All @@ -122,6 +123,7 @@ impl Pipeline {
usage: wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
},
wgpu::util::TextureDataOrder::LayerMajor,
&skybox_data,
);

Expand Down
12 changes: 9 additions & 3 deletions examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use winit::{
keyboard::ModifiersState,
};

use std::sync::Arc;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsCast;
#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -59,6 +61,8 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(not(target_arch = "wasm32"))]
let window = winit::window::Window::new(&event_loop)?;

let window = Arc::new(window);

let physical_size = window.inner_size();
let mut viewport = Viewport::with_physical_size(
Size::new(physical_size.width, physical_size.height),
Expand All @@ -81,7 +85,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
backends: backend,
..Default::default()
});
let surface = unsafe { instance.create_surface(&window) }?;
let surface = instance.create_surface(window.clone())?;

let (format, (device, queue)) =
futures::futures::executor::block_on(async {
Expand Down Expand Up @@ -115,9 +119,9 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: adapter_features
required_features: adapter_features
& wgpu::Features::default(),
limits: needed_limits,
required_limits: needed_limits,
},
None,
)
Expand All @@ -136,6 +140,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
present_mode: wgpu::PresentMode::AutoVsync,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
desired_maximum_frame_latency: 2,
},
);

Expand Down Expand Up @@ -188,6 +193,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
present_mode: wgpu::PresentMode::AutoVsync,
alpha_mode: wgpu::CompositeAlphaMode::Auto,
view_formats: vec![],
desired_maximum_frame_latency: 2,
},
);

Expand Down
4 changes: 2 additions & 2 deletions futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pub use futures;
pub use iced_core as core;

mod maybe_send;
mod maybe;
mod runtime;

pub mod backend;
Expand All @@ -25,7 +25,7 @@ pub mod keyboard;
pub mod subscription;

pub use executor::Executor;
pub use maybe_send::MaybeSend;
pub use maybe::{MaybeSend, MaybeSync};
pub use platform::*;
pub use runtime::Runtime;
pub use subscription::Subscription;
Expand Down
35 changes: 35 additions & 0 deletions futures/src/maybe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#[cfg(not(target_arch = "wasm32"))]
mod platform {
/// An extension trait that enforces `Send` only on native platforms.
///
/// Useful for writing cross-platform async code!
pub trait MaybeSend: Send {}

impl<T> MaybeSend for T where T: Send {}

/// An extension trait that enforces `Sync` only on native platforms.
///
/// Useful for writing cross-platform async code!
pub trait MaybeSync: Sync {}

impl<T> MaybeSync for T where T: Sync {}
}

#[cfg(target_arch = "wasm32")]
mod platform {
/// An extension trait that enforces `Send` only on native platforms.
///
/// Useful for writing cross-platform async code!
pub trait MaybeSend {}

impl<T> MaybeSend for T {}

/// An extension trait that enforces `Sync` only on native platforms.
///
/// Useful for writing cross-platform async code!
pub trait MaybeSync {}

impl<T> MaybeSync for T {}
}

pub use platform::{MaybeSend, MaybeSync};
21 changes: 0 additions & 21 deletions futures/src/maybe_send.rs

This file was deleted.

1 change: 1 addition & 0 deletions graphics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ web-colors = []

[dependencies]
iced_core.workspace = true
iced_futures.workspace = true

bitflags.workspace = true
bytemuck.workspace = true
Expand Down
27 changes: 21 additions & 6 deletions graphics/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
//! surfaces.
use crate::{Error, Viewport};

use iced_core::Color;
use crate::core::Color;
use crate::futures::{MaybeSend, MaybeSync};

use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use thiserror::Error;

/// A graphics compositor that can draw to windows.
Expand All @@ -19,9 +20,9 @@ pub trait Compositor: Sized {
type Surface;

/// Creates a new [`Compositor`].
fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(
fn new<W: Window + Clone>(
settings: Self::Settings,
compatible_window: Option<&W>,
compatible_window: W,
) -> Result<Self, Error>;

/// Creates a [`Self::Renderer`] for the [`Compositor`].
Expand All @@ -30,9 +31,9 @@ pub trait Compositor: Sized {
/// Crates a new [`Surface`] for the given window.
///
/// [`Surface`]: Self::Surface
fn create_surface<W: HasRawWindowHandle + HasRawDisplayHandle>(
fn create_surface<W: Window + Clone>(
&mut self,
window: &W,
window: W,
width: u32,
height: u32,
) -> Self::Surface;
Expand Down Expand Up @@ -77,6 +78,20 @@ pub trait Compositor: Sized {
) -> Vec<u8>;
}

/// A window that can be used in a [`Compositor`].
///
/// This is just a convenient super trait of the `raw-window-handle`
/// traits.
pub trait Window:
HasWindowHandle + HasDisplayHandle + MaybeSend + MaybeSync + 'static
{
}

impl<T> Window for T where
T: HasWindowHandle + HasDisplayHandle + MaybeSend + MaybeSync + 'static
{
}

/// Result of an unsuccessful call to [`Compositor::present`].
#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum SurfaceError {
Expand Down
1 change: 1 addition & 0 deletions graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ pub use transformation::Transformation;
pub use viewport::Viewport;

pub use iced_core as core;
pub use iced_futures as futures;
1 change: 0 additions & 1 deletion renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ iced_wgpu.workspace = true
iced_wgpu.optional = true

log.workspace = true
raw-window-handle.workspace = true
thiserror.workspace = true
20 changes: 10 additions & 10 deletions renderer/src/compositor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::core::Color;
use crate::graphics::compositor::{Information, SurfaceError};
use crate::graphics::compositor::{Information, SurfaceError, Window};
use crate::graphics::{Error, Viewport};
use crate::{Renderer, Settings};

use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use std::env;

pub enum Compositor<Theme> {
Expand All @@ -15,25 +14,25 @@ pub enum Compositor<Theme> {
pub enum Surface {
TinySkia(iced_tiny_skia::window::Surface),
#[cfg(feature = "wgpu")]
Wgpu(iced_wgpu::window::Surface),
Wgpu(iced_wgpu::window::Surface<'static>),
}

impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
type Settings = Settings;
type Renderer = Renderer<Theme>;
type Surface = Surface;

fn new<W: HasRawWindowHandle + HasRawDisplayHandle>(
fn new<W: Window + Clone>(
settings: Self::Settings,
compatible_window: Option<&W>,
compatible_window: W,
) -> Result<Self, Error> {
let candidates =
Candidate::list_from_env().unwrap_or(Candidate::default_list());

let mut error = Error::GraphicsAdapterNotFound;

for candidate in candidates {
match candidate.build(settings, compatible_window) {
match candidate.build(settings, compatible_window.clone()) {
Ok(compositor) => return Ok(compositor),
Err(new_error) => {
error = new_error;
Expand All @@ -56,9 +55,9 @@ impl<Theme> crate::graphics::Compositor for Compositor<Theme> {
}
}

fn create_surface<W: HasRawWindowHandle + HasRawDisplayHandle>(
fn create_surface<W: Window + Clone>(
&mut self,
window: &W,
window: W,
width: u32,
height: u32,
) -> Surface {
Expand Down Expand Up @@ -226,10 +225,10 @@ impl Candidate {
)
}

fn build<Theme, W: HasRawWindowHandle + HasRawDisplayHandle>(
fn build<Theme, W: Window>(
self,
settings: Settings,
_compatible_window: Option<&W>,
_compatible_window: W,
) -> Result<Compositor<Theme>, Error> {
match self {
Self::TinySkia => {
Expand All @@ -238,6 +237,7 @@ impl Candidate {
default_font: settings.default_font,
default_text_size: settings.default_text_size,
},
_compatible_window,
);

Ok(Compositor::TinySkia(compositor))
Expand Down
1 change: 0 additions & 1 deletion tiny_skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bytemuck.workspace = true
cosmic-text.workspace = true
kurbo.workspace = true
log.workspace = true
raw-window-handle.workspace = true
rustc-hash.workspace = true
softbuffer.workspace = true
tiny-skia.workspace = true
Expand Down
Loading
Loading