mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-15 12:39:38 +00:00
Move font handler and platform-independent shell stuff
This commit is contained in:
@@ -62,8 +62,7 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\GpMainApp.props" />
|
||||
<Import Project="..\FreeTypePublic.props" />
|
||||
<Import Project="..\FreeTypeImport.props" />
|
||||
<Import Project="GpShell.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -71,9 +70,8 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\GpMainApp.props" />
|
||||
<Import Project="..\FreeTypePublic.props" />
|
||||
<Import Project="..\FreeTypeImport.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="GpShell.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -81,8 +79,7 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\GpMainApp.props" />
|
||||
<Import Project="..\FreeTypePublic.props" />
|
||||
<Import Project="..\FreeTypeImport.props" />
|
||||
<Import Project="GpShell.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -90,9 +87,8 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\GpMainApp.props" />
|
||||
<Import Project="..\FreeTypePublic.props" />
|
||||
<Import Project="..\FreeTypeImport.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="GpShell.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
@@ -145,26 +141,16 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="GpAppEnvironment.cpp" />
|
||||
<ClCompile Include="GpAudioDriverFactory.cpp" />
|
||||
<ClCompile Include="GpColorCursor_Win32.cpp" />
|
||||
<ClCompile Include="GpDisplayDriverFactory.cpp" />
|
||||
<ClCompile Include="GpFiber_Win32.cpp" />
|
||||
<ClCompile Include="GpFileStream_Win32.cpp" />
|
||||
<ClCompile Include="GpFileSystem_Win32.cpp" />
|
||||
<ClCompile Include="GpFontHandlerFactory.cpp" />
|
||||
<ClCompile Include="GpFontHandler_FreeType2.cpp" />
|
||||
<ClCompile Include="GpGlobalConfig.cpp" />
|
||||
<ClCompile Include="GpInputDriverFactory.cpp" />
|
||||
<ClCompile Include="GpLogDriver_Win32.cpp" />
|
||||
<ClCompile Include="GpMain.cpp" />
|
||||
<ClCompile Include="GpMain_Win32.cpp" />
|
||||
<ClCompile Include="GpMemoryBuffer.cpp" />
|
||||
<ClCompile Include="GpMutex_Win32.cpp" />
|
||||
<ClCompile Include="GpSystemServices_Win32.cpp" />
|
||||
<ClCompile Include="GpFiberStarter_Win32.cpp" />
|
||||
<ClCompile Include="GpThreadEvent_Win32.cpp" />
|
||||
<ClCompile Include="GpVOSEventQueue.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\GpCommon\EGpInputDriverType.h" />
|
||||
@@ -179,30 +165,17 @@
|
||||
<ClInclude Include="..\GpCommon\IGpDisplayDriverSurface.h" />
|
||||
<ClInclude Include="..\GpCommon\IGpLogDriver.h" />
|
||||
<ClInclude Include="..\GpCommon\IGpPrefsHandler.h" />
|
||||
<ClInclude Include="GpAppEnvironment.h" />
|
||||
<ClInclude Include="GpAudioDriverFactory.h" />
|
||||
<ClInclude Include="GpDisplayDriverFactory.h" />
|
||||
<ClInclude Include="GpFiber_Win32.h" />
|
||||
<ClInclude Include="GpFileStream_Win32.h" />
|
||||
<ClInclude Include="GpFileSystem_Win32.h" />
|
||||
<ClInclude Include="GpFontHandler_FreeType2.h" />
|
||||
<ClInclude Include="GpFontHandlerFactory.h" />
|
||||
<ClInclude Include="GpGlobalConfig.h" />
|
||||
<ClInclude Include="GpInputDriverFactory.h" />
|
||||
<ClInclude Include="GpLogDriver_Win32.h" />
|
||||
<ClInclude Include="GpMain.h" />
|
||||
<ClInclude Include="GpMemoryBuffer.h" />
|
||||
<ClInclude Include="GpMutex_Win32.h" />
|
||||
<ClInclude Include="GpSystemServices_Win32.h" />
|
||||
<ClInclude Include="GpFiberStarter.h" />
|
||||
<ClInclude Include="GpThreadEvent_Win32.h" />
|
||||
<ClInclude Include="GpVOSEventQueue.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FreeType\FreeType.vcxproj">
|
||||
<Project>{487216d8-16ba-4b4c-b5bf-43feedfee03a}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\GpApp\GpApp.vcxproj">
|
||||
<Project>{6233c3f2-5781-488e-b190-4fa8836f5a77}</Project>
|
||||
</ProjectReference>
|
||||
@@ -212,9 +185,15 @@
|
||||
<ProjectReference Include="..\GpDisplayDriver_D3D11\GpDisplayDriver_D3D11.vcxproj">
|
||||
<Project>{ffc961ac-55b4-4a38-a83e-06ae98f59acc}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\GpFontHandler_FreeType2\GpFontHandler_FreeType2.vcxproj">
|
||||
<Project>{4b564030-8985-4975-91e1-e1b2c16ae2a1}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\GpInputDriver_XInput\GpInputDriver_XInput.vcxproj">
|
||||
<Project>{17b96f07-ef92-47cd-95a5-8e6ee38ab564}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\GpShell\GpShell.vcxproj">
|
||||
<Project>{10cf9b5f-61d0-4b5b-89f4-810b58fc053d}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Aerofoil.rc" />
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="GpVOSEventQueue.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpAppEnvironment.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpAudioDriverFactory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpColorCursor_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpDisplayDriverFactory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpFiber_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -28,27 +16,9 @@
|
||||
<ClCompile Include="GpFileSystem_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpFontHandler_FreeType2.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpFontHandlerFactory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpGlobalConfig.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpInputDriverFactory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpMain.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpMain_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpMemoryBuffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GpMutex_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -69,27 +39,15 @@
|
||||
<ClInclude Include="..\GpCommon\EGpStandardCursor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpAppEnvironment.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\GpCommon\GpApplicationName.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpAudioDriverFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpDisplayDriverFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\GpCommon\GpDisplayDriverTickStatus.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpFiber_Win32.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpFiberStarter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\GpCommon\GpFileCreationDisposition.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -102,24 +60,9 @@
|
||||
<ClInclude Include="GpFontHandler_FreeType2.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpFontHandlerFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpGlobalConfig.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpInputDriverFactory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\GpCommon\GpInputDriverProperties.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpMain.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpMemoryBuffer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpMutex_Win32.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -129,9 +72,6 @@
|
||||
<ClInclude Include="GpThreadEvent_Win32.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GpVOSEventQueue.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\GpCommon\IGpAudioChannelCallbacks.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
#include "GpAppEnvironment.h"
|
||||
#include "GpFiberStarter.h"
|
||||
#include "GpAppInterface.h"
|
||||
#include "GpDisplayDriverTickStatus.h"
|
||||
#include "GpFontHandlerFactory.h"
|
||||
#include "HostSuspendCallArgument.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpFiber.h"
|
||||
#include "IGpInputDriver.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
GpAppEnvironment::GpAppEnvironment()
|
||||
: m_applicationState(ApplicationState_NotStarted)
|
||||
, m_displayDriver(nullptr)
|
||||
, m_audioDriver(nullptr)
|
||||
, m_inputDrivers(nullptr)
|
||||
, m_numInputDrivers(0)
|
||||
, m_fontHandler(nullptr)
|
||||
, m_vosEventQueue(nullptr)
|
||||
, m_applicationFiber(nullptr)
|
||||
, m_vosFiber(nullptr)
|
||||
, m_suspendCallID(PortabilityLayer::HostSuspendCallID_Unknown)
|
||||
, m_suspendArgs(nullptr)
|
||||
, m_suspendReturnValue(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
GpAppEnvironment::~GpAppEnvironment()
|
||||
{
|
||||
assert(m_applicationFiber == nullptr);
|
||||
}
|
||||
|
||||
void GpAppEnvironment::Init()
|
||||
{
|
||||
}
|
||||
|
||||
GpDisplayDriverTickStatus_t GpAppEnvironment::Tick(IGpFiber *vosFiber)
|
||||
{
|
||||
GpAppInterface_Get()->PL_IncrementTickCounter(1);
|
||||
|
||||
m_vosFiber = vosFiber;
|
||||
|
||||
if (m_applicationState == ApplicationState_WaitingForEvents)
|
||||
m_applicationState = ApplicationState_Running;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
switch (m_applicationState)
|
||||
{
|
||||
case ApplicationState_NotStarted:
|
||||
InitializeApplicationState();
|
||||
m_applicationFiber = GpFiberStarter::StartFiber(GpAppEnvironment::StaticAppThreadFunc, this, vosFiber);
|
||||
m_applicationState = ApplicationState_Running;
|
||||
break;
|
||||
case ApplicationState_WaitingForEvents:
|
||||
return GpDisplayDriverTickStatuses::kOK;
|
||||
case ApplicationState_Running:
|
||||
SynchronizeState();
|
||||
m_applicationFiber->YieldTo();
|
||||
break;
|
||||
case ApplicationState_SystemCall:
|
||||
{
|
||||
PortabilityLayer::HostSuspendCallID callID = m_suspendCallID;
|
||||
const PortabilityLayer::HostSuspendCallArgument *args = m_suspendArgs;
|
||||
PortabilityLayer::HostSuspendCallArgument *returnValue = m_suspendReturnValue;
|
||||
|
||||
DispatchSystemCall(callID, args, returnValue);
|
||||
assert(m_applicationState != ApplicationState_SystemCall);
|
||||
}
|
||||
break;
|
||||
case ApplicationState_TimedSuspend:
|
||||
if (m_delaySuspendTicks == 0)
|
||||
m_applicationState = ApplicationState_Running;
|
||||
else
|
||||
{
|
||||
m_delaySuspendTicks--;
|
||||
return GpDisplayDriverTickStatuses::kOK;
|
||||
}
|
||||
break;
|
||||
case ApplicationState_Terminated:
|
||||
m_applicationFiber->Destroy();
|
||||
m_applicationFiber = nullptr;
|
||||
return GpDisplayDriverTickStatuses::kApplicationTerminated;
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void GpAppEnvironment::Render()
|
||||
{
|
||||
GpAppInterface_Get()->PL_Render(m_displayDriver);
|
||||
}
|
||||
|
||||
bool GpAppEnvironment::AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY)
|
||||
{
|
||||
return GpAppInterface_Get()->PL_AdjustRequestedResolution(physicalWidth, physicalHeight, virtualWidth, virtualheight, pixelScaleX, pixelScaleY);
|
||||
}
|
||||
|
||||
void GpAppEnvironment::SetDisplayDriver(IGpDisplayDriver *displayDriver)
|
||||
{
|
||||
m_displayDriver = displayDriver;
|
||||
}
|
||||
|
||||
void GpAppEnvironment::SetAudioDriver(IGpAudioDriver *audioDriver)
|
||||
{
|
||||
m_audioDriver = audioDriver;
|
||||
}
|
||||
|
||||
void GpAppEnvironment::SetInputDrivers(IGpInputDriver *const* inputDrivers, size_t numDrivers)
|
||||
{
|
||||
m_inputDrivers = inputDrivers;
|
||||
m_numInputDrivers = numDrivers;
|
||||
}
|
||||
|
||||
void GpAppEnvironment::SetFontHandler(PortabilityLayer::HostFontHandler *fontHandler)
|
||||
{
|
||||
m_fontHandler = fontHandler;
|
||||
}
|
||||
|
||||
void GpAppEnvironment::SetVOSEventQueue(GpVOSEventQueue *eventQueue)
|
||||
{
|
||||
m_vosEventQueue = eventQueue;
|
||||
}
|
||||
|
||||
void GpAppEnvironment::StaticAppThreadFunc(void *context)
|
||||
{
|
||||
static_cast<GpAppEnvironment*>(context)->AppThreadFunc();
|
||||
}
|
||||
|
||||
void GpAppEnvironment::AppThreadFunc()
|
||||
{
|
||||
GpAppInterface_Get()->ApplicationMain();
|
||||
|
||||
m_applicationState = ApplicationState_Terminated;
|
||||
m_vosFiber->YieldTo();
|
||||
}
|
||||
|
||||
void GpAppEnvironment::InitializeApplicationState()
|
||||
{
|
||||
GpAppInterface_Get()->PL_HostDisplayDriver_SetInstance(m_displayDriver);
|
||||
GpAppInterface_Get()->PL_HostAudioDriver_SetInstance(m_audioDriver);
|
||||
GpAppInterface_Get()->PL_HostInputDriver_SetInstances(m_inputDrivers, m_numInputDrivers);
|
||||
GpAppInterface_Get()->PL_InstallHostSuspendHook(GpAppEnvironment::StaticSuspendHookFunc, this);
|
||||
|
||||
GpAppInterface_Get()->PL_HostFontHandler_SetInstance(m_fontHandler);
|
||||
GpAppInterface_Get()->PL_HostVOSEventQueue_SetInstance(m_vosEventQueue);
|
||||
}
|
||||
|
||||
void GpAppEnvironment::SynchronizeState()
|
||||
{
|
||||
const size_t numInputDrivers = m_numInputDrivers;
|
||||
for (size_t i = 0; i < numInputDrivers; i++)
|
||||
m_inputDrivers[i]->ProcessInput();
|
||||
}
|
||||
|
||||
void GpAppEnvironment::StaticSuspendHookFunc(void *context, PortabilityLayer::HostSuspendCallID callID, const PortabilityLayer::HostSuspendCallArgument *args, PortabilityLayer::HostSuspendCallArgument *returnValue)
|
||||
{
|
||||
GpAppEnvironment *appEnv = static_cast<GpAppEnvironment*>(context);
|
||||
|
||||
appEnv->m_suspendCallID = callID;
|
||||
appEnv->m_suspendArgs = args;
|
||||
appEnv->m_suspendReturnValue = returnValue;
|
||||
appEnv->m_applicationState = ApplicationState_SystemCall;
|
||||
|
||||
appEnv->m_vosFiber->YieldTo();
|
||||
}
|
||||
|
||||
void GpAppEnvironment::DispatchSystemCall(PortabilityLayer::HostSuspendCallID callID, const PortabilityLayer::HostSuspendCallArgument *args, PortabilityLayer::HostSuspendCallArgument *returnValue)
|
||||
{
|
||||
switch (callID)
|
||||
{
|
||||
case PortabilityLayer::HostSuspendCallID_Delay:
|
||||
m_applicationState = ApplicationState_TimedSuspend;
|
||||
m_delaySuspendTicks = args[0].m_uint;
|
||||
break;
|
||||
case PortabilityLayer::HostSuspendCallID_CallOnVOSThread:
|
||||
args[0].m_functionPtr(static_cast<const PortabilityLayer::HostSuspendCallArgument*>(args[1].m_constPointer), static_cast<PortabilityLayer::HostSuspendCallArgument*>(args[2].m_pointer));
|
||||
m_applicationState = ApplicationState_Running;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "GpDisplayDriverTickStatus.h"
|
||||
#include "GpVOSEventQueue.h"
|
||||
#include "HostSuspendCallID.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
union HostSuspendCallArgument;
|
||||
class HostFontHandler;
|
||||
class HostVOSEventQueue;
|
||||
}
|
||||
|
||||
struct IGpDisplayDriver;
|
||||
struct IGpAudioDriver;
|
||||
struct IGpInputDriver;
|
||||
struct IGpFiber;
|
||||
|
||||
class GpAppEnvironment
|
||||
{
|
||||
public:
|
||||
GpAppEnvironment();
|
||||
~GpAppEnvironment();
|
||||
|
||||
void Init();
|
||||
|
||||
GpDisplayDriverTickStatus_t Tick(IGpFiber *vosFiber);
|
||||
void Render();
|
||||
bool AdjustRequestedResolution(uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY);
|
||||
|
||||
void SetDisplayDriver(IGpDisplayDriver *displayDriver);
|
||||
void SetAudioDriver(IGpAudioDriver *audioDriver);
|
||||
void SetInputDrivers(IGpInputDriver *const* inputDrivers, size_t numDrivers);
|
||||
void SetFontHandler(PortabilityLayer::HostFontHandler *fontHandler);
|
||||
void SetVOSEventQueue(GpVOSEventQueue *eventQueue);
|
||||
|
||||
private:
|
||||
enum ApplicationState
|
||||
{
|
||||
ApplicationState_NotStarted,
|
||||
ApplicationState_WaitingForEvents,
|
||||
ApplicationState_Running,
|
||||
ApplicationState_Terminated,
|
||||
ApplicationState_SystemCall,
|
||||
ApplicationState_TimedSuspend,
|
||||
};
|
||||
|
||||
static void StaticAppThreadFunc(void *context);
|
||||
void AppThreadFunc();
|
||||
void InitializeApplicationState();
|
||||
void SynchronizeState();
|
||||
|
||||
static void StaticSuspendHookFunc(void *context, PortabilityLayer::HostSuspendCallID callID, const PortabilityLayer::HostSuspendCallArgument *args, PortabilityLayer::HostSuspendCallArgument *returnValue);
|
||||
void DispatchSystemCall(PortabilityLayer::HostSuspendCallID callID, const PortabilityLayer::HostSuspendCallArgument *args, PortabilityLayer::HostSuspendCallArgument *returnValue);
|
||||
|
||||
ApplicationState m_applicationState;
|
||||
IGpDisplayDriver *m_displayDriver;
|
||||
IGpAudioDriver *m_audioDriver;
|
||||
IGpInputDriver *const* m_inputDrivers;
|
||||
PortabilityLayer::HostFontHandler *m_fontHandler;
|
||||
GpVOSEventQueue *m_vosEventQueue;
|
||||
IGpFiber *m_applicationFiber;
|
||||
IGpFiber *m_vosFiber;
|
||||
|
||||
uint32_t m_delaySuspendTicks;
|
||||
size_t m_numInputDrivers;
|
||||
|
||||
PortabilityLayer::HostSuspendCallID m_suspendCallID;
|
||||
const PortabilityLayer::HostSuspendCallArgument *m_suspendArgs;
|
||||
PortabilityLayer::HostSuspendCallArgument *m_suspendReturnValue;
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "GpAudioDriverFactory.h"
|
||||
#include "GpAudioDriverProperties.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
IGpAudioDriver *GpAudioDriverFactory::CreateAudioDriver(const GpAudioDriverProperties &properties)
|
||||
{
|
||||
assert(properties.m_type < EGpAudioDriverType_Count);
|
||||
|
||||
if (ms_registry[properties.m_type])
|
||||
return ms_registry[properties.m_type](properties);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType type, FactoryFunc_t func)
|
||||
{
|
||||
assert(type < EGpAudioDriverType_Count);
|
||||
|
||||
ms_registry[type] = func;
|
||||
}
|
||||
|
||||
GpAudioDriverFactory::FactoryFunc_t GpAudioDriverFactory::ms_registry[EGpAudioDriverType_Count];
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "EGpAudioDriverType.h"
|
||||
|
||||
struct IGpAudioDriver;
|
||||
struct GpAudioDriverProperties;
|
||||
|
||||
class GpAudioDriverFactory
|
||||
{
|
||||
public:
|
||||
typedef IGpAudioDriver *(*FactoryFunc_t)(const GpAudioDriverProperties &properties);
|
||||
|
||||
static IGpAudioDriver *CreateAudioDriver(const GpAudioDriverProperties &properties);
|
||||
static void RegisterAudioDriverFactory(EGpAudioDriverType type, FactoryFunc_t func);
|
||||
|
||||
private:
|
||||
static FactoryFunc_t ms_registry[EGpAudioDriverType_Count];
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "GpDisplayDriverFactory.h"
|
||||
#include "GpDisplayDriverProperties.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
IGpDisplayDriver *GpDisplayDriverFactory::CreateDisplayDriver(const GpDisplayDriverProperties &properties)
|
||||
{
|
||||
assert(properties.m_type < EGpDisplayDriverType_Count);
|
||||
|
||||
if (ms_registry[properties.m_type])
|
||||
return ms_registry[properties.m_type](properties);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType type, FactoryFunc_t func)
|
||||
{
|
||||
assert(type < EGpDisplayDriverType_Count);
|
||||
|
||||
ms_registry[type] = func;
|
||||
}
|
||||
|
||||
GpDisplayDriverFactory::FactoryFunc_t GpDisplayDriverFactory::ms_registry[EGpDisplayDriverType_Count];
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "EGpDisplayDriverType.h"
|
||||
|
||||
struct IGpDisplayDriver;
|
||||
struct GpDisplayDriverProperties;
|
||||
|
||||
class GpDisplayDriverFactory
|
||||
{
|
||||
public:
|
||||
typedef IGpDisplayDriver *(*FactoryFunc_t)(const GpDisplayDriverProperties &properties);
|
||||
|
||||
static IGpDisplayDriver *CreateDisplayDriver(const GpDisplayDriverProperties &properties);
|
||||
static void RegisterDisplayDriverFactory(EGpDisplayDriverType type, FactoryFunc_t func);
|
||||
|
||||
private:
|
||||
static FactoryFunc_t ms_registry[EGpDisplayDriverType_Count];
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
struct IGpFiber;
|
||||
|
||||
class GpFiberStarter
|
||||
{
|
||||
public:
|
||||
typedef void(*ThreadFunc_t)(void *context);
|
||||
|
||||
static IGpFiber *StartFiber(ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber);
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "GpFontHandlerFactory.h"
|
||||
#include "GpFontHandler_FreeType2.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
PortabilityLayer::HostFontHandler *GpFontHandlerFactory::Create()
|
||||
{
|
||||
return GpFontHandler_FreeType2::Create();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class HostFontHandler;
|
||||
}
|
||||
|
||||
class GpFontHandlerFactory final
|
||||
{
|
||||
public:
|
||||
static PortabilityLayer::HostFontHandler *Create();
|
||||
};
|
||||
@@ -1,425 +0,0 @@
|
||||
#include "GpFontHandler_FreeType2.h"
|
||||
|
||||
#include "CoreDefs.h"
|
||||
#include "IOStream.h"
|
||||
#include "HostFont.h"
|
||||
#include "HostFontRenderedGlyph.h"
|
||||
#include "RenderedGlyphMetrics.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include FT_MODULE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
class GpFontRenderedGlyph_FreeType2 final : public PortabilityLayer::HostFontRenderedGlyph
|
||||
{
|
||||
public:
|
||||
const PortabilityLayer::RenderedGlyphMetrics &GetMetrics() const override;
|
||||
const void *GetData() const override;
|
||||
void Destroy() override;
|
||||
|
||||
static GpFontRenderedGlyph_FreeType2 *Create(size_t dataSize, const PortabilityLayer::RenderedGlyphMetrics &metrics);
|
||||
|
||||
void *GetMutableData();
|
||||
|
||||
private:
|
||||
GpFontRenderedGlyph_FreeType2(void *data, const PortabilityLayer::RenderedGlyphMetrics &metrics);
|
||||
~GpFontRenderedGlyph_FreeType2();
|
||||
|
||||
void *m_data;
|
||||
PortabilityLayer::RenderedGlyphMetrics m_metrics;
|
||||
};
|
||||
|
||||
class GpFont_FreeType2 final : public PortabilityLayer::HostFont
|
||||
{
|
||||
public:
|
||||
void Destroy() override;
|
||||
GpFontRenderedGlyph_FreeType2 *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) override;
|
||||
bool GetLineSpacing(unsigned int size, int32_t &outSpacing) override;
|
||||
|
||||
static GpFont_FreeType2 *Create(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream);
|
||||
|
||||
bool FTLoad(const FT_Library &library);
|
||||
|
||||
private:
|
||||
explicit GpFont_FreeType2(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream);
|
||||
~GpFont_FreeType2();
|
||||
|
||||
FT_StreamRec_ m_ftStream;
|
||||
FT_Face m_face;
|
||||
PortabilityLayer::IOStream *m_stream;
|
||||
unsigned int m_currentSize;
|
||||
};
|
||||
|
||||
const PortabilityLayer::RenderedGlyphMetrics &GpFontRenderedGlyph_FreeType2::GetMetrics() const
|
||||
{
|
||||
return m_metrics;
|
||||
}
|
||||
|
||||
const void *GpFontRenderedGlyph_FreeType2::GetData() const
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
void GpFontRenderedGlyph_FreeType2::Destroy()
|
||||
{
|
||||
this->~GpFontRenderedGlyph_FreeType2();
|
||||
free(this);
|
||||
}
|
||||
|
||||
GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(size_t dataSize, const PortabilityLayer::RenderedGlyphMetrics &metrics)
|
||||
{
|
||||
size_t alignedPrefixSize = (sizeof(GpFontRenderedGlyph_FreeType2) + GP_SYSTEM_MEMORY_ALIGNMENT - 1);
|
||||
alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT;
|
||||
|
||||
void *storage = malloc(alignedPrefixSize + dataSize);
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
return new (storage) GpFontRenderedGlyph_FreeType2(static_cast<uint8_t*>(storage) + alignedPrefixSize, metrics);
|
||||
}
|
||||
|
||||
void *GpFontRenderedGlyph_FreeType2::GetMutableData()
|
||||
{
|
||||
return m_data;
|
||||
}
|
||||
|
||||
|
||||
GpFontRenderedGlyph_FreeType2::GpFontRenderedGlyph_FreeType2(void *data, const PortabilityLayer::RenderedGlyphMetrics &metrics)
|
||||
: m_metrics(metrics)
|
||||
, m_data(data)
|
||||
{
|
||||
}
|
||||
|
||||
GpFontRenderedGlyph_FreeType2::~GpFontRenderedGlyph_FreeType2()
|
||||
{
|
||||
}
|
||||
|
||||
void GpFont_FreeType2::Destroy()
|
||||
{
|
||||
this->~GpFont_FreeType2();
|
||||
free(this);
|
||||
}
|
||||
|
||||
GpFontRenderedGlyph_FreeType2 *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsigned int size, bool aa)
|
||||
{
|
||||
if (m_currentSize != size)
|
||||
{
|
||||
if (FT_Set_Pixel_Sizes(m_face, 0, size) != 0)
|
||||
return nullptr;
|
||||
|
||||
m_currentSize = size;
|
||||
}
|
||||
|
||||
FT_UInt glyphIndex = FT_Get_Char_Index(m_face, unicodeCodePoint);
|
||||
if (!glyphIndex)
|
||||
return nullptr;
|
||||
|
||||
FT_Int32 loadFlags = 0;
|
||||
FT_Render_Mode renderMode = FT_RENDER_MODE_NORMAL;
|
||||
|
||||
if (aa)
|
||||
{
|
||||
renderMode = FT_RENDER_MODE_NORMAL;
|
||||
loadFlags = FT_LOAD_TARGET_NORMAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
loadFlags = FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO;
|
||||
renderMode = FT_RENDER_MODE_MONO;
|
||||
}
|
||||
|
||||
if (FT_Load_Glyph(m_face, glyphIndex, loadFlags) != 0)
|
||||
return nullptr;
|
||||
|
||||
if (FT_Render_Glyph(m_face->glyph, renderMode) != 0)
|
||||
return nullptr;
|
||||
|
||||
const FT_GlyphSlot glyph = m_face->glyph;
|
||||
|
||||
if (aa == false && glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO)
|
||||
return nullptr;
|
||||
|
||||
if (aa == true)
|
||||
{
|
||||
if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
|
||||
return nullptr;
|
||||
|
||||
if (glyph->bitmap.num_grays < 2)
|
||||
return nullptr; // This should never happen
|
||||
}
|
||||
|
||||
PortabilityLayer::RenderedGlyphMetrics metrics;
|
||||
memset(&metrics, 0, sizeof(metrics));
|
||||
|
||||
metrics.m_bearingX = glyph->metrics.horiBearingX / 64;
|
||||
metrics.m_bearingY = glyph->metrics.horiBearingY / 64;
|
||||
metrics.m_glyphWidth = glyph->bitmap.width;
|
||||
metrics.m_glyphHeight = glyph->bitmap.rows;
|
||||
metrics.m_advanceX = glyph->metrics.horiAdvance / 64;
|
||||
|
||||
const size_t numRowsRequired = glyph->bitmap.rows;
|
||||
size_t pitchRequired = 0;
|
||||
|
||||
if (aa)
|
||||
pitchRequired = (glyph->bitmap.width + 1) / 2;
|
||||
else
|
||||
pitchRequired = (glyph->bitmap.width + 7) / 8;
|
||||
|
||||
pitchRequired = pitchRequired + (GP_SYSTEM_MEMORY_ALIGNMENT - 1);
|
||||
pitchRequired -= pitchRequired % GP_SYSTEM_MEMORY_ALIGNMENT;
|
||||
|
||||
const size_t glyphDataSize = numRowsRequired * pitchRequired;
|
||||
|
||||
metrics.m_glyphDataPitch = pitchRequired;
|
||||
|
||||
GpFontRenderedGlyph_FreeType2 *renderedGlyph = GpFontRenderedGlyph_FreeType2::Create(glyphDataSize, metrics);
|
||||
if (!renderedGlyph)
|
||||
return nullptr;
|
||||
|
||||
uint8_t *fillData = static_cast<uint8_t*>(renderedGlyph->GetMutableData());
|
||||
|
||||
unsigned int bmWidth = glyph->bitmap.width;
|
||||
unsigned int bmHeight = glyph->bitmap.rows;
|
||||
unsigned int bmPitch = glyph->bitmap.pitch;
|
||||
const uint8_t *bmBytes = glyph->bitmap.buffer;
|
||||
const uint16_t numGrays = glyph->bitmap.num_grays;
|
||||
|
||||
size_t fillOffset = 0;
|
||||
for (unsigned int row = 0; row < bmHeight; row++)
|
||||
{
|
||||
const uint8_t *bmReadStart = bmBytes + bmPitch * row;
|
||||
uint8_t *bmWriteStart = fillData + pitchRequired * row;
|
||||
|
||||
if (aa)
|
||||
{
|
||||
for (size_t i = 0; i < pitchRequired; i++)
|
||||
bmWriteStart[i] = 0;
|
||||
|
||||
for (size_t i = 0; i < bmWidth; i++)
|
||||
{
|
||||
const uint8_t b = bmReadStart[i];
|
||||
const uint8_t normalizedGray = (b * 30 + (numGrays - 1)) / ((numGrays - 1) * 2);
|
||||
|
||||
if (i & 1)
|
||||
bmWriteStart[i / 2] |= (normalizedGray << 4);
|
||||
else
|
||||
bmWriteStart[i / 2] = normalizedGray;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t copyableBytesPerRow = (glyph->bitmap.width + 7) / 8;
|
||||
|
||||
for (size_t i = 0; i < copyableBytesPerRow; i++)
|
||||
{
|
||||
const uint8_t b = bmReadStart[i];
|
||||
|
||||
uint8_t fillByte = 0;
|
||||
for (int bit = 0; bit < 8; bit++)
|
||||
fillByte |= ((b >> (7 - bit)) & 1) << bit;
|
||||
|
||||
bmWriteStart[i] = fillByte;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return renderedGlyph;
|
||||
}
|
||||
|
||||
bool GpFont_FreeType2::GetLineSpacing(unsigned int size, int32_t &outSpacing)
|
||||
{
|
||||
if (m_currentSize != size)
|
||||
{
|
||||
if (FT_Set_Pixel_Sizes(m_face, 0, size) != 0)
|
||||
return false;
|
||||
|
||||
m_currentSize = size;
|
||||
}
|
||||
|
||||
outSpacing = m_face->size->metrics.height / 64;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
GpFont_FreeType2 *GpFont_FreeType2::Create(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream)
|
||||
{
|
||||
void *storage = malloc(sizeof(GpFont_FreeType2));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
return new (storage) GpFont_FreeType2(streamRec, stream);
|
||||
}
|
||||
|
||||
bool GpFont_FreeType2::FTLoad(const FT_Library &library)
|
||||
{
|
||||
FT_Open_Args openArgs;
|
||||
memset(&openArgs, 0, sizeof(openArgs));
|
||||
openArgs.flags = FT_OPEN_STREAM;
|
||||
openArgs.stream = &m_ftStream;
|
||||
|
||||
FT_Error errorCode = FT_Open_Face(library, &openArgs, 0, &m_face);
|
||||
if (errorCode != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
GpFont_FreeType2::GpFont_FreeType2(const FT_StreamRec_ &streamRec, PortabilityLayer::IOStream *stream)
|
||||
: m_face(nullptr)
|
||||
, m_ftStream(streamRec)
|
||||
, m_stream(stream)
|
||||
, m_currentSize(0)
|
||||
{
|
||||
assert(stream);
|
||||
}
|
||||
|
||||
GpFont_FreeType2::~GpFont_FreeType2()
|
||||
{
|
||||
if (m_face)
|
||||
FT_Done_Face(m_face);
|
||||
|
||||
m_stream->Close();
|
||||
}
|
||||
|
||||
GpFontHandler_FreeType2 *GpFontHandler_FreeType2::Create()
|
||||
{
|
||||
void *storage = malloc(sizeof(GpFontHandler_FreeType2));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
GpFontHandler_FreeType2 *fh = new (storage) GpFontHandler_FreeType2();
|
||||
if (!fh->Init())
|
||||
{
|
||||
fh->Shutdown();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return fh;
|
||||
}
|
||||
|
||||
PortabilityLayer::HostFont *GpFontHandler_FreeType2::LoadFont(PortabilityLayer::IOStream *stream)
|
||||
{
|
||||
FT_StreamRec_ ftStream;
|
||||
memset(&ftStream, 0, sizeof(ftStream));
|
||||
ftStream.size = 0x7fffffff;
|
||||
ftStream.pos = 0;
|
||||
ftStream.descriptor.pointer = stream;
|
||||
ftStream.read = FTStreamIo;
|
||||
ftStream.close = FTStreamClose;
|
||||
|
||||
GpFont_FreeType2 *font = GpFont_FreeType2::Create(ftStream, stream);
|
||||
if (!font)
|
||||
{
|
||||
stream->Close();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!font->FTLoad(m_library))
|
||||
{
|
||||
font->Destroy();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
bool GpFontHandler_FreeType2::KeepStreamOpen() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void GpFontHandler_FreeType2::Shutdown()
|
||||
{
|
||||
this->~GpFontHandler_FreeType2();
|
||||
free(this);
|
||||
}
|
||||
|
||||
GpFontHandler_FreeType2::GpFontHandler_FreeType2()
|
||||
: m_ftIsInitialized(false)
|
||||
, m_library(nullptr)
|
||||
, m_currentSize(0)
|
||||
{
|
||||
}
|
||||
|
||||
GpFontHandler_FreeType2::~GpFontHandler_FreeType2()
|
||||
{
|
||||
if (m_ftIsInitialized)
|
||||
FT_Done_Library(m_library);
|
||||
}
|
||||
|
||||
|
||||
void *GpFontHandler_FreeType2::FTAllocThunk(FT_Memory memory, long size)
|
||||
{
|
||||
return static_cast<GpFontHandler_FreeType2*>(memory->user)->FTAlloc(size);
|
||||
}
|
||||
|
||||
void GpFontHandler_FreeType2::FTFreeThunk(FT_Memory memory, void* block)
|
||||
{
|
||||
static_cast<GpFontHandler_FreeType2*>(memory->user)->FTFree(block);
|
||||
}
|
||||
|
||||
void *GpFontHandler_FreeType2::FTReallocThunk(FT_Memory memory, long curSize, long newSize, void *block)
|
||||
{
|
||||
return static_cast<GpFontHandler_FreeType2*>(memory->user)->FTRealloc(curSize, newSize, block);
|
||||
}
|
||||
|
||||
|
||||
unsigned long GpFontHandler_FreeType2::FTStreamIo(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count)
|
||||
{
|
||||
PortabilityLayer::IOStream *ioStream = static_cast<PortabilityLayer::IOStream*>(stream->descriptor.pointer);
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
if (!ioStream->SeekStart(static_cast<PortabilityLayer::UFilePos_t>(offset)))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const size_t bytesRead = ioStream->Read(buffer, count);
|
||||
return static_cast<unsigned long>(bytesRead);
|
||||
}
|
||||
|
||||
void GpFontHandler_FreeType2::FTStreamClose(FT_Stream stream)
|
||||
{
|
||||
(void)stream;
|
||||
}
|
||||
|
||||
void *GpFontHandler_FreeType2::FTAlloc(long size)
|
||||
{
|
||||
return malloc(static_cast<size_t>(size));
|
||||
}
|
||||
|
||||
void GpFontHandler_FreeType2::FTFree(void* block)
|
||||
{
|
||||
free(block);
|
||||
}
|
||||
|
||||
void *GpFontHandler_FreeType2::FTRealloc(long curSize, long newSize, void *block)
|
||||
{
|
||||
(void)curSize;
|
||||
return realloc(block, static_cast<size_t>(newSize));
|
||||
}
|
||||
|
||||
bool GpFontHandler_FreeType2::Init()
|
||||
{
|
||||
m_mem.user = this;
|
||||
m_mem.alloc = FTAllocThunk;
|
||||
m_mem.free = FTFreeThunk;
|
||||
m_mem.realloc = FTReallocThunk;
|
||||
|
||||
if (FT_New_Library(&m_mem, &m_library) != 0)
|
||||
return false;
|
||||
|
||||
m_ftIsInitialized = true;
|
||||
|
||||
FT_Add_Default_Modules(m_library);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "HostFontHandler.h"
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_SYSTEM_H
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
class IOStream;
|
||||
class HostFont;
|
||||
}
|
||||
|
||||
class GpFontHandler_FreeType2 final : public PortabilityLayer::HostFontHandler
|
||||
{
|
||||
public:
|
||||
PortabilityLayer::HostFont *LoadFont(PortabilityLayer::IOStream *stream) override;
|
||||
void Shutdown() override;
|
||||
|
||||
bool KeepStreamOpen() const override;
|
||||
|
||||
static GpFontHandler_FreeType2 *Create();
|
||||
|
||||
private:
|
||||
GpFontHandler_FreeType2();
|
||||
~GpFontHandler_FreeType2();
|
||||
|
||||
static void *FTAllocThunk(FT_Memory memory, long size);
|
||||
static void FTFreeThunk(FT_Memory memory, void* block);
|
||||
static void *FTReallocThunk(FT_Memory memory, long curSize, long newSize, void *block);
|
||||
|
||||
static unsigned long FTStreamIo(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count);
|
||||
static void FTStreamClose(FT_Stream stream);
|
||||
|
||||
void *FTAlloc(long size);
|
||||
void FTFree(void* block);
|
||||
void *FTRealloc(long curSize, long newSize, void *block);
|
||||
|
||||
bool Init();
|
||||
|
||||
FT_MemoryRec_ m_mem;
|
||||
FT_Library m_library;
|
||||
unsigned int m_currentSize;
|
||||
bool m_ftIsInitialized;
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "GpGlobalConfig.h"
|
||||
|
||||
GpGlobalConfig g_gpGlobalConfig;
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "EGpDisplayDriverType.h"
|
||||
#include "EGpAudioDriverType.h"
|
||||
#include "EGpInputDriverType.h"
|
||||
|
||||
struct IGpLogDriver;
|
||||
|
||||
struct GpGlobalConfig
|
||||
{
|
||||
EGpDisplayDriverType m_displayDriverType;
|
||||
EGpAudioDriverType m_audioDriverType;
|
||||
const EGpInputDriverType *m_inputDriverTypes;
|
||||
size_t m_numInputDrivers;
|
||||
|
||||
IGpLogDriver *m_logger;
|
||||
void *m_osGlobals;
|
||||
};
|
||||
|
||||
extern GpGlobalConfig g_gpGlobalConfig;
|
||||
@@ -1,23 +0,0 @@
|
||||
#include "GpInputDriverFactory.h"
|
||||
#include "GpInputDriverProperties.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
IGpInputDriver *GpInputDriverFactory::CreateInputDriver(const GpInputDriverProperties &properties)
|
||||
{
|
||||
assert(properties.m_type < EGpInputDriverType_Count);
|
||||
|
||||
if (ms_registry[properties.m_type])
|
||||
return ms_registry[properties.m_type](properties);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType type, FactoryFunc_t func)
|
||||
{
|
||||
assert(type < EGpInputDriverType_Count);
|
||||
|
||||
ms_registry[type] = func;
|
||||
}
|
||||
|
||||
GpInputDriverFactory::FactoryFunc_t GpInputDriverFactory::ms_registry[EGpInputDriverType_Count];
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "EGpInputDriverType.h"
|
||||
|
||||
struct IGpInputDriver;
|
||||
struct GpInputDriverProperties;
|
||||
|
||||
class GpInputDriverFactory
|
||||
{
|
||||
public:
|
||||
typedef IGpInputDriver *(*FactoryFunc_t)(const GpInputDriverProperties &properties);
|
||||
|
||||
static IGpInputDriver *CreateInputDriver(const GpInputDriverProperties &properties);
|
||||
static void RegisterInputDriverFactory(EGpInputDriverType type, FactoryFunc_t func);
|
||||
|
||||
private:
|
||||
static FactoryFunc_t ms_registry[EGpInputDriverType_Count];
|
||||
};
|
||||
@@ -1,127 +0,0 @@
|
||||
#include "GpMain.h"
|
||||
#include "GpAudioDriverFactory.h"
|
||||
#include "GpAudioDriverProperties.h"
|
||||
#include "GpFontHandlerFactory.h"
|
||||
#include "GpDisplayDriverFactory.h"
|
||||
#include "GpDisplayDriverProperties.h"
|
||||
#include "GpDisplayDriverTickStatus.h"
|
||||
#include "GpInputDriverFactory.h"
|
||||
#include "GpInputDriverProperties.h"
|
||||
#include "GpGlobalConfig.h"
|
||||
#include "GpAppEnvironment.h"
|
||||
#include "IGpAudioDriver.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpInputDriver.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
GpDisplayDriverTickStatus_t TickAppEnvironment(void *context, IGpFiber *vosFiber)
|
||||
{
|
||||
return static_cast<GpAppEnvironment*>(context)->Tick(vosFiber);
|
||||
}
|
||||
|
||||
void RenderAppEnvironment(void *context)
|
||||
{
|
||||
static_cast<GpAppEnvironment*>(context)->Render();
|
||||
}
|
||||
|
||||
bool AdjustRequestedResolution(void *context, uint32_t &physicalWidth, uint32_t &physicalHeight, uint32_t &virtualWidth, uint32_t &virtualheight, float &pixelScaleX, float &pixelScaleY)
|
||||
{
|
||||
return static_cast<GpAppEnvironment*>(context)->AdjustRequestedResolution(physicalWidth, physicalHeight, virtualWidth, virtualheight, pixelScaleX, pixelScaleY);
|
||||
}
|
||||
}
|
||||
|
||||
int GpMain::Run()
|
||||
{
|
||||
GpVOSEventQueue *eventQueue = new GpVOSEventQueue();
|
||||
GpAppEnvironment *appEnvironment = new GpAppEnvironment();
|
||||
|
||||
GpDisplayDriverProperties ddProps;
|
||||
memset(&ddProps, 0, sizeof(ddProps));
|
||||
|
||||
ddProps.m_frameTimeLockNumerator = 1;
|
||||
ddProps.m_frameTimeLockDenominator = 60;
|
||||
|
||||
// +/- 1% tolerance for frame time variance
|
||||
ddProps.m_frameTimeLockMinNumerator = 99;
|
||||
ddProps.m_frameTimeLockMinDenominator = 6000;
|
||||
ddProps.m_frameTimeLockMaxNumerator = 101;
|
||||
ddProps.m_frameTimeLockMaxDenominator = 6000;
|
||||
|
||||
ddProps.m_tickFunc = TickAppEnvironment;
|
||||
ddProps.m_tickFuncContext = appEnvironment;
|
||||
|
||||
ddProps.m_renderFunc = RenderAppEnvironment;
|
||||
ddProps.m_renderFuncContext = appEnvironment;
|
||||
|
||||
ddProps.m_adjustRequestedResolutionFunc = AdjustRequestedResolution;
|
||||
ddProps.m_adjustRequestedResolutionFuncContext = appEnvironment;
|
||||
|
||||
ddProps.m_type = g_gpGlobalConfig.m_displayDriverType;
|
||||
ddProps.m_osGlobals = g_gpGlobalConfig.m_osGlobals;
|
||||
ddProps.m_eventQueue = eventQueue;
|
||||
ddProps.m_logger = g_gpGlobalConfig.m_logger;
|
||||
|
||||
GpAudioDriverProperties adProps;
|
||||
memset(&adProps, 0, sizeof(adProps));
|
||||
|
||||
// The sample rate used in all of Glider PRO's sound is 0x56ee8ba3
|
||||
// This appears to be the "standard" Mac sample rate, probably rounded from 244800/11.
|
||||
adProps.m_type = g_gpGlobalConfig.m_audioDriverType;
|
||||
adProps.m_sampleRate = (244800 * 2 + 11) / (11 * 2);
|
||||
#ifdef NDEBUG
|
||||
adProps.m_debug = false;
|
||||
#else
|
||||
adProps.m_debug = true;
|
||||
#endif
|
||||
adProps.m_logger = g_gpGlobalConfig.m_logger;
|
||||
|
||||
IGpInputDriver **inputDrivers = static_cast<IGpInputDriver**>(malloc(sizeof(IGpInputDriver*) * g_gpGlobalConfig.m_numInputDrivers));
|
||||
|
||||
size_t numCreatedInputDrivers = 0;
|
||||
if (inputDrivers)
|
||||
{
|
||||
for (size_t i = 0; i < g_gpGlobalConfig.m_numInputDrivers; i++)
|
||||
{
|
||||
GpInputDriverProperties inputProps;
|
||||
memset(&inputProps, 0, sizeof(inputProps));
|
||||
|
||||
inputProps.m_type = g_gpGlobalConfig.m_inputDriverTypes[i];
|
||||
inputProps.m_eventQueue = eventQueue;
|
||||
|
||||
if (IGpInputDriver *driver = GpInputDriverFactory::CreateInputDriver(inputProps))
|
||||
inputDrivers[numCreatedInputDrivers++] = driver;
|
||||
}
|
||||
}
|
||||
|
||||
IGpDisplayDriver *displayDriver = GpDisplayDriverFactory::CreateDisplayDriver(ddProps);
|
||||
IGpAudioDriver *audioDriver = GpAudioDriverFactory::CreateAudioDriver(adProps);
|
||||
PortabilityLayer::HostFontHandler *fontHandler = GpFontHandlerFactory::Create();
|
||||
|
||||
appEnvironment->Init();
|
||||
|
||||
appEnvironment->SetDisplayDriver(displayDriver);
|
||||
appEnvironment->SetAudioDriver(audioDriver);
|
||||
appEnvironment->SetInputDrivers(inputDrivers, numCreatedInputDrivers);
|
||||
appEnvironment->SetFontHandler(fontHandler);
|
||||
appEnvironment->SetVOSEventQueue(eventQueue);
|
||||
|
||||
// Start the display loop
|
||||
displayDriver->Run();
|
||||
|
||||
// Clean up
|
||||
if (inputDrivers)
|
||||
{
|
||||
for (size_t i = 0; i < numCreatedInputDrivers; i++)
|
||||
inputDrivers[i]->Shutdown();
|
||||
|
||||
free(inputDrivers);
|
||||
}
|
||||
|
||||
// GP TODO: Cleanup
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace GpMain
|
||||
{
|
||||
int Run();
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "GpFiber_Win32.h"
|
||||
#include "GpFileSystem_Win32.h"
|
||||
#include "GpLogDriver_Win32.h"
|
||||
#include "GpFontHandlerFactory.h"
|
||||
#include "GpInputDriverFactory.h"
|
||||
#include "GpAppInterface.h"
|
||||
#include "GpSystemServices_Win32.h"
|
||||
@@ -27,6 +28,7 @@ GpWindowsGlobals g_gpWindowsGlobals;
|
||||
extern "C" __declspec(dllimport) IGpAudioDriver *GpDriver_CreateAudioDriver_XAudio2(const GpAudioDriverProperties &properties);
|
||||
extern "C" __declspec(dllimport) IGpDisplayDriver *GpDriver_CreateDisplayDriver_D3D11(const GpDisplayDriverProperties &properties);
|
||||
extern "C" __declspec(dllimport) IGpInputDriver *GpDriver_CreateInputDriver_XInput(const GpInputDriverProperties &properties);
|
||||
extern "C" __declspec(dllimport) PortabilityLayer::HostFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties);
|
||||
|
||||
static void PostMouseEvent(IGpVOSEventQueue *eventQueue, GpMouseEventType_t eventType, GpMouseButton_t button, int32_t x, int32_t y, float pixelScaleX, float pixelScaleY)
|
||||
{
|
||||
@@ -432,6 +434,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
|
||||
g_gpGlobalConfig.m_audioDriverType = EGpAudioDriverType_XAudio2;
|
||||
|
||||
g_gpGlobalConfig.m_fontHandlerType = EGpFontHandlerType_FreeType2;
|
||||
|
||||
EGpInputDriverType inputDrivers[] =
|
||||
{
|
||||
EGpInputDriverType_XInput
|
||||
@@ -446,6 +450,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_D3D11, GpDriver_CreateDisplayDriver_D3D11);
|
||||
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_XAudio2, GpDriver_CreateAudioDriver_XAudio2);
|
||||
GpInputDriverFactory::RegisterInputDriverFactory(EGpInputDriverType_XInput, GpDriver_CreateInputDriver_XInput);
|
||||
GpFontHandlerFactory::RegisterFontHandlerFactory(EGpFontHandlerType_FreeType2, GpDriver_CreateFontHandler_FreeType2);
|
||||
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Windows environment configured, starting up");
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#include "GpMemoryBuffer.h"
|
||||
|
||||
#include <new>
|
||||
|
||||
void *GpMemoryBuffer::Contents()
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>(this) + AlignedSize();
|
||||
}
|
||||
|
||||
size_t GpMemoryBuffer::Size()
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
void GpMemoryBuffer::Destroy()
|
||||
{
|
||||
delete[] reinterpret_cast<uint8_t*>(this);
|
||||
}
|
||||
|
||||
GpMemoryBuffer *GpMemoryBuffer::Create(size_t sz)
|
||||
{
|
||||
const size_t allowedSize = SIZE_MAX - AlignedSize();
|
||||
if (sz > allowedSize)
|
||||
return nullptr;
|
||||
|
||||
const size_t bufferSize = GpMemoryBuffer::AlignedSize() + sz;
|
||||
|
||||
uint8_t *buffer = new uint8_t[bufferSize];
|
||||
new (buffer) GpMemoryBuffer(sz);
|
||||
|
||||
return reinterpret_cast<GpMemoryBuffer*>(buffer);
|
||||
}
|
||||
|
||||
GpMemoryBuffer::GpMemoryBuffer(size_t sz)
|
||||
: m_size(sz)
|
||||
{
|
||||
}
|
||||
|
||||
GpMemoryBuffer::~GpMemoryBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
size_t GpMemoryBuffer::AlignedSize()
|
||||
{
|
||||
const size_t paddedSize = (sizeof(GpMemoryBuffer) + GP_SYSTEM_MEMORY_ALIGNMENT - 1);
|
||||
const size_t sz = paddedSize - paddedSize % GP_SYSTEM_MEMORY_ALIGNMENT;
|
||||
|
||||
return sz;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "HostMemoryBuffer.h"
|
||||
|
||||
class GpMemoryBuffer final : public PortabilityLayer::HostMemoryBuffer
|
||||
{
|
||||
public:
|
||||
void *Contents() override;
|
||||
size_t Size() override;
|
||||
void Destroy() override;
|
||||
|
||||
static GpMemoryBuffer *Create(size_t sz);
|
||||
|
||||
private:
|
||||
explicit GpMemoryBuffer(size_t sz);
|
||||
~GpMemoryBuffer();
|
||||
|
||||
static size_t AlignedSize();
|
||||
|
||||
size_t m_size;
|
||||
};
|
||||
10
Aerofoil/GpShell.props
Normal file
10
Aerofoil/GpShell.props
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<IncludePath>$(SolutionDir)GpShell;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup />
|
||||
<ItemGroup />
|
||||
</Project>
|
||||
@@ -1,45 +0,0 @@
|
||||
#include "GpVOSEventQueue.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
GpVOSEventQueue::GpVOSEventQueue()
|
||||
: m_firstEvent(0)
|
||||
, m_numEventsQueued(0)
|
||||
{
|
||||
}
|
||||
|
||||
GpVOSEventQueue::~GpVOSEventQueue()
|
||||
{
|
||||
}
|
||||
|
||||
const GpVOSEvent *GpVOSEventQueue::GetNext()
|
||||
{
|
||||
if (m_numEventsQueued)
|
||||
return m_events + m_firstEvent;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GpVOSEventQueue::DischargeOne()
|
||||
{
|
||||
assert(m_numEventsQueued > 0);
|
||||
|
||||
m_numEventsQueued--;
|
||||
m_firstEvent++;
|
||||
if (m_firstEvent == kMaxEvents)
|
||||
m_firstEvent = 0;
|
||||
}
|
||||
|
||||
GpVOSEvent *GpVOSEventQueue::QueueEvent()
|
||||
{
|
||||
if (m_numEventsQueued == kMaxEvents)
|
||||
return nullptr;
|
||||
|
||||
size_t nextEvent = m_firstEvent + m_numEventsQueued;
|
||||
if (nextEvent >= kMaxEvents)
|
||||
nextEvent -= kMaxEvents;
|
||||
|
||||
m_numEventsQueued++;
|
||||
|
||||
return m_events + nextEvent;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HostVOSEventQueue.h"
|
||||
#include "GpVOSEvent.h"
|
||||
|
||||
class GpVOSEventQueue final : public PortabilityLayer::HostVOSEventQueue
|
||||
{
|
||||
public:
|
||||
GpVOSEventQueue();
|
||||
~GpVOSEventQueue();
|
||||
|
||||
const GpVOSEvent *GetNext() override;
|
||||
void DischargeOne() override;
|
||||
|
||||
GpVOSEvent *QueueEvent() override;
|
||||
|
||||
private:
|
||||
static const size_t kMaxEvents = 10000;
|
||||
|
||||
GpVOSEvent m_events[kMaxEvents];
|
||||
size_t m_firstEvent;
|
||||
size_t m_numEventsQueued;
|
||||
};
|
||||
Reference in New Issue
Block a user