[mutter] drm-buffer: Replace 'use-modifier' boolean with flags



commit 6ba86366b3b6d4e97cce872dc569c7d96b5d083a
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Wed May 5 10:15:18 2021 +0200

    drm-buffer: Replace 'use-modifier' boolean with flags
    
    This lets us add more customization to the buffer instance without
    adding more boolean arguments.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1854>

 src/backends/native/meta-cursor-renderer-native.c | 10 ++++++++--
 src/backends/native/meta-drm-buffer-dumb.c        |  3 ++-
 src/backends/native/meta-drm-buffer-gbm.c         | 22 ++++++++++-----------
 src/backends/native/meta-drm-buffer-gbm.h         | 10 +++++-----
 src/backends/native/meta-drm-buffer-import.c      |  2 +-
 src/backends/native/meta-drm-buffer-private.h     |  1 -
 src/backends/native/meta-drm-buffer.c             | 24 +++++++++++++++++++++--
 src/backends/native/meta-drm-buffer.h             |  6 ++++++
 src/backends/native/meta-onscreen-native.c        | 17 ++++++++++++----
 src/meson.build                                   |  1 +
 src/wayland/meta-wayland-buffer.c                 | 10 ++++++----
 src/wayland/meta-wayland-dma-buf.c                | 10 ++++++----
 12 files changed, 81 insertions(+), 35 deletions(-)
---
diff --git a/src/backends/native/meta-cursor-renderer-native.c 
b/src/backends/native/meta-cursor-renderer-native.c
index effa0851dc..d4ef4ed4e2 100644
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ b/src/backends/native/meta-cursor-renderer-native.c
@@ -1260,6 +1260,7 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
       uint8_t buf[4 * cursor_width * cursor_height];
       uint i;
       g_autoptr (GError) error = NULL;
+      MetaDrmBufferFlags flags;
       MetaDrmBufferGbm *buffer_gbm;
 
       device_file = meta_device_pool_open (device_pool,
@@ -1293,7 +1294,9 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
           return;
         }
 
