drm-buffer: Don't always generate fb_id on construction

It might not be needed by the user of the buffer, so don't always
require it up front. Instead make sure that any user that needs it first
calls "meta_drm_buffer_ensure_fb_id()" to create the ID.

Only the plain gbm implementation creates the ID lazilly, the other
still does it on construction due to the objects used to create them
only existing during construction.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1854>
This commit is contained in:
Jonas Ådahl 2021-05-05 14:35:48 +02:00
parent a1266e19f4
commit b3dffb43b3
8 changed files with 49 additions and 23 deletions

View File

@ -251,7 +251,7 @@ init_dumb_buffer (MetaDrmBufferDumb *buffer_dumb,
.handles = { create_arg.handle }, .handles = { create_arg.handle },
.strides = { create_arg.pitch }, .strides = { create_arg.pitch },
}; };
if (!meta_drm_buffer_ensure_fb_id (buffer, &fb_args, error)) if (!meta_drm_buffer_do_ensure_fb_id (buffer, &fb_args, error))
goto err_add_fb; goto err_add_fb;
map_arg = (struct drm_mode_map_dumb) { map_arg = (struct drm_mode_map_dumb) {

View File

@ -133,11 +133,12 @@ meta_drm_buffer_gbm_get_modifier (MetaDrmBuffer *buffer)
} }
static gboolean static gboolean
init_fb_id (MetaDrmBufferGbm *buffer_gbm, meta_drm_buffer_gbm_ensure_fb_id (MetaDrmBuffer *buffer,
struct gbm_bo *bo, GError **error)
GError **error)
{ {
MetaDrmBufferGbm *buffer_gbm = META_DRM_BUFFER_GBM (buffer);
MetaDrmFbArgs fb_args = { 0, }; MetaDrmFbArgs fb_args = { 0, };
struct gbm_bo *bo = buffer_gbm->bo;
if (gbm_bo_get_handle_for_plane (bo, 0).s32 == -1) if (gbm_bo_get_handle_for_plane (bo, 0).s32 == -1)
{ {
@ -164,8 +165,8 @@ init_fb_id (MetaDrmBufferGbm *buffer_gbm,
fb_args.height = gbm_bo_get_height (bo); fb_args.height = gbm_bo_get_height (bo);
fb_args.format = gbm_bo_get_format (bo); fb_args.format = gbm_bo_get_format (bo);
if (!meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_gbm), if (!meta_drm_buffer_do_ensure_fb_id (META_DRM_BUFFER (buffer_gbm),
&fb_args, error)) &fb_args, error))
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -185,7 +186,7 @@ lock_front_buffer (MetaDrmBufferGbm *buffer_gbm,
return FALSE; return FALSE;
} }
return init_fb_id (buffer_gbm, buffer_gbm->bo, error); return meta_drm_buffer_gbm_ensure_fb_id (META_DRM_BUFFER (buffer_gbm), error);
} }
MetaDrmBufferGbm * MetaDrmBufferGbm *
@ -223,13 +224,6 @@ meta_drm_buffer_gbm_new_take (MetaDeviceFile *device_file,
"device-file", device_file, "device-file", device_file,
"flags", flags, "flags", flags,
NULL); NULL);
if (!init_fb_id (buffer_gbm, bo, error))
{
g_object_unref (buffer_gbm);
return NULL;
}
buffer_gbm->bo = bo; buffer_gbm->bo = bo;
return buffer_gbm; return buffer_gbm;
@ -510,6 +504,7 @@ meta_drm_buffer_gbm_class_init (MetaDrmBufferGbmClass *klass)
object_class->finalize = meta_drm_buffer_gbm_finalize; object_class->finalize = meta_drm_buffer_gbm_finalize;
buffer_class->export_fd = meta_drm_buffer_gbm_export_fd; buffer_class->export_fd = meta_drm_buffer_gbm_export_fd;
buffer_class->ensure_fb_id = meta_drm_buffer_gbm_ensure_fb_id;
buffer_class->get_width = meta_drm_buffer_gbm_get_width; buffer_class->get_width = meta_drm_buffer_gbm_get_width;
buffer_class->get_height = meta_drm_buffer_gbm_get_height; buffer_class->get_height = meta_drm_buffer_gbm_get_height;
buffer_class->get_stride = meta_drm_buffer_gbm_get_stride; buffer_class->get_stride = meta_drm_buffer_gbm_get_stride;

View File

@ -181,9 +181,9 @@ import_gbm_buffer (MetaDrmBufferImport *buffer_import,
fb_args.handles[0] = gbm_bo_get_handle (imported_bo).u32; fb_args.handles[0] = gbm_bo_get_handle (imported_bo).u32;
ret = meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_import), ret = meta_drm_buffer_do_ensure_fb_id (META_DRM_BUFFER (buffer_import),
&fb_args, &fb_args,
error); error);
gbm_bo_destroy (imported_bo); gbm_bo_destroy (imported_bo);

