Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,6 @@ debug = true
[patch.crates-io]
rfd = { git = "https://github.com/timon-schelling/rfd.git", branch = "graphite" } # TODO: Remove this once https://github.com/PolyMeilex/rfd/pull/317 is merged and released
# TODO: Remove these once the fork's fixes are upstreamed and released
vello_gpu = { git = "https://github.com/Keavon/vello.git", rev = "4df331db2a02cb0f1cef4a0190dbbb2a00f4b075" }
vello_common = { git = "https://github.com/Keavon/vello.git", rev = "4df331db2a02cb0f1cef4a0190dbbb2a00f4b075" }
vello_gpu_shaders = { git = "https://github.com/Keavon/vello.git", rev = "4df331db2a02cb0f1cef4a0190dbbb2a00f4b075" }
vello_gpu = { git = "https://github.com/Keavon/vello.git", rev = "41dfe98e61b6322db38301025cc7eff51d6e9844" }
vello_common = { git = "https://github.com/Keavon/vello.git", rev = "41dfe98e61b6322db38301025cc7eff51d6e9844" }
vello_gpu_shaders = { git = "https://github.com/Keavon/vello.git", rev = "41dfe98e61b6322db38301025cc7eff51d6e9844" }
4 changes: 2 additions & 2 deletions desktop/src/render/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) struct RenderState {
ui_texture: Option<wgpu::Texture>,
bind_group: Option<wgpu::BindGroup>,
#[derivative(Debug = "ignore")]
overlays_scene: Option<VelloSceneBuilder>,
overlays_scene: Option<VelloSceneBuilder<'static>>,
#[derivative(Debug = "ignore")]
overlays_canvas: VelloCanvas,
surface_outdated: bool,
Expand Down Expand Up @@ -220,7 +220,7 @@ impl RenderState {
self.viewport_offset = offset;
}

pub(crate) fn set_overlays_scene(&mut self, scene: VelloSceneBuilder) {
pub(crate) fn set_overlays_scene(&mut self, scene: VelloSceneBuilder<'static>) {
self.surface_outdated = true;
self.overlays_scene = Some(scene);
}
Expand Down
2 changes: 1 addition & 1 deletion desktop/wrapper/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum DesktopFrontendMessage {
WindowUpdateDirectInput {
enabled: bool,
},
UpdateOverlays(Box<wgpu_executor::VelloSceneBuilder>),
UpdateOverlays(Box<wgpu_executor::VelloSceneBuilder<'static>>),
PersistenceUpdatePreferences {
preferences: Preferences,
},
Expand Down
4 changes: 4 additions & 0 deletions document/migrations/nodes/src/blending_nodes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Migrations of the nodes in `blending_nodes`.

mod paint_overlay_from_color_overlay;
mod renames;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use migration_core::attr::node::ui::DISPLAY_NAME;
use migration_core::{Attributes, Node, migration};

/// 'Color Overlay' became the 'Paint Overlay' effect, which takes its color as a solid paint. A name it stored as its default would misname it.
#[migration("raster_nodes::blending_nodes::ColorOverlayNode"@1 => "blending_nodes::effects::PaintOverlayNode"@2)]
pub fn paint_overlay_from_color_overlay(node: &Node, attributes: &mut Attributes) {
if node.attributes().get_typed::<String>(DISPLAY_NAME).as_deref() == Some("Color Overlay") {
attributes.remove(node.id(), DISPLAY_NAME);
}
}

#[cfg(test)]
mod tests {
use super::*;
use document_graph_storage::TimeStamp;
use migration_core::{decl, literal};
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};

#[test]
fn rewrites_history() {
let contract = SourceContract {
display_names: &["Color Overlay"],
..SourceContract::new(4, |random, _| literal(random.below(10) as f64))
};
check_commutation(&PaintOverlayFromColorOverlay, &contract);
check_undo(&PaintOverlayFromColorOverlay, &contract);
}

#[test]
fn only_the_old_default_name_is_cleared() {
for (name, kept) in [("Color Overlay", None), ("Tint", Some("Tint"))] {
let mut fixture = Fixture::new(&PaintOverlayFromColorOverlay);
let overlay = fixture.add(decl!("raster_nodes::blending_nodes::ColorOverlayNode"@1), Vec::new());
let attributes = fixture.registry.node_instances.get_mut(&overlay).unwrap().attributes_mut();
attributes.set_serialized(DISPLAY_NAME, &name, TimeStamp::ORIGIN).unwrap();

let migrated = fixture.migrate(&PaintOverlayFromColorOverlay).unwrap();

assert_eq!(fixture.declaration_of(&migrated, overlay), Some(decl!("blending_nodes::effects::PaintOverlayNode"@2)));
assert_eq!(migrated.node_instances[&overlay].attributes().get_typed::<String>(DISPLAY_NAME).as_deref(), kept);
}
}
}
5 changes: 5 additions & 0 deletions document/migrations/nodes/src/blending_nodes/renames.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Nodes that only moved to a new identifier.

use migration_core::rename;

rename!("raster_nodes::filter::BlurNode"@1 => "blending_nodes::effects::BlurNode"@2);
1 change: 1 addition & 0 deletions document/migrations/nodes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Node migrations, in a module per node crate and a file per step, each registering itself. Scaffold one with
//! `cargo run migration new <identifier>` after bumping a node's `version(N)`.

mod blending_nodes;
mod graphene_core;
mod math_nodes;
mod raster_nodes;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use migration_core::attr::node::ui::DISPLAY_NAME;
use migration_core::{Attributes, Inputs, MigrationError, Node, literal, literal_of, migration};
use serde::{Deserialize, Serialize};

/// Frozen mirror of the `TaggedValue` variants this migration uses.
#[derive(Serialize, Deserialize)]
enum Tagged {
Number(f64),
GradientForm(GradientForm),
}

#[derive(Serialize, Deserialize)]
enum GradientForm {
Linear,
Radial,
}

const FORM: u32 = 1;

/// 'Gradient Form' became 'Gradient Curvature', whose start and end curvatures take the presets of the form it set: 0 and 0 for linear, 1 and 0.5 for
/// radial. A wired form becomes linear, and a name it stored as its default is cleared.
#[migration("math_nodes::GradientFormNode"@1 => "math_nodes::GradientCurvatureNode"@2)]
pub fn gradient_curvature_from_gradient_form(node: &Node, inputs: &mut Inputs, attributes: &mut Attributes) -> Result<(), MigrationError> {
let [_, form] = node.inputs() else {
return Err(MigrationError::invariant("Gradient Form has two inputs"));
};
let [start, end] = match literal_of::<Tagged>(&form.input) {
Some(Tagged::GradientForm(GradientForm::Radial)) => [1., 0.5],
_ => [0., 0.],
};

inputs.set(FORM, literal(Tagged::Number(start)));
inputs.push(literal(Tagged::Number(end)));

if node.attributes().get_typed::<String>(DISPLAY_NAME).as_deref() == Some("Gradient Form") {
attributes.remove(node.id(), DISPLAY_NAME);
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use document_graph_storage::TimeStamp;
use migration_core::{NodeInput, decl};
use migration_runner::testing::{Fixture, SourceContract, check_commutation, check_undo};

fn form(form: GradientForm) -> NodeInput {
literal(Tagged::GradientForm(form))
}

fn contract() -> SourceContract {
SourceContract {
display_names: &["Gradient Form"],
..SourceContract::new(2, |random, slot| match slot {
1 if random.below(2) == 0 => form(GradientForm::Radial),
1 => form(GradientForm::Linear),
_ => literal(Tagged::Number(random.below(10) as f64)),
})
}
}

#[test]
fn rewrites_history() {
check_commutation(&GradientCurvatureFromGradientForm, &contract());
check_undo(&GradientCurvatureFromGradientForm, &contract());
}

#[test]
fn forms_become_their_curvature_presets() {
let gradient = literal(Tagged::Number(0.));
for (old_form, [start, end]) in [
(form(GradientForm::Linear), [0., 0.]),
(form(GradientForm::Radial), [1., 0.5]),
(NodeInput::Import { index: 0 }, [0., 0.]),
] {
let mut fixture = Fixture::new(&GradientCurvatureFromGradientForm);
let node = fixture.add(decl!("math_nodes::GradientFormNode"@1), vec![gradient.clone(), old_form]);
let migrated = fixture.migrate(&GradientCurvatureFromGradientForm).unwrap();

assert_eq!(fixture.declaration_of(&migrated, node), Some(decl!("math_nodes::GradientCurvatureNode"@2)));
assert_eq!(fixture.inputs(&migrated, node), [gradient.clone(), literal(Tagged::Number(start)), literal(Tagged::Number(end))]);
}
}

#[test]
fn only_the_old_default_name_is_cleared() {
for (name, kept) in [("Gradient Form", None), ("Spotlight", Some("Spotlight"))] {
let mut fixture = Fixture::new(&GradientCurvatureFromGradientForm);
let node = fixture.add(decl!("math_nodes::GradientFormNode"@1), vec![literal(Tagged::Number(0.)), form(GradientForm::Linear)]);
let attributes = fixture.registry.node_instances.get_mut(&node).unwrap().attributes_mut();
attributes.set_serialized(DISPLAY_NAME, &name, TimeStamp::ORIGIN).unwrap();

let migrated = fixture.migrate(&GradientCurvatureFromGradientForm).unwrap();

assert_eq!(migrated.node_instances[&node].attributes().get_typed::<String>(DISPLAY_NAME).as_deref(), kept);
}
}
}
1 change: 1 addition & 0 deletions document/migrations/nodes/src/math_nodes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Migrations of the nodes in `math_nodes`.

mod gradient_curvature_from_gradient_form;
mod math_formula_from_math_f;
mod renames;
Loading
Loading