Avoid preparing layers outside physical bounds in iced_wgpu

This commit is contained in:
Héctor Ramón Jiménez 2025-01-26 03:53:18 +01:00
parent c0db7b8e1f
commit 3428a3d2af
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 13 additions and 33 deletions

View file

@ -145,7 +145,19 @@ impl Renderer {
self.text_viewport.update(queue, viewport.physical_size());
let physical_bounds = Rectangle::<f32>::from(Rectangle::with_size(
viewport.physical_size(),
));
for layer in self.layers.iter_mut() {
if physical_bounds
.intersection(&(layer.bounds * scale_factor))
.and_then(Rectangle::snap)
.is_none()
{
continue;
}
if !layer.quads.is_empty() {
engine.quad_pipeline.prepare(
device,
@ -269,27 +281,9 @@ impl Renderer {
for layer in self.layers.iter() {
let Some(scissor_rect) = physical_bounds
.intersection(&(layer.bounds * scale))
.intersection(&(layer.bounds * scale_factor))
.and_then(Rectangle::snap)
else {
if !layer.quads.is_empty() {
quad_layer += 1;
}
if !layer.triangles.is_empty() {
mesh_layer +=
triangle::Pipeline::layer_count(&layer.triangles);
}
if !layer.text.is_empty() {
text_layer += text::Pipeline::layer_count(&layer.text);
}
#[cfg(any(feature = "svg", feature = "image"))]
if !layer.images.is_empty() {
image_layer += 1;
}
continue;
};

View file

@ -302,13 +302,6 @@ impl Pipeline {
}
}
pub fn layer_count(batch: &Batch) -> usize {
batch
.iter()
.filter(|item| matches!(item, Item::Group { .. }))
.count()
}
pub fn prepare(
&mut self,
device: &wgpu::Device,

View file

@ -177,13 +177,6 @@ impl Pipeline {
}
}
pub fn layer_count(items: &[Item]) -> usize {
items
.iter()
.filter(|item| matches!(item, Item::Group { .. }))
.count()
}
pub fn prepare(
&mut self,
device: &wgpu::Device,