summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2023-06-03 03:04:38 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-03 03:04:38 +0200
commitc15f1b5f6575792cc89bb5fba2e613428397e46a (patch)
tree77526943d7aac8004e3ac7dca07154dcbbe25a0f /wgpu
parentb353767d2d9703aae35f10ebf8a9ee1490c3ae37 (diff)
parentb5fc0f4a3aa45d33d81d5799396f0b0770c4dff3 (diff)
downloadiced-c15f1b5f6575792cc89bb5fba2e613428397e46a.tar.gz
iced-c15f1b5f6575792cc89bb5fba2e613428397e46a.tar.bz2
iced-c15f1b5f6575792cc89bb5fba2e613428397e46a.zip
Merge pull request #1888 from iced-rs/web-colors
Introduce `web-colors` feature flag to enable "sRGB linear" blending
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/Cargo.toml3
-rw-r--r--wgpu/src/backend.rs3
-rw-r--r--wgpu/src/geometry.rs7
-rw-r--r--wgpu/src/image/atlas.rs13
-rw-r--r--wgpu/src/layer.rs3
-rw-r--r--wgpu/src/quad.rs5
-rw-r--r--wgpu/src/quad/solid.rs3
-rw-r--r--wgpu/src/text.rs15
-rw-r--r--wgpu/src/window/compositor.rs22
9 files changed, 52 insertions, 22 deletions
diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml
index b5401626..7e50dff2 100644
--- a/wgpu/Cargo.toml
+++ b/wgpu/Cargo.toml
@@ -11,6 +11,7 @@ repository = "https://github.com/iced-rs/iced"
geometry = ["iced_graphics/geometry", "lyon"]
image = ["iced_graphics/image"]
svg = ["resvg"]
+web-colors = ["iced_graphics/web-colors"]
[dependencies]
wgpu = "0.16"
@@ -44,7 +45,7 @@ path = "../graphics"
[dependencies.glyphon]
version = "0.2"
git = "https://github.com/hecrj/glyphon.git"
-rev = "cf7fe9df00499b868a6a94fa5fdb0a4ca368c9f9"
+rev = "26f92369da3704988e3e27f0b35e705c6b2de203"
[dependencies.glam]
version = "0.24"
diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs
index 844987f2..b524c615 100644
--- a/wgpu/src/backend.rs
+++ b/wgpu/src/backend.rs
@@ -1,6 +1,7 @@
use crate::core;
use crate::core::{Color, Font, Point, Size};
use crate::graphics::backend;
+use crate::graphics::color;
use crate::graphics::{Primitive, Transformation, Viewport};
use crate::quad;
use crate::text;
@@ -239,7 +240,7 @@ impl Backend {
load: match clear_color {
Some(background_color) => wgpu::LoadOp::Clear({
let [r, g, b, a] =
- background_color.into_linear();
+ color::pack(background_color).components();
wgpu::Color {
r: f64::from(r),
diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs
index 740ec20c..f81b5b2f 100644
--- a/wgpu/src/geometry.rs
+++ b/wgpu/src/geometry.rs
@@ -1,5 +1,6 @@
//! Build and draw geometry.
use crate::core::{Point, Rectangle, Size, Vector};
+use crate::graphics::color;
use crate::graphics::geometry::fill::{self, Fill};
use crate::graphics::geometry::{
LineCap, LineDash, LineJoin, Path, Stroke, Style, Text,
@@ -68,7 +69,7 @@ impl BufferStack {
(Style::Solid(color), Buffer::Solid(buffer)) => {
Box::new(tessellation::BuffersBuilder::new(
buffer,
- TriangleVertex2DBuilder(color.into_linear()),
+ TriangleVertex2DBuilder(color::pack(*color)),
))
}
(Style::Gradient(gradient), Buffer::Gradient(buffer)) => {
@@ -91,7 +92,7 @@ impl BufferStack {
(Style::Solid(color), Buffer::Solid(buffer)) => {
Box::new(tessellation::BuffersBuilder::new(
buffer,
- TriangleVertex2DBuilder(color.into_linear()),
+ TriangleVertex2DBuilder(color::pack(*color)),
))
}
(Style::Gradient(gradient), Buffer::Gradient(buffer)) => {
@@ -526,7 +527,7 @@ impl tessellation::StrokeVertexConstructor<primitive::GradientVertex2D>
}
}
-struct TriangleVertex2DBuilder([f32; 4]);
+struct TriangleVertex2DBuilder(color::Packed);
impl tessellation::FillVertexConstructor<primitive::ColoredVertex2D>
for TriangleVertex2DBuilder
diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs
index 9b6dcc46..e3de1290 100644
--- a/wgpu/src/image/atlas.rs
+++ b/wgpu/src/image/atlas.rs
@@ -13,6 +13,7 @@ use allocator::Allocator;
pub const SIZE: u32 = 2048;
use crate::core::Size;
+use crate::graphics::color;
#[derive(Debug)]
pub struct Atlas {
@@ -35,7 +36,11 @@ impl Atlas {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
- format: wgpu::TextureFormat::Rgba8UnormSrgb,
+ format: if color::GAMMA_CORRECTION {
+ wgpu::TextureFormat::Rgba8UnormSrgb
+ } else {
+ wgpu::TextureFormat::Rgba8Unorm
+ },
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
@@ -346,7 +351,11 @@ impl Atlas {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
- format: wgpu::TextureFormat::Rgba8UnormSrgb,
+ format: if color::GAMMA_CORRECTION {
+ wgpu::TextureFormat::Rgba8UnormSrgb
+ } else {
+ wgpu::TextureFormat::Rgba8Unorm
+ },
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs
index 1a870c15..71570e3d 100644
--- a/wgpu/src/layer.rs
+++ b/wgpu/src/layer.rs
@@ -11,6 +11,7 @@ pub use text::Text;
use crate::core;
use crate::core::alignment;
use crate::core::{Color, Font, Point, Rectangle, Size, Vector};
+use crate::graphics::color;
use crate::graphics::{Primitive, Viewport};
use crate::quad::{self, Quad};
@@ -150,7 +151,7 @@ impl<'a> Layer<'a> {
bounds.y + translation.y,
],
size: [bounds.width, bounds.height],
- border_color: border_color.into_linear(),
+ border_color: color::pack(*border_color),
border_radius: *border_radius,
border_width: *border_width,
};
diff --git a/wgpu/src/quad.rs b/wgpu/src/quad.rs
index 9c5ed05f..37d0c623 100644
--- a/wgpu/src/quad.rs
+++ b/wgpu/src/quad.rs
@@ -5,6 +5,7 @@ use gradient::Gradient;
use solid::Solid;
use crate::core::{Background, Rectangle};
+use crate::graphics::color;
use crate::graphics::{self, Transformation};
use bytemuck::{Pod, Zeroable};
@@ -217,7 +218,7 @@ pub struct Quad {
pub size: [f32; 2],
/// The border color of the [`Quad`], in __linear RGB__.
- pub border_color: [f32; 4],
+ pub border_color: color::Packed,
/// The border radii of the [`Quad`].
pub border_radius: [f32; 4],
@@ -250,7 +251,7 @@ impl Batch {
let kind = match background {
Background::Color(color) => {
self.solids.push(Solid {
- color: color.into_linear(),
+ color: color::pack(*color),
quad,
});
diff --git a/wgpu/src/quad/solid.rs b/wgpu/src/quad/solid.rs
index f667c42c..f8f1e3a5 100644
--- a/wgpu/src/quad/solid.rs
+++ b/wgpu/src/quad/solid.rs
@@ -1,3 +1,4 @@
+use crate::graphics::color;
use crate::quad::{self, Quad};
use crate::Buffer;
@@ -9,7 +10,7 @@ use std::ops::Range;
#[repr(C)]
pub struct Solid {
/// The background color data of the quad.
- pub color: [f32; 4],
+ pub color: color::Packed,
/// The [`Quad`] data of the [`Solid`].
pub quad: Quad,
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 714e0400..0d88865c 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -2,6 +2,7 @@ use crate::core::alignment;
use crate::core::font::{self, Font};
use crate::core::text::{Hit, LineHeight, Shaping};
use crate::core::{Pixels, Point, Rectangle, Size};
+use crate::graphics::color;
use crate::layer::Text;
use rustc_hash::{FxHashMap, FxHashSet};
@@ -35,7 +36,16 @@ impl Pipeline {
.into_iter(),
)),
renderers: Vec::new(),
- atlas: glyphon::TextAtlas::new(device, queue, format),
+ atlas: glyphon::TextAtlas::new(
+ device,
+ queue,
+ format,
+ if color::GAMMA_CORRECTION {
+ glyphon::ColorMode::Accurate
+ } else {
+ glyphon::ColorMode::Web
+ },
+ ),
prepare_layer: 0,
measurement_cache: RefCell::new(Cache::new()),
render_cache: Cache::new(),
@@ -155,7 +165,8 @@ impl Pipeline {
bottom: (clip_bounds.y + clip_bounds.height) as i32,
},
default_color: {
- let [r, g, b, a] = section.color.into_linear();
+ let [r, g, b, a] =
+ color::pack(section.color).components();
glyphon::Color::rgba(
(r * 255.0) as u8,
diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs
index 500458e8..2eaafde0 100644
--- a/wgpu/src/window/compositor.rs
+++ b/wgpu/src/window/compositor.rs
@@ -1,6 +1,7 @@
//! Connect a window with a renderer.
use crate::core::Color;
use crate::graphics;
+use crate::graphics::color;
use crate::graphics::compositor;
use crate::graphics::{Error, Primitive, Viewport};
use crate::{Backend, Renderer, Settings};
@@ -69,16 +70,19 @@ impl<Theme> Compositor<Theme> {
let format = compatible_surface.as_ref().and_then(|surface| {
let capabilities = surface.get_capabilities(&adapter);
- capabilities
- .formats
- .iter()
- .copied()
- .find(wgpu::TextureFormat::is_srgb)
- .or_else(|| {
- log::warn!("No sRGB format found!");
+ let mut formats = capabilities.formats.iter().copied();
- capabilities.formats.first().copied()
- })
+ let format = if color::GAMMA_CORRECTION {
+ formats.find(wgpu::TextureFormat::is_srgb)
+ } else {
+ formats.find(|format| !wgpu::TextureFormat::is_srgb(format))
+ };
+
+ format.or_else(|| {
+ log::warn!("No format found!");
+
+ capabilities.formats.first().copied()
+ })
})?;
log::info!("Selected format: {:?}", format);