SDL: SDLTest_CompareSurfaces: If surfaces differ, log their formats

From b2ddfbbec3c28ec6085bf9bedcaf00c0a34e86a4 Mon Sep 17 00:00:00 2001
From: Simon McVittie <[EMAIL REDACTED]>
Date: Fri, 29 Sep 2023 12:52:32 +0100
Subject: [PATCH] SDLTest_CompareSurfaces: If surfaces differ, log their
 formats

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 src/test/SDL_test_compare.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c
index c65b75c72a44..8101d0aae55d 100644
--- a/src/test/SDL_test_compare.c
+++ b/src/test/SDL_test_compare.c
@@ -52,6 +52,16 @@ GetPixel(Uint8 *p, size_t bytes_per_pixel)
     return ret;
 }
 
+static void
+LogErrorFormat(const char *name, const SDL_PixelFormat *format)
+{
+  SDLTest_LogError("%s: %08" SDL_PRIx32 " %s, %u bits/%u bytes per pixel", name, format->format, SDL_GetPixelFormatName(format->format), format->BitsPerPixel, format->BytesPerPixel);
+  SDLTest_LogError("%s: R mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Rmask, format->Rloss, format->Rshift);
+  SDLTest_LogError("%s: G mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Gmask, format->Gloss, format->Gshift);
+  SDLTest_LogError("%s: B mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Bmask, format->Bloss, format->Bshift);
+  SDLTest_LogError("%s: A mask %08" SDL_PRIx32 ", loss %u, shift %u", name, format->Amask, format->Aloss, format->Ashift);
+}
+
 /* Compare surfaces */
 int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error)
 {
@@ -130,6 +140,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
     _CompareSurfaceCount++;
     if (ret != 0) {
         SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
+        LogErrorFormat("Reference surface format", referenceSurface->format);
+        LogErrorFormat("Actual surface format   ", surface->format);
         SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist);
         (void)SDL_snprintf(imageFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
         SDL_SaveBMP(surface, imageFilename);