diff options
author | 2021-07-22 18:21:50 +0700 | |
---|---|---|
committer | 2021-07-22 18:21:50 +0700 | |
commit | 217f5be8272f48a5b043d066ed1788cc127e1164 (patch) | |
tree | ef09f2324d8d44d52938d34d8d007ff1bf681721 | |
parent | 6469e463cd1f99190c6eba4701d4c1059934d3ee (diff) | |
download | iced-217f5be8272f48a5b043d066ed1788cc127e1164.tar.gz iced-217f5be8272f48a5b043d066ed1788cc127e1164.tar.bz2 iced-217f5be8272f48a5b043d066ed1788cc127e1164.zip |
Add `text_multithreading` to `Settings` in `iced_glow` and `iced_wgpu`
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | glow/Cargo.toml | 1 | ||||
-rw-r--r-- | glow/src/backend.rs | 7 | ||||
-rw-r--r-- | glow/src/settings.rs | 5 | ||||
-rw-r--r-- | glow/src/text.rs | 10 | ||||
-rw-r--r-- | wgpu/Cargo.toml | 1 | ||||
-rw-r--r-- | wgpu/src/backend.rs | 9 | ||||
-rw-r--r-- | wgpu/src/settings.rs | 5 | ||||
-rw-r--r-- | wgpu/src/text.rs | 5 |
9 files changed, 31 insertions, 16 deletions
@@ -25,8 +25,6 @@ canvas = ["iced_wgpu/canvas"] qr_code = ["iced_wgpu/qr_code"] # Enables using system fonts default_system_font = ["iced_wgpu/default_system_font"] -# Enables draw_cache_multithread for glyph drawing -glyph_draw_cache_multithread = ["iced_wgpu/glyph_draw_cache_multithread"] # Enables the `iced_glow` renderer. Overrides `iced_wgpu` glow = ["iced_glow", "iced_glutin"] # Enables the `Canvas` widget for `iced_glow` @@ -35,8 +33,6 @@ glow_canvas = ["iced_glow/canvas"] glow_qr_code = ["iced_glow/qr_code"] # Enables using system fonts for `iced_glow` glow_default_system_font = ["iced_glow/default_system_font"] -# Enables draw_cache_multithread for `iced_glow` glyph drawing -glow_glyph_draw_cache_multithread = ["iced_glow/glyph_draw_cache_multithread"] # Enables a debug view in native platforms (press F12) debug = ["iced_winit/debug"] # Enables `tokio` as the `executor::Default` on native platforms diff --git a/glow/Cargo.toml b/glow/Cargo.toml index f5934f8f..e40b8ba8 100644 --- a/glow/Cargo.toml +++ b/glow/Cargo.toml @@ -11,7 +11,6 @@ repository = "https://github.com/hecrj/iced" canvas = ["iced_graphics/canvas"] qr_code = ["iced_graphics/qr_code"] default_system_font = ["iced_graphics/font-source"] -glyph_draw_cache_multithread = [] # Not supported yet! image = [] svg = [] diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 92bb993e..1680fc00 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -24,7 +24,12 @@ pub struct Backend { impl Backend { /// Creates a new [`Backend`]. pub fn new(gl: &glow::Context, settings: Settings) -> Self { - let text_pipeline = text::Pipeline::new(gl, settings.default_font); + let text_pipeline = text::Pipeline::new( + gl, + settings.default_font, + settings.text_multithreading, + ); + let quad_pipeline = quad::Pipeline::new(gl); let triangle_pipeline = triangle::Pipeline::new(gl); diff --git a/glow/src/settings.rs b/glow/src/settings.rs index 8477eb57..cf8e891f 100644 --- a/glow/src/settings.rs +++ b/glow/src/settings.rs @@ -16,6 +16,10 @@ pub struct Settings { /// By default, it will be set to 20. pub default_text_size: u16, + /// If enabled, spread text workload in multiple threads when multiple cores + /// are available. + pub text_multithreading: bool, + /// The antialiasing strategy that will be used for triangle primitives. pub antialiasing: Option<Antialiasing>, } @@ -25,6 +29,7 @@ impl Default for Settings { Settings { default_font: None, default_text_size: 20, + text_multithreading: false, antialiasing: None, } } diff --git a/glow/src/text.rs b/glow/src/text.rs index 7c9574a2..a4c39dfe 100644 --- a/glow/src/text.rs +++ b/glow/src/text.rs @@ -11,7 +11,11 @@ pub struct Pipeline { } impl Pipeline { - pub fn new(gl: &glow::Context, default_font: Option<&[u8]>) -> Self { + pub fn new( + gl: &glow::Context, + default_font: Option<&[u8]>, + multithreading: bool, + ) -> Self { let default_font = default_font.map(|slice| slice.to_vec()); // TODO: Font customization @@ -41,9 +45,7 @@ impl Pipeline { let draw_brush = glow_glyph::GlyphBrushBuilder::using_font(font.clone()) .initial_cache_size((2048, 2048)) - .draw_cache_multithread(cfg!( - feature = "glyph_draw_cache_multithread" - )) + .draw_cache_multithread(multithreading) .build(&gl); let measure_brush = diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index fc9f7379..3eacdd0f 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -24,7 +24,6 @@ farbfeld = ["image_rs/farbfeld"] canvas = ["iced_graphics/canvas"] qr_code = ["iced_graphics/qr_code"] default_system_font = ["iced_graphics/font-source"] -glyph_draw_cache_multithread = [] [dependencies] wgpu = "0.8" diff --git a/wgpu/src/backend.rs b/wgpu/src/backend.rs index 534c6cb7..783079f3 100644 --- a/wgpu/src/backend.rs +++ b/wgpu/src/backend.rs @@ -31,8 +31,13 @@ pub struct Backend { impl Backend { /// Creates a new [`Backend`]. pub fn new(device: &wgpu::Device, settings: Settings) -> Self { - let text_pipeline = - text::Pipeline::new(device, settings.format, settings.default_font); + let text_pipeline = text::Pipeline::new( + device, + settings.format, + settings.default_font, + settings.text_multithreading, + ); + let quad_pipeline = quad::Pipeline::new(device, settings.format); let triangle_pipeline = triangle::Pipeline::new( device, diff --git a/wgpu/src/settings.rs b/wgpu/src/settings.rs index 6c97d895..b490e54e 100644 --- a/wgpu/src/settings.rs +++ b/wgpu/src/settings.rs @@ -29,6 +29,10 @@ pub struct Settings { /// By default, it will be set to 20. pub default_text_size: u16, + /// If enabled, spread text workload in multiple threads when multiple cores + /// are available. + pub text_multithreading: bool, + /// The antialiasing strategy that will be used for triangle primitives. pub antialiasing: Option<Antialiasing>, } @@ -65,6 +69,7 @@ impl Default for Settings { internal_backend: wgpu::BackendBit::PRIMARY, default_font: None, default_text_size: 20, + text_multithreading: false, antialiasing: None, } } diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index eed5de38..2b5b94c9 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -15,6 +15,7 @@ impl Pipeline { device: &wgpu::Device, format: wgpu::TextureFormat, default_font: Option<&[u8]>, + multithreading: bool, ) -> Self { let default_font = default_font.map(|slice| slice.to_vec()); @@ -46,9 +47,7 @@ impl Pipeline { let draw_brush = wgpu_glyph::GlyphBrushBuilder::using_font(font.clone()) .initial_cache_size((2048, 2048)) - .draw_cache_multithread(cfg!( - feature = "glyph_draw_cache_multithread" - )) + .draw_cache_multithread(multithreading) .build(device, format); let measure_brush = |