[mutter] drm-buffer: Create from MetaDeviceFile instead of MetaKmsDevice



commit 10c4bc6e3f0230e587190bcd73f211dd5056b9ca
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Apr 12 16:13:29 2021 +0200

    drm-buffer: Create from MetaDeviceFile instead of MetaKmsDevice
    
    The DRM buffers aren't really tied to mode setting, so they shouldn't
    need to have an associated mode setting device. Now that we have a
    device file level object that can fill this role, port over
    MetaDrmBuffer and friends away from MetaKmsDevice to MetaDeviceFile.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1828>

 src/backends/native/meta-cursor-renderer-native.c |  44 ++++++-
 src/backends/native/meta-drm-buffer-dumb.c        | 141 ++++++---------------
 src/backends/native/meta-drm-buffer-dumb.h        |  12 +-
 src/backends/native/meta-drm-buffer-gbm.c         |  18 +--
 src/backends/native/meta-drm-buffer-gbm.h         |  12 +-
 src/backends/native/meta-drm-buffer-import.c      |   4 +-
 src/backends/native/meta-drm-buffer-import.h      |   2 +-
 src/backends/native/meta-drm-buffer-private.h     |   4 +-
 src/backends/native/meta-drm-buffer.c             | 147 ++++++----------------
 src/backends/native/meta-onscreen-native.c        |  30 ++---
 src/backends/native/meta-renderer-native.c        |  11 ++
 src/backends/native/meta-renderer-native.h        |   2 +
 src/wayland/meta-wayland-buffer.c                 |   7 +-
 src/wayland/meta-wayland-dma-buf.c                |   7 +-
 14 files changed, 183 insertions(+), 258 deletions(-)
---
diff --git a/src/backends/native/meta-cursor-renderer-native.c 
b/src/backends/native/meta-cursor-renderer-native.c
index 098ef24bdf..effa0851dc 100644
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ b/src/backends/native/meta-cursor-renderer-native.c
@@ -38,7 +38,9 @@
 #include "backends/meta-monitor.h"
 #include "backends/meta-monitor-manager-private.h"
 #include "backends/meta-output.h"
+#include "backends/native/meta-backend-native-private.h"
 #include "backends/native/meta-crtc-kms.h"
+#include "backends/native/meta-device-pool.h"
 #include "backends/native/meta-drm-buffer-gbm.h"
 #include "backends/native/meta-kms-device.h"
 #include "backends/native/meta-kms-plane.h"
@@ -1225,6 +1227,8 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
                                        int                       rowstride,
                                        uint32_t                  gbm_format)
 {
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
   uint64_t cursor_width, cursor_height;
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
   struct gbm_device *gbm_device;
@@ -1248,13 +1252,28 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
   if (gbm_device_is_format_supported (gbm_device, gbm_format,
                                       GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE))
     {
-      MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
+      MetaBackendNative *backend_native = META_BACKEND_NATIVE (priv->backend);
+      MetaDevicePool *device_pool =
+        meta_backend_native_get_device_pool (backend_native);
+      g_autoptr (MetaDeviceFile) device_file = NULL;
       struct gbm_bo *bo;
       uint8_t buf[4 * cursor_width * cursor_height];
       uint i;
       g_autoptr (GError) error = NULL;
       MetaDrmBufferGbm *buffer_gbm;
 
+      device_file = meta_device_pool_open (device_pool,
+                                           meta_gpu_kms_get_file_path (gpu_kms),
+                                           META_DEVICE_FILE_FLAG_TAKE_CONTROL,
+                                           &error);
+      if (!device_file)
+        {
+          g_warning ("Failed to open '%s' for updating the cursor: %s",
+                     meta_gpu_kms_get_file_path (gpu_kms),
+                     error->message);
+          return;
+        }
+
       bo = gbm_bo_create (gbm_device, cursor_width, cursor_height,
                           gbm_format, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
       if (!bo)
@@ -1274,7 +1293,7 @@ load_cursor_sprite_gbm_buffer_for_gpu (MetaCursorRendererNative *native,
           return;
         }
 
-      buffer_gbm = meta_drm_buffer_gbm_new_take (kms_device, bo, FALSE, &error);
+      buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &error);
       if (!buffer_gbm)
         {
           meta_warning ("Failed to create DRM buffer wrapper: %s",
@@ -1468,6 +1487,8 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
                                               MetaCursorSpriteWayland *sprite_wayland)
 {
   MetaCursorRendererNative *native = META_CURSOR_RENDERER_NATIVE (renderer);
+  MetaCursorRendererNativePrivate *priv =
+    meta_cursor_renderer_native_get_instance_private (native);
   MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (sprite_wayland);
   MetaCursorRendererNativeGpuData *cursor_renderer_gpu_data;
   uint64_t cursor_width, cursor_height;
@@ -1559,12 +1580,27 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
     }
   else
     {
-      MetaKmsDevice *kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
+      MetaBackendNative *backend_native = META_BACKEND_NATIVE (priv->backend);
+      MetaDevicePool *device_pool =
+        meta_backend_native_get_device_pool (backend_native);
+      g_autoptr (MetaDeviceFile) device_file = NULL;
       struct gbm_device *gbm_device;
       struct gbm_bo *bo;
       g_autoptr (GError) error = NULL;
       MetaDrmBufferGbm *buffer_gbm;
 
+      device_file = meta_device_pool_open (device_pool,
+                                           meta_gpu_kms_get_file_path (gpu_kms),
+                                           META_DEVICE_FILE_FLAG_TAKE_CONTROL,
+                                           &error);
+      if (!device_file)
+        {
+          g_warning ("Failed to open '%s' for updating the cursor: %s",
+                     meta_gpu_kms_get_file_path (gpu_kms),
+                     error->message);
+          return;
+        }
+
       /* HW cursors have a predefined size (at least 64x64), which usually is
        * bigger than cursor theme size, so themed cursors must be padded with
        * transparent pixels to fill the overlay. This is trivial if we have CPU
@@ -1597,7 +1633,7 @@ realize_cursor_sprite_from_wl_buffer_for_gpu (MetaCursorRenderer      *renderer,
 
       unset_can_preprocess (cursor_sprite);
 
-      buffer_gbm = meta_drm_buffer_gbm_new_take (kms_device, bo, FALSE, &error);
+      buffer_gbm = meta_drm_buffer_gbm_new_take (device_file, bo, FALSE, &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 373eb5c735..2df48aa5d9 100644
--- a/src/backends/native/meta-drm-buffer-dumb.c
+++ b/src/backends/native/meta-drm-buffer-dumb.c
@@ -25,13 +25,12 @@
 
 #include "backends/native/meta-drm-buffer-dumb.h"
 
+#include <gio/gio.h>
 #include <xf86drm.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-impl-device.h"
-#include "backends/native/meta-kms-private.h"
+#include "backends/native/meta-device-pool.h"
 
 struct _MetaDrmBufferDumb
 {
@@ -81,28 +80,18 @@ meta_drm_buffer_dumb_get_format (MetaDrmBuffer *buffer)
   return buffer_dumb->drm_format;
 }
 
-typedef struct
-{
-  MetaDrmBufferDumb *buffer_dumb;
-
-  int out_dmabuf_fd;
-} HandleToFdData;
-
-static gpointer
-handle_to_fd_in_impl (MetaKmsImpl  *impl,
-                      gpointer      user_data,
-                      GError      **error)
+static int
+handle_to_dmabuf_fd (MetaDrmBufferDumb  *buffer_dumb,
+                     GError            **error)
 {
-  HandleToFdData *data = user_data;
-  MetaDrmBufferDumb *buffer_dumb = data->buffer_dumb;
   MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
-  MetaKmsDevice *device = meta_drm_buffer_get_device (buffer);
-  MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
+  MetaDeviceFile *device_file;
   int fd;
   int ret;
   int dmabuf_fd;
 
-  fd = meta_kms_impl_device_get_fd (impl_device);
+  device_file = meta_drm_buffer_get_device_file (buffer);
+  fd = meta_device_file_get_fd (device_file);
 
   ret = drmPrimeHandleToFD (fd, buffer_dumb->handle, DRM_CLOEXEC,
                             &dmabuf_fd);
@@ -110,36 +99,20 @@ handle_to_fd_in_impl (MetaKmsImpl  *impl,
     {
       g_set_error (error, G_IO_ERROR, g_io_error_from_errno (-ret),
                    "drmPrimeHandleToFd: %s", g_strerror (-ret));
-      return GINT_TO_POINTER (FALSE);
+      return -1;
     }
 
-  data->out_dmabuf_fd = dmabuf_fd;
-
-  return GINT_TO_POINTER (TRUE);
+  return dmabuf_fd;
 }
 
 int
 meta_drm_buffer_dumb_ensure_dmabuf_fd (MetaDrmBufferDumb  *buffer_dumb,
                                        GError            **error)
 {
-  MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
-  MetaKmsDevice *device = meta_drm_buffer_get_device (buffer);
-  HandleToFdData data;
-
   if (buffer_dumb->dmabuf_fd != -1)
     return buffer_dumb->dmabuf_fd;
 
-  data = (HandleToFdData) {
-    .buffer_dumb = buffer_dumb,
-  };
-
-  if (!meta_kms_run_impl_task_sync (meta_kms_device_get_kms (device),
-                                   handle_to_fd_in_impl,
-                                   &data,
-                                   error))
-    return -1;
-
-  buffer_dumb->dmabuf_fd = data.out_dmabuf_fd;
+  buffer_dumb->dmabuf_fd = handle_to_dmabuf_fd (buffer_dumb, error);
   return buffer_dumb->dmabuf_fd;
 }
 
@@ -149,24 +122,15 @@ meta_drm_buffer_dumb_get_data (MetaDrmBufferDumb *buffer_dumb)
   return buffer_dumb->map;
 }
 
-typedef struct
-{
-  MetaDrmBufferDumb *buffer_dumb;
-  int width;
-  int height;
-  uint32_t format;
-} InitDumbData;
-
-static gpointer
-init_dumb_buffer_in_impl (MetaKmsImpl  *impl,
-                          gpointer      user_data,
-                          GError      **error)
+static gboolean
+init_dumb_buffer (MetaDrmBufferDumb  *buffer_dumb,
+                  int                 width,
+                  int                 height,
+                  uint32_t            format,
+                  GError            **error)
 {
-  InitDumbData *data = user_data;
-  MetaDrmBufferDumb *buffer_dumb = data->buffer_dumb;
   MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
-  MetaKmsDevice *device = meta_drm_buffer_get_device (buffer);
-  MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
+  MetaDeviceFile *device_file;
   int fd;
   struct drm_mode_create_dumb create_arg;
   struct drm_mode_destroy_dumb destroy_arg;
@@ -174,12 +138,13 @@ init_dumb_buffer_in_impl (MetaKmsImpl  *impl,
   void *map;
   MetaDrmFbArgs fb_args;
 
-  fd = meta_kms_impl_device_get_fd (impl_device);
+  device_file = meta_drm_buffer_get_device_file (buffer);
+  fd = meta_device_file_get_fd (device_file);
 
   create_arg = (struct drm_mode_create_dumb) {
     .bpp = 32, /* RGBX8888 */
-    .width = data->width,
-    .height = data->height
+    .width = width,
+    .height = height
   };
   if (drmIoctl (fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_arg) != 0)
     {
@@ -191,9 +156,9 @@ init_dumb_buffer_in_impl (MetaKmsImpl  *impl,
     }
 
   fb_args = (MetaDrmFbArgs) {
-    .width = data->width,
-    .height = data->height,
-    .format = data->format,
+    .width = width,
+    .height = height,
+    .format = format,
     .handles = { create_arg.handle },
     .strides = { create_arg.pitch },
   };
@@ -227,10 +192,10 @@ init_dumb_buffer_in_impl (MetaKmsImpl  *impl,
   buffer_dumb->handle = create_arg.handle;
   buffer_dumb->map = map;
   buffer_dumb->map_size = create_arg.size;
-  buffer_dumb->width = data->width;
-  buffer_dumb->height = data->height;
+  buffer_dumb->width = width;
+  buffer_dumb->height = height;
   buffer_dumb->stride_bytes = create_arg.pitch;
-  buffer_dumb->drm_format = data->format;
+  buffer_dumb->drm_format = format;
 
   return FALSE;
 
@@ -247,30 +212,19 @@ err_ioctl:
 }
 
 MetaDrmBufferDumb *
-meta_drm_buffer_dumb_new (MetaKmsDevice  *device,
-                          int             width,
-                          int             height,
-                          uint32_t        format,
-                          GError        **error)
+meta_drm_buffer_dumb_new (MetaDeviceFile  *device_file,
+                          int              width,
+                          int              height,
+                          uint32_t         format,
+                          GError         **error)
 {
   MetaDrmBufferDumb *buffer_dumb;
-  InitDumbData data;
 
   buffer_dumb = g_object_new (META_TYPE_DRM_BUFFER_DUMB,
-                              "device", device,
+                              "device-file", device_file,
                               NULL);
 
-  data = (InitDumbData) {
-    .buffer_dumb = buffer_dumb,
-    .width = width,
-    .height = height,
-    .format = format,
-  };
-
-  if (meta_kms_run_impl_task_sync (meta_kms_device_get_kms (device),
-                                   init_dumb_buffer_in_impl,
-                                   &data,
-                                   error))
+  if (!init_dumb_buffer (buffer_dumb, width, height, format, error))
     {
       g_object_unref (buffer_dumb);
       return NULL;
@@ -279,19 +233,16 @@ meta_drm_buffer_dumb_new (MetaKmsDevice  *device,
   return buffer_dumb;
 }
 
-static gpointer
-destroy_dumb_in_impl (MetaKmsImpl  *impl,
-                      gpointer      user_data,
-                      GError      **error)
+static void
+destroy_dumb_buffer (MetaDrmBufferDumb *buffer_dumb)
 {
-  MetaDrmBufferDumb *buffer_dumb = user_data;
   MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
-  MetaKmsDevice *device = meta_drm_buffer_get_device (buffer);
-  MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
+  MetaDeviceFile *device_file;
   int fd;
   struct drm_mode_destroy_dumb destroy_arg;
 
-  fd = meta_kms_impl_device_get_fd (impl_device);
+  device_file = meta_drm_buffer_get_device_file (buffer);
+  fd = meta_device_file_get_fd (device_file);
 
   munmap (buffer_dumb->map, buffer_dumb->map_size);
 
@@ -302,8 +253,6 @@ destroy_dumb_in_impl (MetaKmsImpl  *impl,
 
   if (buffer_dumb->dmabuf_fd != -1)
     close (buffer_dumb->dmabuf_fd);
-
-  return GINT_TO_POINTER (TRUE);
 }
 
 static void
@@ -312,15 +261,7 @@ meta_drm_buffer_dumb_finalize (GObject *object)
   MetaDrmBufferDumb *buffer_dumb = META_DRM_BUFFER_DUMB (object);
 
   if (buffer_dumb->handle)
-    {
-      MetaDrmBuffer *buffer = META_DRM_BUFFER (buffer_dumb);
-      MetaKmsDevice *device = meta_drm_buffer_get_device (buffer);
-
-      meta_kms_run_impl_task_sync (meta_kms_device_get_kms (device),
-                                   destroy_dumb_in_impl,
-                                   buffer_dumb,
-                                   NULL);
-    }
+    destroy_dumb_buffer (buffer_dumb);
 
   G_OBJECT_CLASS (meta_drm_buffer_dumb_parent_class)->finalize (object);
 }
diff --git a/src/backends/native/meta-drm-buffer-dumb.h b/src/backends/native/meta-drm-buffer-dumb.h
index 2d3e27c927..afc14660ba 100644
--- a/src/backends/native/meta-drm-buffer-dumb.h
+++ b/src/backends/native/meta-drm-buffer-dumb.h
@@ -22,8 +22,8 @@
 #ifndef META_DRM_BUFFER_DUMB_H
 #define META_DRM_BUFFER_DUMB_H
 
+#include "backends/native/meta-backend-native-types.h"
 #include "backends/native/meta-drm-buffer-private.h"
-#include "backends/native/meta-kms-device.h"
 
 #define META_TYPE_DRM_BUFFER_DUMB (meta_drm_buffer_dumb_get_type ())
 G_DECLARE_FINAL_TYPE (MetaDrmBufferDumb,
@@ -31,11 +31,11 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferDumb,
                       META, DRM_BUFFER_DUMB,
                       MetaDrmBuffer)
 
-MetaDrmBufferDumb * meta_drm_buffer_dumb_new (MetaKmsDevice  *device,
-                                              int             width,
-                                              int             height,
-                                              uint32_t        format,
-                                              GError        **error);
+MetaDrmBufferDumb * meta_drm_buffer_dumb_new (MetaDeviceFile  *device,
+                                              int              width,
+                                              int              height,
+                                              uint32_t         format,
+                                              GError         **error);
 
 int meta_drm_buffer_dumb_ensure_dmabuf_fd (MetaDrmBufferDumb  *buffer_dumb,
                                            GError            **error);
diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c
index 48ee9eb048..6bdc9995a9 100644
--- a/src/backends/native/meta-drm-buffer-gbm.c
+++ b/src/backends/native/meta-drm-buffer-gbm.c
@@ -27,11 +27,13 @@
 
 #include <drm_fourcc.h>
 #include <errno.h>
+#include <gio/gio.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
-#include "backends/native/meta-drm-buffer-private.h"
+#include "backends/meta-backend-private.h"
 #include "backends/native/meta-cogl-utils.h"
+#include "backends/native/meta-drm-buffer-private.h"
 
 struct _MetaDrmBufferGbm
 {
@@ -146,7 +148,7 @@ lock_front_buffer (MetaDrmBufferGbm  *buffer_gbm,
 }
 
 MetaDrmBufferGbm *
-meta_drm_buffer_gbm_new_lock_front (MetaKmsDevice       *device,
+meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile      *device_file,
                                     struct gbm_surface  *gbm_surface,
                                     gboolean             use_modifiers,
                                     GError             **error)
@@ -154,7 +156,7 @@ meta_drm_buffer_gbm_new_lock_front (MetaKmsDevice       *device,
   MetaDrmBufferGbm *buffer_gbm;
 
   buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
-                             "device", device,
+                             "device-file", device_file,
                              NULL);
   buffer_gbm->surface = gbm_surface;
 
@@ -168,15 +170,15 @@ meta_drm_buffer_gbm_new_lock_front (MetaKmsDevice       *device,
 }
 
 MetaDrmBufferGbm *
-meta_drm_buffer_gbm_new_take (MetaKmsDevice  *device,
-                              struct gbm_bo  *bo,
-                              gboolean        use_modifiers,
-                              GError        **error)
+meta_drm_buffer_gbm_new_take (MetaDeviceFile  *device_file,
+                              struct gbm_bo   *bo,
+                              gboolean         use_modifiers,
+                              GError         **error)
 {
   MetaDrmBufferGbm *buffer_gbm;
 
   buffer_gbm = g_object_new (META_TYPE_DRM_BUFFER_GBM,
-                             "device", device,
+                             "device-file", device_file,
                              NULL);
 
   if (!init_fb_id (buffer_gbm, bo, use_modifiers, error))
diff --git a/src/backends/native/meta-drm-buffer-gbm.h b/src/backends/native/meta-drm-buffer-gbm.h
index 43d7e2d8a0..0413c9fa27 100644
--- a/src/backends/native/meta-drm-buffer-gbm.h
+++ b/src/backends/native/meta-drm-buffer-gbm.h
@@ -24,8 +24,8 @@
 
 #include <gbm.h>
 
+#include "backends/native/meta-backend-native-types.h"
 #include "backends/native/meta-drm-buffer-private.h"
-#include "backends/native/meta-gpu-kms.h"
 
 #define META_TYPE_DRM_BUFFER_GBM (meta_drm_buffer_gbm_get_type ())
 G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
@@ -33,16 +33,16 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferGbm,
                       META, DRM_BUFFER_GBM,
                       MetaDrmBuffer)
 
-MetaDrmBufferGbm * meta_drm_buffer_gbm_new_lock_front (MetaKmsDevice       *device,
+MetaDrmBufferGbm * meta_drm_buffer_gbm_new_lock_front (MetaDeviceFile      *device_file,
                                                        struct gbm_surface  *gbm_surface,
                                                        gboolean             use_modifiers,
                                                        GError             **error);
 
 
-MetaDrmBufferGbm * meta_drm_buffer_gbm_new_take (MetaKmsDevice  *device,
-                                                 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,
+                                                 gboolean         use_modifiers,
+                                                 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 1e5a382461..77cd138d20 100644
--- a/src/backends/native/meta-drm-buffer-import.c
+++ b/src/backends/native/meta-drm-buffer-import.c
@@ -158,7 +158,7 @@ out_close:
 }
 
 MetaDrmBufferImport *
-meta_drm_buffer_import_new (MetaKmsDevice      *device,
+meta_drm_buffer_import_new (MetaDeviceFile     *device_file,
                             struct gbm_device  *gbm_device,
                             MetaDrmBufferGbm   *buffer_gbm,
                             GError            **error)
@@ -166,7 +166,7 @@ meta_drm_buffer_import_new (MetaKmsDevice      *device,
   MetaDrmBufferImport *buffer_import;
 
   buffer_import = g_object_new (META_TYPE_DRM_BUFFER_IMPORT,
-                                "device", device,
+                                "device-file", device_file,
                                 NULL);
   g_set_object (&buffer_import->importee, buffer_gbm);
 
diff --git a/src/backends/native/meta-drm-buffer-import.h b/src/backends/native/meta-drm-buffer-import.h
index 48c9bd1903..faff560fa4 100644
--- a/src/backends/native/meta-drm-buffer-import.h
+++ b/src/backends/native/meta-drm-buffer-import.h
@@ -47,7 +47,7 @@ G_DECLARE_FINAL_TYPE (MetaDrmBufferImport,
  * The import has a high chance of failing under normal operating
  * conditions and needs to be handled with fallbacks to something else.
  */
-MetaDrmBufferImport * meta_drm_buffer_import_new (MetaKmsDevice      *device,
+MetaDrmBufferImport * meta_drm_buffer_import_new (MetaDeviceFile     *device_file,
                                                   struct gbm_device  *gbm_device,
                                                   MetaDrmBufferGbm   *buffer_gbm,
                                                   GError            **error);
diff --git a/src/backends/native/meta-drm-buffer-private.h b/src/backends/native/meta-drm-buffer-private.h
index 2c77eb9579..859d21fb93 100644
--- a/src/backends/native/meta-drm-buffer-private.h
+++ b/src/backends/native/meta-drm-buffer-private.h
@@ -21,8 +21,8 @@
 #ifndef META_DRM_BUFFER_PRIVATE_H
 #define META_DRM_BUFFER_PRIVATE_H
 
+#include "backends/native/meta-backend-native-types.h"
 #include "backends/native/meta-drm-buffer.h"
-#include "backends/native/meta-kms-device.h"
 
 typedef struct _MetaDrmFbArgs
 {
@@ -45,7 +45,7 @@ struct _MetaDrmBufferClass
   uint32_t (* get_format) (MetaDrmBuffer *buffer);
 };
 
-MetaKmsDevice * meta_drm_buffer_get_device (MetaDrmBuffer *buffer);
+MetaDeviceFile * meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer);
 
 gboolean meta_drm_buffer_ensure_fb_id (MetaDrmBuffer        *buffer,
                                        gboolean              use_modifiers,
diff --git a/src/backends/native/meta-drm-buffer.c b/src/backends/native/meta-drm-buffer.c
index 81a36196e5..a1a24f0834 100644
--- a/src/backends/native/meta-drm-buffer.c
+++ b/src/backends/native/meta-drm-buffer.c
@@ -28,10 +28,8 @@
 
 #include <drm_fourcc.h>
 
-#include "backends/native/meta-kms-device-private.h"
-#include "backends/native/meta-kms-impl-device.h"
+#include "backends/native/meta-device-pool.h"
 #include "backends/native/meta-kms-utils.h"
-#include "backends/native/meta-kms-private.h"
 
 #define INVALID_FB_ID 0U
 
@@ -39,7 +37,7 @@ enum
 {
   PROP_0,
 
-  PROP_DEVICE,
+  PROP_DEVICE_FILE,
 
   N_PROPS
 };
@@ -48,35 +46,33 @@ static GParamSpec *obj_props[N_PROPS];
 
 typedef struct _MetaDrmBufferPrivate
 {
-  MetaKmsDevice *device;
+  MetaDeviceFile *device_file;
   uint32_t fb_id;
 } MetaDrmBufferPrivate;
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaDrmBuffer, meta_drm_buffer,
                                      G_TYPE_OBJECT)
 
-MetaKmsDevice *
-meta_drm_buffer_get_device (MetaDrmBuffer *buffer)
+MetaDeviceFile *
+meta_drm_buffer_get_device_file (MetaDrmBuffer *buffer)
 {
   MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
 
-  return priv->device;
+  return priv->device_file;
 }
 
 gboolean
-meta_drm_buffer_ensure_fb_in_impl (MetaDrmBuffer        *buffer,
-                                   gboolean              use_modifiers,
-                                   const MetaDrmFbArgs  *fb_args,
-                                   GError              **error)
+meta_drm_buffer_ensure_fb_id (MetaDrmBuffer        *buffer,
+                              gboolean              use_modifiers,
+                              const MetaDrmFbArgs  *fb_args,
+                              GError              **error)
 {
   MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-  MetaKmsDevice *device = priv->device;
-  MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
   int fd;
   MetaDrmFormatBuf tmp;
   uint32_t fb_id;
 
-  fd = meta_kms_impl_device_get_fd (impl_device);
+  fd = meta_device_file_get_fd (priv->device_file);
 
   if (use_modifiers && fb_args->modifiers[0] != DRM_FORMAT_MOD_INVALID)
     {
@@ -139,98 +135,21 @@ meta_drm_buffer_ensure_fb_in_impl (MetaDrmBuffer        *buffer,
     }
 
   priv->fb_id = fb_id;
-
   return TRUE;
 }
 
-typedef struct
-{
-  MetaDrmBuffer *buffer;
-  gboolean use_modifiers;
-  MetaDrmFbArgs fb_args;
-} AddFbData;
-
-static gpointer
-add_fb_in_impl (MetaKmsImpl  *impl,
-                gpointer      user_data,
-                GError      **error)
-{
-  AddFbData *data = user_data;
-
-  if (meta_drm_buffer_ensure_fb_in_impl (data->buffer,
-                                         data->use_modifiers,
-                                         &data->fb_args,
-                                         error))
-    return GINT_TO_POINTER (TRUE);
-  else
-    return GINT_TO_POINTER (FALSE);
-}
-
-gboolean
-meta_drm_buffer_ensure_fb_id (MetaDrmBuffer        *buffer,
-                              gboolean              use_modifiers,
-                              const MetaDrmFbArgs  *fb_args,
-                              GError              **error)
+static void
+meta_drm_buffer_release_fb_id (MetaDrmBuffer *buffer)
 {
   MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-  AddFbData data;
-
-  data = (AddFbData) {
-    .buffer = buffer,
-    .use_modifiers = use_modifiers,
-    .fb_args = *fb_args,
-  };
-
-  if (!meta_kms_run_impl_task_sync (meta_kms_device_get_kms (priv->device),
-                                    add_fb_in_impl,
-                                    &data,
-                                    error))
-    return FALSE;
-
-  return TRUE;
-}
-
-typedef struct
-{
-  MetaKmsDevice *device;
-  uint32_t fb_id;
-} RmFbData;
-
-static gpointer
-rm_fb_in_impl (MetaKmsImpl  *impl,
-               gpointer      user_data,
-               GError      **error)
-{
-  RmFbData *data = user_data;
-  MetaKmsDevice *device = data->device;
-  MetaKmsImplDevice *impl_device = meta_kms_device_get_impl_device (device);
-  uint32_t fb_id = data->fb_id;
   int fd;
   int ret;
 
-  fd = meta_kms_impl_device_get_fd (impl_device);
-  ret = drmModeRmFB (fd, fb_id);
+  fd = meta_device_file_get_fd (priv->device_file);
+  ret = drmModeRmFB (fd, priv->fb_id);
   if (ret != 0)
     g_warning ("drmModeRmFB: %s", g_strerror (-ret));
 
-  return GINT_TO_POINTER (TRUE);
-}
-
-static void
-meta_drm_buffer_release_fb_id (MetaDrmBuffer *buffer)
-{
-  MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
-  RmFbData data;
-
-  data = (RmFbData) {
-    .device = priv->device,
-    .fb_id = priv->fb_id,
-  };
-
-  meta_kms_run_impl_task_sync (meta_kms_device_get_kms (priv->device),
-                               rm_fb_in_impl,
-                               &data,
-                               NULL);
   priv->fb_id = 0;
 }
 
@@ -277,8 +196,8 @@ meta_drm_buffer_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_DEVICE:
-      g_value_set_object (value, priv->device);
+    case PROP_DEVICE_FILE:
+      g_value_set_pointer (value, priv->device_file);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -297,8 +216,8 @@ meta_drm_buffer_set_property (GObject      *object,
 
   switch (prop_id)
     {
-    case PROP_DEVICE:
-      priv->device = g_value_get_object (value);
+    case PROP_DEVICE_FILE:
+      priv->device_file = g_value_get_pointer (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -314,10 +233,22 @@ meta_drm_buffer_finalize (GObject *object)
 
   if (priv->fb_id != INVALID_FB_ID)
     meta_drm_buffer_release_fb_id (buffer);
+  meta_device_file_release (priv->device_file);
 
   G_OBJECT_CLASS (meta_drm_buffer_parent_class)->finalize (object);
 }
 
+static void
+meta_drm_buffer_constructed (GObject *object)
+{
+  MetaDrmBuffer *buffer = META_DRM_BUFFER (object);
+  MetaDrmBufferPrivate *priv = meta_drm_buffer_get_instance_private (buffer);
+
+  meta_device_file_acquire (priv->device_file);
+
+  G_OBJECT_CLASS (meta_drm_buffer_parent_class)->constructed (object);
+}
+
 static void
 meta_drm_buffer_init (MetaDrmBuffer *buffer)
 {
@@ -330,15 +261,15 @@ meta_drm_buffer_class_init (MetaDrmBufferClass *klass)
 
   object_class->get_property = meta_drm_buffer_get_property;
   object_class->set_property = meta_drm_buffer_set_property;
+  object_class->constructed = meta_drm_buffer_constructed;
   object_class->finalize = meta_drm_buffer_finalize;
 
-  obj_props[PROP_DEVICE] =
-    g_param_spec_object ("device",
-                         "device",
-                         "MetaKmsDevice",
-                         META_TYPE_KMS_DEVICE,
-                         G_PARAM_READWRITE |
-                         G_PARAM_CONSTRUCT_ONLY |
-                         G_PARAM_STATIC_STRINGS);
+  obj_props[PROP_DEVICE_FILE] =
+    g_param_spec_pointer ("device-file",
+                          "device file",
+                          "MetaDeviceFile",
+                          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-onscreen-native.c b/src/backends/native/meta-onscreen-native.c
index 016533df7a..e37b86a08f 100644
--- a/src/backends/native/meta-onscreen-native.c
+++ b/src/backends/native/meta-onscreen-native.c
@@ -560,7 +560,7 @@ import_shared_framebuffer (CoglOnscreen                        *onscreen,
 {
   MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
   MetaGpuKms *gpu_kms;
-  MetaKmsDevice *kms_device;
+  MetaDeviceFile *device_file;
   struct gbm_device *gbm_device;
   MetaDrmBufferGbm *buffer_gbm;
   MetaDrmBufferImport *buffer_import;
@@ -569,9 +569,9 @@ import_shared_framebuffer (CoglOnscreen                        *onscreen,
   buffer_gbm = META_DRM_BUFFER_GBM (onscreen_native->gbm.next_fb);
 
   gpu_kms = secondary_gpu_state->gpu_kms;
-  kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
+  device_file = secondary_gpu_state->renderer_gpu_data->device_file;
   gbm_device = meta_gbm_device_from_gpu (gpu_kms);
-  buffer_import = meta_drm_buffer_import_new (kms_device,
+  buffer_import = meta_drm_buffer_import_new (device_file,
                                               gbm_device,
                                               buffer_gbm,
                                               &error);
@@ -639,7 +639,7 @@ copy_shared_framebuffer_gpu (CoglOnscreen                        *onscreen,
   MetaGles3 *gles3 = meta_renderer_native_get_gles3 (renderer_native);
   GError *error = NULL;
   gboolean use_modifiers;
-  MetaKmsDevice *kms_device;
+  MetaDeviceFile *device_file;
   MetaDrmBufferGbm *buffer_gbm;
   struct gbm_bo *bo;
 
@@ -690,9 +690,9 @@ copy_shared_framebuffer_gpu (CoglOnscreen                        *onscreen,
     }
 
   use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
-  kms_device = meta_gpu_kms_get_kms_device (secondary_gpu_state->gpu_kms);
+  device_file = secondary_gpu_state->renderer_gpu_data->device_file;
   buffer_gbm =
-    meta_drm_buffer_gbm_new_lock_front (kms_device,
+    meta_drm_buffer_gbm_new_lock_front (device_file,
                                         secondary_gpu_state->gbm.surface,
                                         use_modifiers,
                                         &error);
@@ -992,7 +992,7 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen  *onscreen,
   MetaKms *kms = meta_backend_native_get_kms (backend_native);
   MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
   MetaGpuKms *render_gpu = onscreen_native->render_gpu;
-  MetaKmsDevice *render_kms_device = meta_gpu_kms_get_kms_device (render_gpu);
+  MetaDeviceFile *render_device_file;
   ClutterFrame *frame = user_data;
   CoglOnscreenClass *parent_class;
   gboolean egl_context_changed = FALSE;
@@ -1020,6 +1020,7 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen  *onscreen,
 
   renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
                                                          render_gpu);
+  render_device_file = renderer_gpu_data->device_file;
   switch (renderer_gpu_data->mode)
     {
     case META_RENDERER_NATIVE_MODE_GBM:
@@ -1028,7 +1029,7 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen  *onscreen,
 
       use_modifiers = meta_renderer_native_use_modifiers (renderer_native);
       buffer_gbm =
-        meta_drm_buffer_gbm_new_lock_front (render_kms_device,
+        meta_drm_buffer_gbm_new_lock_front (render_device_file,
                                             onscreen_native->gbm.surface,
                                             use_modifiers,
                                             &error);
@@ -1700,7 +1701,7 @@ meta_onscreen_native_allocate (CoglFramebuffer  *framebuffer,
   int width;
   int height;
 #ifdef HAVE_EGL_DEVICE
-  MetaKmsDevice *render_kms_device;
+  MetaDeviceFile *render_device_file;
   EGLStreamKHR egl_stream;
 #endif
   CoglFramebufferClass *parent_class;
@@ -1737,10 +1738,9 @@ meta_onscreen_native_allocate (CoglFramebuffer  *framebuffer,
       break;
 #ifdef HAVE_EGL_DEVICE
     case META_RENDERER_NATIVE_MODE_EGL_DEVICE:
-      render_kms_device =
-        meta_gpu_kms_get_kms_device (onscreen_native->render_gpu);
+      render_device_file = renderer_gpu_data->device_file;
       onscreen_native->egl.dumb_fb =
-        meta_drm_buffer_dumb_new (render_kms_device,
+        meta_drm_buffer_dumb_new (render_device_file,
                                   width, height,
                                   DRM_FORMAT_XRGB8888,
                                   error);
@@ -1896,7 +1896,7 @@ init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative         *renderer_nat
   MetaOnscreenNative *onscreen_native = META_ONSCREEN_NATIVE (onscreen);
   MetaOnscreenNativeSecondaryGpuState *secondary_gpu_state;
   MetaGpuKms *gpu_kms;
-  MetaKmsDevice *kms_device;
+  MetaDeviceFile *device_file;
   int width, height;
   unsigned int i;
   uint32_t drm_format;
@@ -1914,7 +1914,7 @@ init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative         *renderer_nat
   height = cogl_framebuffer_get_height (framebuffer);
 
   gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (onscreen_native->crtc));
-  kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
+  device_file = renderer_gpu_data->device_file;
   g_debug ("Secondary GPU %s using DRM format '%s' (0x%x) for a %dx%d output.",
            meta_gpu_kms_get_file_path (gpu_kms),
            meta_drm_format_to_string (&tmp, drm_format),
@@ -1929,7 +1929,7 @@ init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative         *renderer_nat
   for (i = 0; i < G_N_ELEMENTS (secondary_gpu_state->cpu.dumb_fbs); i++)
     {
       secondary_gpu_state->cpu.dumb_fbs[i] =
-        meta_drm_buffer_dumb_new (kms_device,
+        meta_drm_buffer_dumb_new (device_file,
                                   width, height,
                                   drm_format,
                                   error);
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 0df5ea3a6b..54216224a4 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -166,6 +166,17 @@ meta_renderer_native_get_primary_gpu (MetaRendererNative *renderer_native)
   return renderer_native->primary_gpu_kms;
 }
 
+MetaDeviceFile *
+meta_renderer_native_get_primary_device_file (MetaRendererNative *renderer_native)
+{
+  MetaGpuKms *gpu_kms = renderer_native->primary_gpu_kms;
+  MetaRendererNativeGpuData *renderer_gpu_data;
+
+  renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
+                                                         gpu_kms);
+  return renderer_gpu_data->device_file;
+}
+
 static MetaRendererNativeGpuData *
 meta_create_renderer_native_gpu_data (void)
 {
diff --git a/src/backends/native/meta-renderer-native.h b/src/backends/native/meta-renderer-native.h
index 9475e1857f..2c23c651ad 100644
--- a/src/backends/native/meta-renderer-native.h
+++ b/src/backends/native/meta-renderer-native.h
@@ -54,6 +54,8 @@ struct gbm_device * meta_gbm_device_from_gpu (MetaGpuKms *gpu_kms);
 
 MetaGpuKms * meta_renderer_native_get_primary_gpu (MetaRendererNative *renderer_native);
 
+MetaDeviceFile * meta_renderer_native_get_primary_device_file (MetaRendererNative *renderer_native);
+
 void meta_renderer_native_prepare_frame (MetaRendererNative *renderer_native,
                                          MetaRendererView   *view,
                                          ClutterFrame       *frame);
diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c
index f0431af3cc..2b6fe6b6e3 100644
--- a/src/wayland/meta-wayland-buffer.c
+++ b/src/wayland/meta-wayland-buffer.c
@@ -688,7 +688,7 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
   MetaRenderer *renderer = meta_backend_get_renderer (backend);
   MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
   MetaGpuKms *gpu_kms;
-  MetaKmsDevice *kms_device;
+  MetaDeviceFile *device_file;
   struct gbm_device *gbm_device;
   struct gbm_bo *gbm_bo;
   uint32_t drm_format;
@@ -698,7 +698,7 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
   g_autoptr (GError) error = NULL;
 
   gpu_kms = meta_renderer_native_get_primary_gpu (renderer_native);
-  kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
+  device_file = meta_renderer_native_get_primary_device_file (renderer_native);
   gbm_device = meta_gbm_device_from_gpu (gpu_kms);
 
   gbm_bo = gbm_bo_import (gbm_device,
@@ -719,7 +719,8 @@ try_acquire_egl_image_scanout (MetaWaylandBuffer *buffer,
       return NULL;
     }
 
-  fb = meta_drm_buffer_gbm_new_take (kms_device, gbm_bo,
+  fb = meta_drm_buffer_gbm_new_take (device_file,
+                                     gbm_bo,
                                      drm_modifier != DRM_FORMAT_MOD_INVALID,
                                      &error);
   if (!fb)
diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c
index ce89837411..3fc4312015 100644
--- a/src/wayland/meta-wayland-dma-buf.c
+++ b/src/wayland/meta-wayland-dma-buf.c
@@ -273,8 +273,8 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
   MetaBackend *backend = meta_get_backend ();
   MetaRenderer *renderer = meta_backend_get_renderer (backend);
   MetaRendererNative *renderer_native = META_RENDERER_NATIVE (renderer);
+  MetaDeviceFile *device_file;
   MetaGpuKms *gpu_kms;
-  MetaKmsDevice *kms_device;
   int n_planes;
   uint32_t drm_format;
   uint64_t drm_modifier;
@@ -299,8 +299,8 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
                                                           stride))
     return NULL;
 
+  device_file = meta_renderer_native_get_primary_device_file (renderer_native);
   gpu_kms = meta_renderer_native_get_primary_gpu (renderer_native);
-  kms_device = meta_gpu_kms_get_kms_device (gpu_kms);
   gbm_bo = import_scanout_gbm_bo (dma_buf, gpu_kms, n_planes, &use_modifier);
   if (!gbm_bo)
     {
@@ -308,7 +308,8 @@ meta_wayland_dma_buf_try_acquire_scanout (MetaWaylandDmaBufBuffer *dma_buf,
       return NULL;
     }
 
-  fb = meta_drm_buffer_gbm_new_take (kms_device, gbm_bo,
+  fb = meta_drm_buffer_gbm_new_take (device_file,
+                                     gbm_bo,
                                      use_modifier,
                                      &error);
   if (!fb)


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