Introduce canvas::Cache grouping

Caches with the same `Group` will share their text
atlas!
This commit is contained in:
Héctor Ramón Jiménez 2024-04-30 07:57:54 +02:00
parent 24501fd73b
commit b5b78d505e
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
10 changed files with 279 additions and 101 deletions

View file

@ -428,8 +428,8 @@ where
mod geometry {
use super::Renderer;
use crate::core::{Point, Radians, Rectangle, Size, Vector};
use crate::graphics::cache::{self, Cached};
use crate::graphics::geometry::{self, Fill, Path, Stroke, Text};
use crate::graphics::Cached;
impl<A, B> geometry::Renderer for Renderer<A, B>
where
@ -483,21 +483,25 @@ mod geometry {
}
}
fn cache(self, previous: Option<Self::Cache>) -> Self::Cache {
fn cache(
self,
group: cache::Group,
previous: Option<Self::Cache>,
) -> Self::Cache {
match (self, previous) {
(
Self::Primary(geometry),
Some(Geometry::Primary(previous)),
) => Geometry::Primary(geometry.cache(Some(previous))),
) => Geometry::Primary(geometry.cache(group, Some(previous))),
(Self::Primary(geometry), None) => {
Geometry::Primary(geometry.cache(None))
Geometry::Primary(geometry.cache(group, None))
}
(
Self::Secondary(geometry),
Some(Geometry::Secondary(previous)),
) => Geometry::Secondary(geometry.cache(Some(previous))),
) => Geometry::Secondary(geometry.cache(group, Some(previous))),
(Self::Secondary(geometry), None) => {
Geometry::Secondary(geometry.cache(None))
Geometry::Secondary(geometry.cache(group, None))
}
_ => unreachable!(),
}