IHOSBinderDriver.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Ryujinx.Graphics.Gal;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Kernel.Threading;
  5. using Ryujinx.HLE.HOS.Services.SurfaceFlinger;
  6. using System;
  7. namespace Ryujinx.HLE.HOS.Services.Vi.RootService.ApplicationDisplayService
  8. {
  9. class IHOSBinderDriver : IpcService, IDisposable
  10. {
  11. private KEvent _binderEvent;
  12. private NvFlinger _flinger;
  13. public IHOSBinderDriver(Horizon system, IGalRenderer renderer)
  14. {
  15. _binderEvent = new KEvent(system);
  16. _binderEvent.ReadableEvent.Signal();
  17. _flinger = new NvFlinger(renderer, _binderEvent);
  18. }
  19. [Command(0)]
  20. // TransactParcel(s32, u32, u32, buffer<unknown, 5, 0>) -> buffer<unknown, 6, 0>
  21. public ResultCode TransactParcel(ServiceCtx context)
  22. {
  23. int id = context.RequestData.ReadInt32();
  24. int code = context.RequestData.ReadInt32();
  25. long dataPos = context.Request.SendBuff[0].Position;
  26. long dataSize = context.Request.SendBuff[0].Size;
  27. byte[] data = context.Memory.ReadBytes(dataPos, dataSize);
  28. data = Parcel.GetParcelData(data);
  29. return (ResultCode)_flinger.ProcessParcelRequest(context, data, code);
  30. }
  31. [Command(1)]
  32. // AdjustRefcount(s32, s32, s32)
  33. public ResultCode AdjustRefcount(ServiceCtx context)
  34. {
  35. int id = context.RequestData.ReadInt32();
  36. int addVal = context.RequestData.ReadInt32();
  37. int type = context.RequestData.ReadInt32();
  38. return ResultCode.Success;
  39. }
  40. [Command(2)]
  41. // GetNativeHandle(s32, s32) -> handle<copy>
  42. public ResultCode GetNativeHandle(ServiceCtx context)
  43. {
  44. int id = context.RequestData.ReadInt32();
  45. uint unk = context.RequestData.ReadUInt32();
  46. if (context.Process.HandleTable.GenerateHandle(_binderEvent.ReadableEvent, out int handle) != KernelResult.Success)
  47. {
  48. throw new InvalidOperationException("Out of handles!");
  49. }
  50. context.Response.HandleDesc = IpcHandleDesc.MakeMove(handle);
  51. return ResultCode.Success;
  52. }
  53. [Command(3)] // 3.0.0+
  54. // TransactParcelAuto(s32, u32, u32, buffer<unknown, 21, 0>) -> buffer<unknown, 22, 0>
  55. public ResultCode TransactParcelAuto(ServiceCtx context)
  56. {
  57. int id = context.RequestData.ReadInt32();
  58. int code = context.RequestData.ReadInt32();
  59. (long dataPos, long dataSize) = context.Request.GetBufferType0x21();
  60. byte[] data = context.Memory.ReadBytes(dataPos, dataSize);
  61. data = Parcel.GetParcelData(data);
  62. return (ResultCode)_flinger.ProcessParcelRequest(context, data, code);
  63. }
  64. public void Dispose()
  65. {
  66. Dispose(true);
  67. }
  68. protected virtual void Dispose(bool disposing)
  69. {
  70. if (disposing)
  71. {
  72. _flinger.Dispose();
  73. }
  74. }
  75. }
  76. }