2018-07-24 23:38:44 +02:00
|
|
|
using ChocolArm64.Memory;
|
2018-06-11 02:46:42 +02:00
|
|
|
using Ryujinx.HLE.OsHle.Ipc;
|
2018-02-10 01:14:55 +01:00
|
|
|
using System.Collections.Generic;
|
2018-02-05 00:08:20 +01:00
|
|
|
using System.IO;
|
2018-07-24 23:38:44 +02:00
|
|
|
using System.Text;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-06-11 02:46:42 +02:00
|
|
|
using static Ryujinx.HLE.OsHle.Services.Android.Parcel;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-06-11 02:46:42 +02:00
|
|
|
namespace Ryujinx.HLE.OsHle.Services.Vi
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-03-19 19:58:46 +01:00
|
|
|
class IApplicationDisplayService : IpcService
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-10 01:14:55 +01:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-10 01:14:55 +01:00
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
private IdDictionary Displays;
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public IApplicationDisplayService()
|
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
2018-04-24 20:57:39 +02:00
|
|
|
{ 100, GetRelayService },
|
|
|
|
{ 101, GetSystemDisplayService },
|
|
|
|
{ 102, GetManagerDisplayService },
|
|
|
|
{ 103, GetIndirectDisplayTransactionService },
|
2018-07-24 23:38:44 +02:00
|
|
|
{ 1000, ListDisplays },
|
2018-02-10 01:14:55 +01:00
|
|
|
{ 1010, OpenDisplay },
|
2018-03-06 14:25:26 +01:00
|
|
|
{ 1020, CloseDisplay },
|
2018-04-05 00:16:59 +02:00
|
|
|
{ 1102, GetDisplayResolution },
|
2018-02-10 01:14:55 +01:00
|
|
|
{ 2020, OpenLayer },
|
2018-03-06 21:27:50 +01:00
|
|
|
{ 2021, CloseLayer },
|
2018-02-10 01:14:55 +01:00
|
|
|
{ 2030, CreateStrayLayer },
|
2018-03-12 05:04:52 +01:00
|
|
|
{ 2031, DestroyStrayLayer },
|
2018-02-10 01:14:55 +01:00
|
|
|
{ 2101, SetLayerScalingMode },
|
|
|
|
{ 5202, GetDisplayVSyncEvent }
|
|
|
|
};
|
2018-03-12 05:04:52 +01:00
|
|
|
|
|
|
|
Displays = new IdDictionary();
|
2018-02-10 01:14:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public long GetRelayService(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-03-12 05:04:52 +01:00
|
|
|
MakeObject(Context, new IHOSBinderDriver(Context.Ns.Gpu.Renderer));
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long GetSystemDisplayService(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-10 01:14:55 +01:00
|
|
|
MakeObject(Context, new ISystemDisplayService());
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long GetManagerDisplayService(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-10 01:14:55 +01:00
|
|
|
MakeObject(Context, new IManagerDisplayService());
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long GetIndirectDisplayTransactionService(ServiceCtx Context)
|
2018-02-07 00:28:32 +01:00
|
|
|
{
|
2018-03-12 05:04:52 +01:00
|
|
|
MakeObject(Context, new IHOSBinderDriver(Context.Ns.Gpu.Renderer));
|
2018-02-07 00:28:32 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-24 23:38:44 +02:00
|
|
|
public long ListDisplays(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long RecBuffPtr = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
|
|
|
AMemoryHelper.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.ResponseData.Write(1L);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long OpenDisplay(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
string Name = GetDisplayName(Context);
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
long DisplayId = Displays.Add(new Display(Name));
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Context.ResponseData.Write(DisplayId);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-06 14:25:26 +01:00
|
|
|
public long CloseDisplay(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
int DisplayId = Context.RequestData.ReadInt32();
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
Displays.Delete(DisplayId);
|
2018-03-06 14:25:26 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-05 00:16:59 +02:00
|
|
|
public long GetDisplayResolution(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long DisplayId = Context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
Context.ResponseData.Write(1280);
|
|
|
|
Context.ResponseData.Write(720);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long OpenLayer(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
long LayerId = Context.RequestData.ReadInt64();
|
|
|
|
long UserId = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
|
|
|
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
|
|
|
|
|
2018-06-09 18:05:41 +02:00
|
|
|
Context.Memory.WriteBytes(ParcelPtr, Parcel);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Context.ResponseData.Write((long)Parcel.Length);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-06 21:27:50 +01:00
|
|
|
public long CloseLayer(ServiceCtx Context)
|
|
|
|
{
|
2018-03-12 05:04:52 +01:00
|
|
|
long LayerId = Context.RequestData.ReadInt64();
|
|
|
|
|
2018-03-06 21:27:50 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long CreateStrayLayer(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
long LayerFlags = Context.RequestData.ReadInt64();
|
|
|
|
long DisplayId = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
Display Disp = Displays.GetData<Display>((int)DisplayId);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
|
|
|
|
|
2018-06-09 18:05:41 +02:00
|
|
|
Context.Memory.WriteBytes(ParcelPtr, Parcel);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Context.ResponseData.Write(0L);
|
|
|
|
Context.ResponseData.Write((long)Parcel.Length);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
public long DestroyStrayLayer(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long SetLayerScalingMode(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
int ScalingMode = Context.RequestData.ReadInt32();
|
|
|
|
long Unknown = Context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
public long GetDisplayVSyncEvent(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
string Name = GetDisplayName(Context);
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
int Handle = Context.Process.HandleTable.OpenHandle(Context.Ns.Os.VsyncEvent);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 01:14:55 +01:00
|
|
|
private byte[] MakeIGraphicsBufferProducer(long BasePtr)
|
2018-02-05 00:08:20 +01: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-10 01:14:55 +01:00
|
|
|
private string GetDisplayName(ServiceCtx Context)
|
2018-02-05 00:08:20 +01: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|