Correctly set the dimensions of the SVG foreignObject container for the Vello canvas (#1907)

* Correctly set the dimensons of the forgein object element

* Remove dead code

* Fix missing default impl

* Set correct default for not wasm32 targets as well
This commit is contained in:
Dennis Kobert 2024-08-06 10:41:56 +02:00 committed by GitHub
parent f21c8c1b17
commit 00864e274f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 20 deletions

View file

@ -110,6 +110,8 @@ fn render_svg(data: impl GraphicElementRendered, mut render: SvgRender, render_p
#[cfg(feature = "vello")]
#[cfg_attr(not(target_arch = "wasm32"), allow(dead_code))]
async fn render_canvas(render_config: RenderConfig, data: impl GraphicElementRendered, editor: &WasmEditorApi, surface_handle: wgpu_executor::WgpuSurface) -> RenderOutput {
use graphene_core::SurfaceFrame;
if let Some(exec) = editor.application_io.as_ref().unwrap().gpu_executor() {
use vello::*;
@ -129,11 +131,12 @@ async fn render_canvas(render_config: RenderConfig, data: impl GraphicElementRen
} else {
unreachable!("Attempted to render with Vello when no GPU executor is available");
}
let frame = graphene_core::application_io::SurfaceHandleFrame {
surface_handle,
let frame = SurfaceFrame {
surface_id: surface_handle.window_id,
resolution: render_config.viewport.resolution,
transform: glam::DAffine2::IDENTITY,
};
RenderOutput::CanvasFrame(frame.into())
RenderOutput::CanvasFrame(frame)
}
#[cfg(target_arch = "wasm32")]

View file

@ -505,24 +505,28 @@ impl WgpuExecutor {
}
#[cfg(target_arch = "wasm32")]
pub fn create_surface(&self, canvas: graphene_core::WasmSurfaceHandle, resolution: Option<UVec2>) -> Result<SurfaceHandle<Surface>> {
pub fn create_surface(&self, canvas: graphene_core::WasmSurfaceHandle) -> Result<SurfaceHandle<Surface>> {
let surface = self.context.instance.create_surface(wgpu::SurfaceTarget::Canvas(canvas.surface))?;
let resolution = resolution.unwrap_or(UVec2::new(1920, 1080));
Ok(SurfaceHandle {
window_id: canvas.window_id,
surface: Surface { inner: surface, resolution },
surface: Surface {
inner: surface,
resolution: UVec2::ZERO,
},
})
}
#[cfg(not(target_arch = "wasm32"))]
pub fn create_surface(&self, window: SurfaceHandle<Window>, resolution: Option<UVec2>) -> Result<SurfaceHandle<Surface>> {
pub fn create_surface(&self, window: SurfaceHandle<Window>) -> Result<SurfaceHandle<Surface>> {
let size = window.surface.inner_size();
let resolution = resolution.unwrap_or(UVec2 { x: size.width, y: size.height });
let surface = self.context.instance.create_surface(wgpu::SurfaceTarget::Window(Box::new(window.surface)))?;
Ok(SurfaceHandle {
window_id: window.window_id,
surface: Surface { inner: surface, resolution },
surface: Surface {
inner: surface,
resolution: UVec2::ZERO,
},
})
}
}
@ -907,17 +911,7 @@ pub struct CreateGpuSurfaceNode;
async fn create_gpu_surface<'a: 'input, Io: ApplicationIo<Executor = WgpuExecutor, Surface = Window> + 'a + Send + Sync>(editor_api: &'a EditorApi<Io>) -> Option<WgpuSurface> {
let canvas = editor_api.application_io.as_ref()?.window()?;
let executor = editor_api.application_io.as_ref()?.gpu_executor()?;
Some(Arc::new(executor.create_surface(canvas, None).ok()?))
}
pub struct ConfigureGpuSurfaceNode<EditorApi> {
editor_api: EditorApi,
}
#[node_macro::node_fn(ConfigureGpuSurfaceNode)]
async fn create_gpu_surface<'a: 'input, Io: ApplicationIo<Executor = WgpuExecutor, Surface = Window> + 'a + Send + Sync>(resolution: UVec2, editor_api: &'a EditorApi<Io>) -> Option<WgpuSurface> {
let canvas = editor_api.application_io.as_ref()?.create_window();
let executor = editor_api.application_io.as_ref()?.gpu_executor()?;
Some(Arc::new(executor.create_surface(canvas, Some(resolution)).ok()?))
Some(Arc::new(executor.create_surface(canvas).ok()?))
}
pub struct RenderTextureNode<Image, Surface, EditorApi> {