mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-02 06:59:37 +00:00
305f06eb71
* Make all title id instances unsigned * Replace address and size with ulong instead of signed types Long overdue change. Also change some logics here and there to optimize with the new memory manager. * Address Ac_K's comments * Remove uneeded cast all around * Fixes some others misalignment
131 lines
No EOL
4.6 KiB
C#
131 lines
No EOL
4.6 KiB
C#
using Ryujinx.HLE.HOS.Font;
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
using System;
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
|
|
{
|
|
[Service("pl:u")]
|
|
[Service("pl:s")] // 9.0.0+
|
|
class ISharedFontManager : IpcService
|
|
{
|
|
private int _fontSharedMemHandle;
|
|
|
|
public ISharedFontManager(ServiceCtx context) { }
|
|
|
|
[CommandHipc(0)]
|
|
// RequestLoad(u32)
|
|
public ResultCode RequestLoad(ServiceCtx context)
|
|
{
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
|
|
|
// We don't need to do anything here because we do lazy initialization
|
|
// on SharedFontManager (the font is loaded when necessary).
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandHipc(1)]
|
|
// GetLoadState(u32) -> u32
|
|
public ResultCode GetLoadState(ServiceCtx context)
|
|
{
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
|
|
|
// 1 (true) indicates that the font is already loaded.
|
|
// All fonts are already loaded.
|
|
context.ResponseData.Write(1);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandHipc(2)]
|
|
// GetFontSize(u32) -> u32
|
|
public ResultCode GetFontSize(ServiceCtx context)
|
|
{
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
|
|
|
context.ResponseData.Write(context.Device.System.Font.GetFontSize(fontType));
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandHipc(3)]
|
|
// GetSharedMemoryAddressOffset(u32) -> u32
|
|
public ResultCode GetSharedMemoryAddressOffset(ServiceCtx context)
|
|
{
|
|
SharedFontType fontType = (SharedFontType)context.RequestData.ReadInt32();
|
|
|
|
context.ResponseData.Write(context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandHipc(4)]
|
|
// GetSharedMemoryNativeHandle() -> handle<copy>
|
|
public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
|
|
{
|
|
context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager);
|
|
|
|
if (_fontSharedMemHandle == 0)
|
|
{
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out _fontSharedMemHandle) != KernelResult.Success)
|
|
{
|
|
throw new InvalidOperationException("Out of handles!");
|
|
}
|
|
}
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_fontSharedMemHandle);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
[CommandHipc(5)]
|
|
// GetSharedFontInOrderOfPriority(bytes<8, 1>) -> (u8, u32, buffer<unknown, 6>, buffer<unknown, 6>, buffer<unknown, 6>)
|
|
public ResultCode GetSharedFontInOrderOfPriority(ServiceCtx context)
|
|
{
|
|
long languageCode = context.RequestData.ReadInt64();
|
|
int loadedCount = 0;
|
|
|
|
for (SharedFontType type = 0; type < SharedFontType.Count; type++)
|
|
{
|
|
uint offset = (uint)type * 4;
|
|
|
|
if (!AddFontToOrderOfPriorityList(context, type, offset))
|
|
{
|
|
break;
|
|
}
|
|
|
|
loadedCount++;
|
|
}
|
|
|
|
context.ResponseData.Write(loadedCount);
|
|
context.ResponseData.Write((int)SharedFontType.Count);
|
|
|
|
return ResultCode.Success;
|
|
}
|
|
|
|
private bool AddFontToOrderOfPriorityList(ServiceCtx context, SharedFontType fontType, uint offset)
|
|
{
|
|
ulong typesPosition = context.Request.ReceiveBuff[0].Position;
|
|
ulong typesSize = context.Request.ReceiveBuff[0].Size;
|
|
|
|
ulong offsetsPosition = context.Request.ReceiveBuff[1].Position;
|
|
ulong offsetsSize = context.Request.ReceiveBuff[1].Size;
|
|
|
|
ulong fontSizeBufferPosition = context.Request.ReceiveBuff[2].Position;
|
|
ulong fontSizeBufferSize = context.Request.ReceiveBuff[2].Size;
|
|
|
|
if (offset + 4 > (uint)typesSize ||
|
|
offset + 4 > (uint)offsetsSize ||
|
|
offset + 4 > (uint)fontSizeBufferSize)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
context.Memory.Write(typesPosition + offset, (int)fontType);
|
|
context.Memory.Write(offsetsPosition + offset, context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
|
|
context.Memory.Write(fontSizeBufferPosition + offset, context.Device.System.Font.GetFontSize(fontType));
|
|
|
|
return true;
|
|
}
|
|
}
|
|
} |