Skip to content

Commit 1c7a8c7

Browse files
committed
Support transparent windows in vger
1 parent f30fa54 commit 1c7a8c7

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

examples/widget-gallery/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,10 @@ fn app_view() -> impl IntoView {
173173
}
174174

175175
fn main() {
176-
floem::launch(app_view);
176+
floem::Application::new()
177+
.window(
178+
|_| app_view(),
179+
Some(WindowConfig::default().with_transparent(true)),
180+
)
181+
.run();
177182
}

tiny_skia/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle
583583
fn begin(&mut self, _capture: bool) {
584584
assert!(self.layers.len() == 1);
585585
let first_layer = self.layers.last_mut().unwrap();
586-
first_layer.pixmap.fill(tiny_skia::Color::WHITE);
586+
first_layer.pixmap.fill(tiny_skia::Color::TRANSPARENT);
587587
first_layer.clip = None;
588588
first_layer.transform = Affine::IDENTITY;
589589
}
@@ -665,7 +665,8 @@ impl<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle
665665
{
666666
*out_pixel = ((pixel.red() as u32) << 16)
667667
| ((pixel.green() as u32) << 8)
668-
| (pixel.blue() as u32);
668+
| (pixel.blue() as u32)
669+
| ((pixel.alpha() as u32) << 24);
669670
}
670671

671672
buffer

vello/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl VelloRenderer {
8484
width,
8585
height,
8686
present_mode: wgpu::PresentMode::Fifo,
87-
alpha_mode: wgpu::CompositeAlphaMode::Auto,
87+
alpha_mode: wgpu::CompositeAlphaMode::PostMultiplied,
8888
view_formats: vec![],
8989
desired_maximum_frame_latency: 2,
9090
};

vger/src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use peniko::{
1616
kurbo::{Affine, Point, Rect, Shape},
1717
BrushRef, Color, GradientKind,
1818
};
19-
use wgpu::{Device, DeviceType, Queue, StoreOp, Surface, SurfaceConfiguration, TextureFormat};
19+
use wgpu::{
20+
CompositeAlphaMode, Device, DeviceType, Queue, StoreOp, Surface, SurfaceConfiguration,
21+
TextureFormat,
22+
};
2023

2124
pub struct VgerRenderer {
2225
device: Arc<Device>,
@@ -74,14 +77,27 @@ impl VgerRenderer {
7477
.into_iter()
7578
.find(|it| matches!(it, TextureFormat::Rgba8Unorm | TextureFormat::Bgra8Unorm))
7679
.ok_or_else(|| anyhow::anyhow!("surface should support Rgba8Unorm or Bgra8Unorm"))?;
80+
let alpha_mode = if surface_caps
81+
.alpha_modes
82+
.contains(&CompositeAlphaMode::PreMultiplied)
83+
{
84+
CompositeAlphaMode::PreMultiplied
85+
} else if surface_caps
86+
.alpha_modes
87+
.contains(&CompositeAlphaMode::PostMultiplied)
88+
{
89+
CompositeAlphaMode::PostMultiplied
90+
} else {
91+
CompositeAlphaMode::Auto
92+
};
7793

7894
let config = wgpu::SurfaceConfiguration {
7995
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
8096
format: texture_format,
8197
width,
8298
height,
8399
present_mode: wgpu::PresentMode::Fifo,
84-
alpha_mode: wgpu::CompositeAlphaMode::Auto,
100+
alpha_mode,
85101
view_formats: vec![],
86102
desired_maximum_frame_latency: 2,
87103
};

0 commit comments

Comments
 (0)