[mutter] backend/native: Move some KMS utilities to its own file



commit 8932388dda51121c03b03782e832d36c8f8a42b6
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Mar 11 11:13:01 2019 +0100

    backend/native: Move some KMS utilities to its own file
    
    They are not strictly related to any of the KMS objects, and should be
    reusable without adding a dependency on the non-meta-kms-* files in
    meta-kms-*.
    
    https://gitlab.gnome.org/GNOME/mutter/issues/548
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/525

 src/backends/native/meta-crtc-kms.c        | 41 ---------------
 src/backends/native/meta-crtc-kms.h        |  9 ----
 src/backends/native/meta-gpu-kms.c         | 19 +------
 src/backends/native/meta-gpu-kms.h         |  2 -
 src/backends/native/meta-kms-utils.c       | 83 ++++++++++++++++++++++++++++++
 src/backends/native/meta-kms-utils.h       | 37 +++++++++++++
 src/backends/native/meta-output-kms.c      |  1 +
 src/backends/native/meta-renderer-native.c |  1 +
 src/meson.build                            |  2 +
 9 files changed, 125 insertions(+), 70 deletions(-)
---
diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c
index 982a8176a..7d5e72198 100644
--- a/src/backends/native/meta-crtc-kms.c
+++ b/src/backends/native/meta-crtc-kms.c
@@ -24,19 +24,11 @@
 
 #include "backends/native/meta-crtc-kms.h"
 
-#include <drm_fourcc.h>
-#include <drm_mode.h>
-
 #include "backends/meta-backend-private.h"
 #include "backends/native/meta-gpu-kms.h"
 #include "backends/native/meta-kms-device.h"
 #include "backends/native/meta-kms-plane.h"
 
-/* added in libdrm 2.4.95 */
-#ifndef DRM_FORMAT_INVALID
-#define DRM_FORMAT_INVALID 0
-#endif
-
 #define ALL_TRANSFORMS_MASK ((1 << META_MONITOR_N_TRANSFORMS) - 1)
 
 typedef struct _MetaCrtcKms
@@ -49,39 +41,6 @@ typedef struct _MetaCrtcKms
   MetaKmsPlane *primary_plane;
 } MetaCrtcKms;
 
-/**
- * meta_drm_format_to_string:
- * @tmp: temporary buffer
- * @drm_format: DRM fourcc pixel format
- *
- * Returns a pointer to a string naming the given pixel format,
- * usually a pointer to the temporary buffer but not always.
- * Invalid formats may return nonsense names.
- *
- * When calling this, allocate one MetaDrmFormatBuf on the stack to
- * be used as the temporary buffer.
- */
-const char *
-meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
-                           uint32_t          drm_format)
-{
-  int i;
-
-  if (drm_format == DRM_FORMAT_INVALID)
-    return "INVALID";
-
-  G_STATIC_ASSERT (sizeof (tmp->s) == 5);
-  for (i = 0; i < 4; i++)
-    {
-      char c = (drm_format >> (i * 8)) & 0xff;
-      tmp->s[i] = g_ascii_isgraph (c) ? c : '.';
-    }
-
-  tmp->s[i] = 0;
-
-  return tmp->s;
-}
-
 gboolean
 meta_crtc_kms_is_transform_handled (MetaCrtc             *crtc,
                                     MetaMonitorTransform  transform)
diff --git a/src/backends/native/meta-crtc-kms.h b/src/backends/native/meta-crtc-kms.h
index 609154fe7..178c282c3 100644
--- a/src/backends/native/meta-crtc-kms.h
+++ b/src/backends/native/meta-crtc-kms.h
@@ -31,15 +31,6 @@
 #include "backends/native/meta-gpu-kms.h"
 #include "backends/native/meta-kms-crtc.h"
 
-typedef struct _MetaDrmFormatBuf
-{
-  char s[5];
-} MetaDrmFormatBuf;
-
-const char *
-meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
-                           uint32_t          format);
-
 gboolean meta_crtc_kms_is_transform_handled (MetaCrtc             *crtc,
                                              MetaMonitorTransform  transform);
 
diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c
index 8822251fa..596a775f3 100644
--- a/src/backends/native/meta-gpu-kms.c
+++ b/src/backends/native/meta-gpu-kms.c
@@ -39,6 +39,7 @@
 #include "backends/native/meta-crtc-kms.h"
 #include "backends/native/meta-kms-connector.h"
 #include "backends/native/meta-kms-device.h"
+#include "backends/native/meta-kms-utils.h"
 #include "backends/native/meta-kms.h"
 #include "backends/native/meta-launcher.h"
 #include "backends/native/meta-output-kms.h"
@@ -523,24 +524,6 @@ meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms            *gpu_kms,
   return NULL;
 }
 
-float
-meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *mode)
-{
-  float refresh = 0.0;
-
-  if (mode->htotal > 0 && mode->vtotal > 0)
-    {
-      /* Calculate refresh rate in milliHz first for extra precision. */
-      refresh = (mode->clock * 1000000LL) / mode->htotal;
-      refresh += (mode->vtotal / 2);
-      refresh /= mode->vtotal;
-      if (mode->vscan > 1)
-        refresh /= mode->vscan;
-      refresh /= 1000.0;
-    }
-  return refresh;
-}
-
 static MetaCrtcMode *
 create_mode (const drmModeModeInfo *drm_mode,
              long                   mode_id)
diff --git a/src/backends/native/meta-gpu-kms.h b/src/backends/native/meta-gpu-kms.h
index 8d527456d..1dcdc50aa 100644
--- a/src/backends/native/meta-gpu-kms.h
+++ b/src/backends/native/meta-gpu-kms.h
@@ -81,8 +81,6 @@ MetaCrtcMode * meta_gpu_kms_get_mode_from_drm_mode (MetaGpuKms            *gpu_k
 gboolean meta_drm_mode_equal (const drmModeModeInfo *one,
                               const drmModeModeInfo *two);
 
-float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *mode);
-
 MetaGpuKmsFlipClosureContainer * meta_gpu_kms_wrap_flip_closure (MetaGpuKms *gpu_kms,
                                                                  MetaCrtc   *crtc,
                                                                  GClosure   *flip_closure);
diff --git a/src/backends/native/meta-kms-utils.c b/src/backends/native/meta-kms-utils.c
new file mode 100644
index 000000000..11df09be8
--- /dev/null
+++ b/src/backends/native/meta-kms-utils.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2013-2019 Red Hat
+ * Copyright (c) 2018 DisplayLink (UK) Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "backends/native/meta-kms-utils.h"
+
+#include <drm_fourcc.h>
+#include <glib.h>
+
+/* added in libdrm 2.4.95 */
+#ifndef DRM_FORMAT_INVALID
+#define DRM_FORMAT_INVALID 0
+#endif
+
+float
+meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode)
+{
+  float refresh = 0.0;
+
+  if (drm_mode->htotal > 0 && drm_mode->vtotal > 0)
+    {
+      /* Calculate refresh rate in milliHz first for extra precision. */
+      refresh = (drm_mode->clock * 1000000LL) / drm_mode->htotal;
+      refresh += (drm_mode->vtotal / 2);
+      refresh /= drm_mode->vtotal;
+      if (drm_mode->vscan > 1)
+        refresh /= drm_mode->vscan;
+      refresh /= 1000.0;
+    }
+  return refresh;
+}
+
+/**
+ * meta_drm_format_to_string:
+ * @tmp: temporary buffer
+ * @drm_format: DRM fourcc pixel format
+ *
+ * Returns a pointer to a string naming the given pixel format,
+ * usually a pointer to the temporary buffer but not always.
+ * Invalid formats may return nonsense names.
+ *
+ * When calling this, allocate one MetaDrmFormatBuf on the stack to
+ * be used as the temporary buffer.
+ */
+const char *
+meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
+                           uint32_t          drm_format)
+{
+  int i;
+
+  if (drm_format == DRM_FORMAT_INVALID)
+    return "INVALID";
+
+  G_STATIC_ASSERT (sizeof (tmp->s) == 5);
+  for (i = 0; i < 4; i++)
+    {
+      char c = (drm_format >> (i * 8)) & 0xff;
+      tmp->s[i] = g_ascii_isgraph (c) ? c : '.';
+    }
+
+  tmp->s[i] = 0;
+
+  return tmp->s;
+}
+
diff --git a/src/backends/native/meta-kms-utils.h b/src/backends/native/meta-kms-utils.h
new file mode 100644
index 000000000..7a2fdfd79
--- /dev/null
+++ b/src/backends/native/meta-kms-utils.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 DisplayLink (UK) Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef META_KMS_UTILS_H
+#define META_KMS_UTILS_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include <xf86drmMode.h>
+
+typedef struct _MetaDrmFormatBuf
+{
+  char s[5];
+} MetaDrmFormatBuf;
+
+float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode);
+
+const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
+                                        uint32_t          drm_format);
+
+#endif /* META_KMS_UTILS_H */
diff --git a/src/backends/native/meta-output-kms.c b/src/backends/native/meta-output-kms.c
index 42c476479..1d3386387 100644
--- a/src/backends/native/meta-output-kms.c
+++ b/src/backends/native/meta-output-kms.c
@@ -30,6 +30,7 @@
 
 #include "backends/meta-crtc.h"
 #include "backends/native/meta-kms-connector.h"
+#include "backends/native/meta-kms-utils.h"
 #include "backends/native/meta-crtc-kms.h"
 
 #include "meta-default-modes.h"
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 0818f62b6..f44be06fd 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -62,6 +62,7 @@
 #include "backends/native/meta-drm-buffer-gbm.h"
 #include "backends/native/meta-drm-buffer.h"
 #include "backends/native/meta-gpu-kms.h"
+#include "backends/native/meta-kms-utils.h"
 #include "backends/native/meta-monitor-manager-kms.h"
 #include "backends/native/meta-renderer-native-gles3.h"
 #include "backends/native/meta-renderer-native.h"
diff --git a/src/meson.build b/src/meson.build
index 6e13c7c2f..acfd879ef 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -614,6 +614,8 @@ if have_native_backend
     'backends/native/meta-kms-plane.h',
     'backends/native/meta-kms-private.h',
     'backends/native/meta-kms-types.h',
+    'backends/native/meta-kms-utils.c',
+    'backends/native/meta-kms-utils.h',
     'backends/native/meta-kms.c',
     'backends/native/meta-kms.h',
     'backends/native/meta-renderer-native-gles3.c',


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