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

Make image support optional in iced_wgpu #166

Merged
merged 1 commit into from
Jan 20, 2020
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
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]

[features]
# Enables the Image widget
image = ["iced_wgpu/image"]
# Enables the Svg widget
svg = ["iced_wgpu/svg"]
# Enables a debug view in native platforms (press F12)
debug = ["iced_winit/debug"]
# Enables support for SVG rendering
svg = ["iced_wgpu/svg"]

[badges]
maintenance = { status = "actively-developed" }
Expand Down
2 changes: 1 addition & 1 deletion examples/pokedex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
iced = { path = "../..", features = ["image"] }
iced_futures = { path = "../../futures", features = ["async-std"] }
surf = "1.0"
rand = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/tour/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
publish = false

[dependencies]
iced = { path = "../..", features = ["debug"] }
iced = { path = "../..", features = ["image", "debug"] }
env_logger = "0.7"

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ wgpu = "0.4"
glyph_brush = "0.6"
wgpu_glyph = { version = "0.7", git = "https://github.com/hecrj/wgpu_glyph", branch = "fix/font-load-panic" }
raw-window-handle = "0.3"
image = "0.22"
glam = "0.8"
font-kit = "0.4"
log = "0.4"
resvg = { version = "0.8", features = ["raqote-backend"], optional = true }
image = { version = "0.22", optional = true }
24 changes: 19 additions & 5 deletions wgpu/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#[cfg(feature = "image")]
mod raster;
#[cfg(feature = "svg")]
mod vector;

use crate::Transformation;
use iced_native::{image, svg, Rectangle};

use std::{cell::RefCell, mem};
use std::mem;

#[cfg(any(feature = "image", feature = "svg"))]
use std::cell::RefCell;

#[derive(Debug)]
pub struct Pipeline {
#[cfg(feature = "image")]
raster_cache: RefCell<raster::Cache>,
#[cfg(feature = "svg")]
vector_cache: RefCell<vector::Cache>,
Expand Down Expand Up @@ -191,6 +196,7 @@ impl Pipeline {
});

Pipeline {
#[cfg(feature = "image")]
raster_cache: RefCell::new(raster::Cache::new()),
#[cfg(feature = "svg")]
vector_cache: RefCell::new(vector::Cache::new()),
Expand All @@ -205,6 +211,7 @@ impl Pipeline {
}
}

#[cfg(feature = "image")]
pub fn dimensions(&self, handle: &image::Handle) -> (u32, u32) {
let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(&handle);
Expand Down Expand Up @@ -250,11 +257,17 @@ impl Pipeline {
// [1]: https://github.com/nical/guillotiere
for image in instances {
let uploaded_texture = match &image.handle {
Handle::Raster(handle) => {
let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(&handle);
Handle::Raster(_handle) => {
#[cfg(feature = "image")]
{
let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(&_handle);

memory.upload(device, encoder, &self.texture_layout)
memory.upload(device, encoder, &self.texture_layout)
}

#[cfg(not(feature = "image"))]
None
}
Handle::Vector(_handle) => {
#[cfg(feature = "svg")]
Expand Down Expand Up @@ -339,6 +352,7 @@ impl Pipeline {
}

pub fn trim_cache(&mut self) {
#[cfg(feature = "image")]
self.raster_cache.borrow_mut().trim();

#[cfg(feature = "svg")]
Expand Down
4 changes: 3 additions & 1 deletion wgpu/src/renderer/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod button;
mod checkbox;
mod column;
mod container;
mod image;
mod progress_bar;
mod radio;
mod row;
Expand All @@ -14,3 +13,6 @@ mod text_input;

#[cfg(feature = "svg")]
mod svg;

#[cfg(feature = "image")]
mod image;