2018-08-16 16:47:36 -07:00
|
|
|
using Ryujinx.HLE.HOS.Font;
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-09-23 11:11:46 -07:00
|
|
|
using Ryujinx.HLE.HOS.Kernel;
|
|
|
|
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-04 16:52:39 -08:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
2018-02-24 20:34:16 -08:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_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-04 16:52:39 -08:00
|
|
|
m_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-04 16:52:39 -08:00
|
|
|
public long RequestLoad(ServiceCtx Context)
|
2018-03-13 17:24:17 -07:00
|
|
|
{
|
2018-12-04 16:52:39 -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-04 16:52:39 -08:00
|
|
|
public long GetLoadState(ServiceCtx Context)
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -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-04 16:52:39 -08:00
|
|
|
Context.ResponseData.Write(1);
|
2018-02-24 20:34:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
public long GetFontSize(ServiceCtx Context)
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
SharedFontType FontType = (SharedFontType)Context.RequestData.ReadInt32();
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
Context.ResponseData.Write(Context.Device.System.Font.GetFontSize(FontType));
|
2018-02-24 20:34:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
public long GetSharedMemoryAddressOffset(ServiceCtx Context)
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
SharedFontType FontType = (SharedFontType)Context.RequestData.ReadInt32();
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
Context.ResponseData.Write(Context.Device.System.Font.GetSharedMemoryAddressOffset(FontType));
|
2018-02-24 20:34:16 -08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
public long GetSharedMemoryNativeHandle(ServiceCtx Context)
|
2018-02-24 20:34:16 -08:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
Context.Device.System.Font.EnsureInitialized(Context.Device.System.ContentManager);
|
2018-08-15 11:59:51 -07:00
|
|
|
|
2018-12-04 16:52:39 -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-04 16:52:39 -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-04 16:52:39 -08:00
|
|
|
public long GetSharedFontInOrderOfPriority(ServiceCtx Context)
|
2018-08-04 14:38:49 -07:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
long LanguageCode = Context.RequestData.ReadInt64();
|
|
|
|
int LoadedCount = 0;
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
for (SharedFontType Type = 0; Type < SharedFontType.Count; Type++)
|
2018-08-15 11:59:51 -07:00
|
|
|
{
|
2018-12-04 16:52:39 -08:00
|
|
|
int Offset = (int)Type * 4;
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
if (!AddFontToOrderOfPriorityList(Context, (SharedFontType)Type, Offset))
|
2018-08-15 11:59:51 -07:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
LoadedCount++;
|
2018-08-04 14:38:49 -07:00
|
|
|
}
|
|
|
|
|
2018-12-04 16:52:39 -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-04 16:52:39 -08:00
|
|
|
private bool AddFontToOrderOfPriorityList(ServiceCtx Context, SharedFontType FontType, int Offset)
|
2018-08-04 14:38:49 -07:00
|
|
|
{
|
2018-12-04 16:52:39 -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-04 16:52:39 -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-04 16:52:39 -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-04 16:52:39 -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-04 16:52:39 -08:00
|
|
|
Context.Memory.WriteInt32(TypesPosition + Offset, (int)FontType);
|
2018-08-04 14:38:49 -07:00
|
|
|
|
2018-12-04 16:52:39 -08:00
|
|
|
Context.Memory.WriteInt32(OffsetsPosition + Offset, Context.Device.System.Font.GetSharedMemoryAddressOffset(FontType));
|
2018-08-15 11:59:51 -07:00
|
|
|
|
2018-12-04 16:52:39 -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
|
|
|
}
|
|
|
|
}
|