@@ -16,7 +16,10 @@ use peniko::{
16
16
kurbo:: { Affine , Point , Rect , Shape } ,
17
17
BrushRef , Color , GradientKind ,
18
18
} ;
19
- use wgpu:: { Device , DeviceType , Queue , StoreOp , Surface , SurfaceConfiguration , TextureFormat } ;
19
+ use wgpu:: {
20
+ CompositeAlphaMode , Device , DeviceType , Queue , StoreOp , Surface , SurfaceConfiguration ,
21
+ TextureFormat ,
22
+ } ;
20
23
21
24
pub struct VgerRenderer {
22
25
device : Arc < Device > ,
@@ -74,14 +77,27 @@ impl VgerRenderer {
74
77
. into_iter ( )
75
78
. find ( |it| matches ! ( it, TextureFormat :: Rgba8Unorm | TextureFormat :: Bgra8Unorm ) )
76
79
. 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
+ } ;
77
93
78
94
let config = wgpu:: SurfaceConfiguration {
79
95
usage : wgpu:: TextureUsages :: RENDER_ATTACHMENT ,
80
96
format : texture_format,
81
97
width,
82
98
height,
83
99
present_mode : wgpu:: PresentMode :: Fifo ,
84
- alpha_mode : wgpu :: CompositeAlphaMode :: Auto ,
100
+ alpha_mode,
85
101
view_formats : vec ! [ ] ,
86
102
desired_maximum_frame_latency : 2 ,
87
103
} ;
0 commit comments