drm-buffer/gbm: Support both surface and standalone buffers
Surface buffers are created with meta_drm_buffer_new_acquire(), taking a gbm_surface acquiring the gbm itself, and meta_drm_buffer_new_take() that takes over ownership of a passed gbm_bo. https://gitlab.gnome.org/GNOME/mutter/merge_requests/798
This commit is contained in:
parent
47002bf0cd
commit
282aada13a
@ -53,22 +53,12 @@ meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
acquire_swapped_buffer (MetaDrmBufferGbm *buffer_gbm,
|
||||
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,18 +89,31 @@ 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 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,
|
||||
meta_drm_buffer_gbm_new_lock_front (MetaGpuKms *gpu_kms,
|
||||
struct gbm_surface *gbm_surface,
|
||||
gboolean use_modifiers,
|
||||
GError **error)
|
||||
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -33,11 +33,17 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
|
||||
META, DRM_BUFFER_GBM,
|
||||
MetaDrmBuffer)
|
||||
|
||||
MetaDrmBufferGbm * meta_drm_buffer_gbm_new (MetaGpuKms *gpu_kms,
|
||||
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);
|
||||
|
||||
#endif /* META_DRM_BUFFER_GBM_H */
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user