aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/SurfaceFlinger
diff options
context:
space:
mode:
authorgdk <gab.dark.100@gmail.com>2019-10-13 03:02:07 -0300
committerThog <thog@protonmail.com>2020-01-09 02:13:00 +0100
commit1876b346fea647e8284a66bb6d62c38801035cff (patch)
tree6eeff094298cda84d1613dc5ec0691e51d7b35f1 /Ryujinx.HLE/HOS/Services/SurfaceFlinger
parentf617fb542a0e3d36012d77a4b5acbde7b08902f2 (diff)
Initial work
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/SurfaceFlinger')
-rw-r--r--Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs80
1 files changed, 41 insertions, 39 deletions
diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs
index e3e4a1a4..50b55ee0 100644
--- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs
+++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/NvFlinger.cs
@@ -1,6 +1,5 @@
using Ryujinx.Common.Logging;
-using Ryujinx.Graphics.Gal;
-using Ryujinx.Graphics.Memory;
+using Ryujinx.Graphics.GAL;
using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu;
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap;
@@ -23,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
private KEvent _binderEvent;
- private IGalRenderer _renderer;
+ private IRenderer _renderer;
private const int BufferQueueCount = 0x40;
private const int BufferQueueMask = BufferQueueCount - 1;
@@ -34,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
private bool _disposed;
- public NvFlinger(IGalRenderer renderer, KEvent binderEvent)
+ public NvFlinger(IRenderer renderer, KEvent binderEvent)
{
_commands = new Dictionary<(string, int), ServiceProcessParcel>
{
@@ -256,20 +255,20 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
return ResultCode.Success;
}
- private GalImageFormat ConvertColorFormat(ColorFormat colorFormat)
+ private Format ConvertColorFormat(ColorFormat colorFormat)
{
switch (colorFormat)
{
case ColorFormat.A8B8G8R8:
- return GalImageFormat.Rgba8 | GalImageFormat.Unorm;
+ return Format.R8G8B8A8Unorm;
case ColorFormat.X8B8G8R8:
- return GalImageFormat.Rgbx8 | GalImageFormat.Unorm;
+ return Format.R8G8B8A8Unorm;
case ColorFormat.R5G6B5:
- return GalImageFormat.Bgr565 | GalImageFormat.Unorm;
+ return Format.R5G6B5Unorm;
case ColorFormat.A8R8G8B8:
- return GalImageFormat.Bgra8 | GalImageFormat.Unorm;
+ return Format.B8G8R8A8Unorm;
case ColorFormat.A4B4G4R4:
- return GalImageFormat.Rgba4 | GalImageFormat.Unorm;
+ return Format.R4G4B4A4Unorm;
default:
throw new NotImplementedException($"Color Format \"{colorFormat}\" not implemented!");
}
@@ -292,7 +291,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
NvMapHandle map = NvMapDeviceFile.GetMapFromHandle(context.Process, nvMapHandle);
- long fbAddr = map.Address + bufferOffset;
+ ulong fbAddr = (ulong)(map.Address + bufferOffset);
_bufferQueue[slot].State = BufferState.Acquired;
@@ -301,39 +300,42 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
bool flipX = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipX);
bool flipY = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipY);
- GalImageFormat imageFormat = ConvertColorFormat(_bufferQueue[slot].Data.Buffer.Surfaces[0].ColorFormat);
+ Format format = ConvertColorFormat(_bufferQueue[slot].Data.Buffer.Surfaces[0].ColorFormat);
- int BlockHeight = 1 << _bufferQueue[slot].Data.Buffer.Surfaces[0].BlockHeightLog2;
+ int bytesPerPixel =
+ format == Format.R5G6B5Unorm ||
+ format == Format.R4G4B4A4Unorm ? 2 : 4;
- // Note: Rotation is being ignored.
-
- int top = crop.Top;
- int left = crop.Left;
- int right = crop.Right;
- int bottom = crop.Bottom;
-
- NvGpuVmm vmm = NvHostAsGpuDeviceFile.GetAddressSpaceContext(context.Process).Vmm;
-
- _renderer.QueueAction(() =>
- {
- if (!_renderer.Texture.TryGetImage(fbAddr, out GalImage image))
- {
- image = new GalImage(
- fbWidth,
- fbHeight, 1, 1, 1, BlockHeight, 1,
- GalMemoryLayout.BlockLinear,
- imageFormat,
- GalTextureTarget.TwoD);
- }
+ int gobBlocksInY = 1 << _bufferQueue[slot].Data.Buffer.Surfaces[0].BlockHeightLog2;
- context.Device.Gpu.ResourceManager.ClearPbCache();
- context.Device.Gpu.ResourceManager.SendTexture(vmm, fbAddr, image);
+ // Note: Rotation is being ignored.
- _renderer.RenderTarget.SetTransform(flipX, flipY, top, left, right, bottom);
- _renderer.RenderTarget.Present(fbAddr);
+ ITexture texture = context.Device.Gpu.GetTexture(
+ fbAddr,
+ fbWidth,
+ fbHeight,
+ 0,
+ false,
+ gobBlocksInY,
+ format,
+ bytesPerPixel);
+
+ _renderer.Window.RegisterTextureReleaseCallback(ReleaseBuffer);
+
+ ImageCrop imageCrop = new ImageCrop(
+ crop.Left,
+ crop.Right,
+ crop.Top,
+ crop.Bottom,
+ flipX,
+ flipY);
+
+ _renderer.Window.QueueTexture(texture, imageCrop, slot);
+ }
- ReleaseBuffer(slot);
- });
+ private void ReleaseBuffer(object context)
+ {
+ ReleaseBuffer((int)context);
}
private void ReleaseBuffer(int slot)