Add a complexity limit on displaying layer thumbnails to improve performance (#2828)
* Skip complex layer thumbnails * Set Raster<GPU> to have usize::MAX render complexity * Code review --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
parent
ceffcfd8df
commit
13ad814639
|
|
@ -328,6 +328,18 @@ impl NodeRuntime {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip thumbnails if the layer is too complex (for performance)
|
||||||
|
if graphic_element.render_complexity() > 1000 {
|
||||||
|
let old = thumbnail_renders.insert(parent_network_node_id, Vec::new());
|
||||||
|
if old.is_none_or(|v| !v.is_empty()) {
|
||||||
|
responses.push_back(FrontendMessage::UpdateNodeThumbnail {
|
||||||
|
id: parent_network_node_id,
|
||||||
|
value: "<svg viewBox=\"0 0 10 10\"><title>Dense thumbnail omitted for performance</title><line x1=\"0\" y1=\"10\" x2=\"10\" y2=\"0\" stroke=\"red\" /></svg>".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let bounds = graphic_element.bounding_box(DAffine2::IDENTITY, true);
|
let bounds = graphic_element.bounding_box(DAffine2::IDENTITY, true);
|
||||||
|
|
||||||
// Render the thumbnail from a `GraphicElement` into an SVG string
|
// Render the thumbnail from a `GraphicElement` into an SVG string
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ pub mod ops;
|
||||||
pub mod raster;
|
pub mod raster;
|
||||||
pub mod raster_types;
|
pub mod raster_types;
|
||||||
pub mod registry;
|
pub mod registry;
|
||||||
|
pub mod render_complexity;
|
||||||
pub mod structural;
|
pub mod structural;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
pub mod transform;
|
pub mod transform;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
use crate::instances::Instances;
|
||||||
|
use crate::raster_types::{CPU, GPU, Raster};
|
||||||
|
use crate::vector::VectorData;
|
||||||
|
use crate::{Artboard, Color, GraphicElement};
|
||||||
|
use glam::DVec2;
|
||||||
|
|
||||||
|
pub trait RenderComplexity {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: RenderComplexity> RenderComplexity for Instances<T> {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
self.instance_ref_iter().map(|instance| instance.instance.render_complexity()).fold(0, usize::saturating_add)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderComplexity for Artboard {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
self.graphic_group.render_complexity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderComplexity for GraphicElement {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
match self {
|
||||||
|
Self::GraphicGroup(instances) => instances.render_complexity(),
|
||||||
|
Self::VectorData(instances) => instances.render_complexity(),
|
||||||
|
Self::RasterDataCPU(instances) => instances.render_complexity(),
|
||||||
|
Self::RasterDataGPU(instances) => instances.render_complexity(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderComplexity for VectorData {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
self.segment_domain.ids().len()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderComplexity for Raster<CPU> {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
(self.width * self.height / 500) as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderComplexity for Raster<GPU> {
|
||||||
|
fn render_complexity(&self) -> usize {
|
||||||
|
// GPU textures currently can't have a thumbnail
|
||||||
|
usize::MAX
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RenderComplexity for String {}
|
||||||
|
impl RenderComplexity for bool {}
|
||||||
|
impl RenderComplexity for f32 {}
|
||||||
|
impl RenderComplexity for f64 {}
|
||||||
|
impl RenderComplexity for DVec2 {}
|
||||||
|
impl RenderComplexity for Option<Color> {}
|
||||||
|
impl RenderComplexity for Vec<Color> {}
|
||||||
|
|
@ -10,6 +10,7 @@ use graphene_core::instances::Instance;
|
||||||
use graphene_core::math::quad::Quad;
|
use graphene_core::math::quad::Quad;
|
||||||
use graphene_core::raster::Image;
|
use graphene_core::raster::Image;
|
||||||
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
|
use graphene_core::raster_types::{CPU, GPU, RasterDataTable};
|
||||||
|
use graphene_core::render_complexity::RenderComplexity;
|
||||||
use graphene_core::transform::{Footprint, Transform};
|
use graphene_core::transform::{Footprint, Transform};
|
||||||
use graphene_core::uuid::{NodeId, generate_uuid};
|
use graphene_core::uuid::{NodeId, generate_uuid};
|
||||||
use graphene_core::vector::VectorDataTable;
|
use graphene_core::vector::VectorDataTable;
|
||||||
|
|
@ -204,7 +205,7 @@ pub struct RenderMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename to "Graphical"
|
// TODO: Rename to "Graphical"
|
||||||
pub trait GraphicElementRendered: BoundingBox {
|
pub trait GraphicElementRendered: BoundingBox + RenderComplexity {
|
||||||
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams);
|
fn render_svg(&self, render: &mut SvgRender, render_params: &RenderParams);
|
||||||
|
|
||||||
#[cfg(feature = "vello")]
|
#[cfg(feature = "vello")]
|
||||||
|
|
@ -1151,7 +1152,7 @@ impl GraphicElementRendered for GraphicElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to stop rust complaining about upstream traits adding display implementations to `Option<Color>`. This would not be an issue as we control that crate.
|
/// Used to stop rust complaining about upstream traits adding display implementations to `Option<Color>`. This would not be an issue as we control that crate.
|
||||||
trait Primitive: std::fmt::Display + BoundingBox {}
|
trait Primitive: std::fmt::Display + BoundingBox + RenderComplexity {}
|
||||||
impl Primitive for String {}
|
impl Primitive for String {}
|
||||||
impl Primitive for bool {}
|
impl Primitive for bool {}
|
||||||
impl Primitive for f32 {}
|
impl Primitive for f32 {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue