ISharedFontManager.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.Kernel.Common;
  3. using Ryujinx.HLE.HOS.Services.Sdb.Pl.Types;
  4. using System;
  5. namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
  6. {
  7. [Service("pl:u")]
  8. [Service("pl:s")] // 9.0.0+
  9. class ISharedFontManager : IpcService
  10. {
  11. private int _fontSharedMemHandle;
  12. public ISharedFontManager(ServiceCtx context) { }
  13. [CommandHipc(0)]
  14. // RequestLoad(u32)
  15. public ResultCode RequestLoad(ServiceCtx context)
  16. {
  17. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  18. // We don't need to do anything here because we do lazy initialization
  19. // on SharedFontManager (the font is loaded when necessary).
  20. return ResultCode.Success;
  21. }
  22. [CommandHipc(1)]
  23. // GetLoadState(u32) -> u32
  24. public ResultCode GetLoadState(ServiceCtx context)
  25. {
  26. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  27. // 1 (true) indicates that the font is already loaded.
  28. // All fonts are already loaded.
  29. context.ResponseData.Write(1);
  30. return ResultCode.Success;
  31. }
  32. [CommandHipc(2)]
  33. // GetFontSize(u32) -> u32
  34. public ResultCode GetFontSize(ServiceCtx context)
  35. {
  36. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  37. context.ResponseData.Write(context.Device.System.SharedFontManager.GetFontSize(fontType));
  38. return ResultCode.Success;
  39. }
  40. [CommandHipc(3)]
  41. // GetSharedMemoryAddressOffset(u32) -> u32
  42. public ResultCode GetSharedMemoryAddressOffset(ServiceCtx context)
  43. {
  44. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  45. context.ResponseData.Write(context.Device.System.SharedFontManager.GetSharedMemoryAddressOffset(fontType));
  46. return ResultCode.Success;
  47. }
  48. [CommandHipc(4)]
  49. // GetSharedMemoryNativeHandle() -> handle<copy>
  50. public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
  51. {
  52. context.Device.System.SharedFontManager.EnsureInitialized(context.Device.System.ContentManager);
  53. if (_fontSharedMemHandle == 0)
  54. {
  55. if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out _fontSharedMemHandle) != KernelResult.Success)
  56. {
  57. throw new InvalidOperationException("Out of handles!");
  58. }
  59. }
  60. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_fontSharedMemHandle);
  61. return ResultCode.Success;
  62. }
  63. [CommandHipc(5)]
  64. // GetSharedFontInOrderOfPriority(bytes<8, 1>) -> (u8, u32, buffer<unknown, 6>, buffer<unknown, 6>, buffer<unknown, 6>)
  65. public ResultCode GetSharedFontInOrderOfPriority(ServiceCtx context)
  66. {
  67. long languageCode = context.RequestData.ReadInt64();
  68. int loadedCount = 0;
  69. for (SharedFontType type = 0; type < SharedFontType.Count; type++)
  70. {
  71. uint offset = (uint)type * 4;
  72. if (!AddFontToOrderOfPriorityList(context, type, offset))
  73. {
  74. break;
  75. }
  76. loadedCount++;
  77. }
  78. context.ResponseData.Write(loadedCount);
  79. context.ResponseData.Write((int)SharedFontType.Count);
  80. return ResultCode.Success;
  81. }
  82. [CommandHipc(6)] // 4.0.0+
  83. // GetSharedFontInOrderOfPriorityForSystem(bytes<8, 1>) -> (u8, u32, buffer<unknown, 6>, buffer<unknown, 6>, buffer<unknown, 6>)
  84. public ResultCode GetSharedFontInOrderOfPriorityForSystem(ServiceCtx context)
  85. {
  86. // TODO: Check the differencies with GetSharedFontInOrderOfPriority.
  87. return GetSharedFontInOrderOfPriority(context);
  88. }
  89. private bool AddFontToOrderOfPriorityList(ServiceCtx context, SharedFontType fontType, uint offset)
  90. {
  91. ulong typesPosition = context.Request.ReceiveBuff[0].Position;
  92. ulong typesSize = context.Request.ReceiveBuff[0].Size;
  93. ulong offsetsPosition = context.Request.ReceiveBuff[1].Position;
  94. ulong offsetsSize = context.Request.ReceiveBuff[1].Size;
  95. ulong fontSizeBufferPosition = context.Request.ReceiveBuff[2].Position;
  96. ulong fontSizeBufferSize = context.Request.ReceiveBuff[2].Size;
  97. if (offset + 4 > (uint)typesSize ||
  98. offset + 4 > (uint)offsetsSize ||
  99. offset + 4 > (uint)fontSizeBufferSize)
  100. {
  101. return false;
  102. }
  103. context.Memory.Write(typesPosition + offset, (int)fontType);
  104. context.Memory.Write(offsetsPosition + offset, context.Device.System.SharedFontManager.GetSharedMemoryAddressOffset(fontType));
  105. context.Memory.Write(fontSizeBufferPosition + offset, context.Device.System.SharedFontManager.GetFontSize(fontType));
  106. return true;
  107. }
  108. }
  109. }