summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget/canvas/layer/cache.rs
diff options
context:
space:
mode:
Diffstat (limited to 'wgpu/src/widget/canvas/layer/cache.rs')
-rw-r--r--wgpu/src/widget/canvas/layer/cache.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/wgpu/src/widget/canvas/layer/cache.rs b/wgpu/src/widget/canvas/layer/cache.rs
index f05028da..6b69f01e 100644
--- a/wgpu/src/widget/canvas/layer/cache.rs
+++ b/wgpu/src/widget/canvas/layer/cache.rs
@@ -3,8 +3,8 @@ use crate::{
Primitive,
};
-use iced_native::{Point, Size};
-use std::{cell::RefCell, marker::PhantomData};
+use iced_native::Size;
+use std::{cell::RefCell, marker::PhantomData, sync::Arc};
/// A simple cache that stores generated geometry to avoid recomputation.
///
@@ -22,7 +22,10 @@ pub struct Cache<T: Drawable> {
#[derive(Debug)]
enum State {
Empty,
- Filled { bounds: Size, primitive: Primitive },
+ Filled {
+ bounds: Size,
+ primitive: Arc<Primitive>,
+ },
}
impl<T> Cache<T>
@@ -70,7 +73,7 @@ impl<'a, T> Layer for Bind<'a, T>
where
T: Drawable + std::fmt::Debug,
{
- fn draw(&self, origin: Point, current_bounds: Size) -> Primitive {
+ fn draw(&self, current_bounds: Size) -> Arc<Primitive> {
use std::ops::Deref;
if let State::Filled { bounds, primitive } =
@@ -84,7 +87,7 @@ where
let mut frame = Frame::new(current_bounds.width, current_bounds.height);
self.input.draw(&mut frame);
- let primitive = frame.into_primitive(origin);
+ let primitive = Arc::new(frame.into_primitive());
*self.cache.state.borrow_mut() = State::Filled {
bounds: current_bounds,