From 99f04ac1a64400d45052e4a83c572e50ba86de0d Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 20 Jul 2024 16:27:40 -0300
Subject: Fix Skia saving screenshot with transparent background and incorrect
 origin (#7073)

* Fix Skia saving screenshot with transparent background and incorrect origin

* Remove code that is no longer necessary
---
 src/Ryujinx/AppHost.cs | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs
index 8c643f34..0db8ef41 100644
--- a/src/Ryujinx/AppHost.cs
+++ b/src/Ryujinx/AppHost.cs
@@ -367,32 +367,24 @@ namespace Ryujinx.Ava
                         }
 
                         var colorType = e.IsBgra ? SKColorType.Bgra8888 : SKColorType.Rgba8888;
-                        using var bitmap = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul));
+                        using SKBitmap bitmap = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul));
 
                         Marshal.Copy(e.Data, 0, bitmap.GetPixels(), e.Data.Length);
 
-                        SKBitmap bitmapToSave = null;
+                        using SKBitmap bitmapToSave = new SKBitmap(bitmap.Width, bitmap.Height);
+                        using SKCanvas canvas = new SKCanvas(bitmapToSave);
 
-                        if (e.FlipX || e.FlipY)
-                        {
-                            bitmapToSave = new SKBitmap(bitmap.Width, bitmap.Height);
-
-                            using var canvas = new SKCanvas(bitmapToSave);
-
-                            canvas.Clear(SKColors.Transparent);
+                        canvas.Clear(SKColors.Black);
 
-                            float scaleX = e.FlipX ? -1 : 1;
-                            float scaleY = e.FlipY ? -1 : 1;
+                        float scaleX = e.FlipX ? -1 : 1;
+                        float scaleY = e.FlipY ? -1 : 1;
 
-                            var matrix = SKMatrix.CreateScale(scaleX, scaleY, bitmap.Width / 2f, bitmap.Height / 2f);
+                        var matrix = SKMatrix.CreateScale(scaleX, scaleY, bitmap.Width / 2f, bitmap.Height / 2f);
 
-                            canvas.SetMatrix(matrix);
-
-                            canvas.DrawBitmap(bitmap, new SKPoint(e.FlipX ? -bitmap.Width : 0, e.FlipY ? -bitmap.Height : 0));
-                        }
+                        canvas.SetMatrix(matrix);
+                        canvas.DrawBitmap(bitmap, SKPoint.Empty);
 
-                        SaveBitmapAsPng(bitmapToSave ?? bitmap, path);
-                        bitmapToSave?.Dispose();
+                        SaveBitmapAsPng(bitmapToSave, path);
 
                         Logger.Notice.Print(LogClass.Application, $"Screenshot saved to {path}", "Screenshot");
                     }
-- 
cgit v1.2.3-70-g09d2