Fix windows fighting over shared image::Cache
Image caches are local to each window now.
This commit is contained in:
parent
a94984d681
commit
547446f0de
8 changed files with 77 additions and 70 deletions
|
|
@ -67,6 +67,8 @@ use crate::core::{
|
|||
use crate::graphics::text::{Editor, Paragraph};
|
||||
use crate::graphics::Viewport;
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
/// A [`wgpu`] graphics renderer for [`iced`].
|
||||
///
|
||||
/// [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
||||
|
|
@ -82,11 +84,12 @@ pub struct Renderer {
|
|||
|
||||
// TODO: Centralize all the image feature handling
|
||||
#[cfg(any(feature = "svg", feature = "image"))]
|
||||
image_cache: image::cache::Shared,
|
||||
image_cache: RefCell<image::Cache>,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn new(
|
||||
_device: &wgpu::Device,
|
||||
_engine: &Engine,
|
||||
default_font: Font,
|
||||
default_text_size: Pixels,
|
||||
|
|
@ -100,7 +103,7 @@ impl Renderer {
|
|||
text_storage: text::Storage::new(),
|
||||
|
||||
#[cfg(any(feature = "svg", feature = "image"))]
|
||||
image_cache: _engine.image_cache().clone(),
|
||||
image_cache: RefCell::new(_engine.create_image_cache(_device)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -191,6 +194,7 @@ impl Renderer {
|
|||
device,
|
||||
encoder,
|
||||
&mut engine.staging_belt,
|
||||
&mut self.image_cache.borrow_mut(),
|
||||
&layer.images,
|
||||
viewport.projection(),
|
||||
scale_factor,
|
||||
|
|
@ -246,6 +250,8 @@ impl Renderer {
|
|||
|
||||
#[cfg(any(feature = "svg", feature = "image"))]
|
||||
let mut image_layer = 0;
|
||||
#[cfg(any(feature = "svg", feature = "image"))]
|
||||
let image_cache = self.image_cache.borrow();
|
||||
|
||||
let scale_factor = viewport.scale_factor() as f32;
|
||||
let physical_bounds = Rectangle::<f32>::from(Rectangle::with_size(
|
||||
|
|
@ -359,6 +365,7 @@ impl Renderer {
|
|||
#[cfg(any(feature = "svg", feature = "image"))]
|
||||
if !layer.images.is_empty() {
|
||||
engine.image_pipeline.render(
|
||||
&image_cache,
|
||||
image_layer,
|
||||
scissor_rect,
|
||||
&mut render_pass,
|
||||
|
|
@ -509,7 +516,7 @@ impl core::image::Renderer for Renderer {
|
|||
type Handle = core::image::Handle;
|
||||
|
||||
fn measure_image(&self, handle: &Self::Handle) -> Size<u32> {
|
||||
self.image_cache.lock().measure_image(handle)
|
||||
self.image_cache.borrow_mut().measure_image(handle)
|
||||
}
|
||||
|
||||
fn draw_image(
|
||||
|
|
@ -535,7 +542,7 @@ impl core::image::Renderer for Renderer {
|
|||
#[cfg(feature = "svg")]
|
||||
impl core::svg::Renderer for Renderer {
|
||||
fn measure_svg(&self, handle: &core::svg::Handle) -> Size<u32> {
|
||||
self.image_cache.lock().measure_svg(handle)
|
||||
self.image_cache.borrow_mut().measure_svg(handle)
|
||||
}
|
||||
|
||||
fn draw_svg(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue