From ab29521faaed0e1585f287abfebbeabe885b56a7 Mon Sep 17 00:00:00 2001
From: Thog <me@thog.eu>
Date: Thu, 9 Jan 2020 19:12:47 +0100
Subject: [PATCH] Fix R5G6B5 in SurfaceFlinger (#863)

Also fix B5G6R5Unorm wrong definition in Ryujinx.Graphics.OpenGL.
---
 Ryujinx.Graphics.OpenGL/FormatTable.cs               | 2 +-
 Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Ryujinx.Graphics.OpenGL/FormatTable.cs b/Ryujinx.Graphics.OpenGL/FormatTable.cs
index 38197a9053..b178553cd8 100644
--- a/Ryujinx.Graphics.OpenGL/FormatTable.cs
+++ b/Ryujinx.Graphics.OpenGL/FormatTable.cs
@@ -160,7 +160,7 @@ namespace Ryujinx.Graphics.OpenGL
             Add(Format.Astc10x10Srgb,       new FormatInfo(1, false, false, All.CompressedSrgb8Alpha8Astc10X10Khr));
             Add(Format.Astc12x10Srgb,       new FormatInfo(1, false, false, All.CompressedSrgb8Alpha8Astc12X10Khr));
             Add(Format.Astc12x12Srgb,       new FormatInfo(1, false, false, All.CompressedSrgb8Alpha8Astc12X12Khr));
-            Add(Format.B5G6R5Unorm,         new FormatInfo(3, true,  false, All.Rgb565,            PixelFormat.Bgr,            PixelType.UnsignedShort565));
+            Add(Format.B5G6R5Unorm,         new FormatInfo(3, true,  false, All.Rgb565,            PixelFormat.Rgb,            PixelType.UnsignedShort565));
             Add(Format.B5G5R5X1Unorm,       new FormatInfo(4, true,  false, All.Rgb5,              PixelFormat.Bgra,           PixelType.UnsignedShort5551));
             Add(Format.B5G5R5A1Unorm,       new FormatInfo(4, true,  false, All.Rgb5A1,            PixelFormat.Bgra,           PixelType.UnsignedShort5551));
             Add(Format.A1B5G5R5Unorm,       new FormatInfo(4, true,  false, All.Rgb5A1,            PixelFormat.Bgra,           PixelType.UnsignedShort1555Reversed));
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs
index fa79817754..e70666ed9d 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs
@@ -264,7 +264,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
                 case ColorFormat.X8B8G8R8:
                     return Format.R8G8B8A8Unorm;
                 case ColorFormat.R5G6B5:
-                    return Format.R5G6B5Unorm;
+                    return Format.B5G6R5Unorm;
                 case ColorFormat.A8R8G8B8:
                     return Format.B8G8R8A8Unorm;
                 case ColorFormat.A4B4G4R4:
@@ -298,7 +298,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
             Format format = ConvertColorFormat(_bufferQueue[slot].Data.Buffer.Surfaces[0].ColorFormat);
 
             int bytesPerPixel =
-                format == Format.R5G6B5Unorm ||
+                format == Format.B5G6R5Unorm ||
                 format == Format.R4G4B4A4Unorm ? 2 : 4;
 
             int gobBlocksInY = 1 << _bufferQueue[slot].Data.Buffer.Surfaces[0].BlockHeightLog2;