From 95ff96f71f8f8069608ad08985e2b1214dd42284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 7 Jul 2023 07:12:37 +0200 Subject: [PATCH 1/2] Update `cosmic-text` and `glyphon` --- tiny_skia/Cargo.toml | 5 +---- wgpu/Cargo.toml | 2 +- wgpu/src/backend.rs | 53 +++++++++++--------------------------------- wgpu/src/text.rs | 22 +++++------------- 4 files changed, 21 insertions(+), 61 deletions(-) diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml index d9276ea5f5..66ad35fd57 100644 --- a/tiny_skia/Cargo.toml +++ b/tiny_skia/Cargo.toml @@ -12,6 +12,7 @@ geometry = ["iced_graphics/geometry"] raw-window-handle = "0.5" softbuffer = "0.2" tiny-skia = "0.10" +cosmic-text = "0.9" bytemuck = "1" rustc-hash = "1.1" kurbo = "0.9" @@ -21,10 +22,6 @@ log = "0.4" version = "0.8" path = "../graphics" -[dependencies.cosmic-text] -git = "https://github.com/hecrj/cosmic-text.git" -rev = "c3cd24dc972bb8fd55d016c81ac9fa637e0a4ada" - [dependencies.twox-hash] version = "1.6" default-features = false diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 22cfad5553..a47c635abb 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -45,7 +45,7 @@ path = "../graphics" [dependencies.glyphon] version = "0.2" git = "https://github.com/hecrj/glyphon.git" -rev = "8324f20158a62f8520bad4ed09f6aa5552f8f2a6" +rev = "886f47c0a9905af340b07a488c953ac00c4bf370" [dependencies.glam] version = "0.24" diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 4a0c54f043..9966a38c1c 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -94,18 +94,11 @@ impl Backend { queue, encoder, scale_factor, + target_size, transformation, &layers, ); - while !self.prepare_text( - device, - queue, - scale_factor, - target_size, - &layers, - ) {} - self.render( device, encoder, @@ -124,44 +117,13 @@ impl Backend { self.image_pipeline.end_frame(); } - fn prepare_text( - &mut self, - device: &wgpu::Device, - queue: &wgpu::Queue, - scale_factor: f32, - target_size: Size, - layers: &[Layer<'_>], - ) -> bool { - for layer in layers { - let bounds = (layer.bounds * scale_factor).snap(); - - if bounds.width < 1 || bounds.height < 1 { - continue; - } - - if !layer.text.is_empty() - && !self.text_pipeline.prepare( - device, - queue, - &layer.text, - layer.bounds, - scale_factor, - target_size, - ) - { - return false; - } - } - - true - } - fn prepare( &mut self, device: &wgpu::Device, queue: &wgpu::Queue, _encoder: &mut wgpu::CommandEncoder, scale_factor: f32, + target_size: Size, transformation: Transformation, layers: &[Layer<'_>], ) { @@ -210,6 +172,17 @@ impl Backend { ); } } + + if !layer.text.is_empty() { + self.text_pipeline.prepare( + device, + queue, + &layer.text, + layer.bounds, + scale_factor, + target_size, + ); + } } } diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 65d3b81803..ef910c3934 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -35,7 +35,7 @@ impl Pipeline { .into_iter(), )), renderers: Vec::new(), - atlas: glyphon::TextAtlas::new( + atlas: glyphon::TextAtlas::with_color_mode( device, queue, format, @@ -66,7 +66,7 @@ impl Pipeline { bounds: Rectangle, scale_factor: f32, target_size: Size, - ) -> bool { + ) { if self.renderers.len() <= self.prepare_layer { self.renderers.push(glyphon::TextRenderer::new( &mut self.atlas, @@ -188,21 +188,11 @@ impl Pipeline { match result { Ok(()) => { self.prepare_layer += 1; - - true } - Err(glyphon::PrepareError::AtlasFull(content_type)) => { - self.prepare_layer = 0; - - #[allow(clippy::needless_bool)] - if self.atlas.grow(device, content_type) { - false - } else { - // If the atlas cannot grow, then all bets are off. - // Instead of panicking, we will just pray that the result - // will be somewhat readable... - true - } + Err(glyphon::PrepareError::AtlasFull) => { + // If the atlas cannot grow, then all bets are off. + // Instead of panicking, we will just pray that the result + // will be somewhat readable... } } } From 1006206fb260e6382ddf50a543846ccb9ffa957b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 20 Jul 2023 20:48:39 +0200 Subject: [PATCH 2/2] Use official `glyphon` repository instead of fork --- wgpu/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index a47c635abb..a0500f8384 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -44,8 +44,8 @@ path = "../graphics" [dependencies.glyphon] version = "0.2" -git = "https://github.com/hecrj/glyphon.git" -rev = "886f47c0a9905af340b07a488c953ac00c4bf370" +git = "https://github.com/grovesNL/glyphon.git" +rev = "81dedbd04237e181c2118931c5f37d341aeb6837" [dependencies.glam] version = "0.24"