diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c index b446d64e1..1c8a20f77 100644 --- a/src/backends/native/meta-drm-buffer-gbm.c +++ b/src/backends/native/meta-drm-buffer-gbm.c @@ -53,22 +53,12 @@ meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm) } static gboolean -acquire_swapped_buffer (MetaDrmBufferGbm *buffer_gbm, - gboolean use_modifiers, - GError **error) +init_fb_id (MetaDrmBufferGbm *buffer_gbm, + struct gbm_bo *bo, + gboolean use_modifiers, + GError **error) { MetaGpuKmsFBArgs fb_args = { 0, }; - struct gbm_bo *bo; - - bo = gbm_surface_lock_front_buffer (buffer_gbm->surface); - if (!bo) - { - g_set_error (error, - G_IO_ERROR, - G_IO_ERROR_FAILED, - "gbm_surface_lock_front_buffer failed"); - return FALSE; - } if (gbm_bo_get_handle_for_plane (bo, 0).s32 == -1) { @@ -99,21 +89,34 @@ acquire_swapped_buffer (MetaDrmBufferGbm *buffer_gbm, use_modifiers, &fb_args, &buffer_gbm->fb_id, error)) - { - gbm_surface_release_buffer (buffer_gbm->surface, bo); - return FALSE; - } - - buffer_gbm->bo = bo; + return FALSE; return TRUE; } +static gboolean +lock_front_buffer (MetaDrmBufferGbm *buffer_gbm, + gboolean use_modifiers, + GError **error) +{ + buffer_gbm->bo = gbm_surface_lock_front_buffer (buffer_gbm->surface); + if (!buffer_gbm->bo) + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + "gbm_surface_lock_front_buffer failed"); + return FALSE; + } + + return init_fb_id (buffer_gbm, buffer_gbm->bo, use_modifiers, error); +} + MetaDrmBufferGbm * -meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms, - struct gbm_surface *gbm_surface, - gboolean use_modifiers, - GError **error) +meta_drm_buffer_gbm_new_lock_front (MetaGpuKms *gpu_kms, + struct gbm_surface *gbm_surface, + gboolean use_modifiers, + GError **error) { MetaDrmBufferGbm *buffer_gbm; @@ -121,7 +124,7 @@ meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms, buffer_gbm->gpu_kms = gpu_kms; buffer_gbm->surface = gbm_surface; - if (!acquire_swapped_buffer (buffer_gbm, use_modifiers, error)) + if (!lock_front_buffer (buffer_gbm, use_modifiers, error)) { g_object_unref (buffer_gbm); return NULL; @@ -130,6 +133,28 @@ meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms, return buffer_gbm; } +MetaDrmBufferGbm * +meta_drm_buffer_gbm_new_take (MetaGpuKms *gpu_kms, + struct gbm_bo *bo, + gboolean use_modifiers, + GError **error) +{ + MetaDrmBufferGbm *buffer_gbm; + + buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM, NULL); + buffer_gbm->gpu_kms = gpu_kms; + + if (!init_fb_id (buffer_gbm, bo, use_modifiers, error)) + { + g_object_unref (buffer_gbm); + return NULL; + } + + buffer_gbm->bo = bo; + + return buffer_gbm; +} + static uint32_t meta_drm_buffer_gbm_get_fb_id (MetaDrmBuffer *buffer) { @@ -150,7 +175,12 @@ meta_drm_buffer_gbm_finalize (GObject *object) } if (buffer_gbm->bo) - gbm_surface_release_buffer (buffer_gbm->surface, buffer_gbm->bo); + { + if (buffer_gbm->surface) + gbm_surface_release_buffer (buffer_gbm->surface, buffer_gbm->bo); + else + gbm_bo_destroy (buffer_gbm->bo); + } G_OBJECT_CLASS (meta_drm_buffer_gbm_parent_class)->finalize (object); } diff --git a/src/backends/native/meta-drm-buffer-gbm.h b/src/backends/native/meta-drm-buffer-gbm.h index b48cef06a..b46925ecc 100644 --- a/src/backends/native/meta-drm-buffer-gbm.h +++ b/src/backends/native/meta-drm-buffer-gbm.h @@ -33,10 +33,16 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm, META, DRM_BUFFER_GBM, MetaDrmBuffer) -MetaDrmBufferGbm * meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms, - struct gbm_surface *gbm_surface, - gboolean use_modifiers, - GError **error); +MetaDrmBufferGbm * meta_drm_buffer_gbm_new_lock_front (MetaGpuKms *gpu_kms, + struct gbm_surface *gbm_surface, + gboolean use_modifiers, + GError **error); + + +MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaGpuKms *gpu_kms, + struct gbm_bo *gbm_bo, + gboolean use_modifiers, + GError **error); struct gbm_bo * meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm); diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 8d82ad7c4..b363a2b05 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -1621,13 +1621,14 @@ copy_shared_framebuffer_gpu (CoglOnscreen *onscreen, return; } - buffer_gbm = meta_drm_buffer_gbm_new (secondary_gpu_state->gpu_kms, + buffer_gbm = + meta_drm_buffer_gbm_new_lock_front (secondary_gpu_state->gpu_kms, secondary_gpu_state->gbm.surface, renderer_native->use_modifiers, &error); if (!buffer_gbm) { - g_warning ("meta_drm_buffer_gbm_new failed: %s", + g_warning ("meta_drm_buffer_gbm_new_lock_front failed: %s", error->message); g_error_free (error); return; @@ -2071,13 +2072,14 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen, g_warn_if_fail (onscreen_native->gbm.next_fb == NULL); g_clear_object (&onscreen_native->gbm.next_fb); - buffer_gbm = meta_drm_buffer_gbm_new (render_gpu, + buffer_gbm = + meta_drm_buffer_gbm_new_lock_front (render_gpu, onscreen_native->gbm.surface, renderer_native->use_modifiers, &error); if (!buffer_gbm) { - g_warning ("meta_drm_buffer_gbm_new failed: %s", + g_warning ("meta_drm_buffer_gbm_new_lock_front failed: %s", error->message); return; }