summaryrefslogtreecommitdiffstats
path: root/wgpu/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2021-05-17 19:51:17 +0700
committerLibravatar GitHub <noreply@github.com>2021-05-17 19:51:17 +0700
commit70ee917bace13e83158e98cc5d5a1bdff8f04b4f (patch)
treeec584b19e524364a3e31fcd39dc804d78987e343 /wgpu/src
parentfaa68534cfd1797adcc621a2a611a3a825539f0f (diff)
parent77a17cde83c9bdb8a61b871c7a15303f13e8d781 (diff)
downloadiced-70ee917bace13e83158e98cc5d5a1bdff8f04b4f.tar.gz
iced-70ee917bace13e83158e98cc5d5a1bdff8f04b4f.tar.bz2
iced-70ee917bace13e83158e98cc5d5a1bdff8f04b4f.zip
Merge pull request #875 from ZakisM/optimize_svg_algorithm
This commit optimizes the algorithm used to convert rgba pixels into bgra pixels for SVG's.
Diffstat (limited to 'wgpu/src')
-rw-r--r--wgpu/src/image/vector.rs22
1 files changed, 5 insertions, 17 deletions
diff --git a/wgpu/src/image/vector.rs b/wgpu/src/image/vector.rs
index ab0f67d0..8c7de617 100644
--- a/wgpu/src/image/vector.rs
+++ b/wgpu/src/image/vector.rs
@@ -1,7 +1,8 @@
-use crate::image::atlas::{self, Atlas};
use iced_native::svg;
use std::collections::{HashMap, HashSet};
+use crate::image::atlas::{self, Atlas};
+
pub enum Svg {
Loaded(usvg::Tree),
NotFound,
@@ -111,26 +112,13 @@ impl Cache {
let width = img.width();
let height = img.height();
- let mut rgba = img.take().into_iter();
-
- // TODO: Perform conversion in the GPU
- let bgra: Vec<u8> = std::iter::from_fn(move || {
- use std::iter::once;
-
- let r = rgba.next()?;
- let g = rgba.next()?;
- let b = rgba.next()?;
- let a = rgba.next()?;
-
- Some(once(b).chain(once(g)).chain(once(r)).chain(once(a)))
- })
- .flatten()
- .collect();
+ let mut rgba = img.take();
+ rgba.chunks_exact_mut(4).for_each(|rgba| rgba.swap(0, 2));
let allocation = texture_atlas.upload(
width,
height,
- bytemuck::cast_slice(bgra.as_slice()),
+ bytemuck::cast_slice(rgba.as_slice()),
device,
encoder,
)?;