Skip to content

Commit

Permalink
Remove redundant features in iced_wgpu and iced_glow
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 5, 2022
1 parent d3b613d commit 0a23f51
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 37 deletions.
3 changes: 1 addition & 2 deletions glow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ repository = "https://github.com/iced-rs/iced"

[features]
svg = ["iced_graphics/svg"]
image = ["image_rs", "iced_graphics/image", "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"]
image_rs = ["iced_graphics/image_rs"]
image = ["iced_graphics/image"]
png = ["iced_graphics/png"]
jpeg = ["iced_graphics/jpeg"]
jpeg_rayon = ["iced_graphics/jpeg_rayon"]
Expand Down
14 changes: 7 additions & 7 deletions glow/src/backend.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
use crate::image;
use crate::quad;
use crate::text;
Expand All @@ -17,7 +17,7 @@ use iced_native::{Font, Size};
/// [`iced`]: https://github.com/iced-rs/iced
#[derive(Debug)]
pub struct Backend {
#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
image_pipeline: image::Pipeline,
quad_pipeline: quad::Pipeline,
text_pipeline: text::Pipeline,
Expand All @@ -36,13 +36,13 @@ impl Backend {

let shader_version = program::Version::new(gl);

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
let image_pipeline = image::Pipeline::new(gl, &shader_version);
let quad_pipeline = quad::Pipeline::new(gl, &shader_version);
let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version);

Self {
#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
image_pipeline,
quad_pipeline,
text_pipeline,
Expand Down Expand Up @@ -79,7 +79,7 @@ impl Backend {
);
}

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
self.image_pipeline.trim_cache(gl);
}

Expand Down Expand Up @@ -123,7 +123,7 @@ impl Backend {
);
}

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
if !layer.images.is_empty() {
let scaled = transformation
* Transformation::scale(scale_factor, scale_factor);
Expand Down Expand Up @@ -256,7 +256,7 @@ impl backend::Text for Backend {
}
}

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
impl backend::Image for Backend {
fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.image_pipeline.dimensions(handle)
Expand Down
16 changes: 8 additions & 8 deletions glow/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
use crate::program::{self, Shader};
use crate::Transformation;

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
use iced_graphics::image::raster;

#[cfg(feature = "svg")]
Expand All @@ -27,7 +27,7 @@ pub(crate) struct Pipeline {
vertex_buffer: <glow::Context as HasContext>::Buffer,
transform_location: <glow::Context as HasContext>::UniformLocation,
storage: Storage,
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
raster_cache: RefCell<raster::Cache<Storage>>,
#[cfg(feature = "svg")]
vector_cache: RefCell<vector::Cache<Storage>>,
Expand Down Expand Up @@ -115,14 +115,14 @@ impl Pipeline {
vertex_buffer,
transform_location,
storage: Storage::default(),
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
raster_cache: RefCell::new(raster::Cache::default()),
#[cfg(feature = "svg")]
vector_cache: RefCell::new(vector::Cache::default()),
}
}

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
pub fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.raster_cache.borrow_mut().load(handle).dimensions()
}
Expand Down Expand Up @@ -151,20 +151,20 @@ impl Pipeline {
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.vertex_buffer));
}

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
let mut raster_cache = self.raster_cache.borrow_mut();

#[cfg(feature = "svg")]
let mut vector_cache = self.vector_cache.borrow_mut();

