[mutter] renderer/native: Debug print chosen secondary FB format



commit a62dbc668027c719e3cfe13cffba7e408a74ba33
Author: Pekka Paalanen <pekka paalanen collabora com>
Date:   Thu Nov 22 16:26:01 2018 +0200

    renderer/native: Debug print chosen secondary FB format
    
    Print the pixel format chosen for an output on a secondary GPU for
    debugging. Knowing the format can aid in debugging e.g. red/blue channel
    swaps and CPU copy performance issues.
    
    This adds a DRM format printing helper in meta-crtc-kms.h. This header
    is included in most native backend files making it widely available,
    while DRM formats are specific to the native backend. It could be shared
    with Wayland bits, DRM format codes are used there too.
    
    The helper makes the pixel format much more readable than a "%x".
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/341

 src/backends/native/meta-crtc-kms.c        | 38 ++++++++++++++++++++++++++++++
 src/backends/native/meta-crtc-kms.h        |  9 +++++++
 src/backends/native/meta-renderer-native.c |  7 ++++++
 3 files changed, 54 insertions(+)
---
diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c
index 803f6320e..79a9b1e76 100644
--- a/src/backends/native/meta-crtc-kms.c
+++ b/src/backends/native/meta-crtc-kms.c
@@ -30,6 +30,11 @@
 #include "backends/meta-backend-private.h"
 #include "backends/native/meta-gpu-kms.h"
 
+/* added in libdrm 2.4.95 */
+#ifndef DRM_FORMAT_INVALID
+#define DRM_FORMAT_INVALID 0
+#endif
+
 #define ALL_TRANSFORMS (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)
 #define ALL_TRANSFORMS_MASK ((1 << ALL_TRANSFORMS) - 1)
 
@@ -52,6 +57,39 @@ typedef struct _MetaCrtcKms
   GHashTable *formats_modifiers;
 } 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 e3c3da7cc..622ea5502 100644
--- a/src/backends/native/meta-crtc-kms.h
+++ b/src/backends/native/meta-crtc-kms.h
@@ -30,6 +30,15 @@
 #include "backends/meta-crtc.h"
 #include "backends/native/meta-gpu-kms.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-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 0a2f532e9..2c60c7c59 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -803,6 +803,7 @@ init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative         *renderer_nat
   int width, height;
   unsigned int i;
   uint32_t drm_format;
+  MetaDrmFormatBuf tmp;
 
   drm_format = pick_secondary_gpu_framebuffer_format_for_cpu (onscreen,
                                                               META_GPU (gpu_kms));
@@ -816,6 +817,12 @@ init_secondary_gpu_state_cpu_copy_mode (MetaRendererNative         *renderer_nat
   width = cogl_framebuffer_get_width (framebuffer);
   height = cogl_framebuffer_get_height (framebuffer);
 
+  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),
+           drm_format,
+           width, height);
+
   secondary_gpu_state = g_new0 (MetaOnscreenNativeSecondaryGpuState, 1);
   secondary_gpu_state->renderer_gpu_data = renderer_gpu_data;
   secondary_gpu_state->gpu_kms = gpu_kms;


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