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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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