Remove redundant features in iced_wgpu and iced_glow

This commit is contained in:
Héctor Ramón Jiménez 2022-11-05 03:26:19 +01:00
parent d3b613df44
commit 0a23f518c7
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
8 changed files with 35 additions and 37 deletions

View file

@ -9,8 +9,7 @@ repository = "https://github.com/iced-rs/iced"
[features] [features]
svg = ["iced_graphics/svg"] svg = ["iced_graphics/svg"]
image = ["image_rs", "iced_graphics/image", "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] image = ["iced_graphics/image"]
image_rs = ["iced_graphics/image_rs"]
png = ["iced_graphics/png"] png = ["iced_graphics/png"]
jpeg = ["iced_graphics/jpeg"] jpeg = ["iced_graphics/jpeg"]
jpeg_rayon = ["iced_graphics/jpeg_rayon"] jpeg_rayon = ["iced_graphics/jpeg_rayon"]

View file

@ -1,4 +1,4 @@
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
use crate::image; use crate::image;
use crate::quad; use crate::quad;
use crate::text; use crate::text;
@ -17,7 +17,7 @@ use iced_native::{Font, Size};
/// [`iced`]: https://github.com/iced-rs/iced /// [`iced`]: https://github.com/iced-rs/iced
#[derive(Debug)] #[derive(Debug)]
pub struct Backend { pub struct Backend {
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
image_pipeline: image::Pipeline, image_pipeline: image::Pipeline,
quad_pipeline: quad::Pipeline, quad_pipeline: quad::Pipeline,
text_pipeline: text::Pipeline, text_pipeline: text::Pipeline,
@ -36,13 +36,13 @@ impl Backend {
let shader_version = program::Version::new(gl); 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 image_pipeline = image::Pipeline::new(gl, &shader_version);
let quad_pipeline = quad::Pipeline::new(gl, &shader_version); let quad_pipeline = quad::Pipeline::new(gl, &shader_version);
let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version); let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version);
Self { Self {
#[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,
@ -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); self.image_pipeline.trim_cache(gl);
} }
@ -123,7 +123,7 @@ impl Backend {
); );
} }
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
if !layer.images.is_empty() { if !layer.images.is_empty() {
let scaled = transformation let scaled = transformation
* Transformation::scale(scale_factor, scale_factor); * Transformation::scale(scale_factor, scale_factor);
@ -256,7 +256,7 @@ impl backend::Text for Backend {
} }
} }
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
impl backend::Image for Backend { impl backend::Image for Backend {
fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> { fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.image_pipeline.dimensions(handle) self.image_pipeline.dimensions(handle)

View file

@ -7,7 +7,7 @@ pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
use crate::program::{self, Shader}; use crate::program::{self, Shader};
use crate::Transformation; use crate::Transformation;
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
use iced_graphics::image::raster; use iced_graphics::image::raster;
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -27,7 +27,7 @@ pub(crate) struct Pipeline {
vertex_buffer: <glow::Context as HasContext>::Buffer, vertex_buffer: <glow::Context as HasContext>::Buffer,
transform_location: <glow::Context as HasContext>::UniformLocation, transform_location: <glow::Context as HasContext>::UniformLocation,
storage: Storage, storage: Storage,
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
raster_cache: RefCell<raster::Cache<Storage>>, raster_cache: RefCell<raster::Cache<Storage>>,
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
vector_cache: RefCell<vector::Cache<Storage>>, vector_cache: RefCell<vector::Cache<Storage>>,
@ -115,14 +115,14 @@ impl Pipeline {
vertex_buffer, vertex_buffer,
transform_location, transform_location,
storage: Storage::default(), storage: Storage::default(),
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
raster_cache: RefCell::new(raster::Cache::default()), raster_cache: RefCell::new(raster::Cache::default()),
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
vector_cache: RefCell::new(vector::Cache::default()), 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> { pub fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.raster_cache.borrow_mut().load(handle).dimensions() self.raster_cache.borrow_mut().load(handle).dimensions()
} }
@ -151,7 +151,7 @@ impl Pipeline {
gl.bind_buffer(glow::ARRAY_BUFFER, Some(self.vertex_buffer)); 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(); let mut raster_cache = self.raster_cache.borrow_mut();
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -159,12 +159,12 @@ impl Pipeline {
for image in images { for image in images {
let (entry, bounds) = match &image { let (entry, bounds) = match &image {
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
layer::Image::Raster { handle, bounds } => ( layer::Image::Raster { handle, bounds } => (
raster_cache.upload(handle, &mut gl, &mut self.storage), raster_cache.upload(handle, &mut gl, &mut self.storage),
bounds, bounds,
), ),
#[cfg(not(feature = "image_rs"))] #[cfg(not(feature = "image"))]
layer::Image::Raster { handle: _, bounds } => (None, bounds), layer::Image::Raster { handle: _, bounds } => (None, bounds),
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -217,7 +217,7 @@ impl Pipeline {
} }
pub fn trim_cache(&mut self, mut gl: &glow::Context) { pub fn trim_cache(&mut self, mut gl: &glow::Context) {
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
self.raster_cache self.raster_cache
.borrow_mut() .borrow_mut()
.trim(&mut self.storage, &mut gl); .trim(&mut self.storage, &mut gl);

View file

@ -24,7 +24,7 @@
pub use glow; pub use glow;
mod backend; mod backend;
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
mod image; mod image;
mod program; mod program;
mod quad; mod quad;

View file

@ -9,8 +9,7 @@ repository = "https://github.com/iced-rs/iced"
[features] [features]
svg = ["iced_graphics/svg"] svg = ["iced_graphics/svg"]
image = ["image_rs", "iced_graphics/image", "png", "jpeg", "jpeg_rayon", "gif", "webp", "bmp"] image = ["iced_graphics/image"]
image_rs = ["iced_graphics/image_rs"]
png = ["iced_graphics/png"] png = ["iced_graphics/png"]
jpeg = ["iced_graphics/jpeg"] jpeg = ["iced_graphics/jpeg"]
jpeg_rayon = ["iced_graphics/jpeg_rayon"] jpeg_rayon = ["iced_graphics/jpeg_rayon"]

View file

@ -10,7 +10,7 @@ use iced_graphics::{Primitive, Viewport};
use iced_native::alignment; use iced_native::alignment;
use iced_native::{Font, Size}; use iced_native::{Font, Size};
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
use crate::image; use crate::image;
/// A [`wgpu`] graphics backend for [`iced`]. /// A [`wgpu`] graphics backend for [`iced`].
@ -23,7 +23,7 @@ pub struct Backend {
text_pipeline: text::Pipeline, text_pipeline: text::Pipeline,
triangle_pipeline: triangle::Pipeline, triangle_pipeline: triangle::Pipeline,
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
image_pipeline: image::Pipeline, image_pipeline: image::Pipeline,
default_text_size: u16, default_text_size: u16,
@ -47,7 +47,7 @@ impl Backend {
let triangle_pipeline = let triangle_pipeline =
triangle::Pipeline::new(device, format, settings.antialiasing); 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); let image_pipeline = image::Pipeline::new(device, format);
Self { Self {
@ -55,7 +55,7 @@ impl 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: settings.default_text_size, default_text_size: settings.default_text_size,
@ -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); self.image_pipeline.trim_cache(device, encoder);
} }
@ -148,7 +148,7 @@ impl Backend {
); );
} }
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
{ {
if !layer.images.is_empty() { if !layer.images.is_empty() {
let scaled = transformation let scaled = transformation
@ -294,7 +294,7 @@ impl backend::Text for Backend {
} }
} }
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
impl backend::Image for Backend { impl backend::Image for Backend {
fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> { fn dimensions(&self, handle: &iced_native::image::Handle) -> Size<u32> {
self.image_pipeline.dimensions(handle) self.image_pipeline.dimensions(handle)

View file

@ -1,6 +1,6 @@
mod atlas; mod atlas;
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
use iced_graphics::image::raster; use iced_graphics::image::raster;
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -17,7 +17,7 @@ use std::mem;
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
use iced_native::image; use iced_native::image;
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -25,7 +25,7 @@ use iced_native::svg;
#[derive(Debug)] #[derive(Debug)]
pub struct Pipeline { pub struct Pipeline {
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
raster_cache: RefCell<raster::Cache<Atlas>>, raster_cache: RefCell<raster::Cache<Atlas>>,
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
vector_cache: RefCell<vector::Cache<Atlas>>, vector_cache: RefCell<vector::Cache<Atlas>>,
@ -243,7 +243,7 @@ impl Pipeline {
}); });
Pipeline { Pipeline {
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
raster_cache: RefCell::new(raster::Cache::default()), raster_cache: RefCell::new(raster::Cache::default()),
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -262,7 +262,7 @@ impl Pipeline {
} }
} }
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
pub fn dimensions(&self, handle: &image::Handle) -> Size<u32> { pub fn dimensions(&self, handle: &image::Handle) -> Size<u32> {
let mut cache = self.raster_cache.borrow_mut(); let mut cache = self.raster_cache.borrow_mut();
let memory = cache.load(handle); let memory = cache.load(handle);
@ -291,7 +291,7 @@ impl Pipeline {
) { ) {
let instances: &mut Vec<Instance> = &mut Vec::new(); let instances: &mut Vec<Instance> = &mut Vec::new();
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
let mut raster_cache = self.raster_cache.borrow_mut(); let mut raster_cache = self.raster_cache.borrow_mut();
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -299,7 +299,7 @@ impl Pipeline {
for image in images { for image in images {
match &image { match &image {
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
layer::Image::Raster { handle, bounds } => { layer::Image::Raster { handle, bounds } => {
if let Some(atlas_entry) = raster_cache.upload( if let Some(atlas_entry) = raster_cache.upload(
handle, handle,
@ -314,7 +314,7 @@ impl Pipeline {
); );
} }
} }
#[cfg(not(feature = "image_rs"))] #[cfg(not(feature = "image"))]
layer::Image::Raster { .. } => {} layer::Image::Raster { .. } => {}
#[cfg(feature = "svg")] #[cfg(feature = "svg")]
@ -450,7 +450,7 @@ impl Pipeline {
device: &wgpu::Device, device: &wgpu::Device,
encoder: &mut wgpu::CommandEncoder, encoder: &mut wgpu::CommandEncoder,
) { ) {
#[cfg(feature = "image_rs")] #[cfg(feature = "image")]
self.raster_cache self.raster_cache
.borrow_mut() .borrow_mut()
.trim(&mut self.texture_atlas, &mut (device, encoder)); .trim(&mut self.texture_atlas, &mut (device, encoder));

View file

@ -56,7 +56,7 @@ pub use settings::Settings;
pub(crate) use iced_graphics::Transformation; pub(crate) use iced_graphics::Transformation;
#[cfg(any(feature = "image_rs", feature = "svg"))] #[cfg(any(feature = "image", feature = "svg"))]
mod image; mod image;
/// A [`wgpu`] graphics renderer for [`iced`]. /// A [`wgpu`] graphics renderer for [`iced`].