2018-02-04 18:08:20 -05:00
|
|
|
using ChocolArm64.Memory;
|
2018-02-20 15:09:23 -05:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
|
|
|
using Ryujinx.Core.OsHle.Ipc;
|
2018-02-09 19:14:55 -05:00
|
|
|
using System.Collections.Generic;
|
2018-02-04 18:08:20 -05:00
|
|
|
using System.IO;
|
|
|
|
|
2018-02-24 23:34:16 -05:00
|
|
|
using static Ryujinx.Core.OsHle.IpcServices.Android.Parcel;
|
|
|
|
using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-02-24 23:34:16 -05:00
|
|
|
namespace Ryujinx.Core.OsHle.IpcServices.Vi
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-24 23:34:16 -05:00
|
|
|
class IApplicationDisplayService : IIpcService
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
|
|
|
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
|
|
|
|
|
|
|
public IApplicationDisplayService()
|
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 100, GetRelayService },
|
|
|
|
{ 101, GetSystemDisplayService },
|
|
|
|
{ 102, GetManagerDisplayService },
|
|
|
|
{ 103, GetIndirectDisplayTransactionService },
|
|
|
|
{ 1010, OpenDisplay },
|
2018-03-06 08:25:26 -05:00
|
|
|
{ 1020, CloseDisplay },
|
2018-02-09 19:14:55 -05:00
|
|
|
{ 2020, OpenLayer },
|
2018-03-06 15:27:50 -05:00
|
|
|
{ 2021, CloseLayer },
|
2018-02-09 19:14:55 -05:00
|
|
|
{ 2030, CreateStrayLayer },
|
|
|
|
{ 2101, SetLayerScalingMode },
|
|
|
|
{ 5202, GetDisplayVSyncEvent }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public long GetRelayService(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
MakeObject(Context, new IHOSBinderDriver());
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long GetSystemDisplayService(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
MakeObject(Context, new ISystemDisplayService());
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long GetManagerDisplayService(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
MakeObject(Context, new IManagerDisplayService());
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long GetIndirectDisplayTransactionService(ServiceCtx Context)
|
2018-02-06 18:28:32 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
MakeObject(Context, new IHOSBinderDriver());
|
2018-02-06 18:28:32 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long OpenDisplay(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
string Name = GetDisplayName(Context);
|
|
|
|
|
|
|
|
long DisplayId = Context.Ns.Os.Displays.GenerateId(new Display(Name));
|
|
|
|
|
|
|
|
Context.ResponseData.Write(DisplayId);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-06 08:25:26 -05:00
|
|
|
public long CloseDisplay(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
int DisplayId = Context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
Context.Ns.Os.Displays.Delete(DisplayId);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long OpenLayer(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long LayerId = Context.RequestData.ReadInt64();
|
|
|
|
long UserId = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
|
|
|
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
|
|
|
|
|
|
|
|
AMemoryHelper.WriteBytes(Context.Memory, ParcelPtr, Parcel);
|
|
|
|
|
|
|
|
Context.ResponseData.Write((long)Parcel.Length);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-06 15:27:50 -05:00
|
|
|
public long CloseLayer(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long CreateStrayLayer(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long LayerFlags = Context.RequestData.ReadInt64();
|
|
|
|
long DisplayId = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
|
|
|
Display Disp = Context.Ns.Os.Displays.GetData<Display>((int)DisplayId);
|
|
|
|
|
|
|
|
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
|
|
|
|
|
|
|
|
AMemoryHelper.WriteBytes(Context.Memory, ParcelPtr, Parcel);
|
|
|
|
|
|
|
|
Context.ResponseData.Write(0L);
|
|
|
|
Context.ResponseData.Write((long)Parcel.Length);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long SetLayerScalingMode(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
int ScalingMode = Context.RequestData.ReadInt32();
|
|
|
|
long Unknown = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long GetDisplayVSyncEvent(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
string Name = GetDisplayName(Context);
|
|
|
|
|
|
|
|
int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());
|
|
|
|
|
|
|
|
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
private byte[] MakeIGraphicsBufferProducer(long BasePtr)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
long Id = 0x20;
|
|
|
|
long CookiePtr = 0L;
|
|
|
|
|
|
|
|
using (MemoryStream MS = new MemoryStream())
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
return MakeParcel(MS.ToArray(), new byte[] { 0, 0, 0, 0 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
private string GetDisplayName(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
string Name = string.Empty;
|
|
|
|
|
|
|
|
for (int Index = 0; Index < 8 &&
|
|
|
|
Context.RequestData.BaseStream.Position <
|
|
|
|
Context.RequestData.BaseStream.Length; Index++)
|
|
|
|
{
|
|
|
|
byte Chr = Context.RequestData.ReadByte();
|
|
|
|
|
|
|
|
if (Chr >= 0x20 && Chr < 0x7f)
|
|
|
|
{
|
|
|
|
Name += (char)Chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|