From b74e7e7353d69ffb54cf0c0f0574ea7abf0f3a68 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 7 Mar 2020 23:45:54 +0100 Subject: Implement `Primitive::Cached` --- wgpu/src/widget/canvas/layer/cache.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'wgpu/src/widget/canvas/layer/cache.rs') 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 { #[derive(Debug)] enum State { Empty, - Filled { bounds: Size, primitive: Primitive }, + Filled { + bounds: Size, + primitive: Arc, + }, } impl Cache @@ -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 { 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, -- cgit