ISharedFontManager.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Ryujinx.HLE.HOS.Font;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Ryujinx.HLE.HOS.Services.Pl
  7. {
  8. class ISharedFontManager : IpcService
  9. {
  10. private Dictionary<int, ServiceProcessRequest> _commands;
  11. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  12. public ISharedFontManager()
  13. {
  14. _commands = new Dictionary<int, ServiceProcessRequest>
  15. {
  16. { 0, RequestLoad },
  17. { 1, GetLoadState },
  18. { 2, GetFontSize },
  19. { 3, GetSharedMemoryAddressOffset },
  20. { 4, GetSharedMemoryNativeHandle },
  21. { 5, GetSharedFontInOrderOfPriority }
  22. };
  23. }
  24. public long RequestLoad(ServiceCtx context)
  25. {
  26. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  27. //We don't need to do anything here because we do lazy initialization
  28. //on SharedFontManager (the font is loaded when necessary).
  29. return 0;
  30. }
  31. public long GetLoadState(ServiceCtx context)
  32. {
  33. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  34. //1 (true) indicates that the font is already loaded.
  35. //All fonts are already loaded.
  36. context.ResponseData.Write(1);
  37. return 0;
  38. }
  39. public long GetFontSize(ServiceCtx context)
  40. {
  41. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  42. context.ResponseData.Write(context.Device.System.Font.GetFontSize(fontType));
  43. return 0;
  44. }
  45. public long GetSharedMemoryAddressOffset(ServiceCtx context)
  46. {
  47. SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
  48. context.ResponseData.Write(context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
  49. return 0;
  50. }
  51. public long GetSharedMemoryNativeHandle(ServiceCtx context)
  52. {
  53. context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager);
  54. if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out int handle) != KernelResult.Success)
  55. {
  56. throw new InvalidOperationException("Out of handles!");
  57. }
  58. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
  59. return 0;
  60. }
  61. public long 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 0;
  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. }