2018-08-16 16:47:36 -07:00
|
|
|
using Ryujinx.HLE.HOS.Font;
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-12-17 21:33:36 -08:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2018-09-23 11:11:46 -07:00
|
|
|
using System;
|
2018-02-24 20:34:16 -08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-08-16 16:47:36 -07:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Pl
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-04-05 21:01:52 -07:00
|
|
|
class ISharedFontManager : IpcService
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-02-24 20:34:16 -08:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-02-24 20:34:16 -08:00
|
|
|
|
2018-04-05 21:01:52 -07:00
|
|
|
public ISharedFontManager()
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-08-04 14:38:49 -07:00
|
|
|
{ 0, RequestLoad },
|
|
|
|
{ 1, GetLoadState },
|
|
|
|
{ 2, GetFontSize },
|
|
|
|
{ 3, GetSharedMemoryAddressOffset },
|
|
|
|
{ 4, GetSharedMemoryNativeHandle },
|
|
|
|
{ 5, GetSharedFontInOrderOfPriority }
|
2018-02-24 20:34:16 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public long 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
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
//We don't need to do anything here because we do lazy initialization
|
|
|
|
//on SharedFontManager (the font is loaded when necessary).
|
2018-03-13 17:24:17 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public long 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
|
|
|
|
2018-08-15 11:59:51 -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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public long 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
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
context.ResponseData.Write(context.Device.System.Font.GetFontSize(fontType));
|
2018-02-24 20:34:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public long 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
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
context.ResponseData.Write(context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
|
2018-02-24 20:34:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public long GetSharedMemoryNativeHandle(ServiceCtx context)
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager);
|
2018-08-15 11:59:51 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out int handle) != KernelResult.Success)
|
2018-09-23 11:11:46 -07:00
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
}
|
2018-03-11 21:04:52 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
2018-02-24 20:34:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
public long 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
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
int offset = (int)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
|
|
|
|
2018-08-15 11:59:51 -07:00
|
|
|
return 0;
|
2018-08-04 14:38:49 -07:00
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
private bool AddFontToOrderOfPriorityList(ServiceCtx context, SharedFontType fontType, int offset)
|
2018-08-04 14:38:49 -07:00
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
long typesPosition = context.Request.ReceiveBuff[0].Position;
|
|
|
|
long typesSize = context.Request.ReceiveBuff[0].Size;
|
2018-08-15 11:59:51 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
long offsetsPosition = context.Request.ReceiveBuff[1].Position;
|
|
|
|
long offsetsSize = context.Request.ReceiveBuff[1].Size;
|
2018-08-15 11:59:51 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
long fontSizeBufferPosition = context.Request.ReceiveBuff[2].Position;
|
|
|
|
long fontSizeBufferSize = context.Request.ReceiveBuff[2].Size;
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
if ((uint)offset + 4 > (uint)typesSize ||
|
|
|
|
(uint)offset + 4 > (uint)offsetsSize ||
|
|
|
|
(uint)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
|
|
|
}
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
context.Memory.WriteInt32(typesPosition + offset, (int)fontType);
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
context.Memory.WriteInt32(offsetsPosition + offset, context.Device.System.Font.GetSharedMemoryAddressOffset(fontType));
|
2018-08-15 11:59:51 -07:00
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
context.Memory.WriteInt32(fontSizeBufferPosition + offset, context.Device.System.Font.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
|
|
|
}
|
|
|
|
}
|