mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
WIP debugging
This commit is contained in:
@@ -13,7 +13,7 @@ pub trait ExtractFootprint {
|
||||
fn footprint(&self) -> &Footprint {
|
||||
self.try_footprint().unwrap_or_else(|| {
|
||||
log::error!("Context did not have a footprint, called from: {}", Location::caller());
|
||||
&const { Footprint::empty() }
|
||||
&Footprint::DEFAULT
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ impl<T: ExtractFootprint + Sync> ExtractFootprint for Option<T> {
|
||||
fn footprint(&self) -> &Footprint {
|
||||
self.try_footprint().unwrap_or_else(|| {
|
||||
log::warn!("trying to extract footprint from context None {} ", Location::caller());
|
||||
&const { Footprint::empty() }
|
||||
&Footprint::DEFAULT
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -193,7 +193,7 @@ impl ExtractFootprint for OwnedContextImpl {
|
||||
}
|
||||
impl ExtractTime for OwnedContextImpl {
|
||||
fn try_time(&self) -> Option<f64> {
|
||||
self.time
|
||||
self.real_time
|
||||
}
|
||||
}
|
||||
impl ExtractAnimationTime for OwnedContextImpl {
|
||||
@@ -245,10 +245,24 @@ pub struct OwnedContextImpl {
|
||||
parent: Option<Arc<dyn ExtractVarArgs + Sync + Send>>,
|
||||
// This could be converted into a single enum to save extra bytes
|
||||
index: Option<usize>,
|
||||
time: Option<f64>,
|
||||
real_time: Option<f64>,
|
||||
animation_time: Option<f64>,
|
||||
}
|
||||
|
||||
// TODO: Probably delete this before committing
|
||||
impl core::fmt::Debug for OwnedContextImpl {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.debug_struct("OwnedContextImpl")
|
||||
.field("footprint", &self.footprint)
|
||||
.field("varargs", &self.varargs)
|
||||
// .field("parent", &self.parent)
|
||||
.field("index", &self.index)
|
||||
.field("real_time", &self.real_time)
|
||||
.field("animation_time", &self.animation_time)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for OwnedContextImpl {
|
||||
#[track_caller]
|
||||
fn default() -> Self {
|
||||
@@ -258,11 +272,14 @@ impl Default for OwnedContextImpl {
|
||||
|
||||
impl core::hash::Hash for OwnedContextImpl {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
debug!("Calculating hash for {:#?}", self);
|
||||
self.footprint.hash(state);
|
||||
// TODO: Reenable before committing
|
||||
// self.varargs.as_ref().map(|x| Arc::as_ptr(x).addr()).hash(state);
|
||||
// self.parent.as_ref().map(|x| Arc::as_ptr(x).addr()).hash(state);
|
||||
self.index.hash(state);
|
||||
self.time.map(|x| x.to_bits()).hash(state);
|
||||
self.parent.as_ref().map(|x| Arc::as_ptr(x).addr()).hash(state);
|
||||
self.varargs.as_ref().map(|x| Arc::as_ptr(x).addr()).hash(state);
|
||||
self.real_time.map(|x| x.to_bits()).hash(state);
|
||||
self.animation_time.map(|x| x.to_bits()).hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +296,7 @@ impl OwnedContextImpl {
|
||||
varargs: None,
|
||||
parent,
|
||||
index,
|
||||
time,
|
||||
real_time: time,
|
||||
animation_time: frame_time,
|
||||
}
|
||||
}
|
||||
@@ -289,7 +306,7 @@ impl OwnedContextImpl {
|
||||
varargs: None,
|
||||
parent: None,
|
||||
index: None,
|
||||
time: None,
|
||||
real_time: None,
|
||||
animation_time: None,
|
||||
}
|
||||
}
|
||||
@@ -303,8 +320,8 @@ impl OwnedContextImpl {
|
||||
self.footprint = Some(footprint);
|
||||
self
|
||||
}
|
||||
pub fn with_time(mut self, time: f64) -> Self {
|
||||
self.time = Some(time);
|
||||
pub fn with_real_time(mut self, time: f64) -> Self {
|
||||
self.real_time = Some(time);
|
||||
self
|
||||
}
|
||||
pub fn with_animation_time(mut self, animation_time: f64) -> Self {
|
||||
@@ -314,6 +331,10 @@ impl OwnedContextImpl {
|
||||
pub fn into_context(self) -> Option<Arc<Self>> {
|
||||
Some(Arc::new(self))
|
||||
}
|
||||
pub fn erase_parent(mut self) -> Self {
|
||||
self.parent = None;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Copy, dyn_any::DynAny)]
|
||||
|
||||
@@ -25,9 +25,11 @@ where
|
||||
let mut hasher = DefaultHasher::new();
|
||||
input.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
|
||||
if let Some(data) = self.cache.lock().as_ref().unwrap().as_ref().and_then(|data| (data.0 == hash).then_some(data.1.clone())) {
|
||||
Box::pin(async move { data })
|
||||
} else {
|
||||
debug!("Cache miss for {hash}");
|
||||
let fut = self.node.eval(input);
|
||||
let cache = self.cache.clone();
|
||||
Box::pin(async move {
|
||||
|
||||
@@ -4,7 +4,9 @@ use crate::raster::bbox::AxisAlignedBbox;
|
||||
use crate::raster::image::ImageFrameTable;
|
||||
use crate::vector::VectorDataTable;
|
||||
use crate::{Artboard, ArtboardGroupTable, CloneVarArgs, Color, Context, Ctx, ExtractAll, GraphicGroupTable, OwnedContextImpl};
|
||||
use glam::{DAffine2, DVec2};
|
||||
use core::f64;
|
||||
use core::hash::{Hash, Hasher};
|
||||
use glam::{DAffine2, DMat2, DVec2};
|
||||
|
||||
pub trait Transform {
|
||||
fn transform(&self) -> DAffine2;
|
||||
@@ -94,18 +96,26 @@ pub struct Footprint {
|
||||
|
||||
impl Default for Footprint {
|
||||
fn default() -> Self {
|
||||
Self::empty()
|
||||
Self::DEFAULT
|
||||
}
|
||||
}
|
||||
|
||||
impl Footprint {
|
||||
pub const fn empty() -> Self {
|
||||
Self {
|
||||
transform: DAffine2::IDENTITY,
|
||||
resolution: glam::UVec2::new(1920, 1080),
|
||||
quality: RenderQuality::Full,
|
||||
}
|
||||
}
|
||||
pub const DEFAULT: Self = Self {
|
||||
transform: DAffine2::IDENTITY,
|
||||
resolution: glam::UVec2::new(1920, 1080),
|
||||
quality: RenderQuality::Full,
|
||||
};
|
||||
|
||||
pub const BOUNDLESS: Self = Self {
|
||||
transform: DAffine2 {
|
||||
matrix2: DMat2::from_diagonal(DVec2::splat(f64::INFINITY)),
|
||||
translation: DVec2::ZERO,
|
||||
},
|
||||
resolution: glam::UVec2::new(0, 0),
|
||||
quality: RenderQuality::Full,
|
||||
};
|
||||
|
||||
pub fn viewport_bounds_in_local_space(&self) -> AxisAlignedBbox {
|
||||
let inverse = self.transform.inverse();
|
||||
let start = inverse.transform_point2((0., 0.).into());
|
||||
@@ -198,3 +208,24 @@ fn replace_transform<Data, TransformInput: Transform>(
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Debug"))]
|
||||
async fn boundless_footprint<T: 'n + 'static>(
|
||||
ctx: impl Ctx + CloneVarArgs + ExtractAll,
|
||||
#[implementations(
|
||||
Context -> VectorDataTable,
|
||||
Context -> GraphicGroupTable,
|
||||
Context -> ImageFrameTable<Color>,
|
||||
Context -> TextureFrameTable,
|
||||
)]
|
||||
transform_target: impl Node<Context<'static>, Output = Instances<T>>,
|
||||
) -> Instances<T> {
|
||||
let ctx = OwnedContextImpl::from(ctx).with_footprint(Footprint::BOUNDLESS).with_real_time(0.).erase_parent();
|
||||
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
ctx.hash(&mut hasher);
|
||||
let hash = hasher.finish();
|
||||
debug!("The context with hash {hash} is now: {ctx:#?}");
|
||||
|
||||
transform_target.eval(ctx.into_context()).await
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ async fn render<'a: 'n, T: 'n + GraphicElementRendered + WasmNotSend>(
|
||||
let footprint = render_config.viewport;
|
||||
let ctx = OwnedContextImpl::default()
|
||||
.with_footprint(footprint)
|
||||
.with_time(render_config.time.time)
|
||||
.with_real_time(render_config.time.time)
|
||||
.with_animation_time(render_config.time.animation_time.as_secs_f64())
|
||||
.into_context();
|
||||
ctx.footprint();
|
||||
|
||||
Reference in New Issue
Block a user