Move ReadStruct/WriteStruct to Ryujinx.Common
This commit is contained in:
parent
0e77305c3d
commit
e6b3b22981
3 changed files with 51 additions and 42 deletions
37
Ryujinx.Common/StructIOExtension.cs
Normal file
37
Ryujinx.Common/StructIOExtension.cs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Ryujinx.Common
|
||||||
|
{
|
||||||
|
public static class StructIOExtension
|
||||||
|
{
|
||||||
|
public unsafe static T ReadStruct<T>(this BinaryReader reader) where T : struct
|
||||||
|
{
|
||||||
|
int size = Marshal.SizeOf<T>();
|
||||||
|
|
||||||
|
byte[] data = reader.ReadBytes(size);
|
||||||
|
|
||||||
|
fixed (byte* ptr = data)
|
||||||
|
{
|
||||||
|
return Marshal.PtrToStructure<T>((IntPtr)ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public unsafe static void WriteStruct<T>(this BinaryWriter writer, T value) where T : struct
|
||||||
|
{
|
||||||
|
long size = Marshal.SizeOf<T>();
|
||||||
|
|
||||||
|
byte[] data = new byte[size];
|
||||||
|
|
||||||
|
fixed (byte* ptr = data)
|
||||||
|
{
|
||||||
|
Marshal.StructureToPtr<T>(value, (IntPtr)ptr, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Write(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Ryujinx.Common;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -141,7 +142,7 @@ namespace Ryujinx.HLE.HOS.Services.Android
|
||||||
|
|
||||||
public GbpBuffer(BinaryReader reader)
|
public GbpBuffer(BinaryReader reader)
|
||||||
{
|
{
|
||||||
Header = NvFlinger.ReadStruct<GraphicBufferHeader>(reader);
|
Header = reader.ReadStruct<GraphicBufferHeader>();
|
||||||
|
|
||||||
// ignore fds
|
// ignore fds
|
||||||
// TODO: check if that is used in official implementation
|
// TODO: check if that is used in official implementation
|
||||||
|
@ -152,13 +153,13 @@ namespace Ryujinx.HLE.HOS.Services.Android
|
||||||
throw new System.NotImplementedException($"Unexpected Graphic Buffer ints count (expected 0x51, found 0x{Header.IntsCount:x}");
|
throw new System.NotImplementedException($"Unexpected Graphic Buffer ints count (expected 0x51, found 0x{Header.IntsCount:x}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer = NvFlinger.ReadStruct<NvGraphicBuffer>(reader);
|
Buffer = reader.ReadStruct<NvGraphicBuffer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(BinaryWriter writer)
|
public void Write(BinaryWriter writer)
|
||||||
{
|
{
|
||||||
NvFlinger.WriteStruct(writer, Header);
|
writer.WriteStruct(Header);
|
||||||
NvFlinger.WriteStruct(writer, Buffer);
|
writer.WriteStruct(Buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -85,31 +85,31 @@ namespace Ryujinx.HLE.HOS.Services.Android
|
||||||
private struct QueueBufferObject
|
private struct QueueBufferObject
|
||||||
{
|
{
|
||||||
[FieldOffset(0x0)]
|
[FieldOffset(0x0)]
|
||||||
public long Timestamp;
|
public long Timestamp;
|
||||||
|
|
||||||
[FieldOffset(0x8)]
|
[FieldOffset(0x8)]
|
||||||
public int IsAutoTimestamp;
|
public int IsAutoTimestamp;
|
||||||
|
|
||||||
[FieldOffset(0xC)]
|
[FieldOffset(0xC)]
|
||||||
public Rect Crop;
|
public Rect Crop;
|
||||||
|
|
||||||
[FieldOffset(0x1C)]
|
[FieldOffset(0x1C)]
|
||||||
public int ScalingMode;
|
public int ScalingMode;
|
||||||
|
|
||||||
[FieldOffset(0x20)]
|
[FieldOffset(0x20)]
|
||||||
public HalTransform Transform;
|
public HalTransform Transform;
|
||||||
|
|
||||||
[FieldOffset(0x24)]
|
[FieldOffset(0x24)]
|
||||||
public int StickyTransform;
|
public int StickyTransform;
|
||||||
|
|
||||||
[FieldOffset(0x28)]
|
[FieldOffset(0x28)]
|
||||||
public int Unknown;
|
public int Unknown;
|
||||||
|
|
||||||
[FieldOffset(0x2C)]
|
[FieldOffset(0x2C)]
|
||||||
public int SwapInterval;
|
public int SwapInterval;
|
||||||
|
|
||||||
[FieldOffset(0x30)]
|
[FieldOffset(0x30)]
|
||||||
public MultiFence Fence;
|
public MultiFence Fence;
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct BufferEntry
|
private struct BufferEntry
|
||||||
|
@ -238,7 +238,7 @@ namespace Ryujinx.HLE.HOS.Services.Android
|
||||||
parcelReader.BaseStream.Position = Position;
|
parcelReader.BaseStream.Position = Position;
|
||||||
|
|
||||||
_bufferQueue[slot].Transform = queueBufferObject.Transform;
|
_bufferQueue[slot].Transform = queueBufferObject.Transform;
|
||||||
_bufferQueue[slot].Crop = queueBufferObject.Crop;
|
_bufferQueue[slot].Crop = queueBufferObject.Crop;
|
||||||
|
|
||||||
_bufferQueue[slot].State = BufferState.Queued;
|
_bufferQueue[slot].State = BufferState.Queued;
|
||||||
|
|
||||||
|
@ -325,34 +325,6 @@ namespace Ryujinx.HLE.HOS.Services.Android
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: move this (extension?)
|
|
||||||
public unsafe static T ReadStruct<T>(BinaryReader reader) where T : struct
|
|
||||||
{
|
|
||||||
int size = Marshal.SizeOf<T>();
|
|
||||||
|
|
||||||
byte[] data = reader.ReadBytes(size);
|
|
||||||
|
|
||||||
fixed (byte* ptr = data)
|
|
||||||
{
|
|
||||||
return Marshal.PtrToStructure<T>((IntPtr)ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: move this (extension?)
|
|
||||||
public unsafe static void WriteStruct<T>(BinaryWriter writer, T value) where T : struct
|
|
||||||
{
|
|
||||||
long size = Marshal.SizeOf<T>();
|
|
||||||
|
|
||||||
byte[] data = new byte[size];
|
|
||||||
|
|
||||||
fixed (byte* ptr = data)
|
|
||||||
{
|
|
||||||
Marshal.StructureToPtr<T>(value, (IntPtr)ptr, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.Write(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private long MakeReplyParcel(ServiceCtx context, params int[] ints)
|
private long MakeReplyParcel(ServiceCtx context, params int[] ints)
|
||||||
{
|
{
|
||||||
using (MemoryStream ms = new MemoryStream())
|
using (MemoryStream ms = new MemoryStream())
|
||||||
|
@ -429,7 +401,6 @@ namespace Ryujinx.HLE.HOS.Services.Android
|
||||||
int right = crop.Right;
|
int right = crop.Right;
|
||||||
int bottom = crop.Bottom;
|
int bottom = crop.Bottom;
|
||||||
|
|
||||||
|
|
||||||
NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm;
|
NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm;
|
||||||
|
|
||||||
_renderer.QueueAction(() =>
|
_renderer.QueueAction(() =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue