2018-08-16 19:47:36 -04:00
|
|
|
using Ryujinx.HLE.HOS.Font;
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-12-18 00:33:36 -05:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2018-09-23 14:11:46 -04:00
|
|
|
using System;
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-09-18 20:45:11 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-07-10 11:59:54 -04:00
|
|
|
[Service("pl:u")]
|
2019-09-18 20:45:11 -04:00
|
|
|
[Service("pl:s")] // 9.0.0+
|
2018-04-06 00:01:52 -04:00
|
|
|
class ISharedFontManager : IpcService
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
private int _fontSharedMemHandle;
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
public ISharedFontManager(ServiceCtx context) { }
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(0)]
|
|
|
|
// RequestLoad(u32)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode RequestLoad(ServiceCtx context)
|
2018-03-13 20:24:17 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
2018-03-13 20:24:17 -04:00
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
// We don't need to do anything here because we do lazy initialization
|
|
|
|
// on SharedFontManager (the font is loaded when necessary).
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-03-13 20:24:17 -04:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(1)]
|
|
|
|
// GetLoadState(u32) -> u32
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetLoadState(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
// 1 (true) indicates that the font is already loaded.
|
|
|
|
// All fonts are already loaded.
|
2018-12-06 06:16:24 -05:00
|
|
|
context.ResponseData.Write(1);
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(2)]
|
|
|
|
// GetFontSize(u32) -> u32
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetFontSize(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
context.ResponseData.Write(context.Device.System.Font.GetFontSize(fontType));
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(3)]
|
|
|
|
// GetSharedMemoryAddressOffset(u32) -> u32
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetSharedMemoryAddressOffset(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
context.ResponseData.Write(context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(4)]
|
|
|
|
// GetSharedMemoryNativeHandle() -> handle<copy>
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2020-01-21 17:23:11 -05:00
|
|
|
context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager);
|
2018-08-15 14:59:51 -04:00
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
if (_fontSharedMemHandle == 0)
|
2018-09-23 14:11:46 -04:00
|
|
|
{
|
2020-12-01 18:23:43 -05:00
|
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out _fontSharedMemHandle) != KernelResult.Success)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
}
|
2018-09-23 14:11:46 -04:00
|
|
|
}
|
2018-03-12 00:04:52 -04:00
|
|
|
|
2020-12-01 18:23:43 -05:00
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_fontSharedMemHandle);
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(5)]
|
|
|
|
// GetSharedFontInOrderOfPriority(bytes<8, 1>) -> (u8, u32, buffer<unknown, 6>, buffer<unknown, 6>, buffer<unknown, 6>)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetSharedFontInOrderOfPriority(ServiceCtx context)
|
2018-08-04 17:38:49 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
long languageCode = context.RequestData.ReadInt64();
|
|
|
|
int loadedCount = 0;
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
for (SharedFontType type = 0; type < SharedFontType.Count; type++)
|
2018-08-15 14:59:51 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
int offset = (int)type * 4;
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (!AddFontToOrderOfPriorityList(context, type, offset))
|
2018-08-15 14:59:51 -04:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
loadedCount++;
|
2018-08-04 17:38:49 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
context.ResponseData.Write(loadedCount);
|
|
|
|
context.ResponseData.Write((int)SharedFontType.Count);
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-08-04 17:38:49 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private bool AddFontToOrderOfPriorityList(ServiceCtx context, SharedFontType fontType, int offset)
|
2018-08-04 17:38:49 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
long typesPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
long typesSize = context.Request.ReceiveBuff[0].Size;
|
2018-08-15 14:59:51 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
long offsetsPosition = context.Request.ReceiveBuff[1].Position;
|
|
|
|
long offsetsSize = context.Request.ReceiveBuff[1].Size;
|
2018-08-15 14:59:51 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
long fontSizeBufferPosition = context.Request.ReceiveBuff[2].Position;
|
|
|
|
long fontSizeBufferSize = context.Request.ReceiveBuff[2].Size;
|
2018-08-04 17:38:49 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if ((uint)offset + 4 > (uint)typesSize ||
|
|
|
|
(uint)offset + 4 > (uint)offsetsSize ||
|
|
|
|
(uint)offset + 4 > (uint)fontSizeBufferSize)
|
2018-08-04 17:38:49 -04:00
|
|
|
{
|
2018-08-15 14:59:51 -04:00
|
|
|
return false;
|
2018-08-04 17:38:49 -04:00
|
|
|
}
|
|
|
|
|
2020-05-03 18:54:50 -04:00
|
|
|
context.Memory.Write((ulong)(typesPosition + offset), (int)fontType);
|
|
|
|
context.Memory.Write((ulong)(offsetsPosition + offset), context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
|
|
|
|
context.Memory.Write((ulong)(fontSizeBufferPosition + offset), context.Device.System.Font.GetFontSize(fontType));
|
2018-08-15 14:59:51 -04:00
|
|
|
|
|
|
|
return true;
|
2018-08-04 17:38:49 -04:00
|
|
|
}
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
}
|