mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-07 23:08:07 +00:00
Fix clippy lints (#1327)
* Fix clippy lints * Update formatting * Remove unsafe send impls * New type for Rc<NodeContainer>
This commit is contained in:
parent
743803ce04
commit
80cc5bee73
80 changed files with 549 additions and 445 deletions
|
@ -1,9 +1,9 @@
|
|||
use dyn_any::StaticType;
|
||||
pub use graph_craft::proto::{Any, NodeContainer, TypeErasedBox, TypeErasedNode};
|
||||
use graph_craft::proto::{DynFuture, FutureAny};
|
||||
use graph_craft::proto::{DynFuture, FutureAny, SharedNodeContainer};
|
||||
use graphene_core::NodeIO;
|
||||
pub use graphene_core::{generic, ops, Node};
|
||||
use std::{marker::PhantomData, sync::Arc};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct DynAnyNode<I, O, Node> {
|
||||
node: Node,
|
||||
|
@ -164,7 +164,7 @@ where
|
|||
/// Wraps around a node taking Box<dyn DynAny> and returning Box<dyn DynAny>
|
||||
#[derive(Clone)]
|
||||
pub struct DowncastBothNode<I, O> {
|
||||
node: Arc<NodeContainer>,
|
||||
node: SharedNodeContainer,
|
||||
_i: PhantomData<I>,
|
||||
_o: PhantomData<O>,
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ impl<'input, O: 'input + StaticType, I: 'input + StaticType> Node<'input, I> for
|
|||
}
|
||||
}
|
||||
impl<I, O> DowncastBothNode<I, O> {
|
||||
pub const fn new(node: Arc<NodeContainer>) -> Self {
|
||||
pub const fn new(node: SharedNodeContainer) -> Self {
|
||||
Self {
|
||||
node,
|
||||
_i: core::marker::PhantomData,
|
||||
|
@ -196,7 +196,7 @@ impl<I, O> DowncastBothNode<I, O> {
|
|||
/// Wraps around a node taking Box<dyn DynAny> and returning Box<dyn DynAny>
|
||||
#[derive(Clone)]
|
||||
pub struct DowncastBothRefNode<I, O> {
|
||||
node: Arc<NodeContainer>,
|
||||
node: SharedNodeContainer,
|
||||
_i: PhantomData<(I, O)>,
|
||||
}
|
||||
impl<'input, O: 'input + StaticType, I: 'input + StaticType> Node<'input, I> for DowncastBothRefNode<I, O> {
|
||||
|
@ -214,14 +214,14 @@ impl<'input, O: 'input + StaticType, I: 'input + StaticType> Node<'input, I> for
|
|||
}
|
||||
}
|
||||
impl<I, O> DowncastBothRefNode<I, O> {
|
||||
pub const fn new(node: Arc<NodeContainer>) -> Self {
|
||||
pub const fn new(node: SharedNodeContainer) -> Self {
|
||||
Self { node, _i: core::marker::PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ComposeTypeErased {
|
||||
first: Arc<NodeContainer>,
|
||||
second: Arc<NodeContainer>,
|
||||
first: SharedNodeContainer,
|
||||
second: SharedNodeContainer,
|
||||
}
|
||||
|
||||
impl<'i, 'a: 'i> Node<'i, Any<'i>> for ComposeTypeErased {
|
||||
|
@ -235,12 +235,12 @@ impl<'i, 'a: 'i> Node<'i, Any<'i>> for ComposeTypeErased {
|
|||
}
|
||||
|
||||
impl ComposeTypeErased {
|
||||
pub const fn new(first: Arc<NodeContainer>, second: Arc<NodeContainer>) -> Self {
|
||||
pub const fn new(first: SharedNodeContainer, second: SharedNodeContainer) -> Self {
|
||||
ComposeTypeErased { first, second }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn input_node<O: StaticType>(n: Arc<NodeContainer>) -> DowncastBothNode<(), O> {
|
||||
pub fn input_node<O: StaticType>(n: SharedNodeContainer) -> DowncastBothNode<(), O> {
|
||||
DowncastBothNode::new(n)
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ impl<I, O> PanicNode<I, O> {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use graphene_core::{ops::AddNode, ops::IdNode, value::ValueNode};
|
||||
use graphene_core::{ops::AddNode, ops::IdNode};
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
|
|
|
@ -318,7 +318,7 @@ async fn brush(image: ImageFrame<Color>, bounds: ImageFrame<Color>, strokes: Vec
|
|||
// Compute transformation from stroke texture space into layer space, and create the stroke texture.
|
||||
let skip = if idx == 0 { brush_plan.first_stroke_point_skip } else { 0 };
|
||||
let positions: Vec<_> = stroke.compute_blit_points().into_iter().skip(skip).collect();
|
||||
let stroke_texture = if idx == 0 && positions.len() == 0 {
|
||||
let stroke_texture = if idx == 0 && positions.is_empty() {
|
||||
core::mem::take(&mut brush_plan.first_stroke_texture)
|
||||
} else {
|
||||
let mut bbox = stroke.bounding_box();
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use dyn_any::{StaticType, StaticTypeSized};
|
||||
use dyn_any::StaticTypeSized;
|
||||
use glam::{DAffine2, DVec2, Mat2, Vec2};
|
||||
use gpu_executor::{Bindgroup, ComputePassDimensions, PipelineLayout, StorageBufferOptions};
|
||||
use gpu_executor::{GpuExecutor, ShaderIO, ShaderInput};
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::*;
|
||||
use graph_craft::proto::*;
|
||||
use graphene_core::quantization::{PackedPixel, QuantizationChannels};
|
||||
use graphene_core::quantization::QuantizationChannels;
|
||||
use graphene_core::raster::*;
|
||||
use graphene_core::*;
|
||||
use wgpu_executor::WgpuExecutor;
|
||||
|
@ -292,7 +292,7 @@ async fn create_compute_pass_descriptor<T: Clone + Pixel + StaticTypeSized>(
|
|||
)
|
||||
.unwrap();
|
||||
let width_uniform = Arc::new(width_uniform);
|
||||
let quantization_uniform = Arc::new(quantization_uniform);
|
||||
let _quantization_uniform = Arc::new(quantization_uniform);
|
||||
let storage_buffer = Arc::new(storage_buffer);
|
||||
let output_buffer = executor.create_output_buffer(len, concrete!(Color), false).unwrap();
|
||||
let output_buffer = Arc::new(output_buffer);
|
||||
|
@ -322,11 +322,10 @@ async fn create_compute_pass_descriptor<T: Clone + Pixel + StaticTypeSized>(
|
|||
};
|
||||
log::debug!("created pipeline");
|
||||
|
||||
let compute_pass_descriptor = ComputePass {
|
||||
ComputePass {
|
||||
pipeline_layout: pipeline,
|
||||
readback_buffer: Some(readback_buffer.clone()),
|
||||
};
|
||||
compute_pass_descriptor
|
||||
}
|
||||
}
|
||||
/*
|
||||
#[node_macro::node_fn(MapGpuNode)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::wasm_application_io::WasmEditorApi;
|
|||
use core::any::TypeId;
|
||||
use core::future::Future;
|
||||
use futures::{future::Either, TryFutureExt};
|
||||
use glam::DVec2;
|
||||
use glam::{DVec2, U64Vec2};
|
||||
use graph_craft::imaginate_input::{ImaginateController, ImaginateMaskStartingFill, ImaginatePreferences, ImaginateSamplingMethod, ImaginateServerStatus, ImaginateStatus, ImaginateTerminationHandle};
|
||||
use graphene_core::application_io::NodeGraphUpdateMessage;
|
||||
use graphene_core::raster::{Color, Image, Luma, Pixel};
|
||||
|
@ -62,6 +62,8 @@ impl Default for ImaginatePersistentData {
|
|||
}
|
||||
}
|
||||
|
||||
type ImaginateFuture = core::pin::Pin<Box<dyn Future<Output = ()> + 'static>>;
|
||||
|
||||
impl ImaginatePersistentData {
|
||||
pub fn set_host_name(&mut self, name: &str) {
|
||||
match parse_url(name) {
|
||||
|
@ -70,9 +72,11 @@ impl ImaginatePersistentData {
|
|||
}
|
||||
}
|
||||
|
||||
fn initiate_server_check_maybe_fail(&mut self) -> Result<Option<core::pin::Pin<Box<dyn Future<Output = ()> + 'static>>>, Error> {
|
||||
fn initiate_server_check_maybe_fail(&mut self) -> Result<Option<ImaginateFuture>, Error> {
|
||||
use futures::future::FutureExt;
|
||||
let Some(client) = &self.client else { return Ok(None); };
|
||||
let Some(client) = &self.client else {
|
||||
return Ok(None);
|
||||
};
|
||||
if self.pending_server_check.is_some() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
@ -87,7 +91,7 @@ impl ImaginatePersistentData {
|
|||
Ok(Some(Box::pin(response_future)))
|
||||
}
|
||||
|
||||
pub fn initiate_server_check(&mut self) -> Option<core::pin::Pin<Box<dyn Future<Output = ()> + 'static>>> {
|
||||
pub fn initiate_server_check(&mut self) -> Option<ImaginateFuture> {
|
||||
match self.initiate_server_check_maybe_fail() {
|
||||
Ok(f) => f,
|
||||
Err(err) => {
|
||||
|
@ -256,6 +260,7 @@ struct ImaginateCommonImageRequest<'a> {
|
|||
}
|
||||
|
||||
#[cfg(feature = "imaginate")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn imaginate<'a, P: Pixel>(
|
||||
image: Image<P>,
|
||||
editor_api: impl Future<Output = WasmEditorApi<'a>>,
|
||||
|
@ -323,6 +328,7 @@ pub async fn imaginate<'a, P: Pixel>(
|
|||
}
|
||||
|
||||
#[cfg(feature = "imaginate")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn imaginate_maybe_fail<'a, P: Pixel, F: Fn(ImaginateStatus)>(
|
||||
image: Image<P>,
|
||||
host_name: &str,
|
||||
|
@ -492,26 +498,25 @@ pub fn pick_safe_imaginate_resolution((width, height): (f64, f64)) -> (u64, u64)
|
|||
const MAX_DIMENSION: u64 = (MAX_RESOLUTION / 64) & !63;
|
||||
|
||||
// round the resolution to the nearest multiple of 64
|
||||
let [width, height] = [width, height].map(|c| (c.round().clamp(0., MAX_DIMENSION as _) as u64 + 32).max(64) & !63);
|
||||
let resolution = width * height;
|
||||
let size = (DVec2::new(width, height).round().clamp(DVec2::ZERO, DVec2::splat(MAX_DIMENSION as _)).as_u64vec2() + U64Vec2::splat(32)).max(U64Vec2::splat(64)) & !U64Vec2::splat(63);
|
||||
let resolution = size.x * size.y;
|
||||
|
||||
if resolution > MAX_RESOLUTION {
|
||||
// scale down the image, so it is smaller than MAX_RESOLUTION
|
||||
let scale = (MAX_RESOLUTION as f64 / resolution as f64).sqrt();
|
||||
let [width, height] = [width, height].map(|c| c as f64 * scale);
|
||||
let size = size.as_dvec2() * scale;
|
||||
|
||||
if width < 64.0 {
|
||||
if size.x < 64.0 {
|
||||
// the image is extremely wide
|
||||
(64, MAX_DIMENSION)
|
||||
} else if height < 64.0 {
|
||||
} else if size.y < 64.0 {
|
||||
// the image is extremely high
|
||||
(MAX_DIMENSION, 64)
|
||||
} else {
|
||||
// round down to a multiple of 64, so that the resolution still is smaller than MAX_RESOLUTION
|
||||
let [width, height] = [width, height].map(|c| c as u64 & !63);
|
||||
(width, height)
|
||||
(size.as_u64vec2() & !U64Vec2::splat(63)).into()
|
||||
}
|
||||
} else {
|
||||
(width, height)
|
||||
size.into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,7 +256,9 @@ where
|
|||
let foreground_aabb = Bbox::unit().affine_transform(foreground.transform()).to_axis_aligned_bbox();
|
||||
let background_aabb = Bbox::unit().affine_transform(background.transform()).to_axis_aligned_bbox();
|
||||
|
||||
let Some(aabb) = foreground_aabb.union_non_empty(&background_aabb) else {return ImageFrame::empty()};
|
||||
let Some(aabb) = foreground_aabb.union_non_empty(&background_aabb) else {
|
||||
return ImageFrame::empty();
|
||||
};
|
||||
|
||||
if background_aabb.contains(foreground_aabb.start) && background_aabb.contains(foreground_aabb.end) {
|
||||
return blend_image(foreground, background, map_fn);
|
||||
|
@ -434,6 +436,7 @@ macro_rules! generate_imaginate_node {
|
|||
E: for<'any_input> Node<'any_input, (), Output = DynFuture<'any_input, WasmEditorApi<'e>>>,
|
||||
C: for<'any_input> Node<'any_input, (), Output = DynFuture<'any_input, ImaginateController>>,
|
||||
{
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(editor_api: E, controller: C, $($val: $t,)* ) -> Self {
|
||||
Self { editor_api, controller, $($val,)* cache: Default::default() }
|
||||
}
|
||||
|
|
|
@ -1,23 +1,27 @@
|
|||
use std::any::Any;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use core::future::Future;
|
||||
use dyn_any::StaticType;
|
||||
use graphene_core::application_io::{ApplicationError, ApplicationIo, SurfaceHandle, SurfaceHandleFrame, SurfaceId};
|
||||
use graphene_core::application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceHandleFrame, SurfaceId};
|
||||
use graphene_core::raster::Image;
|
||||
use graphene_core::Color;
|
||||
use graphene_core::{
|
||||
raster::{color::SRGBA8, ImageFrame},
|
||||
Node,
|
||||
};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use js_sys::{Object, Reflect};
|
||||
use std::collections::HashMap;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
#[cfg(feature = "tokio")]
|
||||
use tokio::io::AsyncReadExt;
|
||||
use wasm_bindgen::{Clamped, JsCast, JsValue};
|
||||
use web_sys::{window, CanvasRenderingContext2d, HtmlCanvasElement};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen::JsValue;
|
||||
use wasm_bindgen::{Clamped, JsCast};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use web_sys::window;
|
||||
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
|
||||
#[cfg(feature = "wgpu")]
|
||||
use wgpu_executor::WgpuExecutor;
|
||||
|
||||
|
@ -25,6 +29,7 @@ pub struct Canvas(CanvasRenderingContext2d);
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct WasmApplicationIo {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
ids: RefCell<u64>,
|
||||
#[cfg(feature = "wgpu")]
|
||||
pub(crate) gpu_executor: Option<WgpuExecutor>,
|
||||
|
@ -36,6 +41,7 @@ pub struct WasmApplicationIo {
|
|||
impl WasmApplicationIo {
|
||||
pub async fn new() -> Self {
|
||||
let mut io = Self {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
ids: RefCell::new(0),
|
||||
#[cfg(feature = "wgpu")]
|
||||
gpu_executor: WgpuExecutor::new().await,
|
||||
|
@ -161,7 +167,7 @@ impl ApplicationIo for WasmApplicationIo {
|
|||
self.gpu_executor.as_ref()
|
||||
}
|
||||
|
||||
fn load_resource(&self, url: impl AsRef<str>) -> Result<Pin<Box<dyn Future<Output = Result<Arc<[u8]>, ApplicationError>>>>, ApplicationError> {
|
||||
fn load_resource(&self, url: impl AsRef<str>) -> Result<ResourceFuture, ApplicationError> {
|
||||
let url = url::Url::parse(url.as_ref()).map_err(|_| ApplicationError::InvalidUrl)?;
|
||||
log::info!("Loading resource: {:?}", url);
|
||||
match url.scheme() {
|
||||
|
@ -223,7 +229,7 @@ async fn draw_image_frame_node<'a: 'input>(image: ImageFrame<SRGBA8>, surface_ha
|
|||
canvas.set_height(image.image.height);
|
||||
// TODO: replace "2d" with "bitmaprenderer" once we switch to ImageBitmap (lives on gpu) from ImageData (lives on cpu)
|
||||
let context = canvas.get_context("2d").unwrap().unwrap().dyn_into::<CanvasRenderingContext2d>().unwrap();
|
||||
let image_data = web_sys::ImageData::new_with_u8_clamped_array_and_sh(array, image.image.width as u32, image.image.height as u32).expect("Failed to construct ImageData");
|
||||
let image_data = web_sys::ImageData::new_with_u8_clamped_array_and_sh(array, image.image.width, image.image.height).expect("Failed to construct ImageData");
|
||||
context.put_image_data(&image_data, 0.0, 0.0).unwrap();
|
||||
}
|
||||
SurfaceHandleFrame {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue