@@ -338,20 +338,23 @@ static void on_dmabuf_device_opened(ctx_t * ctx, bool success) {
338338
339339// --- init_mirror_screencopy ---
340340
341- void wlm_mirror_screencopy_shm_init (ctx_t * ctx ) {
341+ static void wlm_mirror_screencopy_init (ctx_t * ctx , bool use_dmabuf ) {
342342 // check for required protocols
343- if (ctx -> wl .shm == NULL ) {
343+ if (use_dmabuf && ctx -> wl .linux_dmabuf == NULL ) {
344+ wlm_log_error ("mirror-screencopy::dmabuf_init(): missing linux_dmabuf protocol\n" );
345+ return ;
346+ } else if (!use_dmabuf && ctx -> wl .shm == NULL ) {
344347 wlm_log_error ("mirror-screencopy::shm_init(): missing wl_shm protocol\n" );
345348 return ;
346349 } else if (ctx -> wl .screencopy_manager == NULL ) {
347- wlm_log_error ("mirror-screencopy::shm_init (): missing wlr_screencopy protocol\n" );
350+ wlm_log_error ("mirror-screencopy::init (): missing wlr_screencopy protocol\n" );
348351 return ;
349352 }
350353
351354 // allocate backend context structure
352355 screencopy_mirror_backend_t * backend = calloc (1 , sizeof (screencopy_mirror_backend_t ));
353356 if (backend == NULL ) {
354- wlm_log_error ("mirror-screencopy::shm_init (): failed to allocate backend state\n" );
357+ wlm_log_error ("mirror-screencopy::init (): failed to allocate backend state\n" );
355358 return ;
356359 }
357360
@@ -360,7 +363,7 @@ void wlm_mirror_screencopy_shm_init(ctx_t * ctx) {
360363 backend -> header .do_cleanup = do_cleanup ;
361364 backend -> header .on_options_updated = NULL ;
362365 backend -> header .fail_count = 0 ;
363- backend -> use_dmabuf = false ;
366+ backend -> use_dmabuf = use_dmabuf ;
364367
365368 backend -> screencopy_frame = NULL ;
366369
@@ -370,56 +373,30 @@ void wlm_mirror_screencopy_shm_init(ctx_t * ctx) {
370373 backend -> frame_format = 0 ;
371374 backend -> frame_flags = 0 ;
372375
373- backend -> state = STATE_READY ;
374-
375376 // set backend object as current backend
376377 ctx -> mirror .backend = (mirror_backend_t * )backend ;
377378
378- // create shm pool
379- if (!wlm_wayland_shm_create_pool (ctx )) {
380- wlm_log_error ("mirror-screencopy::shm_init(): failed to create shm pool\n" );
381- wlm_mirror_backend_fail (ctx );
382- return ;
383- }
384- }
379+ if (use_dmabuf ) {
380+ backend -> state = STATE_WAIT_DMABUF_DEVICE ;
385381
386- void wlm_mirror_screencopy_dmabuf_init (ctx_t * ctx ) {
387- // check for required protocols
388- if (ctx -> wl .linux_dmabuf == NULL ) {
389- wlm_log_error ("mirror-screencopy::dmabuf_init(): missing linux_dmabuf protocol\n" );
390- return ;
391- } else if (ctx -> wl .screencopy_manager == NULL ) {
392- wlm_log_error ("mirror-screencopy::dmabuf_init(): missing wlr_screencopy protocol\n" );
393- return ;
394- }
382+ // open dmabuf device
383+ wlm_wayland_dmabuf_open_main_device (ctx , on_dmabuf_device_opened );
384+ } else {
385+ backend -> state = STATE_READY ;
395386
396- // allocate backend context structure
397- screencopy_mirror_backend_t * backend = calloc (1 , sizeof (screencopy_mirror_backend_t ));
398- if (backend == NULL ) {
399- wlm_log_error ("mirror-screencopy::dmabuf_init(): failed to allocate backend state\n" );
400- return ;
387+ // create shm pool
388+ if (!wlm_wayland_shm_create_pool (ctx )) {
389+ wlm_log_error ("mirror-screencopy::shm_init(): failed to create shm pool\n" );
390+ wlm_mirror_backend_fail (ctx );
391+ return ;
392+ }
401393 }
394+ }
402395
403- // initialize context structure
404- backend -> header .do_capture = do_capture ;
405- backend -> header .do_cleanup = do_cleanup ;
406- backend -> header .on_options_updated = NULL ;
407- backend -> header .fail_count = 0 ;
408- backend -> use_dmabuf = true;
409-
410- backend -> screencopy_frame = NULL ;
411-
412- backend -> frame_width = 0 ;
413- backend -> frame_height = 0 ;
414- backend -> frame_stride = 0 ;
415- backend -> frame_format = 0 ;
416- backend -> frame_flags = 0 ;
417-
418- backend -> state = STATE_WAIT_DMABUF_DEVICE ;
419-
420- // set backend object as current backend
421- ctx -> mirror .backend = (mirror_backend_t * )backend ;
396+ void wlm_mirror_screencopy_shm_init (ctx_t * ctx ) {
397+ wlm_mirror_screencopy_init (ctx , false);
398+ }
422399
423- // open dmabuf device
424- wlm_wayland_dmabuf_open_main_device (ctx , on_dmabuf_device_opened );
400+ void wlm_mirror_screencopy_dmabuf_init ( ctx_t * ctx ) {
401+ wlm_mirror_screencopy_init (ctx , true );
425402}
0 commit comments