IApplicationDisplayService.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Core.OsHle.Handles;
  3. using Ryujinx.Core.OsHle.Ipc;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using static Ryujinx.Core.OsHle.IpcServices.Android.Parcel;
  7. using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
  8. namespace Ryujinx.Core.OsHle.IpcServices.Vi
  9. {
  10. class IApplicationDisplayService : IIpcService
  11. {
  12. private Dictionary<int, ServiceProcessRequest> m_Commands;
  13. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  14. public IApplicationDisplayService()
  15. {
  16. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  17. {
  18. { 100, GetRelayService },
  19. { 101, GetSystemDisplayService },
  20. { 102, GetManagerDisplayService },
  21. { 103, GetIndirectDisplayTransactionService },
  22. { 1010, OpenDisplay },
  23. { 1020, CloseDisplay },
  24. { 2020, OpenLayer },
  25. { 2021, CloseLayer },
  26. { 2030, CreateStrayLayer },
  27. { 2101, SetLayerScalingMode },
  28. { 5202, GetDisplayVSyncEvent }
  29. };
  30. }
  31. public long GetRelayService(ServiceCtx Context)
  32. {
  33. MakeObject(Context, new IHOSBinderDriver());
  34. return 0;
  35. }
  36. public long GetSystemDisplayService(ServiceCtx Context)
  37. {
  38. MakeObject(Context, new ISystemDisplayService());
  39. return 0;
  40. }
  41. public long GetManagerDisplayService(ServiceCtx Context)
  42. {
  43. MakeObject(Context, new IManagerDisplayService());
  44. return 0;
  45. }
  46. public long GetIndirectDisplayTransactionService(ServiceCtx Context)
  47. {
  48. MakeObject(Context, new IHOSBinderDriver());
  49. return 0;
  50. }
  51. public long OpenDisplay(ServiceCtx Context)
  52. {
  53. string Name = GetDisplayName(Context);
  54. long DisplayId = Context.Ns.Os.Displays.GenerateId(new Display(Name));
  55. Context.ResponseData.Write(DisplayId);
  56. return 0;
  57. }
  58. public long CloseDisplay(ServiceCtx Context)
  59. {
  60. int DisplayId = Context.RequestData.ReadInt32();
  61. Context.Ns.Os.Displays.Delete(DisplayId);
  62. return 0;
  63. }
  64. public long OpenLayer(ServiceCtx Context)
  65. {
  66. long LayerId = Context.RequestData.ReadInt64();
  67. long UserId = Context.RequestData.ReadInt64();
  68. long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
  69. byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
  70. AMemoryHelper.WriteBytes(Context.Memory, ParcelPtr, Parcel);
  71. Context.ResponseData.Write((long)Parcel.Length);
  72. return 0;
  73. }
  74. public long CloseLayer(ServiceCtx Context)
  75. {
  76. return 0;
  77. }
  78. public long CreateStrayLayer(ServiceCtx Context)
  79. {
  80. long LayerFlags = Context.RequestData.ReadInt64();
  81. long DisplayId = Context.RequestData.ReadInt64();
  82. long ParcelPtr = Context.Request.ReceiveBuff[0].Position;
  83. Display Disp = Context.Ns.Os.Displays.GetData<Display>((int)DisplayId);
  84. byte[] Parcel = MakeIGraphicsBufferProducer(ParcelPtr);
  85. AMemoryHelper.WriteBytes(Context.Memory, ParcelPtr, Parcel);
  86. Context.ResponseData.Write(0L);
  87. Context.ResponseData.Write((long)Parcel.Length);
  88. return 0;
  89. }
  90. public long SetLayerScalingMode(ServiceCtx Context)
  91. {
  92. int ScalingMode = Context.RequestData.ReadInt32();
  93. long Unknown = Context.RequestData.ReadInt64();
  94. return 0;
  95. }
  96. public long GetDisplayVSyncEvent(ServiceCtx Context)
  97. {
  98. string Name = GetDisplayName(Context);
  99. int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());
  100. Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
  101. return 0;
  102. }
  103. private byte[] MakeIGraphicsBufferProducer(long BasePtr)
  104. {
  105. long Id = 0x20;
  106. long CookiePtr = 0L;
  107. using (MemoryStream MS = new MemoryStream())
  108. {
  109. BinaryWriter Writer = new BinaryWriter(MS);
  110. //flat_binder_object (size is 0x28)
  111. Writer.Write(2); //Type (BINDER_TYPE_WEAK_BINDER)
  112. Writer.Write(0); //Flags
  113. Writer.Write((int)(Id >> 0));
  114. Writer.Write((int)(Id >> 32));
  115. Writer.Write((int)(CookiePtr >> 0));
  116. Writer.Write((int)(CookiePtr >> 32));
  117. Writer.Write((byte)'d');
  118. Writer.Write((byte)'i');
  119. Writer.Write((byte)'s');
  120. Writer.Write((byte)'p');
  121. Writer.Write((byte)'d');
  122. Writer.Write((byte)'r');
  123. Writer.Write((byte)'v');
  124. Writer.Write((byte)'\0');
  125. Writer.Write(0L); //Pad
  126. return MakeParcel(MS.ToArray(), new byte[] { 0, 0, 0, 0 });
  127. }
  128. }
  129. private string GetDisplayName(ServiceCtx Context)
  130. {
  131. string Name = string.Empty;
  132. for (int Index = 0; Index < 8 &&
  133. Context.RequestData.BaseStream.Position <
  134. Context.RequestData.BaseStream.Length; Index++)
  135. {
  136. byte Chr = Context.RequestData.ReadByte();
  137. if (Chr >= 0x20 && Chr < 0x7f)
  138. {
  139. Name += (char)Chr;
  140. }
  141. }
  142. return Name;
  143. }
  144. }
  145. }