mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-24 04:18:11 +08:00
Share scope values as owned Arc handles
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use graph_craft::document::value::{RenderOutputType, TaggedValue, UVec2};
|
use graph_craft::document::value::{RenderOutputType, TaggedValue, UVec2};
|
||||||
use graph_craft::graphene_compiler::Executor;
|
use graph_craft::graphene_compiler::Executor;
|
||||||
use graphene_std::application_io::{ExportFormat, RenderConfig, TimingInformation};
|
use graphene_std::application_io::{ExportFormat, RenderConfig, TimingInformation};
|
||||||
use graphene_std::core_types::ops::{Convert, ConvertAsync};
|
use graphene_std::core_types::ops::ConvertAsync;
|
||||||
use graphene_std::core_types::transform::Footprint;
|
use graphene_std::core_types::transform::Footprint;
|
||||||
use graphene_std::raster_types::{CPU, GPU, Raster};
|
use graphene_std::raster_types::{CPU, GPU, Raster};
|
||||||
use interpreted_executor::dynamic_executor::DynamicExecutor;
|
use interpreted_executor::dynamic_executor::DynamicExecutor;
|
||||||
@@ -30,7 +30,7 @@ pub fn detect_file_type(path: &Path) -> Result<FileType, String> {
|
|||||||
|
|
||||||
pub async fn export_document(
|
pub async fn export_document(
|
||||||
executor: &DynamicExecutor,
|
executor: &DynamicExecutor,
|
||||||
wgpu_executor: &wgpu_executor::WgpuExecutor,
|
wgpu_executor: wgpu_executor::WgpuExecutorHandle,
|
||||||
output_path: PathBuf,
|
output_path: PathBuf,
|
||||||
file_type: FileType,
|
file_type: FileType,
|
||||||
scale: f64,
|
scale: f64,
|
||||||
@@ -73,7 +73,7 @@ pub async fn export_document(
|
|||||||
RenderOutputType::Texture(texture) => {
|
RenderOutputType::Texture(texture) => {
|
||||||
// Convert GPU texture to CPU buffer
|
// Convert GPU texture to CPU buffer
|
||||||
let gpu_raster = Raster::<GPU>::new_gpu(texture);
|
let gpu_raster = Raster::<GPU>::new_gpu(texture);
|
||||||
let cpu_raster: Raster<CPU> = gpu_raster.convert(Footprint::BOUNDLESS, wgpu_executor).await;
|
let cpu_raster: Raster<CPU> = gpu_raster.convert(Footprint::BOUNDLESS, wgpu_executor.clone()).await;
|
||||||
let (data, width, height) = cpu_raster.to_flat_u8();
|
let (data, width, height) = cpu_raster.to_flat_u8();
|
||||||
|
|
||||||
// Encode and write raster image
|
// Encode and write raster image
|
||||||
@@ -154,7 +154,7 @@ impl AnimationParams {
|
|||||||
/// Export an animated GIF by rendering multiple frames at different animation times
|
/// Export an animated GIF by rendering multiple frames at different animation times
|
||||||
pub async fn export_gif(
|
pub async fn export_gif(
|
||||||
executor: &DynamicExecutor,
|
executor: &DynamicExecutor,
|
||||||
wgpu_executor: &wgpu_executor::WgpuExecutor,
|
wgpu_executor: wgpu_executor::WgpuExecutorHandle,
|
||||||
output_path: PathBuf,
|
output_path: PathBuf,
|
||||||
scale: f64,
|
scale: f64,
|
||||||
(width, height): (Option<u32>, Option<u32>),
|
(width, height): (Option<u32>, Option<u32>),
|
||||||
@@ -208,7 +208,7 @@ pub async fn export_gif(
|
|||||||
TaggedValue::RenderOutput(output) => match output.data {
|
TaggedValue::RenderOutput(output) => match output.data {
|
||||||
RenderOutputType::Texture(texture) => {
|
RenderOutputType::Texture(texture) => {
|
||||||
let gpu_raster = Raster::<GPU>::new_gpu(texture);
|
let gpu_raster = Raster::<GPU>::new_gpu(texture);
|
||||||
let cpu_raster: Raster<CPU> = gpu_raster.convert(Footprint::BOUNDLESS, wgpu_executor).await;
|
let cpu_raster: Raster<CPU> = gpu_raster.convert(Footprint::BOUNDLESS, wgpu_executor.clone()).await;
|
||||||
cpu_raster.to_flat_u8()
|
cpu_raster.to_flat_u8()
|
||||||
}
|
}
|
||||||
RenderOutputType::Buffer { data, width, height } => (data, width, height),
|
RenderOutputType::Buffer { data, width, height } => (data, width, height),
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let application_io_for_api = application_io_arc.clone();
|
let application_io_for_api = application_io_arc.clone();
|
||||||
|
|
||||||
// Get reference to wgpu executor and clone device handle
|
// Get reference to wgpu executor and clone device handle
|
||||||
let wgpu_executor_ref = application_io_arc.gpu_executor().unwrap();
|
let wgpu_executor_ref = wgpu_executor::WgpuExecutorHandle(application_io_arc.gpu_executor_arc().unwrap());
|
||||||
let device = wgpu_executor_ref.context().device.clone();
|
let device = wgpu_executor_ref.context().device.clone();
|
||||||
|
|
||||||
let preferences = EditorPreferences {
|
let preferences = EditorPreferences {
|
||||||
@@ -227,9 +227,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
// Perform export based on file type
|
// Perform export based on file type
|
||||||
if file_type == export::FileType::Gif {
|
if file_type == export::FileType::Gif {
|
||||||
let animation = export::AnimationParams::new(fps, frames, duration);
|
let animation = export::AnimationParams::new(fps, frames, duration);
|
||||||
export::export_gif(&executor, wgpu_executor_ref, output, scale, (width, height), animation).await?;
|
export::export_gif(&executor, wgpu_executor_ref.clone(), output, scale, (width, height), animation).await?;
|
||||||
} else {
|
} else {
|
||||||
export::export_document(&executor, wgpu_executor_ref, output, file_type, scale, (width, height), transparent).await?;
|
export::export_document(&executor, wgpu_executor_ref.clone(), output, file_type, scale, (width, height), transparent).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!("All other commands should be handled before this match statement is run"),
|
_ => unreachable!("All other commands should be handled before this match statement is run"),
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, Vec<RegistryEntry>> {
|
|||||||
async_node!(graphene_core::memo::MonitorNode<_, _>, input: Context, fn_params: [Context => graphene_std::vector::misc::InterpolationDistribution]),
|
async_node!(graphene_core::memo::MonitorNode<_, _>, input: Context, fn_params: [Context => graphene_std::vector::misc::InterpolationDistribution]),
|
||||||
// Context nullification
|
// Context nullification
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &PlatformEditorApi, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => std::sync::Arc<PlatformEditorApi>, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => RenderOutput, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => RenderOutput, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => AttributeDyn, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => AttributeDyn, Context => graphene_std::ContextFeatures]),
|
||||||
@@ -196,9 +196,9 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, Vec<RegistryEntry>> {
|
|||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => ListDyn, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => ListDyn, Context => graphene_std::ContextFeatures]),
|
||||||
#[cfg(target_family = "wasm")]
|
#[cfg(target_family = "wasm")]
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => CanvasHandle, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => CanvasHandle, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &PlatformEditorApi, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => std::sync::Arc<PlatformEditorApi>, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &wgpu_executor::WgpuExecutor, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuExecutorHandle, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => Option<&wgpu_executor::WgpuExecutor>, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => Option<wgpu_executor::WgpuExecutorHandle>, Context => graphene_std::ContextFeatures]),
|
||||||
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache, Context => graphene_std::ContextFeatures]),
|
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache, Context => graphene_std::ContextFeatures]),
|
||||||
// ==========
|
// ==========
|
||||||
// MEMO NODES
|
// MEMO NODES
|
||||||
@@ -235,7 +235,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, Vec<RegistryEntry>> {
|
|||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => DAffine2]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => DAffine2]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Footprint]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Footprint]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => RenderOutput]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => RenderOutput]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => &PlatformEditorApi]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => std::sync::Arc<PlatformEditorApi>]),
|
||||||
#[cfg(feature = "gpu")]
|
#[cfg(feature = "gpu")]
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => List<Raster<GPU>>]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => List<Raster<GPU>>]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Option<f64>]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Option<f64>]),
|
||||||
@@ -283,8 +283,8 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, Vec<RegistryEntry>> {
|
|||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => graphene_std::transform::ScaleType]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => graphene_std::transform::ScaleType]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => graphene_std::vector::misc::InterpolationDistribution]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => graphene_std::vector::misc::InterpolationDistribution]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => &wgpu_executor::WgpuExecutor]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuExecutorHandle]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Option<&wgpu_executor::WgpuExecutor>]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Option<wgpu_executor::WgpuExecutorHandle>]),
|
||||||
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache]),
|
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache]),
|
||||||
];
|
];
|
||||||
// =============
|
// =============
|
||||||
|
|||||||
Reference in New Issue
Block a user