Desktop: Fix bitmap file export not preserving alpha (#3673)
Fix Export not preserving alpha
This commit is contained in:
parent
c07124332b
commit
b4e9d7b9eb
|
|
@ -1,7 +1,7 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::window::Window;
|
use crate::window::Window;
|
||||||
use crate::wrapper::{Color, TargetTexture, WgpuContext, WgpuExecutor};
|
use crate::wrapper::{TargetTexture, WgpuContext, WgpuExecutor};
|
||||||
|
|
||||||
#[derive(derivative::Derivative)]
|
#[derive(derivative::Derivative)]
|
||||||
#[derivative(Debug)]
|
#[derivative(Debug)]
|
||||||
|
|
@ -232,10 +232,7 @@ impl RenderState {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let size = glam::UVec2::new(viewport_texture.width(), viewport_texture.height());
|
let size = glam::UVec2::new(viewport_texture.width(), viewport_texture.height());
|
||||||
let result = futures::executor::block_on(
|
let result = futures::executor::block_on(self.executor.render_vello_scene_to_target_texture(&scene, size, &Default::default(), None, &mut self.overlays_texture));
|
||||||
self.executor
|
|
||||||
.render_vello_scene_to_target_texture(&scene, size, &Default::default(), Color::TRANSPARENT, &mut self.overlays_texture),
|
|
||||||
);
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
tracing::error!("Error rendering overlays: {:?}", e);
|
tracing::error!("Error rendering overlays: {:?}", e);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ use graphite_editor::application::{Editor, Environment, Host, Platform};
|
||||||
use graphite_editor::messages::prelude::{FrontendMessage, Message};
|
use graphite_editor::messages::prelude::{FrontendMessage, Message};
|
||||||
|
|
||||||
pub use graphite_editor::consts::FILE_EXTENSION;
|
pub use graphite_editor::consts::FILE_EXTENSION;
|
||||||
// TODO: Remove usage of this reexport in desktop create and remove this line
|
|
||||||
pub use graphene_std::Color;
|
|
||||||
|
|
||||||
pub use wgpu_executor::TargetTexture;
|
pub use wgpu_executor::TargetTexture;
|
||||||
pub use wgpu_executor::WgpuContext;
|
pub use wgpu_executor::WgpuContext;
|
||||||
|
|
|
||||||
|
|
@ -112,12 +112,12 @@ unsafe impl StaticType for Surface {
|
||||||
const VELLO_SURFACE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
const VELLO_SURFACE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
||||||
|
|
||||||
impl WgpuExecutor {
|
impl WgpuExecutor {
|
||||||
pub async fn render_vello_scene_to_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Color) -> Result<wgpu::Texture> {
|
pub async fn render_vello_scene_to_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Option<Color>) -> Result<wgpu::Texture> {
|
||||||
let mut output = None;
|
let mut output = None;
|
||||||
self.render_vello_scene_to_target_texture(scene, size, context, background, &mut output).await?;
|
self.render_vello_scene_to_target_texture(scene, size, context, background, &mut output).await?;
|
||||||
Ok(output.unwrap().texture)
|
Ok(output.unwrap().texture)
|
||||||
}
|
}
|
||||||
pub async fn render_vello_scene_to_target_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Color, output: &mut Option<TargetTexture>) -> Result<()> {
|
pub async fn render_vello_scene_to_target_texture(&self, scene: &Scene, size: UVec2, context: &RenderContext, background: Option<Color>, output: &mut Option<TargetTexture>) -> Result<()> {
|
||||||
// Initialize (lazily) if this is the first call
|
// Initialize (lazily) if this is the first call
|
||||||
if output.is_none() {
|
if output.is_none() {
|
||||||
*output = Some(TargetTexture::new(&self.context.device, size));
|
*output = Some(TargetTexture::new(&self.context.device, size));
|
||||||
|
|
@ -126,7 +126,7 @@ impl WgpuExecutor {
|
||||||
if let Some(target_texture) = output.as_mut() {
|
if let Some(target_texture) = output.as_mut() {
|
||||||
target_texture.ensure_size(&self.context.device, size);
|
target_texture.ensure_size(&self.context.device, size);
|
||||||
|
|
||||||
let [r, g, b, a] = background.to_rgba8_srgb();
|
let [r, g, b, a] = background.unwrap_or(Color::TRANSPARENT).to_rgba8_srgb();
|
||||||
let render_params = RenderParams {
|
let render_params = RenderParams {
|
||||||
base_color: vello::peniko::Color::from_rgba8(r, g, b, a),
|
base_color: vello::peniko::Color::from_rgba8(r, g, b, a),
|
||||||
width: size.x,
|
width: size.x,
|
||||||
|
|
|
||||||
|
|
@ -189,10 +189,11 @@ async fn render<'a: 'n>(ctx: impl Ctx + ExtractFootprint + ExtractVarArgs, edito
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut background = Color::from_rgb8_srgb(0x22, 0x22, 0x22);
|
let background = if !render_params.for_export && !contains_artboard && !render_params.hide_artboards {
|
||||||
if !contains_artboard && !render_params.hide_artboards {
|
Some(Color::WHITE)
|
||||||
background = Color::WHITE;
|
} else {
|
||||||
}
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let texture = exec
|
let texture = exec
|
||||||
.render_vello_scene_to_texture(&scene, physical_resolution, context, background)
|
.render_vello_scene_to_texture(&scene, physical_resolution, context, background)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue