Adjust naming conventions and general refactoring in HLE Project (#490)

* Rename enum fields

* Naming conventions

* Remove unneeded ".this"

* Remove unneeded semicolons

* Remove unused Usings

* Don't use var

* Remove unneeded enum underlying types

* Explicitly label class visibility

* Remove unneeded @ prefixes

* Remove unneeded commas

* Remove unneeded if expressions

* Method doesn't use unsafe code

* Remove unneeded casts

* Initialized objects don't need an empty constructor

* Remove settings from DotSettings

* Revert "Explicitly label class visibility"

This reverts commit ad5eb5787c.

* Small changes

* Revert external enum renaming

* Changes from feedback

* Remove unneeded property setters
This commit is contained in:
Alex Barney
2018-12-04 14:23:37 -06:00
committed by gdkchan
parent c86aacde76
commit 85dbb9559a
299 changed files with 12268 additions and 12276 deletions

View File

@ -2,11 +2,11 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class Display
{
public string Name { get; private set; }
public string Name { get; }
public Display(string Name)
public Display(string name)
{
this.Name = Name;
Name = name;
}
}
}

View File

@ -4,57 +4,57 @@ namespace Ryujinx.HLE.HOS.Services.Android
{
struct GbpBuffer
{
public int Magic { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
public int Stride { get; private set; }
public int Format { get; private set; }
public int Usage { get; private set; }
public int Magic { get; }
public int Width { get; }
public int Height { get; }
public int Stride { get; }
public int Format { get; }
public int Usage { get; }
public int Pid { get; private set; }
public int RefCount { get; private set; }
public int Pid { get; }
public int RefCount { get; }
public int FdsCount { get; private set; }
public int IntsCount { get; private set; }
public int FdsCount { get; }
public int IntsCount { get; }
public byte[] RawData { get; private set; }
public byte[] RawData { get; }
public int Size => RawData.Length + 10 * 4;
public GbpBuffer(BinaryReader Reader)
public GbpBuffer(BinaryReader reader)
{
Magic = Reader.ReadInt32();
Width = Reader.ReadInt32();
Height = Reader.ReadInt32();
Stride = Reader.ReadInt32();
Format = Reader.ReadInt32();
Usage = Reader.ReadInt32();
Magic = reader.ReadInt32();
Width = reader.ReadInt32();
Height = reader.ReadInt32();
Stride = reader.ReadInt32();
Format = reader.ReadInt32();
Usage = reader.ReadInt32();
Pid = Reader.ReadInt32();
RefCount = Reader.ReadInt32();
Pid = reader.ReadInt32();
RefCount = reader.ReadInt32();
FdsCount = Reader.ReadInt32();
IntsCount = Reader.ReadInt32();
FdsCount = reader.ReadInt32();
IntsCount = reader.ReadInt32();
RawData = Reader.ReadBytes((FdsCount + IntsCount) * 4);
RawData = reader.ReadBytes((FdsCount + IntsCount) * 4);
}
public void Write(BinaryWriter Writer)
public void Write(BinaryWriter writer)
{
Writer.Write(Magic);
Writer.Write(Width);
Writer.Write(Height);
Writer.Write(Stride);
Writer.Write(Format);
Writer.Write(Usage);
writer.Write(Magic);
writer.Write(Width);
writer.Write(Height);
writer.Write(Stride);
writer.Write(Format);
writer.Write(Usage);
Writer.Write(Pid);
Writer.Write(RefCount);
writer.Write(Pid);
writer.Write(RefCount);
Writer.Write(FdsCount);
Writer.Write(IntsCount);
writer.Write(FdsCount);
writer.Write(IntsCount);
Writer.Write(RawData);
writer.Write(RawData);
}
}
}

View File

@ -12,15 +12,15 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class IApplicationDisplayService : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
private IdDictionary Displays;
private IdDictionary _displays;
public IApplicationDisplayService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 100, GetRelayService },
{ 101, GetSystemDisplayService },
@ -38,205 +38,205 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{ 5202, GetDisplayVSyncEvent }
};
Displays = new IdDictionary();
_displays = new IdDictionary();
}
public long GetRelayService(ServiceCtx Context)
public long GetRelayService(ServiceCtx context)
{
MakeObject(Context, new IHOSBinderDriver(
Context.Device.System,
Context.Device.Gpu.Renderer));
MakeObject(context, new IhosBinderDriver(
context.Device.System,
context.Device.Gpu.Renderer));
return 0;
}
public long GetSystemDisplayService(ServiceCtx Context)
public long GetSystemDisplayService(ServiceCtx context)
{
MakeObject(Context, new ISystemDisplayService());
MakeObject(context, new ISystemDisplayService());
return 0;
}
public long GetManagerDisplayService(ServiceCtx Context)
public long GetManagerDisplayService(ServiceCtx context)
{
MakeObject(Context, new IManagerDisplayService());
MakeObject(context, new IManagerDisplayService());
return 0;
}
public long GetIndirectDisplayTransactionService(ServiceCtx Context)
public long GetIndirectDisplayTransactionService(ServiceCtx context)
{
MakeObject(Context, new IHOSBinderDriver(
Context.Device.System,
Context.Device.Gpu.Renderer));
MakeObject(context, new IhosBinderDriver(
context.Device.System,
context.Device.Gpu.Renderer));
return 0;
}
public long ListDisplays(ServiceCtx Context)
public long ListDisplays(ServiceCtx context)
{
long RecBuffPtr = Context.Request.ReceiveBuff[0].Position;
long recBuffPtr = context.Request.ReceiveBuff[0].Position;
MemoryHelper.FillWithZeros(Context.Memory, RecBuffPtr, 0x60);
MemoryHelper.FillWithZeros(context.Memory, recBuffPtr, 0x60);
//Add only the default display to buffer
Context.Memory.WriteBytes(RecBuffPtr, Encoding.ASCII.GetBytes("Default"));
Context.Memory.WriteInt64(RecBuffPtr + 0x40, 0x1L);
Context.Memory.WriteInt64(RecBuffPtr + 0x48, 0x1L);
Context.Memory.WriteInt64(RecBuffPtr + 0x50, 1920L);
Context.Memory.WriteInt64(RecBuffPtr + 0x58, 1080L);
context.Memory.WriteBytes(recBuffPtr, Encoding.ASCII.GetBytes("Default"));
context.Memory.WriteInt64(recBuffPtr + 0x40, 0x1L);
context.Memory.WriteInt64(recBuffPtr + 0x48, 0x1L);
context.Memory.WriteInt64(recBuffPtr + 0x50, 1920L);
context.Memory.WriteInt64(recBuffPtr + 0x58, 1080L);
Context.ResponseData.Write(1L);
context.ResponseData.Write(1L);
return 0;
}
public long OpenDisplay(ServiceCtx Context)
public long OpenDisplay(ServiceCtx context)
{
string Name = GetDisplayName(Context);
string name = GetDisplayName(context);
long DisplayId = Displays.Add(new Display(Name));
long displayId = _displays.Add(new Display(name));
Context.ResponseData.Write(DisplayId);
context.ResponseData.Write(displayId);
return 0;
}
public long CloseDisplay(ServiceCtx Context)
public long CloseDisplay(ServiceCtx context)
{
int DisplayId = Context.RequestData.ReadInt32();
int displayId = context.RequestData.ReadInt32();
Displays.Delete(DisplayId);
_displays.Delete(displayId);
return 0;
}
public long GetDisplayResolution(ServiceCtx Context)
public long GetDisplayResolution(ServiceCtx context)
{
long DisplayId = Context.RequestData.ReadInt32();
long displayId = context.RequestData.ReadInt32();
Context.ResponseData.Write(1280);
Context.ResponseData.Write(720);
context.ResponseData.Write(1280);
context.ResponseData.Write(720);
return 0;
}
public long OpenLayer(ServiceCtx Context)
public long OpenLayer(ServiceCtx context)
{
long LayerId = Context.RequestData.ReadInt64();
long UserId = Context.RequestData.ReadInt64();
long layerId = context.RequestData.ReadInt64();
long userId = context.RequestData.ReadInt64();
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
long parcelPtr = context.Request.ReceiveBuff[0].Position;
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
byte[] parcel = MakeIGraphicsBufferProducer(parcelPtr);
Context.Memory.WriteBytes(ParcelPtr, Parcel);
context.Memory.WriteBytes(parcelPtr, parcel);
Context.ResponseData.Write((long)Parcel.Length);
context.ResponseData.Write((long)parcel.Length);
return 0;
}
public long CloseLayer(ServiceCtx Context)
public long CloseLayer(ServiceCtx context)
{
long LayerId = Context.RequestData.ReadInt64();
long layerId = context.RequestData.ReadInt64();
return 0;
}
public long CreateStrayLayer(ServiceCtx Context)
public long CreateStrayLayer(ServiceCtx context)
{
long LayerFlags = Context.RequestData.ReadInt64();
long DisplayId = Context.RequestData.ReadInt64();
long layerFlags = context.RequestData.ReadInt64();
long displayId = context.RequestData.ReadInt64();
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
long parcelPtr = context.Request.ReceiveBuff[0].Position;
Display Disp = Displays.GetData<Display>((int)DisplayId);
Display disp = _displays.GetData<Display>((int)displayId);
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
byte[] parcel = MakeIGraphicsBufferProducer(parcelPtr);
Context.Memory.WriteBytes(ParcelPtr, Parcel);
context.Memory.WriteBytes(parcelPtr, parcel);
Context.ResponseData.Write(0L);
Context.ResponseData.Write((long)Parcel.Length);
context.ResponseData.Write(0L);
context.ResponseData.Write((long)parcel.Length);
return 0;
}
public long DestroyStrayLayer(ServiceCtx Context)
public long DestroyStrayLayer(ServiceCtx context)
{
return 0;
}
public long SetLayerScalingMode(ServiceCtx Context)
public long SetLayerScalingMode(ServiceCtx context)
{
int ScalingMode = Context.RequestData.ReadInt32();
long Unknown = Context.RequestData.ReadInt64();
int scalingMode = context.RequestData.ReadInt32();
long unknown = context.RequestData.ReadInt64();
return 0;
}
public long GetDisplayVSyncEvent(ServiceCtx Context)
public long GetDisplayVSyncEvent(ServiceCtx context)
{
string Name = GetDisplayName(Context);
string name = GetDisplayName(context);
if (Context.Process.HandleTable.GenerateHandle(Context.Device.System.VsyncEvent.ReadableEvent, out int Handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(context.Device.System.VsyncEvent.ReadableEvent, out int handle) != KernelResult.Success)
{
throw new InvalidOperationException("Out of handles!");
}
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
return 0;
}
private byte[] MakeIGraphicsBufferProducer(long BasePtr)
private byte[] MakeIGraphicsBufferProducer(long basePtr)
{
long Id = 0x20;
long CookiePtr = 0L;
long id = 0x20;
long cookiePtr = 0L;
using (MemoryStream MS = new MemoryStream())
using (MemoryStream ms = new MemoryStream())
{
BinaryWriter Writer = new BinaryWriter(MS);
BinaryWriter writer = new BinaryWriter(ms);
//flat_binder_object (size is 0x28)
Writer.Write(2); //Type (BINDER_TYPE_WEAK_BINDER)
Writer.Write(0); //Flags
Writer.Write((int)(Id >> 0));
Writer.Write((int)(Id >> 32));
Writer.Write((int)(CookiePtr >> 0));
Writer.Write((int)(CookiePtr >> 32));
Writer.Write((byte)'d');
Writer.Write((byte)'i');
Writer.Write((byte)'s');
Writer.Write((byte)'p');
Writer.Write((byte)'d');
Writer.Write((byte)'r');
Writer.Write((byte)'v');
Writer.Write((byte)'\0');
Writer.Write(0L); //Pad
writer.Write(2); //Type (BINDER_TYPE_WEAK_BINDER)
writer.Write(0); //Flags
writer.Write((int)(id >> 0));
writer.Write((int)(id >> 32));
writer.Write((int)(cookiePtr >> 0));
writer.Write((int)(cookiePtr >> 32));
writer.Write((byte)'d');
writer.Write((byte)'i');
writer.Write((byte)'s');
writer.Write((byte)'p');
writer.Write((byte)'d');
writer.Write((byte)'r');
writer.Write((byte)'v');
writer.Write((byte)'\0');
writer.Write(0L); //Pad
return MakeParcel(MS.ToArray(), new byte[] { 0, 0, 0, 0 });
return MakeParcel(ms.ToArray(), new byte[] { 0, 0, 0, 0 });
}
}
private string GetDisplayName(ServiceCtx Context)
private string GetDisplayName(ServiceCtx context)
{
string Name = string.Empty;
string name = string.Empty;
for (int Index = 0; Index < 8 &&
Context.RequestData.BaseStream.Position <
Context.RequestData.BaseStream.Length; Index++)
for (int index = 0; index < 8 &&
context.RequestData.BaseStream.Position <
context.RequestData.BaseStream.Length; index++)
{
byte Chr = Context.RequestData.ReadByte();
byte chr = context.RequestData.ReadByte();
if (Chr >= 0x20 && Chr < 0x7f)
if (chr >= 0x20 && chr < 0x7f)
{
Name += (char)Chr;
name += (char)chr;
}
}
return Name;
return name;
}
}
}

