Generate new layers only for clip primitives in `Layer::generate`
This commit is contained in:
parent
4e923290cc
commit
5e2743361b
|
@ -82,7 +82,12 @@ impl<'a> Layer<'a> {
|
||||||
|
|
||||||
let mut layers = vec![first_layer];
|
let mut layers = vec![first_layer];
|
||||||
|
|
||||||
Self::process_primitive(&mut layers, Vector::new(0.0, 0.0), primitive);
|
Self::process_primitive(
|
||||||
|
&mut layers,
|
||||||
|
Vector::new(0.0, 0.0),
|
||||||
|
primitive,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
layers
|
layers
|
||||||
}
|
}
|
||||||
|
@ -91,13 +96,19 @@ impl<'a> Layer<'a> {
|
||||||
layers: &mut Vec<Self>,
|
layers: &mut Vec<Self>,
|
||||||
translation: Vector,
|
translation: Vector,
|
||||||
primitive: &'a Primitive,
|
primitive: &'a Primitive,
|
||||||
|
current_layer: usize,
|
||||||
) {
|
) {
|
||||||
match primitive {
|
match primitive {
|
||||||
Primitive::None => {}
|
Primitive::None => {}
|
||||||
Primitive::Group { primitives } => {
|
Primitive::Group { primitives } => {
|
||||||
// TODO: Inspect a bit and regroup (?)
|
// TODO: Inspect a bit and regroup (?)
|
||||||
for primitive in primitives {
|
for primitive in primitives {
|
||||||
Self::process_primitive(layers, translation, primitive)
|
Self::process_primitive(
|
||||||
|
layers,
|
||||||
|
translation,
|
||||||
|
primitive,
|
||||||
|
current_layer,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Primitive::Text {
|
Primitive::Text {
|
||||||
|
@ -109,7 +120,7 @@ impl<'a> Layer<'a> {
|
||||||
horizontal_alignment,
|
horizontal_alignment,
|
||||||
vertical_alignment,
|
vertical_alignment,
|
||||||
} => {
|
} => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = &mut layers[current_layer];
|
||||||
|
|
||||||
layer.text.push(Text {
|
layer.text.push(Text {
|
||||||
content,
|
content,
|
||||||
|
@ -128,7 +139,7 @@ impl<'a> Layer<'a> {
|
||||||
border_width,
|
border_width,
|
||||||
border_color,
|
border_color,
|
||||||
} => {
|
} => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = &mut layers[current_layer];
|
||||||
|
|
||||||
// TODO: Move some of these computations to the GPU (?)
|
// TODO: Move some of these computations to the GPU (?)
|
||||||
layer.quads.push(Quad {
|
layer.quads.push(Quad {
|
||||||
|
@ -146,7 +157,7 @@ impl<'a> Layer<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Primitive::Mesh2D { buffers, size } => {
|
Primitive::Mesh2D { buffers, size } => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = &mut layers[current_layer];
|
||||||
|
|
||||||
let bounds = Rectangle::new(
|
let bounds = Rectangle::new(
|
||||||
Point::new(translation.x, translation.y),
|
Point::new(translation.x, translation.y),
|
||||||
|
@ -167,7 +178,7 @@ impl<'a> Layer<'a> {
|
||||||
offset,
|
offset,
|
||||||
content,
|
content,
|
||||||
} => {
|
} => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = &mut layers[current_layer];
|
||||||
let translated_bounds = *bounds + translation;
|
let translated_bounds = *bounds + translation;
|
||||||
|
|
||||||
// Only draw visible content
|
// Only draw visible content
|
||||||
|
@ -175,16 +186,15 @@ impl<'a> Layer<'a> {
|
||||||
layer.bounds.intersection(&translated_bounds)
|
layer.bounds.intersection(&translated_bounds)
|
||||||
{
|
{
|
||||||
let clip_layer = Layer::new(clip_bounds);
|
let clip_layer = Layer::new(clip_bounds);
|
||||||
let new_layer = Layer::new(layer.bounds);
|
|
||||||
|
|
||||||
layers.push(clip_layer);
|
layers.push(clip_layer);
|
||||||
|
|
||||||
Self::process_primitive(
|
Self::process_primitive(
|
||||||
layers,
|
layers,
|
||||||
translation
|
translation
|
||||||
- Vector::new(offset.x as f32, offset.y as f32),
|
- Vector::new(offset.x as f32, offset.y as f32),
|
||||||
content,
|
content,
|
||||||
|
layers.len() - 1,
|
||||||
);
|
);
|
||||||
layers.push(new_layer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Primitive::Translate {
|
Primitive::Translate {
|
||||||
|
@ -195,13 +205,19 @@ impl<'a> Layer<'a> {
|
||||||
layers,
|
layers,
|
||||||
translation + *new_translation,
|
translation + *new_translation,
|
||||||
&content,
|
&content,
|
||||||
|
current_layer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Primitive::Cached { cache } => {
|
Primitive::Cached { cache } => {
|
||||||
Self::process_primitive(layers, translation, &cache);
|
Self::process_primitive(
|
||||||
|
layers,
|
||||||
|
translation,
|
||||||
|
&cache,
|
||||||
|
current_layer,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Primitive::Image { handle, bounds } => {
|
Primitive::Image { handle, bounds } => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = &mut layers[current_layer];
|
||||||
|
|
||||||
layer.images.push(Image::Raster {
|
layer.images.push(Image::Raster {
|
||||||
handle: handle.clone(),
|
handle: handle.clone(),
|
||||||
|
@ -209,7 +225,7 @@ impl<'a> Layer<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Primitive::Svg { handle, bounds } => {
|
Primitive::Svg { handle, bounds } => {
|
||||||
let layer = layers.last_mut().unwrap();
|
let layer = &mut layers[current_layer];
|
||||||
|
|
||||||
layer.images.push(Image::Vector {
|
layer.images.push(Image::Vector {
|
||||||
handle: handle.clone(),
|
handle: handle.clone(),
|
||||||
|
|
Loading…
Reference in New Issue