Fix geometry::Cache not reusing previous geometry
This commit is contained in:
parent
1672b0d619
commit
e2c129c057
2 changed files with 24 additions and 16 deletions
|
|
@ -22,13 +22,20 @@ where
|
||||||
/// Creates a new empty [`Cache`].
|
/// Creates a new empty [`Cache`].
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Cache {
|
Cache {
|
||||||
state: RefCell::new(State::Empty),
|
state: RefCell::new(State::Empty { previous: None }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clears the [`Cache`], forcing a redraw the next time it is used.
|
/// Clears the [`Cache`], forcing a redraw the next time it is used.
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
*self.state.borrow_mut() = State::Empty;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
let previous = match self.state.borrow().deref() {
|
||||||
|
State::Empty { previous } => previous.clone(),
|
||||||
|
State::Filled { geometry, .. } => Some(geometry.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
|
*self.state.borrow_mut() = State::Empty { previous };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draws geometry using the provided closure and stores it in the
|
/// Draws geometry using the provided closure and stores it in the
|
||||||
|
|
@ -49,18 +56,18 @@ where
|
||||||
) -> Renderer::Geometry {
|
) -> Renderer::Geometry {
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
let previous = if let State::Filled {
|
let previous = match self.state.borrow().deref() {
|
||||||
bounds: cached_bounds,
|
State::Empty { previous } => previous.clone(),
|
||||||
geometry,
|
State::Filled {
|
||||||
} = self.state.borrow().deref()
|
bounds: cached_bounds,
|
||||||
{
|
geometry,
|
||||||
if *cached_bounds == bounds {
|
} => {
|
||||||
return Cached::load(geometry);
|
if *cached_bounds == bounds {
|
||||||
}
|
return Cached::load(geometry);
|
||||||
|
}
|
||||||
|
|
||||||
Some(geometry.clone())
|
Some(geometry.clone())
|
||||||
} else {
|
}
|
||||||
None
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut frame = Frame::new(renderer, bounds);
|
let mut frame = Frame::new(renderer, bounds);
|
||||||
|
|
@ -83,7 +90,7 @@ where
|
||||||
let state = self.state.borrow();
|
let state = self.state.borrow();
|
||||||
|
|
||||||
match *state {
|
match *state {
|
||||||
State::Empty => write!(f, "Cache::Empty"),
|
State::Empty { .. } => write!(f, "Cache::Empty"),
|
||||||
State::Filled { bounds, .. } => {
|
State::Filled { bounds, .. } => {
|
||||||
write!(f, "Cache::Filled {{ bounds: {bounds:?} }}")
|
write!(f, "Cache::Filled {{ bounds: {bounds:?} }}")
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +111,9 @@ enum State<Geometry>
|
||||||
where
|
where
|
||||||
Geometry: Cached,
|
Geometry: Cached,
|
||||||
{
|
{
|
||||||
Empty,
|
Empty {
|
||||||
|
previous: Option<Geometry::Cache>,
|
||||||
|
},
|
||||||
Filled {
|
Filled {
|
||||||
bounds: Size,
|
bounds: Size,
|
||||||
geometry: Geometry::Cache,
|
geometry: Geometry::Cache,
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,6 @@ impl Pipeline {
|
||||||
needs_reupload: false,
|
needs_reupload: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::Uploaded {
|
Cache::Uploaded {
|
||||||
batch,
|
batch,
|
||||||
layer,
|
layer,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue