ISharedFontManager.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Ryujinx.HLE.HOS.Font;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  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. [Command(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. [Command(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. [Command(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.Font.GetFontSize(fontType));
  38. return ResultCode.Success;
  39. }
  40. [Command(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.Font.GetSharedMemoryAddressOffset(fontType));
  46. return ResultCode.Success;
  47. }
  48. [Command(4)]
  49. // GetSharedMemoryNativeHandle() -> handle<copy>
  50. public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
  51. {
  52. context.Device.System.Font.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. [Command(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. int offset = (int)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. private bool AddFontToOrderOfPriorityList(ServiceCtx context, SharedFontType fontType, int offset)
  83. {
  84. long typesPosition = context.Request.ReceiveBuff[0].Position;
  85. long typesSize = context.Request.ReceiveBuff[0].Size;
  86. long offsetsPosition = context.Request.ReceiveBuff[1].Position;
  87. long offsetsSize = context.Request.ReceiveBuff[1].Size;
  88. long fontSizeBufferPosition = context.Request.ReceiveBuff[2].Position;
  89. long fontSizeBufferSize = context.Request.ReceiveBuff[2].Size;
  90. if ((uint)offset + 4 > (uint)typesSize ||
  91. (uint)offset + 4 > (uint)offsetsSize ||
  92. (uint)offset + 4 > (uint)fontSizeBufferSize)
  93. {
  94. return false;
  95. }
  96. context.Memory.Write((ulong)(typesPosition + offset), (int)fontType);
  97. context.Memory.Write((ulong)(offsetsPosition + offset), context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
  98. context.Memory.Write((ulong)(fontSizeBufferPosition + offset), context.Device.System.Font.GetFontSize(fontType));
  99. return true;
  100. }
  101. }
  102. }