Skip to content

Commit 14e3be4

Browse files
committed
Support transparent windows in vger
1 parent ded3c62 commit 14e3be4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

tiny_skia/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle
374374
{
375375
fn begin(&mut self, _capture: bool) {
376376
self.transform = Affine::IDENTITY;
377-
self.pixmap.fill(tiny_skia::Color::WHITE);
377+
self.pixmap.fill(tiny_skia::Color::TRANSPARENT);
378378
self.clip = None;
379379
}
380380

@@ -613,7 +613,8 @@ impl<W: raw_window_handle::HasWindowHandle + raw_window_handle::HasDisplayHandle
613613
for (out_pixel, pixel) in (buffer.iter_mut()).zip(self.pixmap.pixels().iter()) {
614614
*out_pixel = ((pixel.red() as u32) << 16)
615615
| ((pixel.green() as u32) << 8)
616-
| (pixel.blue() as u32);
616+
| (pixel.blue() as u32)
617+
| ((pixel.alpha() as u32) << 24);
617618
}
618619

619620
buffer

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)