mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 15:53:26 -10:00
Load images into CPU rasters by default again
This commit is contained in:
1 parent
95e9c2852e
commit
e6cb938ff9
16 files changed
+169
-118
No files matched your search
@@ -611,10 +611,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
||||
..Default::default()
|
||||
},
|
||||
NodeTemplate {
|
||||
inputs: vec![
|
||||
NodeInput::node(NodeId(0), 0),
|
||||
NodeInput::scope(raster_nodes::raster_kernel::raster_kernel_pipeline::IDENTIFIER.as_str().to_string()),
|
||||
],
|
||||
inputs: vec![NodeInput::node(NodeId(0), 0)],
|
||||
implementation: NodeTemplateImplementation::ProtoNode(platform_application_io::bytes_to_image::IDENTIFIER),
|
||||
node_type_metadata: NodeTypePersistentMetadata::node(IVec2::new(7, 0)),
|
||||
..Default::default()
|
||||
|
||||
@@ -16,7 +16,6 @@ use graphene_std::ParameterRef;
|
||||
use graphene_std::ProtoNodeIdentifier;
|
||||
use graphene_std::extract_xy::XY;
|
||||
use graphene_std::raster::RedGreenBlueAlpha;
|
||||
use graphene_std::raster_types::{CPU, GPU, Raster};
|
||||
use graphene_std::text::{TextAlign, TypesettingConfig};
|
||||
use graphene_std::transform::ScaleType;
|
||||
use graphene_std::uuid::NodeId;
|
||||
@@ -1859,35 +1858,6 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_
|
||||
.set_input(&InputConnector::node_at_index(node_id, index), NodeInput::value(TaggedValue::Integer(integer), exposed), &network_path);
|
||||
}
|
||||
|
||||
let cpu_raster_type_defaults: Vec<(NodeId, Vec<NodeId>, usize, Type, bool)> = document
|
||||
.network_interface
|
||||
.document_network()
|
||||
.recursive_nodes()
|
||||
.flat_map(|(node_id, node, path)| {
|
||||
node.inputs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, input)| {
|
||||
let NodeInput::Value { tagged_value, exposed } = input else { return None };
|
||||
let TaggedValue::TypeDefault(stored_type) = &**tagged_value else { return None };
|
||||
let gpu_type = if *stored_type == item!(Raster<CPU>) {
|
||||
item!(Raster<GPU>)
|
||||
} else if *stored_type == list!(Raster<CPU>) {
|
||||
list!(Raster<GPU>)
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
Some((*node_id, path.clone(), index, gpu_type, *exposed))
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect();
|
||||
for (node_id, network_path, index, gpu_type, exposed) in cpu_raster_type_defaults {
|
||||
document
|
||||
.network_interface
|
||||
.set_input(&InputConnector::node_at_index(node_id, index), NodeInput::type_default(gpu_type, exposed), &network_path);
|
||||
}
|
||||
|
||||
// Bringing an old document up to date is not a set of edits on it, it is how the document arrives.
|
||||
// The upgrades run through the ordinary mutators, so the store records them; dropping what they
|
||||
// recorded leaves the opened document as the baseline rather than as a pile of changes to itself.
|
||||
@@ -3575,8 +3545,6 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
|
||||
graphene_std::raster_nodes::effects::blur::IDENTIFIER,
|
||||
graphene_std::raster_nodes::image_color_palette::image_color_palette::IDENTIFIER,
|
||||
graphene_std::raster_nodes::dehaze::dehaze::IDENTIFIER,
|
||||
graphene_std::raster_nodes::std_nodes::image::IDENTIFIER,
|
||||
graphene_std::platform_application_io::bytes_to_image::IDENTIFIER,
|
||||
graphene_std::platform_application_io::image_to_bytes::IDENTIFIER,
|
||||
graphene_std::platform_application_io::rasterize::IDENTIFIER,
|
||||
]
|
||||
@@ -4672,7 +4640,7 @@ mod tests {
|
||||
migrate(&mut document);
|
||||
|
||||
let image_node = &document.network_interface.document_network().nodes[&image_id];
|
||||
assert_eq!(image_node.inputs.len(), 3, "the image node should gain its placeholder primary input and pipeline scope input");
|
||||
assert_eq!(image_node.inputs.len(), 2, "the image node should gain its placeholder primary input");
|
||||
let migrated = &image_node.inputs[1];
|
||||
match legacy_input.as_value() {
|
||||
None => assert_eq!(migrated.as_node(), Some(upstream_id), "the wire should sit at input 1"),
|
||||
@@ -4707,27 +4675,6 @@ mod tests {
|
||||
assert!(matches!(migrated, NodeInput::Value { exposed: true, .. }), "the exposed flag should be kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cpu_raster_type_defaults_become_gpu_defaults() {
|
||||
let node_id = NodeId(1);
|
||||
let mut document = DocumentMessageHandler::default();
|
||||
let mut blur_template = resolve_document_node_type(&DefinitionIdentifier::ProtoNode(graphene_std::raster_nodes::effects::blur::IDENTIFIER))
|
||||
.expect("the definition should exist")
|
||||
.default_node_template();
|
||||
blur_template.inputs[0] = NodeInput::type_default(item!(Raster<CPU>), true);
|
||||
document.network_interface.insert_node(node_id, blur_template, &[]);
|
||||
|
||||
migrate(&mut document);
|
||||
|
||||
let migrated = &document.network_interface.document_network().nodes[&node_id].inputs[0];
|
||||
assert_eq!(
|
||||
migrated.as_value(),
|
||||
Some(&TaggedValue::TypeDefault(item!(Raster<GPU>))),
|
||||
"the CPU raster default should become the GPU raster default"
|
||||
);
|
||||
assert!(matches!(migrated, NodeInput::Value { exposed: true, .. }), "the exposed flag should be kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_duplicate_node_replacements() {
|
||||
let mut hashmap = HashMap::<ProtoNodeIdentifier, u32>::new();
|
||||
|
||||
@@ -1238,3 +1238,82 @@ mod test {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod raster_input_adapter_tests {
|
||||
use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, OutputConnector};
|
||||
use crate::test_utils::test_prelude::*;
|
||||
use graph_craft::ProtoNodeIdentifier;
|
||||
use graph_craft::document::{DocumentNodeImplementation, NodeId};
|
||||
use graphene_std::Effects;
|
||||
use graphene_std::list::{ATTR_EFFECTS, Item};
|
||||
use graphene_std::ops::ConvertAsync;
|
||||
use graphene_std::raster_nodes::adjustments::invert;
|
||||
use graphene_std::raster_nodes::dehaze::dehaze;
|
||||
use graphene_std::raster_nodes::filter::median_filter;
|
||||
use graphene_std::raster_types::{CPU, GPU, Raster};
|
||||
use graphene_std::transform::Footprint;
|
||||
|
||||
/// A document whose image feeds `nodes` in turn, ending in the export, with each node's ID.
|
||||
async fn image_through(editor: &mut EditorTestUtils, color: Color, nodes: &[ProtoNodeIdentifier]) -> Vec<NodeId> {
|
||||
editor.new_document().await;
|
||||
editor.create_raster_image(Image::new(4, 4, color), None).await;
|
||||
let image = editor
|
||||
.active_document()
|
||||
.network_interface
|
||||
.document_network()
|
||||
.nodes
|
||||
.iter()
|
||||
.find(|(_, node)| matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(identifier) if *identifier == graphene_std::raster_nodes::std_nodes::image::IDENTIFIER))
|
||||
.map(|(id, _)| *id)
|
||||
.expect("the pasted image should be an Image node");
|
||||
|
||||
let mut ids = Vec::new();
|
||||
let mut previous = OutputConnector::node(image, 0);
|
||||
for (index, identifier) in nodes.iter().enumerate() {
|
||||
let id = editor.create_node_by_name_at(DefinitionIdentifier::ProtoNode(identifier.clone()), (index as i32 + 1) * 10, 0).await;
|
||||
let input = InputConnector::node_at_index(id, 0);
|
||||
editor.active_document_mut().network_interface.create_wire(&previous, &input, &[]);
|
||||
previous = OutputConnector::node(id, 0);
|
||||
ids.push(id);
|
||||
}
|
||||
editor.active_document_mut().network_interface.create_wire(&previous, &InputConnector::Export(0), &[]);
|
||||
ids
|
||||
}
|
||||
|
||||
async fn read(editor: &EditorTestUtils, raster: Raster<GPU>) -> Raster<CPU> {
|
||||
let executor = editor.gpu_executor();
|
||||
raster.convert(Footprint::DEFAULT, executor).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_images_stamped_effects_are_carried_out_before_the_gpu_only_node_it_feeds() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
image_through(&mut editor, Color::WHITE, &[invert::IDENTIFIER, median_filter::IDENTIFIER, invert::IDENTIFIER]).await;
|
||||
|
||||
let instrumented = editor.eval_graph_until_finished().await.expect("the CPU raster should reach Median through its input adapter");
|
||||
let reached_median: Item<Raster<CPU>> = instrumented
|
||||
.grab_all_input::<median_filter::ImageFrameInput, Item<Raster<CPU>>>(&editor.runtime)
|
||||
.next()
|
||||
.expect("the image should arrive at Median as a CPU raster");
|
||||
assert!(reached_median.attribute::<Effects>(ATTR_EFFECTS).is_some(), "the first Invert should only stamp the image");
|
||||
|
||||
// Median at its default radius passes its input through, so its output shows what the adapter gave it
|
||||
let output = instrumented
|
||||
.grab_all_input::<invert::InputInput, Item<Raster<GPU>>>(&editor.runtime)
|
||||
.next()
|
||||
.expect("Median should output a GPU raster");
|
||||
assert!(output.attribute::<Effects>(ATTR_EFFECTS).is_none(), "no stamp should be left to apply after Median");
|
||||
let raster = read(&editor, output.into_element()).await;
|
||||
assert!(raster.data[0].r() < 0.01, "the white image should be black by the time Median reads it, not {:?}", raster.data[0]);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_image_feeding_dehaze_compiles_and_renders_without_a_migration() {
|
||||
let mut editor = EditorTestUtils::create();
|
||||
image_through(&mut editor, Color::from_rgbaf32_unchecked(0.5, 0.6, 0.7, 1.), &[dehaze::IDENTIFIER]).await;
|
||||
|
||||
// A compile error or a failed render fails this
|
||||
editor.eval_graph_uninstrumented().await.expect("the image should reach Dehaze through its input adapter");
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,11 @@ impl EditorTestUtils {
|
||||
editor
|
||||
}
|
||||
|
||||
/// The GPU executor the graph runs on.
|
||||
pub fn gpu_executor(&self) -> <PlatformApplicationIo as ApplicationIo>::Executor {
|
||||
gpu_application_io().gpu_executor().cloned().expect("tests render on the GPU")
|
||||
}
|
||||
|
||||
pub fn dispatch(&mut self, message: impl Into<Message>) -> Vec<FrontendMessage> {
|
||||
let mut responses = self.editor.handle_message(message);
|
||||
while self.woken.swap(false, Ordering::Relaxed) {
|
||||
@@ -108,6 +113,33 @@ impl EditorTestUtils {
|
||||
Ok(instrumented)
|
||||
}
|
||||
|
||||
/// Compiles and runs the graph without the monitors of [`Instrumented`], which can't wrap the runtime handle that asynchronous nodes take.
|
||||
pub async fn eval_graph_uninstrumented(&mut self) -> Result<(), String> {
|
||||
let portfolio = &mut self.portfolio_message_handler_mut();
|
||||
let document_id = portfolio.active_document_id.unwrap();
|
||||
let (executor, documents) = (&mut portfolio.executor, &mut portfolio.documents);
|
||||
let document = documents.get_mut(&document_id).unwrap();
|
||||
|
||||
if let Err(e) = executor.submit_node_graph_evaluation(document, document_id, UVec2::ONE, 1., Default::default(), Vec::new(), true, Default::default()) {
|
||||
return Err(format!("submit_node_graph_evaluation failed\n\n{e}"));
|
||||
}
|
||||
self.finish_evaluation().await
|
||||
}
|
||||
|
||||
/// Waits for the submitted evaluation and processes its results, failing if the graph didn't render.
|
||||
async fn finish_evaluation(&mut self) -> Result<(), String> {
|
||||
self.runtime.run().await;
|
||||
|
||||
let frontend_messages = self.dispatch(Message::Wake);
|
||||
if frontend_messages.contains(&FrontendMessage::UpdateRenderStatus { status: RenderStatus::Error }) {
|
||||
return Err("Graph should render".to_string());
|
||||
}
|
||||
for message in frontend_messages {
|
||||
message.check_node_graph_error();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Repeatedly calls [`Self::eval_graph_once`] until no more runs are triggered by deferred messages.
|
||||
pub async fn eval_graph_until_finished(&mut self) -> Result<Instrumented, TestGraphError> {
|
||||
const MAX_ITERATIONS: usize = 16;
|
||||
|
||||
@@ -10,7 +10,7 @@ use vector_types::Gradient;
|
||||
fn blend_mode<T>(
|
||||
_: impl Ctx,
|
||||
/// The content that will be composited when rendering.
|
||||
#[implementations(Graphic, Vector, Raster<GPU>, Raster<CPU>, Color, Gradient, String)]
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String)]
|
||||
content: Item<T>,
|
||||
/// The choice of equation that controls how brightness and color blends between overlapping pixels.
|
||||
blend_mode: Item<BlendMode>,
|
||||
@@ -29,7 +29,7 @@ fn blend_mode<T>(
|
||||
fn opacity<T>(
|
||||
_: impl Ctx,
|
||||
/// The content that will be composited when rendering.
|
||||
#[implementations(Graphic, Vector, Raster<GPU>, Raster<CPU>, Color, Gradient, String)]
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String)]
|
||||
content: Item<T>,
|
||||
/// Whether the *Opacity* property is enabled, multiplying the existing opacity by the chosen percentage.
|
||||
#[widget(ParsedWidgetOverride::Hidden)]
|
||||
@@ -76,7 +76,7 @@ fn opacity<T>(
|
||||
fn clipping_mask<T>(
|
||||
_: impl Ctx,
|
||||
/// The content that will be composited when rendering.
|
||||
#[implementations(Graphic, Vector, Raster<GPU>, Raster<CPU>, Color, Gradient, String)]
|
||||
#[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String)]
|
||||
content: Item<T>,
|
||||
/// Whether the content inherits the alpha of the content beneath it.
|
||||
clip: Item<bool>,
|
||||
|
||||
@@ -85,8 +85,8 @@ fn step_real_time<T>(
|
||||
Context -> Item<DVec2>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<Artboard>,
|
||||
@@ -95,8 +95,8 @@ fn step_real_time<T>(
|
||||
Context -> List<DVec2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
@@ -131,8 +131,8 @@ fn step_animation_time<T>(
|
||||
Context -> Item<DVec2>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<Artboard>,
|
||||
@@ -141,8 +141,8 @@ fn step_animation_time<T>(
|
||||
Context -> List<DVec2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
|
||||
@@ -25,8 +25,8 @@ fn context_modification<T>(
|
||||
Context -> Item<DVec2>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Artboard>,
|
||||
Context -> Item<Gradient>,
|
||||
@@ -38,8 +38,8 @@ fn context_modification<T>(
|
||||
Context -> List<DVec2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Artboard>,
|
||||
Context -> List<Gradient>,
|
||||
|
||||
@@ -16,8 +16,8 @@ fn create_artboard<T: IntoGraphicList>(
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<String>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> Item<DAffine2>, // TODO: Remove this
|
||||
|
||||
@@ -30,8 +30,8 @@ fn remove_at_index<T: graphic_types::graphic::OmitIndex + Clone + Default>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -64,8 +64,8 @@ fn item_at_index<T: Clone + Default + Send + Sync + 'static>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -102,8 +102,8 @@ fn filter<T: Send + Sync + Clone + 'static>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -135,8 +135,8 @@ fn reverse<T: Send + Sync + Clone + 'static>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -160,8 +160,8 @@ fn shift<T: Send + Sync + Clone + 'static>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -205,8 +205,8 @@ fn shuffle<T: Send + Sync + Clone + 'static>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -277,8 +277,8 @@ fn slice<T: Send + Sync + Clone + 'static>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -351,9 +351,9 @@ fn sort<T: ElementOrder + Clone + Send + Sync + 'static, U: ElementOrder + Send
|
||||
_: impl Ctx,
|
||||
/// The list of data to reorder.
|
||||
#[implementations(
|
||||
List<String>, List<bool>, List<f64>, List<i64>, List<DVec2>, List<DAffine2>, List<Vector>, List<Graphic>, List<Raster<GPU>>, List<Raster<CPU>>, List<Color>, List<Gradient>, List<Artboard>,
|
||||
List<String>, List<bool>, List<f64>, List<i64>, List<DVec2>, List<DAffine2>, List<Vector>, List<Graphic>, List<Raster<GPU>>, List<Raster<CPU>>, List<Color>, List<Gradient>, List<Artboard>,
|
||||
List<String>, List<bool>, List<f64>, List<i64>, List<DVec2>, List<DAffine2>, List<Vector>, List<Graphic>, List<Raster<GPU>>, List<Raster<CPU>>, List<Color>, List<Gradient>, List<Artboard>,
|
||||
List<String>, List<bool>, List<f64>, List<i64>, List<DVec2>, List<DAffine2>, List<Vector>, List<Graphic>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>, List<Artboard>,
|
||||
List<String>, List<bool>, List<f64>, List<i64>, List<DVec2>, List<DAffine2>, List<Vector>, List<Graphic>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>, List<Artboard>,
|
||||
List<String>, List<bool>, List<f64>, List<i64>, List<DVec2>, List<DAffine2>, List<Vector>, List<Graphic>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>, List<Artboard>,
|
||||
)]
|
||||
list: List<T>,
|
||||
/// The optional list of orderable values, corresponding item-to-item with the input list, to sort by instead of the items' own values.
|
||||
@@ -412,8 +412,8 @@ fn map<Item: AnyHash + Send + Sync + CacheHash + Clone>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -428,8 +428,8 @@ fn map<Item: AnyHash + Send + Sync + CacheHash + Clone>(
|
||||
Context -> List<DAffine2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
@@ -489,8 +489,8 @@ fn mirror<T: BoundingBox + HasText + Send + Clone + 'static>(
|
||||
#[implementations(
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<String>,
|
||||
@@ -598,8 +598,8 @@ fn write_attribute<T: AnyHash + Clone + Send + Sync + CacheHash>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -911,8 +911,8 @@ fn extend<T: Send + Clone>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -930,8 +930,8 @@ fn extend<T: Send + Clone>(
|
||||
List<DAffine2>,
|
||||
List<Vector>,
|
||||
List<Graphic>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<Artboard>,
|
||||
@@ -951,9 +951,9 @@ fn extend<T: Send + Clone>(
|
||||
#[node_macro::node(category(""))]
|
||||
fn legacy_layer_extend<T: Send + Clone>(
|
||||
_: impl Ctx,
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<GPU>>, List<Raster<CPU>>, List<Color>, List<Gradient>)] base: List<T>,
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>)] base: List<T>,
|
||||
#[expose]
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<GPU>>, List<Raster<CPU>>, List<Color>, List<Gradient>)]
|
||||
#[implementations(List<Artboard>, List<Graphic>, List<Vector>, List<String>, List<Raster<CPU>>, List<Raster<GPU>>, List<Color>, List<Gradient>)]
|
||||
new: List<T>,
|
||||
nested_node_path: Item<NodeIdPath>,
|
||||
) -> List<T> {
|
||||
@@ -981,8 +981,8 @@ fn into_group<T: Into<Graphic>>(
|
||||
#[implementations(
|
||||
List<Graphic>,
|
||||
List<Vector>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<Gradient>,
|
||||
List<String>,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use core_types::Ctx;
|
||||
use core_types::NodeError;
|
||||
use core_types::color::SRGBA8;
|
||||
use core_types::list::{Item, List};
|
||||
use core_types::math::bbox::Bbox;
|
||||
use core_types::ops::{Convert, ConvertAsync};
|
||||
use core_types::ops::ConvertAsync;
|
||||
use core_types::transform::Footprint;
|
||||
use core_types::{ATTR_EDITOR_MERGED_LAYERS, ATTR_TRANSFORM, Interrupt, NodeError};
|
||||
use core_types::{ATTR_EDITOR_MERGED_LAYERS, ATTR_TRANSFORM};
|
||||
use glam::{DAffine2, UVec2};
|
||||
pub use graph_craft::application_io::resource::{Resource, ResourceHash};
|
||||
pub use graph_craft::application_io::*;
|
||||
@@ -12,8 +13,8 @@ pub use graph_craft::document::value::RenderOutputType;
|
||||
#[cfg(target_family = "wasm")]
|
||||
pub use graphene_canvas_utils as canvas_utils;
|
||||
use graphic_types::Graphic;
|
||||
use graphic_types::raster_types::Image;
|
||||
use graphic_types::raster_types::{GPU, Raster, Storage};
|
||||
use graphic_types::raster_types::{CPU, GPU, Raster, Storage};
|
||||
use graphic_types::raster_types::{Image, ImageError};
|
||||
use raster_nodes::raster_kernel::raster_kernel_pipeline;
|
||||
use rendering::{Render, RenderParams};
|
||||
use std::sync::Arc;
|
||||
@@ -219,15 +220,14 @@ fn pending_resource(_primary: &(), _url: &Item<String>) -> Item<Resource> {
|
||||
///
|
||||
/// Supports the formats: PNG, JPG, GIF, WEBP, TIFF, BMP, TGA, ICO, HDR, EXR.
|
||||
#[node_macro::node(category("Data: I/O"), icon("NodeBytesToImage"), name("Bytes to Image"), memoize)]
|
||||
fn bytes_to_image(_: impl Ctx, data: Item<Resource>, #[scope(raster_kernel_pipeline::IDENTIFIER)] pipeline: Item<::wgpu_executor::WgpuPipelineCache>) -> Result<Item<Raster<GPU>>, Interrupt> {
|
||||
fn bytes_to_image(_: impl Ctx, data: Item<Resource>) -> Result<Item<Raster<CPU>>, ImageError> {
|
||||
let data = data.into_element();
|
||||
if data.is_empty() {
|
||||
return Ok(Item::default());
|
||||
}
|
||||
let image = Image::from_encoded(data.as_ref()).map_err(NodeError::new)?;
|
||||
let image = Image::from_encoded(data.as_ref())?;
|
||||
|
||||
let executor = pipeline.element().executor().cloned().ok_or_else(|| NodeError::new("A GPU is required to load an image"))?;
|
||||
Ok(Item::new_from_element(Raster::new_cpu(image).convert(Footprint::DEFAULT, executor)))
|
||||
Ok(Item::new_from_element(Raster::new_cpu(image)))
|
||||
}
|
||||
|
||||
/// Renders a view of the input graphic within an area defined by the *Footprint*.
|
||||
@@ -325,7 +325,6 @@ mod tests {
|
||||
use super::*;
|
||||
use core_types::Color;
|
||||
use glam::DVec2;
|
||||
use graphic_types::raster_types::CPU;
|
||||
|
||||
#[tokio::test]
|
||||
async fn rasterize_renders_the_footprint_area_at_its_resolution() {
|
||||
|
||||
@@ -30,8 +30,8 @@ fn render_intermediate<T: 'static + Render + WasmNotSend + Send + Sync>(
|
||||
Context -> List<Artboard>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<String>,
|
||||
|
||||
@@ -1609,8 +1609,8 @@ fn switch<T: Send>(
|
||||
Context -> Item<DAffine2>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<Artboard>,
|
||||
@@ -1639,8 +1639,8 @@ fn switch<T: Send>(
|
||||
Context -> Item<DAffine2>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<Artboard>,
|
||||
|
||||
@@ -5,14 +5,13 @@ use core_types::ATTR_TRANSFORM;
|
||||
use core_types::context::{Ctx, ExtractFootprint};
|
||||
use core_types::list::Item;
|
||||
use core_types::math::bbox::Bbox;
|
||||
use core_types::ops::Convert;
|
||||
use core_types::transform::{Footprint, Transform};
|
||||
use core_types::transform::Transform;
|
||||
use core_types::{Interrupt, NodeError};
|
||||
use glam::{DAffine2, DVec2, UVec2};
|
||||
use graphene_resource::Resource;
|
||||
use graphic_types::generator::{GeneratorPattern, NoiseSettings};
|
||||
use raster_types::Image;
|
||||
use raster_types::{GPU, Raster, Storage};
|
||||
use raster_types::{CPU, GPU, Raster, Storage};
|
||||
use raster_types::{Image, ImageError};
|
||||
use wgpu_executor::WgpuPipelineCache;
|
||||
use wgpu_executor::raster_kernel::render_generator;
|
||||
|
||||
@@ -204,16 +203,14 @@ fn image(
|
||||
/// The image file to display.
|
||||
#[widget(ParsedWidgetOverride::Custom = "image_file")]
|
||||
resource: Item<Resource>,
|
||||
#[scope(raster_kernel_pipeline::IDENTIFIER)] pipeline: Item<WgpuPipelineCache>,
|
||||
) -> Result<Item<Raster<GPU>>, Interrupt> {
|
||||
) -> Result<Item<Raster<CPU>>, ImageError> {
|
||||
let resource = resource.into_element();
|
||||
if resource.is_empty() {
|
||||
return Ok(Item::default());
|
||||
}
|
||||
let image = Image::from_encoded(resource.as_ref()).map_err(NodeError::new)?;
|
||||
let image = Image::from_encoded(resource.as_ref())?;
|
||||
|
||||
let executor = pipeline.element().executor().cloned().ok_or_else(|| NodeError::new("A GPU is required to load an image"))?;
|
||||
Ok(Item::new_from_element(Raster::new_cpu(image).convert(Footprint::DEFAULT, executor)))
|
||||
Ok(Item::new_from_element(Raster::new_cpu(image)))
|
||||
}
|
||||
|
||||
/// Generates customizable procedural noise patterns.
|
||||
|
||||
@@ -53,8 +53,8 @@ fn repeat<T: Send + Clone + 'static>(
|
||||
Context -> List<DAffine2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
@@ -98,8 +98,8 @@ fn repeat_array<T: Send + Clone + 'static>(
|
||||
Context -> List<DAffine2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
@@ -160,8 +160,8 @@ fn repeat_radial<T: Send + Clone + 'static>(
|
||||
Context -> List<DAffine2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
@@ -220,8 +220,8 @@ fn repeat_on_points<T: Send + Clone + 'static>(
|
||||
Context -> List<DAffine2>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
Context -> List<Artboard>,
|
||||
|
||||
@@ -18,8 +18,8 @@ fn transform<T: Send + 'static>(
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<String>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
)]
|
||||
@@ -95,8 +95,8 @@ fn reset_transform<T: 'static>(
|
||||
#[implementations(
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<String>,
|
||||
@@ -143,8 +143,8 @@ fn replace_transform<T: 'static>(
|
||||
#[implementations(
|
||||
Context -> Item<Graphic>,
|
||||
Context -> Item<Vector>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Raster<CPU>>,
|
||||
Context -> Item<Raster<GPU>>,
|
||||
Context -> Item<Color>,
|
||||
Context -> Item<Gradient>,
|
||||
Context -> Item<String>,
|
||||
@@ -182,7 +182,7 @@ fn replaced_transform_context<T, N: Node<Context<'static>, Output = Item<T>>>(
|
||||
|
||||
/// Obtains the transform of the input content.
|
||||
#[node_macro::node(category("Transform"), icon("NodeExtractTransform"), path(core_types::vector))]
|
||||
fn extract_transform<T: Send>(_: impl Ctx, #[implementations(Graphic, Vector, Raster<GPU>, Raster<CPU>, Color, Gradient, String, Artboard)] content: Item<T>) -> Item<DAffine2> {
|
||||
fn extract_transform<T: Send>(_: impl Ctx, #[implementations(Graphic, Vector, Raster<CPU>, Raster<GPU>, Color, Gradient, String, Artboard)] content: Item<T>) -> Item<DAffine2> {
|
||||
Item::new_from_element(content.attribute_cloned_or_default(ATTR_TRANSFORM))
|
||||
}
|
||||
|
||||
|
||||
@@ -553,8 +553,8 @@ fn copy_to_points<I: Send + Clone>(
|
||||
Context -> List<Graphic>,
|
||||
Context -> List<Vector>,
|
||||
Context -> List<String>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Raster<CPU>>,
|
||||
Context -> List<Raster<GPU>>,
|
||||
Context -> List<Color>,
|
||||
Context -> List<Gradient>,
|
||||
)]
|
||||
@@ -1263,8 +1263,8 @@ fn pack_strips<T: Send + Clone>(
|
||||
#[implementations(
|
||||
List<Graphic>,
|
||||
List<Vector>,
|
||||
List<Raster<GPU>>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
)]
|
||||
elements: List<T>,
|
||||
#[default(0.)]
|
||||
|
||||
Reference in new issue
Block a user