-      buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
+      flags = META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
+      buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, flags,
+                                                 &error);
       if (!buffer_gbm)
         {
           meta_warning ("Failed to create DRM buffer wrapper: %s",
@@ -1587,6 +1590,7 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
       struct gbm_device *gbm_device;
       struct gbm_bo *bo;
       g_autoptr (GError) error = NULL;
+      MetaDrmBufferFlags flags;
       MetaDrmBufferGbm *buffer_gbm;
 
       device_file = meta_device_pool_open (device_pool,
@@ -1633,7 +1637,9 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
 
       unset_can_preprocess (cursor_sprite);
 
-      buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
+      flags = META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
+      buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, flags,
+                                                 &error);
       if (!buffer_gbm)
         {
           meta_warning ("Failed to create DRM buffer wrapper: %s",
diff --git a/src/backends/native/meta-drm-buffer-dumb.c b/src/backends/native/meta-drm-buffer-dumb.c
index 91daeb6d40..3e4988fcd8 100644
--- a/src/backends/native/meta-drm-buffer-dumb.c
+++ b/src/backends/native/meta-drm-buffer-dumb.c
@@ -242,7 +242,7 @@ init_dumb_buffer (MetaDrmBufferDumb  *buffer_dumb,
     .handles = { create_arg.handle },
     .strides = { create_arg.pitch },
   };
-  if (!meta_drm_buffer_ensure_fb_id (buffer, FALSE, &fb_args, error))
+  if (!meta_drm_buffer_ensure_fb_id (buffer, &fb_args, error))
     goto err_add_fb;
 
   map_arg = (struct drm_mode_map_dumb) {
@@ -303,6 +303,7 @@ meta_drm_buffer_dumb_new (MetaDeviceFile  *device_file,
 
   buffer_dumb = g_object_new (META_TYPE_DRM_BUFFER_DUMB,
                               "device-file", device_file,
+                              "flags", META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS,
                               NULL);
 
   if (!init_dumb_buffer (buffer_dumb, width, height, format, error))
diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c
index d417700ff0..9ad49be0dc 100644
--- a/src/backends/native/meta-drm-buffer-gbm.c
+++ b/src/backends/native/meta-drm-buffer-gbm.c
@@ -117,7 +117,6 @@ meta_drm_buffer_gbm_get_modifier (MetaDrmBuffer *buffer)
 static gboolean
 init_fb_id (MetaDrmBufferGbm  *buffer_gbm,
             struct gbm_bo     *bo,
-            gboolean           use_modifiers,
             GError           **error)
 {
   MetaDrmFbArgs fb_args = { 0, };
@@ -148,7 +147,7 @@ init_fb_id (MetaDrmBufferGbm  *buffer_gbm,
   fb_args.format = gbm_bo_get_format (bo);
 
   if (!meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_gbm),
-                                     use_modifiers, &fb_args, error))
+                                     &fb_args, error))
     return FALSE;
 
   return TRUE;
@@ -156,7 +155,6 @@ init_fb_id (MetaDrmBufferGbm  *buffer_gbm,
 
 static gboolean
 lock_front_buffer (MetaDrmBufferGbm  *buffer_gbm,
-                   gboolean           use_modifiers,
                    GError           **error)
 {
   buffer_gbm->bo = gbm_surface_lock_front_buffer (buffer_gbm->surface);
@@ -169,23 +167,24 @@ lock_front_buffer (MetaDrmBufferGbm  *buffer_gbm,
       return FALSE;
     }
 
-  return init_fb_id (buffer_gbm, buffer_gbm->bo, use_modifiers, error);
+  return init_fb_id (buffer_gbm, buffer_gbm->bo, error);
 }
 
 MetaDrmBufferGbm *
 meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile      *device_file,
                                     struct gbm_surface  *gbm_surface,
-                                    gboolean             use_modifiers,
+                                    MetaDrmBufferFlags   flags,
                                     GError             **error)
 {
   MetaDrmBufferGbm *buffer_gbm;
 
   buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
                              "device-file", device_file,
+                             "flags", flags,
                              NULL);
   buffer_gbm->surface = gbm_surface;
 
-  if (!lock_front_buffer (buffer_gbm, use_modifiers, error))
+  if (!lock_front_buffer (buffer_gbm, error))
     {
       g_object_unref (buffer_gbm);
       return NULL;
@@ -195,18 +194,19 @@ meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile      *device_file,
 }
 
 MetaDrmBufferGbm *
-meta_drm_buffer_gbm_new_take (MetaDeviceFile  *device_file,
-                              struct gbm_bo   *bo,
-                              gboolean         use_modifiers,
-                              GError         **error)
+meta_drm_buffer_gbm_new_take (MetaDeviceFile      *device_file,
+                              struct gbm_bo       *bo,
+                              MetaDrmBufferFlags   flags,
+                              GError             **error)
 {
   MetaDrmBufferGbm *buffer_gbm;
 
   buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
                              "device-file", device_file,
+                             "flags", flags,
                              NULL);
 
-  if (!init_fb_id (buffer_gbm, bo, use_modifiers, error))
+  if (!init_fb_id (buffer_gbm, bo, error))
     {
       g_object_unref (buffer_gbm);
       return NULL;
diff --git a/src/backends/native/meta-drm-buffer-gbm.h b/src/backends/native/meta-drm-buffer-gbm.h
index 0413c9fa27..ab994a25d0 100644
--- a/src/backends/native/meta-drm-buffer-gbm.h
+++ b/src/backends/native/meta-drm-buffer-gbm.h
@@ -35,14 +35,14 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
 
 MetaDrmBufferGbm * meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile      *device_file,
                                                        struct gbm_surface  *gbm_surface,
-                                                       gboolean             use_modifiers,
+                                                       MetaDrmBufferFlags   flags,
                                                        GError             **error);
 
 
-MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaDeviceFile  *device_file,
-                                                 struct gbm_bo   *gbm_bo,
-                                                 gboolean         use_modifiers,
-                                                 GError         **error);
+MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaDeviceFile      *device_file,
+                                                 struct gbm_bo       *gbm_bo,
+                                                 MetaDrmBufferFlags   flags,
+                                                 GError             **error);
 
 struct gbm_bo * meta_drm_buffer_gbm_get_bo (MetaDrmBufferGbm *buffer_gbm);
 
diff --git a/src/backends/native/meta-drm-buffer-import.c b/src/backends/native/meta-drm-buffer-import.c
index 40d11a79ca..b947bd1f92 100644
--- a/src/backends/native/meta-drm-buffer-import.c
+++ b/src/backends/native/meta-drm-buffer-import.c
@@ -172,7 +172,6 @@ import_gbm_buffer (MetaDrmBufferImport  *buffer_import,
   fb_args.handles[0] = gbm_bo_get_handle (imported_bo).u32;
 
   ret = meta_drm_buffer_ensure_fb_id (META_DRM_BUFFER (buffer_import),
-                                      FALSE /* use_modifiers */,
                                       &fb_args,
                                       error);
 
@@ -194,6 +193,7 @@ meta_drm_buffer_import_new (MetaDeviceFile     *device_file,
 
   buffer_import = g_object_new (META_TYPE_DRM_BUFFER_IMPORT,
                                 "device-file", device_file,
+                                "flags", META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS,
                                 NULL);
   g_set_object (&buffer_import->importee, buffer_gbm);
 
diff --git a/src/backends/native/meta-drm-buffer-private.h b/src/backends/native/meta-drm-buffer-private.h
index 7c8c26482c..08d8ae88e0 100644
--- a/src/backends/native/meta-drm-buffer-private.h
+++ b/src/backends/native/meta-drm-buffer-private.h
@@ -59,7 +59,6 @@ struct _MetaDrmBufferClass
 MetaDeviceFile * meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer);
 
 gboolean meta_drm_buffer_ensure_fb_id (MetaDrmBuffer        *buffer,
-                                       gboolean              use_modifiers,
                                        const MetaDrmFbArgs  *fb_args,
                                        GError              **error);
 
diff --git a/src/backends/native/meta-drm-buffer.c b/src/backends/native/meta-drm-buffer.c
index 5e60f9a5ed..4ec9d820c6 100644
--- a/src/backends/native/meta-drm-buffer.c
+++ b/src/backends/native/meta-drm-buffer.c
@@ -31,6 +31,8 @@
 #include "backends/native/meta-device-pool.h"
 #include "backends/native/meta-kms-utils.h"
 
+#include "meta-private-enum-types.h"
+
 #define INVALID_FB_ID 0U
 
 enum
@@ -38,6 +40,7 @@ enum
   PROP_0,
 
   PROP_DEVICE_FILE,
+  PROP_FLAGS,
 
   N_PROPS
 };
@@ -47,6 +50,8 @@ static GParamSpec *obj_props[N_PROPS];
 typedef struct _MetaDrmBufferPrivate
 {
   MetaDeviceFile *device_file;
+  MetaDrmBufferFlags flags;
+
   uint32_t fb_id;
 } MetaDrmBufferPrivate;
 
@@ -63,7 +68,6 @@ meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer)
 
 gboolean
 meta_drm_buffer_ensure_fb_id (MetaDrmBuffer        *buffer,
-                              gboolean              use_modifiers,
                               const MetaDrmFbArgs  *fb_args,
                               GError              **error)
 {
@@ -74,7 +78,8 @@ meta_drm_buffer_ensure_fb_id (MetaDrmBuffer        *buffer,
 
   fd = meta_device_file_get_fd (priv->device_file);
 
-  if (use_modifiers && fb_args->modifiers[0] != DRM_FORMAT_MOD_INVALID)
+  if (!(priv->flags & META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS) &&
+      fb_args->modifiers[0] != DRM_FORMAT_MOD_INVALID)
     {
       if (drmModeAddFB2WithModifiers (fd,
                                       fb_args->width,
@@ -239,6 +244,9 @@ meta_drm_buffer_get_property (GObject    *object,
     case PROP_DEVICE_FILE:
       g_value_set_pointer (value, priv->device_file);
       break;
+    case PROP_FLAGS:
+      g_value_set_flags (value, priv->flags);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -259,6 +267,9 @@ meta_drm_buffer_set_property (GObject      *object,
     case PROP_DEVICE_FILE:
       priv->device_file = g_value_get_pointer (value);
       break;
+    case PROP_FLAGS:
+      priv->flags = g_value_get_flags (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -311,5 +322,14 @@ meta_drm_buffer_class_init (MetaDrmBufferClass *klass)
                           G_PARAM_READWRITE |
                           G_PARAM_CONSTRUCT_ONLY |
                           G_PARAM_STATIC_STRINGS);
+  obj_props[PROP_FLAGS] =
+    g_param_spec_flags ("flags",
+                        "flags",
+                        "MetaDrmBufferFlags",
+                        META_TYPE_DRM_BUFFER_FLAGS,
+                        META_DRM_BUFFER_FLAG_NONE,
+                        G_PARAM_READWRITE |
+                        G_PARAM_CONSTRUCT_ONLY |
+                        G_PARAM_STATIC_STRINGS);
   g_object_class_install_properties (object_class, N_PROPS, obj_props);
 }
diff --git a/src/backends/native/meta-drm-buffer.h b/src/backends/native/meta-drm-buffer.h
index c5b152bb8e..ac4a83ef76 100644
--- a/src/backends/native/meta-drm-buffer.h
+++ b/src/backends/native/meta-drm-buffer.h
@@ -28,6 +28,12 @@
 
 #include "cogl/cogl.h"
 
+typedef enum _MetaDrmBufferFlags
+{
+  META_DRM_BUFFER_FLAG_NONE = 0,
+  META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS = 1 << 0,
+} MetaDrmBufferFlags;
+
 #define META_TYPE_DRM_BUFFER (meta_drm_buffer_get_type ())
 G_DECLARE_DERIVABLE_TYPE (MetaDrmBuffer,
                           meta_drm_buffer,
diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c
index 00b2d9f89c..3ff2504157 100644
--- a/src/backends/native/meta-onscreen-native.c
+++ b/src/backends/native/meta-onscreen-native.c
@@ -654,6 +654,7 @@ copy_shared_framebuffer_gpu (CoglOnscreen                        *onscreen,
   GError *error = NULL;
   gboolean use_modifiers;
   MetaDeviceFile *device_file;
+  MetaDrmBufferFlags flags;
   MetaDrmBufferGbm *buffer_gbm;
   struct gbm_bo *bo;
 
@@ -705,10 +706,15 @@ copy_shared_framebuffer_gpu (CoglOnscreen                        *onscreen,
 
   use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
   device_file = secondary_gpu_state->renderer_gpu_data->device_file;
+
+  flags = META_DRM_BUFFER_FLAG_NONE;
+  if (!use_modifiers)
+    flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
+
   buffer_gbm =
     meta_drm_buffer_gbm_new_lock_front (device_file,
                                         secondary_gpu_state->gbm.surface,
-                                        use_modifiers,
+                                        flags,
                                         &error);
   if (!buffer_gbm)
     {
@@ -1016,9 +1022,9 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen  *onscreen,
   ClutterFrame *frame = user_data;
   CoglOnscreenClass *parent_class;
   gboolean egl_context_changed = FALSE;
-  gboolean use_modifiers;
   MetaPowerSave power_save_mode;
   g_autoptr (GError) error = NULL;
+  MetaDrmBufferFlags buffer_flags;
   MetaDrmBufferGbm *buffer_gbm;
   MetaKmsCrtc *kms_crtc;
   MetaKmsDevice *kms_device;
@@ -1047,11 +1053,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);
 
-      use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
+      buffer_flags = META_DRM_BUFFER_FLAG_NONE;
+      if (!meta_renderer_native_use_modifiers (renderer_native))
+        buffer_flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
+
       buffer_gbm =
         meta_drm_buffer_gbm_new_lock_front (render_device_file,
                                             onscreen_native->gbm.surface,
-                                            use_modifiers,
+                                            buffer_flags,
                                             &error);
       if (!buffer_gbm)
         {
diff --git a/src/meson.build b/src/meson.build
index f4ecba3b31..655b5bfcab 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -804,6 +804,7 @@ endif
 if have_native_backend
   mutter_private_enum_sources += [
     'backends/native/meta-backend-native-types.h',
+    'backends/native/meta-drm-buffer.h',
     'backends/native/meta-kms-types.h',
   ]
 endif
diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c
index 2b6fe6b6e3..bb547f7117 100644
--- a/src/wayland/meta-wayland-buffer.c
+++ b/src/wayland/meta-wayland-buffer.c
@@ -694,6 +694,7 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
   uint32_t drm_format;
   uint64_t drm_modifier;
   uint32_t stride;
+  MetaDrmBufferFlags flags;
   MetaDrmBufferGbm *fb;
   g_autoptr (GError) error = NULL;
 
@@ -719,10 +720,11 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
       return NULL;
     }
 
-  fb = meta_drm_buffer_gbm_new_take (device_file,
-                                     gbm_bo,
-                                     drm_modifier != DRM_FORMAT_MOD_INVALID,
-                                     &error);
+  flags = META_DRM_BUFFER_FLAG_NONE;
+  if (drm_modifier == DRM_FORMAT_MOD_INVALID)
+    flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
+
+  fb = meta_drm_buffer_gbm_new_take (device_file, gbm_bo, flags, &error);
   if (!fb)
     {
       g_debug ("Failed to create scanout buffer: %s", error->message);
diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c
index 0d30684b7b..c4081db426 100644
--- a/src/wayland/meta-wayland-dma-buf.c
+++ b/src/wayland/meta-wayland-dma-buf.c
@@ -295,6 +295,7 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
   struct gbm_bo *gbm_bo;
   gboolean use_modifier;
   g_autoptr (GError) error = NULL;
+  MetaDrmBufferFlags flags;
   MetaDrmBufferGbm *fb;
 
   for (n_planes = 0; n_planes < META_WAYLAND_DMA_BUF_MAX_FDS; n_planes++)
@@ -321,10 +322,11 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
       return NULL;
     }
 
-  fb = meta_drm_buffer_gbm_new_take (device_file,
-                                     gbm_bo,
-                                     use_modifier,
-                                     &error);
+  flags = META_DRM_BUFFER_FLAG_NONE;
+  if (!use_modifier)
+    flags |= META_DRM_BUFFER_FLAG_DISABLE_MODIFIERS;
+
+  fb = meta_drm_buffer_gbm_new_take (device_file, gbm_bo, flags, &error);
   if (!fb)
     {
       g_debug ("Failed to create scanout buffer: %s", error->message);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]