for image in images {
let (entry, bounds) = match &image {
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
layer::Image::Raster { handle, bounds } => (
raster_cache.upload(handle, &mut gl, &mut self.storage),
bounds,
),
#[cfg(not(feature = "image_rs"))]
#[cfg(not(feature = "image"))]
layer::Image::Raster { handle: _, bounds } => (None, bounds),

#[cfg(feature = "svg")]
Expand Down Expand Up @@ -217,7 +217,7 @@ impl Pipeline {
}

pub fn trim_cache(&mut self, mut gl: &glow::Context) {
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
self.raster_cache
.borrow_mut()
.trim(&mut self.storage, &mut gl);
Expand Down
2 changes: 1 addition & 1 deletion glow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
pub use glow;

mod backend;
#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
mod image;
mod program;
mod quad;
Expand Down
3 changes: 1 addition & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ repository = "https://github.com/iced-rs/iced"

[features]
svg = ["iced_graphics/svg"]
image = ["image_rs", "iced_graphics/image", "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"]
image_rs = ["iced_graphics/image_rs"]
image = ["iced_graphics/image"]
png = ["iced_graphics/png"]
jpeg = ["iced_graphics/jpeg"]
jpeg_rayon = ["iced_graphics/jpeg_rayon"]
Expand Down
14 changes: 7 additions & 7 deletions wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use iced_graphics::{Primitive, Viewport};
use iced_native::alignment;
use iced_native::{Font, Size};

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
use crate::image;

/// A [`wgpu`] graphics backend for [`iced`].
Expand All @@ -23,7 +23,7 @@ pub struct Backend {
text_pipeline: text::Pipeline,
triangle_pipeline: triangle::Pipeline,

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
image_pipeline: image::Pipeline,

default_text_size: u16,
Expand All @@ -47,15 +47,15 @@ impl Backend {
let triangle_pipeline =
triangle::Pipeline::new(device, format, settings.antialiasing);

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
let image_pipeline = image::Pipeline::new(device, format);

Self {
quad_pipeline,
text_pipeline,
triangle_pipeline,

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
image_pipeline,

default_text_size: settings.default_text_size,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Backend {
);
}

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
self.image_pipeline.trim_cache(device, encoder);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ impl Backend {
);
}

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
{
if !layer.images.is_empty() {
let scaled = transformation
Expand Down Expand Up @@ -294,7 +294,7 @@ impl backend::Text for Backend {
}
}

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
impl backend::Image for Backend {
fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.image_pipeline.dimensions(handle)
Expand Down
18 changes: 9 additions & 9 deletions wgpu/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod atlas;

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
use iced_graphics::image::raster;

#[cfg(feature = "svg")]
Expand All @@ -17,15 +17,15 @@ use std::mem;

use bytemuck::{Pod, Zeroable};

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
use iced_native::image;

#[cfg(feature = "svg")]
use iced_native::svg;

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

Pipeline {
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
raster_cache: RefCell::new(raster::Cache::default()),

#[cfg(feature = "svg")]
Expand All @@ -262,7 +262,7 @@ impl Pipeline {
}
}

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
pub fn dimensions(&self, handle: &image::Handle) -> Size<u32> {
let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(handle);
Expand Down Expand Up @@ -291,15 +291,15 @@ impl Pipeline {
) {
let instances: &mut Vec<Instance> = &mut Vec::new();

#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
let mut raster_cache = self.raster_cache.borrow_mut();

#[cfg(feature = "svg")]
let mut vector_cache = self.vector_cache.borrow_mut();

for image in images {
match &image {
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
layer::Image::Raster { handle, bounds } => {
if let Some(atlas_entry) = raster_cache.upload(
handle,
Expand All @@ -314,7 +314,7 @@ impl Pipeline {
);
}
}
#[cfg(not(feature = "image_rs"))]
#[cfg(not(feature = "image"))]
layer::Image::Raster { .. } => {}

#[cfg(feature = "svg")]
Expand Down Expand Up @@ -450,7 +450,7 @@ impl Pipeline {
device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder,
) {
#[cfg(feature = "image_rs")]
#[cfg(feature = "image")]
self.raster_cache
.borrow_mut()
.trim(&mut self.texture_atlas, &mut (device, encoder));
Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use settings::Settings;

pub(crate) use iced_graphics::Transformation;

#[cfg(any(feature = "image_rs", feature = "svg"))]
#[cfg(any(feature = "image", feature = "svg"))]
mod image;

/// A [`wgpu`] graphics renderer for [`iced`].
Expand Down

0 comments on commit 0a23f51

Please sign in to comment.