ISharedFontManager.cs 4.4 KB

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