@@ -23,22 +23,24 @@ static void frame_handle_presentation_time(void*,
2323{}
2424
2525static void frame_handle_ready (void *data,
26- struct ext_image_copy_capture_frame_v1 * )
26+ struct ext_image_copy_capture_frame_v1 *frame )
2727{
2828 WayfireChooserOutput *output = (WayfireChooserOutput*)data;
29+
2930 output->buffer_ready ();
30- output->frame_in_flight = false ;
31+
32+ ext_image_copy_capture_frame_v1_destroy (frame);
33+ output->frame = nullptr ;
3134}
3235
3336static void frame_handle_failed (void *data,
34- struct ext_image_copy_capture_frame_v1 *handle ,
37+ struct ext_image_copy_capture_frame_v1 *frame ,
3538 uint32_t reason)
3639{
3740 WayfireChooserOutput *output = (WayfireChooserOutput*)data;
38- std::cerr << " Failed to copy frame because reason: " << reason << std::endl;
39- ext_image_copy_capture_frame_v1_destroy (handle );
41+
42+ ext_image_copy_capture_frame_v1_destroy (frame );
4043 output->frame = nullptr ;
41- output->frame_in_flight = false ;
4244}
4345
4446static const struct ext_image_copy_capture_frame_v1_listener frame_listener = {
@@ -94,36 +96,31 @@ static const struct ext_image_copy_capture_session_v1_listener recording_session
9496 .stopped = session_handle_stopped,
9597};
9698
97- static void dmabuf_created (void *data, struct zwp_linux_buffer_params_v1 *,
98- struct wl_buffer *wl_buffer)
99- {
100- auto output = (WayfireChooserOutput*)data;
101- output->buffer ->buffer = wl_buffer;
102- }
103-
104- static void dmabuf_failed (void *, struct zwp_linux_buffer_params_v1 *)
105- {
106- std::cerr << " Failed to create dmabuf" << std::endl;
107- }
108-
109- static const struct zwp_linux_buffer_params_v1_listener params_listener = {
110- .created = dmabuf_created,
111- .failed = dmabuf_failed,
112- };
113-
11499static void frame_handle_linux_dmabuf (uint32_t width, uint32_t height, WayfireChooserOutput *output)
115100{
116101 auto format = (output->current_buffer_format == WL_SHM_FORMAT_XRGB8888 ) ?
117102 GBM_FORMAT_XRGB8888 : GBM_FORMAT_ARGB8888 ;
118103
119104 auto buffer = output->buffer ;
120105
106+ if (buffer->gbm_fd > 0 )
107+ {
108+ close (buffer->gbm_fd );
109+ buffer->gbm_fd = -1 ;
110+ }
111+
121112 if (buffer->bo )
122113 {
123114 gbm_bo_destroy (buffer->bo );
124115 buffer->bo = nullptr ;
125116 }
126117
118+ if (buffer->buffer )
119+ {
120+ wl_buffer_destroy (buffer->buffer );
121+ buffer->buffer = nullptr ;
122+ }
123+
127124 if (buffer->params )
128125 {
129126 zwp_linux_buffer_params_v1_destroy (buffer->params );
@@ -154,14 +151,14 @@ static void frame_handle_linux_dmabuf(uint32_t width, uint32_t height, WayfireCh
154151 buffer->params = zwp_linux_dmabuf_v1_create_params (WayfireStreamChooserApp::getInstance ().dmabuf );
155152
156153 uint64_t mod = gbm_bo_get_modifier (buffer->bo );
154+ buffer->gbm_fd = gbm_bo_get_fd (buffer->bo );
157155 zwp_linux_buffer_params_v1_add (buffer->params ,
158- gbm_bo_get_fd ( buffer->bo ) , 0 ,
156+ buffer->gbm_fd , 0 ,
159157 gbm_bo_get_offset (buffer->bo , 0 ),
160158 gbm_bo_get_stride (buffer->bo ),
161159 mod >> 32 , mod & 0xffffffff );
162160
163- zwp_linux_buffer_params_v1_add_listener (buffer->params , ¶ms_listener, output);
164- zwp_linux_buffer_params_v1_create (buffer->params , w, h, format, 0 );
161+ buffer->buffer = zwp_linux_buffer_params_v1_create_immed (buffer->params , w, h, format, 0 );
165162}
166163
167164void WayfireChooserOutput::start_output_source_ssession ()
@@ -294,16 +291,21 @@ WayfireChooserOutput::~WayfireChooserOutput()
294291 ext_image_copy_capture_session_v1_destroy (recording_session);
295292 }
296293
297- if (buffer->buffer )
294+ if (buffer->gbm_fd > 0 )
298295 {
299- wl_buffer_destroy (buffer->buffer );
296+ close (buffer->gbm_fd );
300297 }
301298
302299 if (buffer->bo )
303300 {
304301 gbm_bo_destroy (buffer->bo );
305302 }
306303
304+ if (buffer->buffer )
305+ {
306+ wl_buffer_destroy (buffer->buffer );
307+ }
308+
307309 if (buffer->params )
308310 {
309311 zwp_linux_buffer_params_v1_destroy (buffer->params );
@@ -355,11 +357,6 @@ void WayfireChooserOutput::frame_request()
355357 return ;
356358 }
357359
358- if (frame_in_flight)
359- {
360- return ;
361- }
362-
363360 if (frame)
364361 {
365362 ext_image_copy_capture_frame_v1_destroy (frame);
@@ -373,7 +370,6 @@ void WayfireChooserOutput::frame_request()
373370 ext_image_copy_capture_frame_v1_attach_buffer (buffer->frame , buffer->buffer );
374371 ext_image_copy_capture_frame_v1_damage_buffer (buffer->frame , 0 , 0 , buffer->width , buffer->height );
375372 ext_image_copy_capture_frame_v1_capture (buffer->frame );
376- frame_in_flight = true ;
377373}
378374
379375void WayfireChooserOutput::buffer_ready ()
@@ -399,10 +395,10 @@ void WayfireChooserOutput::buffer_ready()
399395 std::shared_ptr<Glib::Bytes> bytes = 0 ;
400396 size_t size = stride * buffer->height ;
401397 bytes = Glib::Bytes::create ((unsigned char *)data, size);
398+ gbm_bo_unmap (buffer->bo , map_data);
402399
403400 if (!bytes)
404401 {
405- gbm_bo_unmap (buffer->bo , map_data);
406402 return ;
407403 }
408404
@@ -416,6 +412,4 @@ void WayfireChooserOutput::buffer_ready()
416412 auto texture = builder->build ();
417413
418414 contents.set_paintable (texture);
419-
420- gbm_bo_unmap (buffer->bo , map_data);
421415}
0 commit comments