View File

@ -5,23 +5,23 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class IApplicationRootService : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IApplicationRootService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 0, GetDisplayService }
};
}
public long GetDisplayService(ServiceCtx Context)
public long GetDisplayService(ServiceCtx context)
{
int ServiceType = Context.RequestData.ReadInt32();
int serviceType = context.RequestData.ReadInt32();
MakeObject(Context, new IApplicationDisplayService());
MakeObject(context, new IApplicationDisplayService());
return 0;
}

View File

@ -7,19 +7,19 @@ using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Services.Vi
{
class IHOSBinderDriver : IpcService, IDisposable
class IhosBinderDriver : IpcService, IDisposable
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
private KEvent BinderEvent;
private KEvent _binderEvent;
private NvFlinger Flinger;
private NvFlinger _flinger;
public IHOSBinderDriver(Horizon System, IGalRenderer Renderer)
public IhosBinderDriver(Horizon system, IGalRenderer renderer)
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 0, TransactParcel },
{ 1, AdjustRefcount },
@ -27,62 +27,62 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{ 3, TransactParcelAuto }
};
BinderEvent = new KEvent(System);
_binderEvent = new KEvent(system);
BinderEvent.ReadableEvent.Signal();
_binderEvent.ReadableEvent.Signal();
Flinger = new NvFlinger(Renderer, BinderEvent);
_flinger = new NvFlinger(renderer, _binderEvent);
}
public long TransactParcel(ServiceCtx Context)
public long TransactParcel(ServiceCtx context)
{
int Id = Context.RequestData.ReadInt32();
int Code = Context.RequestData.ReadInt32();
int id = context.RequestData.ReadInt32();
int code = context.RequestData.ReadInt32();
long DataPos = Context.Request.SendBuff[0].Position;
long DataSize = Context.Request.SendBuff[0].Size;
long dataPos = context.Request.SendBuff[0].Position;
long dataSize = context.Request.SendBuff[0].Size;
byte[] Data = Context.Memory.ReadBytes(DataPos, DataSize);
byte[] data = context.Memory.ReadBytes(dataPos, dataSize);
Data = Parcel.GetParcelData(Data);
data = Parcel.GetParcelData(data);
return Flinger.ProcessParcelRequest(Context, Data, Code);
return _flinger.ProcessParcelRequest(context, data, code);
}
public long TransactParcelAuto(ServiceCtx Context)
public long TransactParcelAuto(ServiceCtx context)
{
int Id = Context.RequestData.ReadInt32();
int Code = Context.RequestData.ReadInt32();
int id = context.RequestData.ReadInt32();
int code = context.RequestData.ReadInt32();
(long DataPos, long DataSize) = Context.Request.GetBufferType0x21();
(long dataPos, long dataSize) = context.Request.GetBufferType0x21();
byte[] Data = Context.Memory.ReadBytes(DataPos, DataSize);
byte[] data = context.Memory.ReadBytes(dataPos, dataSize);
Data = Parcel.GetParcelData(Data);
data = Parcel.GetParcelData(data);
return Flinger.ProcessParcelRequest(Context, Data, Code);
return _flinger.ProcessParcelRequest(context, data, code);
}
public long AdjustRefcount(ServiceCtx Context)
public long AdjustRefcount(ServiceCtx context)
{
int Id = Context.RequestData.ReadInt32();
int AddVal = Context.RequestData.ReadInt32();
int Type = Context.RequestData.ReadInt32();
int id = context.RequestData.ReadInt32();
int addVal = context.RequestData.ReadInt32();
int type = context.RequestData.ReadInt32();
return 0;
}
public long GetNativeHandle(ServiceCtx Context)
public long GetNativeHandle(ServiceCtx context)
{
int Id = Context.RequestData.ReadInt32();
uint Unk = Context.RequestData.ReadUInt32();
int id = context.RequestData.ReadInt32();
uint unk = context.RequestData.ReadUInt32();
if (Context.Process.HandleTable.GenerateHandle(BinderEvent.ReadableEvent, out int Handle) != KernelResult.Success)
if (context.Process.HandleTable.GenerateHandle(_binderEvent.ReadableEvent, out int handle) != KernelResult.Success)
{
throw new InvalidOperationException("Out of handles!");
}
Context.Response.HandleDesc = IpcHandleDesc.MakeMove(Handle);
context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);
return 0;
}
@ -92,11 +92,11 @@ namespace Ryujinx.HLE.HOS.Services.Vi
Dispose(true);
}
protected virtual void Dispose(bool Disposing)
protected virtual void Dispose(bool disposing)
{
if (Disposing)
if (disposing)
{
Flinger.Dispose();
_flinger.Dispose();
}
}
}

View File

@ -6,13 +6,13 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class IManagerDisplayService : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IManagerDisplayService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 2010, CreateManagedLayer },
{ 2011, DestroyManagedLayer },
@ -21,30 +21,30 @@ namespace Ryujinx.HLE.HOS.Services.Vi
};
}
public static long CreateManagedLayer(ServiceCtx Context)
public static long CreateManagedLayer(ServiceCtx context)
{
Logger.PrintStub(LogClass.ServiceVi, "Stubbed.");
Context.ResponseData.Write(0L); //LayerId
context.ResponseData.Write(0L); //LayerId
return 0;
}
public long DestroyManagedLayer(ServiceCtx Context)
public long DestroyManagedLayer(ServiceCtx context)
{
Logger.PrintStub(LogClass.ServiceVi, "Stubbed.");
return 0;
}
public static long AddToLayerStack(ServiceCtx Context)
public static long AddToLayerStack(ServiceCtx context)
{
Logger.PrintStub(LogClass.ServiceVi, "Stubbed.");
return 0;
}
public static long SetLayerVisibility(ServiceCtx Context)
public static long SetLayerVisibility(ServiceCtx context)
{
Logger.PrintStub(LogClass.ServiceVi, "Stubbed.");

View File

@ -5,23 +5,23 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class IManagerRootService : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IManagerRootService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 2, GetDisplayService }
};
}
public long GetDisplayService(ServiceCtx Context)
public long GetDisplayService(ServiceCtx context)
{
int ServiceType = Context.RequestData.ReadInt32();
int serviceType = context.RequestData.ReadInt32();
MakeObject(Context, new IApplicationDisplayService());
MakeObject(context, new IApplicationDisplayService());
return 0;
}

