1
1
use crate :: { error:: unwrap, SoftBufferError } ;
2
2
use raw_window_handle:: { WaylandDisplayHandle , WaylandWindowHandle } ;
3
- use std:: collections:: VecDeque ;
4
3
use wayland_client:: {
5
4
backend:: { Backend , ObjectId } ,
6
5
globals:: { registry_queue_init, GlobalListContents } ,
@@ -18,8 +17,7 @@ pub struct WaylandImpl {
18
17
qh : QueueHandle < State > ,
19
18
surface : wl_surface:: WlSurface ,
20
19
shm : wl_shm:: WlShm ,
21
- // 0-2 buffers
22
- buffers : VecDeque < WaylandBuffer > ,
20
+ buffers : Option < ( WaylandBuffer , WaylandBuffer ) > ,
23
21
}
24
22
25
23
impl WaylandImpl {
@@ -61,24 +59,22 @@ impl WaylandImpl {
61
59
} )
62
60
}
63
61
64
- // Allocate or reuse a buffer of the given size
65
62
fn buffer ( & mut self , width : i32 , height : i32 ) -> & WaylandBuffer {
66
- let buffer = if let Some ( mut buffer) = self . buffers . pop_front ( ) {
67
- if buffer. released ( ) {
68
- buffer. resize ( width, height) ;
69
- buffer
70
- } else {
71
- // If we have more than 1 unreleased buffer, destroy it
72
- if self . buffers . is_empty ( ) {
73
- self . buffers . push_back ( buffer) ;
74
- }
75
- WaylandBuffer :: new ( & self . shm , width, height, & self . qh )
63
+ self . buffers = Some ( if let Some ( ( front, mut back) ) = self . buffers . take ( ) {
64
+ // Swap buffers; block if back buffer not released yet
65
+ while !back. released ( ) {
66
+ self . event_queue . blocking_dispatch ( & mut State ) . unwrap ( ) ;
76
67
}
68
+ back. resize ( width, height) ;
69
+ ( back, front)
77
70
} else {
78
- WaylandBuffer :: new ( & self . shm , width, height, & self . qh )
79
- } ;
80
- self . buffers . push_back ( buffer) ;
81
- self . buffers . back ( ) . unwrap ( )
71
+ // Allocate front and back buffer
72
+ (
73
+ WaylandBuffer :: new ( & self . shm , width, height, & self . qh ) ,
74
+ WaylandBuffer :: new ( & self . shm , width, height, & self . qh ) ,
75
+ )
76
+ } ) ;
77
+ & self . buffers . as_ref ( ) . unwrap ( ) . 0
82
78
}
83
79
84
80
pub ( super ) unsafe fn set_buffer ( & mut self , buffer : & [ u32 ] , width : u16 , height : u16 ) {
0 commit comments