Add text_multithreading to Settings in iced_glow and iced_wgpu

This commit is contained in:
Héctor Ramón Jiménez 2021-07-22 18:21:50 +07:00
parent 6469e463cd
commit 217f5be827
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
9 changed files with 31 additions and 16 deletions

View file

@ -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

View file

@ -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 = []

View file

@ -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);

View file

@ -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,
}
}

View file

@ -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 =

View file

@ -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"

View file

@ -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,

View file

@ -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,
}
}

View file

@ -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 =