2019-01-05 16:26:16 -05:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using System;
|
2018-02-23 16:48:27 -05:00
|
|
|
using System.IO;
|
2019-01-05 16:26:16 -05:00
|
|
|
using System.Runtime.InteropServices;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Android
|
2018-02-23 16:48:27 -05:00
|
|
|
{
|
2019-01-05 16:26:16 -05:00
|
|
|
[StructLayout(LayoutKind.Sequential, Size = 0x28)]
|
|
|
|
struct GraphicBufferHeader
|
2018-02-23 16:48:27 -05:00
|
|
|
{
|
2019-01-05 16:26:16 -05:00
|
|
|
public int Magic;
|
|
|
|
public int Width;
|
|
|
|
public int Height;
|
|
|
|
public int Stride;
|
|
|
|
public int Format;
|
|
|
|
public int Usage;
|
|
|
|
|
|
|
|
public int Pid;
|
|
|
|
public int RefCount;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
public int FdsCount;
|
|
|
|
public int IntsCount;
|
|
|
|
}
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[StructLayout(LayoutKind.Explicit, Size = 0x58)]
|
|
|
|
struct NvGraphicBufferSurface
|
|
|
|
{
|
|
|
|
[FieldOffset(0)]
|
|
|
|
public uint Width;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[FieldOffset(0x4)]
|
|
|
|
public uint Height;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[FieldOffset(0x8)]
|
|
|
|
public ColorFormat ColorFormat;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[FieldOffset(0x10)]
|
|
|
|
public int Layout;
|
|
|
|
|
|
|
|
[FieldOffset(0x14)]
|
|
|
|
public int Pitch;
|
|
|
|
|
|
|
|
[FieldOffset(0x18)]
|
|
|
|
public int NvMapHandle;
|
|
|
|
|
|
|
|
[FieldOffset(0x1C)]
|
|
|
|
public int Offset;
|
|
|
|
|
|
|
|
[FieldOffset(0x20)]
|
|
|
|
public int Kind;
|
|
|
|
|
|
|
|
[FieldOffset(0x24)]
|
|
|
|
public int BlockHeightLog2;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[FieldOffset(0x28)]
|
|
|
|
public int ScanFormat;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[FieldOffset(0x30)]
|
|
|
|
public long Flags;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[FieldOffset(0x38)]
|
|
|
|
public long Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Explicit)]
|
|
|
|
struct NvGraphicBufferSurfaceArray
|
|
|
|
{
|
|
|
|
[FieldOffset(0x0)]
|
|
|
|
private NvGraphicBufferSurface Surface0;
|
|
|
|
|
|
|
|
[FieldOffset(0x58)]
|
|
|
|
private NvGraphicBufferSurface Surface1;
|
|
|
|
|
|
|
|
[FieldOffset(0xb0)]
|
|
|
|
private NvGraphicBufferSurface Surface2;
|
|
|
|
|
|
|
|
public NvGraphicBufferSurface this[int index]
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
return Surface0;
|
|
|
|
}
|
|
|
|
else if (index == 1)
|
|
|
|
{
|
|
|
|
return Surface1;
|
|
|
|
}
|
|
|
|
else if (index == 2)
|
|
|
|
{
|
|
|
|
return Surface2;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new IndexOutOfRangeException();
|
|
|
|
}
|
2018-02-23 16:48:27 -05:00
|
|
|
}
|
2019-01-05 16:26:16 -05:00
|
|
|
}
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
[StructLayout(LayoutKind.Explicit, Size = 0x144)]
|
|
|
|
struct NvGraphicBuffer
|
|
|
|
{
|
|
|
|
[FieldOffset(0x4)]
|
|
|
|
public int NvMapId;
|
|
|
|
|
|
|
|
[FieldOffset(0xC)]
|
|
|
|
public int Magic;
|
|
|
|
|
|
|
|
[FieldOffset(0x10)]
|
|
|
|
public int Pid;
|
|
|
|
|
|
|
|
[FieldOffset(0x14)]
|
|
|
|
public int Type;
|
|
|
|
|
|
|
|
[FieldOffset(0x18)]
|
|
|
|
public int Usage;
|
|
|
|
|
|
|
|
[FieldOffset(0x1C)]
|
|
|
|
public int PixelFormat;
|
|
|
|
|
|
|
|
[FieldOffset(0x20)]
|
|
|
|
public int ExternalPixelFormat;
|
|
|
|
|
|
|
|
[FieldOffset(0x24)]
|
|
|
|
public int Stride;
|
|
|
|
|
|
|
|
[FieldOffset(0x28)]
|
|
|
|
public int FrameBufferSize;
|
|
|
|
|
|
|
|
[FieldOffset(0x2C)]
|
|
|
|
public int PlanesCount;
|
|
|
|
|
|
|
|
[FieldOffset(0x34)]
|
|
|
|
public NvGraphicBufferSurfaceArray Surfaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GbpBuffer
|
|
|
|
{
|
|
|
|
public GraphicBufferHeader Header { get; private set; }
|
|
|
|
public NvGraphicBuffer Buffer { get; private set; }
|
|
|
|
|
|
|
|
public int Size => Marshal.SizeOf<NvGraphicBuffer>() + Marshal.SizeOf<GraphicBufferHeader>();
|
|
|
|
|
|
|
|
public GbpBuffer(BinaryReader reader)
|
2018-02-23 16:48:27 -05:00
|
|
|
{
|
2019-01-05 16:26:16 -05:00
|
|
|
Header = reader.ReadStruct<GraphicBufferHeader>();
|
|
|
|
|
|
|
|
// ignore fds
|
|
|
|
// TODO: check if that is used in official implementation
|
|
|
|
reader.BaseStream.Position += Header.FdsCount * 4;
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
if (Header.IntsCount != 0x51)
|
|
|
|
{
|
2019-07-01 22:39:22 -04:00
|
|
|
throw new NotImplementedException($"Unexpected Graphic Buffer ints count (expected 0x51, found 0x{Header.IntsCount:x}");
|
2019-01-05 16:26:16 -05:00
|
|
|
}
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
Buffer = reader.ReadStruct<NvGraphicBuffer>();
|
|
|
|
}
|
2018-02-23 16:48:27 -05:00
|
|
|
|
2019-01-05 16:26:16 -05:00
|
|
|
public void Write(BinaryWriter writer)
|
|
|
|
{
|
|
|
|
writer.WriteStruct(Header);
|
|
|
|
writer.WriteStruct(Buffer);
|
2018-02-23 16:48:27 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|