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