[mutter/wip/rstrode/rhel-8.0.0: 29/30] renderer/native: Debug print chosen secondary FB format



commit c0d96999770a69255540b40daa227f2477c483d1
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 21d7defbc..f2f02c370 100644
--- a/src/backends/native/meta-crtc-kms.c
+++ b/src/backends/native/meta-crtc-kms.c
@@ -32,6 +32,11 @@
 
 #include <drm_fourcc.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)
 
@@ -54,6 +59,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 94ff13537..0d503c30f 100644
--- a/src/backends/native/meta-crtc-kms.h
+++ b/src/backends/native/meta-crtc-kms.h
@@ -30,6 +30,15 @@
 #include "backends/meta-gpu.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 b64f3b4be..82b4f62e9 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -799,6 +799,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));
@@ -812,6 +813,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]