@@ -27,11 +27,12 @@ struct SurfaceData
27
27
SurfaceRole role ;
28
28
struct wl_resource * surface ;
29
29
struct wl_resource * pending_frame ;
30
+ struct wl_resource * pending_buffer ; // The attached but not committed buffer
31
+ char buffer_cleared ; // If the buffer has been explicitly cleared since the last commit
30
32
struct wl_resource * xdg_toplevel ;
31
33
struct wl_resource * xdg_popup ;
32
34
struct wl_resource * xdg_surface ;
33
35
struct wl_resource * layer_surface ;
34
- char has_pending_buffer ; // If the pending buffer is non-null; same as has_committed_buffer if no pending buffer
35
36
char has_committed_buffer ; // This surface has a non-null committed buffer
36
37
char initial_commit_for_role ; // Set to 1 when a role is created for a surface, and cleared after the first commit
37
38
char layer_send_configure ; // If to send a layer surface configure on the next commit
@@ -98,16 +99,30 @@ static void wl_surface_attach(struct wl_resource *resource, const struct wl_mess
98
99
{
99
100
RESOURCE_ARG (wl_buffer , buffer , 0 );
100
101
SurfaceData * data = wl_resource_get_user_data (resource );
101
- data -> has_pending_buffer = (buffer != NULL );
102
+ data -> pending_buffer = buffer ;
103
+ data -> buffer_cleared = buffer == NULL ;
102
104
data -> click_on_surface = 1 ;
103
105
}
104
106
105
107
static void wl_surface_commit (struct wl_resource * resource , const struct wl_message * message , union wl_argument * args )
106
108
{
107
109
SurfaceData * data = wl_resource_get_user_data (resource );
108
- data -> has_committed_buffer = data -> has_pending_buffer ;
110
+ if (data -> buffer_cleared )
111
+ {
112
+ data -> has_committed_buffer = 0 ;
113
+ data -> buffer_cleared = 0 ;
114
+ }
115
+ else if (data -> pending_buffer )
116
+ {
117
+ data -> has_committed_buffer = 1 ;
118
+ }
119
+
120
+ if (data -> pending_buffer )
121
+ {
122
+ wl_buffer_send_release (data -> pending_buffer );
123
+ data -> pending_buffer = NULL ;
124
+ }
109
125
110
- // leave the contents of has_pending_buffer alone
111
126
if (data -> pending_frame )
112
127
{
113
128
wl_callback_send_done (data -> pending_frame , 0 );
0 commit comments