View File

@ -42,6 +42,9 @@ struct _MetaDrmBufferClass
int (* export_fd) (MetaDrmBuffer *buffer, int (* export_fd) (MetaDrmBuffer *buffer,
GError **error); GError **error);
gboolean (* ensure_fb_id) (MetaDrmBuffer *buffer,
GError **error);
int (* get_width) (MetaDrmBuffer *buffer); int (* get_width) (MetaDrmBuffer *buffer);
int (* get_height) (MetaDrmBuffer *buffer); int (* get_height) (MetaDrmBuffer *buffer);
int (* get_stride) (MetaDrmBuffer *buffer); int (* get_stride) (MetaDrmBuffer *buffer);
@ -58,8 +61,8 @@ struct _MetaDrmBufferClass
MetaDeviceFile * meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer); MetaDeviceFile * meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer);
gboolean meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer, gboolean meta_drm_buffer_do_ensure_fb_id (MetaDrmBuffer *buffer,
const MetaDrmFbArgs *fb_args, const MetaDrmFbArgs *fb_args,
GError **error); GError **error);
#endif /* META_DRM_BUFFER_PRIVATE_H */ #endif /* META_DRM_BUFFER_PRIVATE_H */

View File

@ -67,9 +67,21 @@ meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer)
} }
gboolean gboolean
meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer, meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
const MetaDrmFbArgs *fb_args, GError **error)
GError **error) {
MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
if (priv->fb_id)
return TRUE;
return META_DRM_BUFFER_GET_CLASS (buffer)->ensure_fb_id (buffer, error);
}
gboolean
meta_drm_buffer_do_ensure_fb_id (MetaDrmBuffer *buffer,
const MetaDrmFbArgs *fb_args,
GError **error)
{ {
MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer); MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
int fd; int fd;

View File

@ -43,6 +43,9 @@ G_DECLARE_DERIVABLE_TYPE (MetaDrmBuffer,
int meta_drm_buffer_export_fd (MetaDrmBuffer *buffer, int meta_drm_buffer_export_fd (MetaDrmBuffer *buffer,
GError **error); GError **error);
gboolean meta_drm_buffer_ensure_fb_id (MetaDrmBuffer *buffer,
GError **error);
uint32_t meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer); uint32_t meta_drm_buffer_get_fb_id (MetaDrmBuffer *buffer);
int meta_drm_buffer_get_width (MetaDrmBuffer *buffer); int meta_drm_buffer_get_width (MetaDrmBuffer *buffer);

View File

@ -421,6 +421,9 @@ process_plane_assignment (MetaKmsImplDevice *impl_device,
buffer = plane_assignment->buffer; buffer = plane_assignment->buffer;
if (buffer && !meta_drm_buffer_ensure_fb_id (buffer, error))
return FALSE;
meta_topic (META_DEBUG_KMS, meta_topic (META_DEBUG_KMS,
"[atomic] Assigning %s plane (%u, %s) to %u, " "[atomic] Assigning %s plane (%u, %s) to %u, "
"%hdx%hd+%hd+%hd -> %dx%d+%d+%d", "%hdx%hd+%hd+%hd -> %dx%d+%d+%d",

View File

@ -396,6 +396,9 @@ process_mode_set (MetaKmsImplDevice *impl_device,
} }
buffer = plane_assignment->buffer; buffer = plane_assignment->buffer;
if (!meta_drm_buffer_ensure_fb_id (buffer, error))
return FALSE;
fb_id = meta_drm_buffer_get_fb_id (buffer); fb_id = meta_drm_buffer_get_fb_id (buffer);
for (l = mode_set->connectors; l; l = l->next) for (l = mode_set->connectors; l; l = l->next)
@ -822,6 +825,9 @@ mode_set_fallback (MetaKmsImplDeviceSimple *impl_device_simple,
return FALSE; return FALSE;
} }
if (!meta_drm_buffer_ensure_fb_id (plane_assignment->buffer, error))
return FALSE;
fill_connector_ids_array (cached_mode_set->connectors, fill_connector_ids_array (cached_mode_set->connectors,
&connectors, &connectors,
&n_connectors); &n_connectors);
@ -926,6 +932,10 @@ dispatch_page_flip (MetaKmsImplDevice *impl_device,
return TRUE; return TRUE;
} }
if (plane_assignment && plane_assignment->buffer &&
!meta_drm_buffer_ensure_fb_id (plane_assignment->buffer, error))
return FALSE;
fd = meta_kms_impl_device_get_fd (impl_device); fd = meta_kms_impl_device_get_fd (impl_device);
if (custom_page_flip) if (custom_page_flip)
{ {