View File

@ -6,13 +6,13 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class ISystemDisplayService : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public ISystemDisplayService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 2205, SetLayerZ },
{ 2207, SetLayerVisibility },
@ -20,27 +20,27 @@ namespace Ryujinx.HLE.HOS.Services.Vi
};
}
public static long SetLayerZ(ServiceCtx Context)
public static long SetLayerZ(ServiceCtx context)
{
Logger.PrintStub(LogClass.ServiceVi, "Stubbed.");
return 0;
}
public static long SetLayerVisibility(ServiceCtx Context)
public static long SetLayerVisibility(ServiceCtx context)
{
Logger.PrintStub(LogClass.ServiceVi, "Stubbed.");
return 0;
}
public static long GetDisplayMode(ServiceCtx Context)
public static long GetDisplayMode(ServiceCtx context)
{
//TODO: De-hardcode resolution.
Context.ResponseData.Write(1280);
Context.ResponseData.Write(720);
Context.ResponseData.Write(60.0f);
Context.ResponseData.Write(0);
context.ResponseData.Write(1280);
context.ResponseData.Write(720);
context.ResponseData.Write(60.0f);
context.ResponseData.Write(0);
return 0;
}

View File

@ -5,23 +5,23 @@ namespace Ryujinx.HLE.HOS.Services.Vi
{
class ISystemRootService : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
private Dictionary<int, ServiceProcessRequest> _commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public ISystemRootService()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 1, GetDisplayService }
};
}
public long GetDisplayService(ServiceCtx Context)
public long GetDisplayService(ServiceCtx context)
{
int ServiceType = Context.RequestData.ReadInt32();
int serviceType = context.RequestData.ReadInt32();
MakeObject(Context, new IApplicationDisplayService());
MakeObject(context, new IApplicationDisplayService());
return 0;
}

