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
This commit is contained in:
Pekka Paalanen 2018-11-22 16:26:01 +02:00 committed by Jonas Ådahl
parent 442dcc7855
commit a62dbc6680
3 changed files with 54 additions and 0 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;