View File

@ -16,13 +16,13 @@ namespace Ryujinx.HLE.HOS.Services.Android
{
class NvFlinger : IDisposable
{
private delegate long ServiceProcessParcel(ServiceCtx Context, BinaryReader ParcelReader);
private delegate long ServiceProcessParcel(ServiceCtx context, BinaryReader parcelReader);
private Dictionary<(string, int), ServiceProcessParcel> Commands;
private Dictionary<(string, int), ServiceProcessParcel> _commands;
private KEvent BinderEvent;
private KEvent _binderEvent;
private IGalRenderer Renderer;
private IGalRenderer _renderer;
private const int BufferQueueCount = 0x40;
private const int BufferQueueMask = BufferQueueCount - 1;
@ -62,15 +62,15 @@ namespace Ryujinx.HLE.HOS.Services.Android
public GbpBuffer Data;
}
private BufferEntry[] BufferQueue;
private BufferEntry[] _bufferQueue;
private AutoResetEvent WaitBufferFree;
private AutoResetEvent _waitBufferFree;
private bool Disposed;
private bool _disposed;
public NvFlinger(IGalRenderer Renderer, KEvent BinderEvent)
public NvFlinger(IGalRenderer renderer, KEvent binderEvent)
{
Commands = new Dictionary<(string, int), ServiceProcessParcel>()
_commands = new Dictionary<(string, int), ServiceProcessParcel>
{
{ ("android.gui.IGraphicBufferProducer", 0x1), GbpRequestBuffer },
{ ("android.gui.IGraphicBufferProducer", 0x3), GbpDequeueBuffer },
@ -83,307 +83,307 @@ namespace Ryujinx.HLE.HOS.Services.Android
{ ("android.gui.IGraphicBufferProducer", 0xe), GbpPreallocBuffer }
};
this.Renderer = Renderer;
this.BinderEvent = BinderEvent;
_renderer = renderer;
_binderEvent = binderEvent;
BufferQueue = new BufferEntry[0x40];
_bufferQueue = new BufferEntry[0x40];
WaitBufferFree = new AutoResetEvent(false);
_waitBufferFree = new AutoResetEvent(false);
}
public long ProcessParcelRequest(ServiceCtx Context, byte[] ParcelData, int Code)
public long ProcessParcelRequest(ServiceCtx context, byte[] parcelData, int code)
{
using (MemoryStream MS = new MemoryStream(ParcelData))
using (MemoryStream ms = new MemoryStream(parcelData))
{
BinaryReader Reader = new BinaryReader(MS);
BinaryReader reader = new BinaryReader(ms);
MS.Seek(4, SeekOrigin.Current);
ms.Seek(4, SeekOrigin.Current);
int StrSize = Reader.ReadInt32();
int strSize = reader.ReadInt32();
string InterfaceName = Encoding.Unicode.GetString(Reader.ReadBytes(StrSize * 2));
string interfaceName = Encoding.Unicode.GetString(reader.ReadBytes(strSize * 2));
long Remainder = MS.Position & 0xf;
long remainder = ms.Position & 0xf;
if (Remainder != 0)
if (remainder != 0)
{
MS.Seek(0x10 - Remainder, SeekOrigin.Current);
ms.Seek(0x10 - remainder, SeekOrigin.Current);
}
MS.Seek(0x50, SeekOrigin.Begin);
ms.Seek(0x50, SeekOrigin.Begin);
if (Commands.TryGetValue((InterfaceName, Code), out ServiceProcessParcel ProcReq))
if (_commands.TryGetValue((interfaceName, code), out ServiceProcessParcel procReq))
{
Logger.PrintDebug(LogClass.ServiceVi, $"{InterfaceName} {ProcReq.Method.Name}");
Logger.PrintDebug(LogClass.ServiceVi, $"{interfaceName} {procReq.Method.Name}");
return ProcReq(Context, Reader);
return procReq(context, reader);
}
else
{
throw new NotImplementedException($"{InterfaceName} {Code}");
throw new NotImplementedException($"{interfaceName} {code}");
}
}
}
private long GbpRequestBuffer(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpRequestBuffer(ServiceCtx context, BinaryReader parcelReader)
{
int Slot = ParcelReader.ReadInt32();
int slot = parcelReader.ReadInt32();
using (MemoryStream MS = new MemoryStream())
using (MemoryStream ms = new MemoryStream())
{
BinaryWriter Writer = new BinaryWriter(MS);
BinaryWriter writer = new BinaryWriter(ms);
BufferEntry Entry = BufferQueue[Slot];
BufferEntry entry = _bufferQueue[slot];
int BufferCount = 1; //?
long BufferSize = Entry.Data.Size;
int bufferCount = 1; //?
long bufferSize = entry.Data.Size;
Writer.Write(BufferCount);
Writer.Write(BufferSize);
writer.Write(bufferCount);
writer.Write(bufferSize);
Entry.Data.Write(Writer);
entry.Data.Write(writer);
Writer.Write(0);
writer.Write(0);
return MakeReplyParcel(Context, MS.ToArray());
return MakeReplyParcel(context, ms.ToArray());
}
}
private long GbpDequeueBuffer(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpDequeueBuffer(ServiceCtx context, BinaryReader parcelReader)
{
//TODO: Errors.
int Format = ParcelReader.ReadInt32();
int Width = ParcelReader.ReadInt32();
int Height = ParcelReader.ReadInt32();
int GetTimestamps = ParcelReader.ReadInt32();
int Usage = ParcelReader.ReadInt32();
int format = parcelReader.ReadInt32();
int width = parcelReader.ReadInt32();
int height = parcelReader.ReadInt32();
int getTimestamps = parcelReader.ReadInt32();
int usage = parcelReader.ReadInt32();
int Slot = GetFreeSlotBlocking(Width, Height);
int slot = GetFreeSlotBlocking(width, height);
return MakeReplyParcel(Context, Slot, 1, 0x24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
return MakeReplyParcel(context, slot, 1, 0x24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
private long GbpQueueBuffer(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpQueueBuffer(ServiceCtx context, BinaryReader parcelReader)
{
Context.Device.Statistics.RecordGameFrameTime();
context.Device.Statistics.RecordGameFrameTime();
//TODO: Errors.
int Slot = ParcelReader.ReadInt32();
int Unknown4 = ParcelReader.ReadInt32();
int Unknown8 = ParcelReader.ReadInt32();
int Unknownc = ParcelReader.ReadInt32();
int Timestamp = ParcelReader.ReadInt32();
int IsAutoTimestamp = ParcelReader.ReadInt32();
int CropTop = ParcelReader.ReadInt32();
int CropLeft = ParcelReader.ReadInt32();
int CropRight = ParcelReader.ReadInt32();
int CropBottom = ParcelReader.ReadInt32();
int ScalingMode = ParcelReader.ReadInt32();
int Transform = ParcelReader.ReadInt32();
int StickyTransform = ParcelReader.ReadInt32();
int Unknown34 = ParcelReader.ReadInt32();
int Unknown38 = ParcelReader.ReadInt32();
int IsFenceValid = ParcelReader.ReadInt32();
int Fence0Id = ParcelReader.ReadInt32();
int Fence0Value = ParcelReader.ReadInt32();
int Fence1Id = ParcelReader.ReadInt32();
int Fence1Value = ParcelReader.ReadInt32();
int slot = parcelReader.ReadInt32();
int unknown4 = parcelReader.ReadInt32();
int unknown8 = parcelReader.ReadInt32();
int unknownC = parcelReader.ReadInt32();
int timestamp = parcelReader.ReadInt32();
int isAutoTimestamp = parcelReader.ReadInt32();
int cropTop = parcelReader.ReadInt32();
int cropLeft = parcelReader.ReadInt32();
int cropRight = parcelReader.ReadInt32();
int cropBottom = parcelReader.ReadInt32();
int scalingMode = parcelReader.ReadInt32();
int transform = parcelReader.ReadInt32();
int stickyTransform = parcelReader.ReadInt32();
int unknown34 = parcelReader.ReadInt32();
int unknown38 = parcelReader.ReadInt32();
int isFenceValid = parcelReader.ReadInt32();
int fence0Id = parcelReader.ReadInt32();
int fence0Value = parcelReader.ReadInt32();
int fence1Id = parcelReader.ReadInt32();
int fence1Value = parcelReader.ReadInt32();
BufferQueue[Slot].Transform = (HalTransform)Transform;
_bufferQueue[slot].Transform = (HalTransform)transform;
BufferQueue[Slot].Crop.Top = CropTop;
BufferQueue[Slot].Crop.Left = CropLeft;
BufferQueue[Slot].Crop.Right = CropRight;
BufferQueue[Slot].Crop.Bottom = CropBottom;
_bufferQueue[slot].Crop.Top = cropTop;
_bufferQueue[slot].Crop.Left = cropLeft;
_bufferQueue[slot].Crop.Right = cropRight;
_bufferQueue[slot].Crop.Bottom = cropBottom;
BufferQueue[Slot].State = BufferState.Queued;
_bufferQueue[slot].State = BufferState.Queued;
SendFrameBuffer(Context, Slot);
SendFrameBuffer(context, slot);
if (Context.Device.EnableDeviceVsync)
if (context.Device.EnableDeviceVsync)
{
Context.Device.VsyncEvent.WaitOne();
context.Device.VsyncEvent.WaitOne();
}
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
return MakeReplyParcel(context, 1280, 720, 0, 0, 0);
}
private long GbpDetachBuffer(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpDetachBuffer(ServiceCtx context, BinaryReader parcelReader)
{
return MakeReplyParcel(Context, 0);
return MakeReplyParcel(context, 0);
}
private long GbpCancelBuffer(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpCancelBuffer(ServiceCtx context, BinaryReader parcelReader)
{
//TODO: Errors.
int Slot = ParcelReader.ReadInt32();
int slot = parcelReader.ReadInt32();
BufferQueue[Slot].State = BufferState.Free;
_bufferQueue[slot].State = BufferState.Free;
WaitBufferFree.Set();
_waitBufferFree.Set();
return MakeReplyParcel(Context, 0);
return MakeReplyParcel(context, 0);
}
private long GbpQuery(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpQuery(ServiceCtx context, BinaryReader parcelReader)
{
return MakeReplyParcel(Context, 0, 0);
return MakeReplyParcel(context, 0, 0);
}
private long GbpConnect(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpConnect(ServiceCtx context, BinaryReader parcelReader)
{
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
return MakeReplyParcel(context, 1280, 720, 0, 0, 0);
}
private long GbpDisconnect(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpDisconnect(ServiceCtx context, BinaryReader parcelReader)
{
return MakeReplyParcel(Context, 0);
return MakeReplyParcel(context, 0);
}
private long GbpPreallocBuffer(ServiceCtx Context, BinaryReader ParcelReader)
private long GbpPreallocBuffer(ServiceCtx context, BinaryReader parcelReader)
{
int Slot = ParcelReader.ReadInt32();
int slot = parcelReader.ReadInt32();
int BufferCount = ParcelReader.ReadInt32();
int bufferCount = parcelReader.ReadInt32();
if (BufferCount > 0)
if (bufferCount > 0)
{
long BufferSize = ParcelReader.ReadInt64();
long bufferSize = parcelReader.ReadInt64();
BufferQueue[Slot].State = BufferState.Free;
_bufferQueue[slot].State = BufferState.Free;
BufferQueue[Slot].Data = new GbpBuffer(ParcelReader);
_bufferQueue[slot].Data = new GbpBuffer(parcelReader);
}
return MakeReplyParcel(Context, 0);
return MakeReplyParcel(context, 0);
}
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())
{
BinaryWriter Writer = new BinaryWriter(MS);
BinaryWriter writer = new BinaryWriter(ms);
foreach (int Int in Ints)
foreach (int Int in ints)
{
Writer.Write(Int);
writer.Write(Int);
}
return MakeReplyParcel(Context, MS.ToArray());
return MakeReplyParcel(context, ms.ToArray());
}
}
private long MakeReplyParcel(ServiceCtx Context, byte[] Data)
private long MakeReplyParcel(ServiceCtx context, byte[] data)
{
(long ReplyPos, long ReplySize) = Context.Request.GetBufferType0x22();
(long replyPos, long replySize) = context.Request.GetBufferType0x22();
byte[] Reply = MakeParcel(Data, new byte[0]);
byte[] reply = MakeParcel(data, new byte[0]);
Context.Memory.WriteBytes(ReplyPos, Reply);
context.Memory.WriteBytes(replyPos, reply);
return 0;
}
private void SendFrameBuffer(ServiceCtx Context, int Slot)
private void SendFrameBuffer(ServiceCtx context, int slot)
{
int FbWidth = BufferQueue[Slot].Data.Width;
int FbHeight = BufferQueue[Slot].Data.Height;
int fbWidth = _bufferQueue[slot].Data.Width;
int fbHeight = _bufferQueue[slot].Data.Height;
int NvMapHandle = BitConverter.ToInt32(BufferQueue[Slot].Data.RawData, 0x4c);
int BufferOffset = BitConverter.ToInt32(BufferQueue[Slot].Data.RawData, 0x50);
int nvMapHandle = BitConverter.ToInt32(_bufferQueue[slot].Data.RawData, 0x4c);
int bufferOffset = BitConverter.ToInt32(_bufferQueue[slot].Data.RawData, 0x50);
NvMapHandle Map = NvMapIoctl.GetNvMap(Context, NvMapHandle);;
NvMapHandle map = NvMapIoctl.GetNvMap(context, nvMapHandle);
long FbAddr = Map.Address + BufferOffset;
long fbAddr = map.Address + bufferOffset;
BufferQueue[Slot].State = BufferState.Acquired;
_bufferQueue[slot].State = BufferState.Acquired;
Rect Crop = BufferQueue[Slot].Crop;
Rect crop = _bufferQueue[slot].Crop;
bool FlipX = BufferQueue[Slot].Transform.HasFlag(HalTransform.FlipX);
bool FlipY = BufferQueue[Slot].Transform.HasFlag(HalTransform.FlipY);
bool flipX = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipX);
bool flipY = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipY);
//Note: Rotation is being ignored.
int Top = Crop.Top;
int Left = Crop.Left;
int Right = Crop.Right;
int Bottom = Crop.Bottom;
int top = crop.Top;
int left = crop.Left;
int right = crop.Right;
int bottom = crop.Bottom;
NvGpuVmm Vmm = NvGpuASIoctl.GetASCtx(Context).Vmm;
NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm;
Renderer.QueueAction(() =>
_renderer.QueueAction(() =>
{
if (!Renderer.Texture.TryGetImage(FbAddr, out GalImage Image))
if (!_renderer.Texture.TryGetImage(fbAddr, out GalImage image))
{
Image = new GalImage(
FbWidth,
FbHeight, 1, 16,
image = new GalImage(
fbWidth,
fbHeight, 1, 16,
GalMemoryLayout.BlockLinear,
GalImageFormat.RGBA8 | GalImageFormat.Unorm);
}
Context.Device.Gpu.ResourceManager.ClearPbCache();
Context.Device.Gpu.ResourceManager.SendTexture(Vmm, FbAddr, Image);
context.Device.Gpu.ResourceManager.ClearPbCache();
context.Device.Gpu.ResourceManager.SendTexture(vmm, fbAddr, image);
Renderer.RenderTarget.SetTransform(FlipX, FlipY, Top, Left, Right, Bottom);
Renderer.RenderTarget.Present(FbAddr);
_renderer.RenderTarget.SetTransform(flipX, flipY, top, left, right, bottom);
_renderer.RenderTarget.Present(fbAddr);
ReleaseBuffer(Slot);
ReleaseBuffer(slot);
});
}
private void ReleaseBuffer(int Slot)
private void ReleaseBuffer(int slot)
{
BufferQueue[Slot].State = BufferState.Free;
_bufferQueue[slot].State = BufferState.Free;
BinderEvent.ReadableEvent.Signal();
_binderEvent.ReadableEvent.Signal();
WaitBufferFree.Set();
_waitBufferFree.Set();
}
private int GetFreeSlotBlocking(int Width, int Height)
private int GetFreeSlotBlocking(int width, int height)
{
int Slot;
int slot;
do
{
if ((Slot = GetFreeSlot(Width, Height)) != -1)
if ((slot = GetFreeSlot(width, height)) != -1)
{
break;
}
if (Disposed)
if (_disposed)
{
break;
}
WaitBufferFree.WaitOne();
_waitBufferFree.WaitOne();
}
while (!Disposed);
while (!_disposed);
return Slot;
return slot;
}
private int GetFreeSlot(int Width, int Height)
private int GetFreeSlot(int width, int height)
{
lock (BufferQueue)
lock (_bufferQueue)
{
for (int Slot = 0; Slot < BufferQueue.Length; Slot++)
for (int slot = 0; slot < _bufferQueue.Length; slot++)
{
if (BufferQueue[Slot].State != BufferState.Free)
if (_bufferQueue[slot].State != BufferState.Free)
{
continue;
}
GbpBuffer Data = BufferQueue[Slot].Data;
GbpBuffer data = _bufferQueue[slot].Data;
if (Data.Width == Width &&
Data.Height == Height)
if (data.Width == width &&
data.Height == height)
{
BufferQueue[Slot].State = BufferState.Dequeued;
_bufferQueue[slot].State = BufferState.Dequeued;
return Slot;
return slot;
}
}
}
@ -396,14 +396,14 @@ namespace Ryujinx.HLE.HOS.Services.Android
Dispose(true);
}
protected virtual void Dispose(bool Disposing)
protected virtual void Dispose(bool disposing)
{
if (Disposing && !Disposed)
if (disposing && !_disposed)
{
Disposed = true;
_disposed = true;
WaitBufferFree.Set();
WaitBufferFree.Dispose();
_waitBufferFree.Set();
_waitBufferFree.Dispose();
}
}
}

View File

@ -5,53 +5,53 @@ namespace Ryujinx.HLE.HOS.Services.Android
{
static class Parcel
{
public static byte[] GetParcelData(byte[] Parcel)
public static byte[] GetParcelData(byte[] parcel)
{
if (Parcel == null)
if (parcel == null)
{
throw new ArgumentNullException(nameof(Parcel));
throw new ArgumentNullException(nameof(parcel));
}
using (MemoryStream MS = new MemoryStream(Parcel))
using (MemoryStream ms = new MemoryStream(parcel))
{
BinaryReader Reader = new BinaryReader(MS);
BinaryReader reader = new BinaryReader(ms);
int DataSize = Reader.ReadInt32();
int DataOffset = Reader.ReadInt32();
int ObjsSize = Reader.ReadInt32();
int ObjsOffset = Reader.ReadInt32();
int dataSize = reader.ReadInt32();
int dataOffset = reader.ReadInt32();
int objsSize = reader.ReadInt32();
int objsOffset = reader.ReadInt32();
MS.Seek(DataOffset - 0x10, SeekOrigin.Current);
ms.Seek(dataOffset - 0x10, SeekOrigin.Current);
return Reader.ReadBytes(DataSize);
return reader.ReadBytes(dataSize);
}
}
public static byte[] MakeParcel(byte[] Data, byte[] Objs)
public static byte[] MakeParcel(byte[] data, byte[] objs)
{
if (Data == null)
if (data == null)
{
throw new ArgumentNullException(nameof(Data));
throw new ArgumentNullException(nameof(data));
}
if (Objs == null)
if (objs == null)
{
throw new ArgumentNullException(nameof(Objs));
throw new ArgumentNullException(nameof(objs));
}
using (MemoryStream MS = new MemoryStream())
using (MemoryStream ms = new MemoryStream())
{
BinaryWriter Writer = new BinaryWriter(MS);
BinaryWriter writer = new BinaryWriter(ms);
Writer.Write(Data.Length);
Writer.Write(0x10);
Writer.Write(Objs.Length);
Writer.Write(Data.Length + 0x10);
writer.Write(data.Length);
writer.Write(0x10);
writer.Write(objs.Length);
writer.Write(data.Length + 0x10);
Writer.Write(Data);
Writer.Write(Objs);
writer.Write(data);
writer.Write(objs);
return MS.ToArray();
return ms.ToArray();
}
}
}