Move font handler and platform-independent shell stuff

This commit is contained in:
elasota
2020-09-12 11:52:19 -04:00
parent 4a78f10975
commit 1d3c84a473
37 changed files with 597 additions and 117 deletions

View File

@@ -0,0 +1,186 @@
#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);
}
}

View File

@@ -0,0 +1,73 @@
#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;
};

View File

@@ -0,0 +1,23 @@
#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];

View File

@@ -0,0 +1,18 @@
#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];
};

View File

@@ -0,0 +1,23 @@
#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];

View File

@@ -0,0 +1,18 @@
#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];
};

11
GpShell/GpFiberStarter.h Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
struct IGpFiber;
class GpFiberStarter
{
public:
typedef void(*ThreadFunc_t)(void *context);
static IGpFiber *StartFiber(ThreadFunc_t threadFunc, void *context, IGpFiber *creatingFiber);
};

View File

@@ -0,0 +1,23 @@
#include "GpFontHandlerFactory.h"
#include "GpFontHandlerProperties.h"
#include <assert.h>
PortabilityLayer::HostFontHandler *GpFontHandlerFactory::CreateFontHandler(const GpFontHandlerProperties &properties)
{
assert(properties.m_type < EGpFontHandlerType_Count);
if (ms_registry[properties.m_type])
return ms_registry[properties.m_type](properties);
else
return nullptr;
}
void GpFontHandlerFactory::RegisterFontHandlerFactory(EGpFontHandlerType type, FactoryFunc_t func)
{
assert(type < EGpFontHandlerType_Count);
ms_registry[type] = func;
}
GpFontHandlerFactory::FactoryFunc_t GpFontHandlerFactory::ms_registry[EGpFontHandlerType_Count];

View File

@@ -0,0 +1,22 @@
#pragma once
#include "EGpFontHandlerType.h"
namespace PortabilityLayer
{
class HostFontHandler;
}
struct GpFontHandlerProperties;
class GpFontHandlerFactory
{
public:
typedef PortabilityLayer::HostFontHandler *(*FactoryFunc_t)(const GpFontHandlerProperties &properties);
static PortabilityLayer::HostFontHandler *CreateFontHandler(const GpFontHandlerProperties &properties);
static void RegisterFontHandlerFactory(EGpFontHandlerType type, FactoryFunc_t func);
private:
static FactoryFunc_t ms_registry[EGpFontHandlerType_Count];
};

View File

@@ -0,0 +1,3 @@
#include "GpGlobalConfig.h"
GpGlobalConfig g_gpGlobalConfig;

23
GpShell/GpGlobalConfig.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include "EGpDisplayDriverType.h"
#include "EGpAudioDriverType.h"
#include "EGpFontHandlerType.h"
#include "EGpInputDriverType.h"
struct IGpLogDriver;
struct GpGlobalConfig
{
EGpDisplayDriverType m_displayDriverType;
EGpAudioDriverType m_audioDriverType;
EGpFontHandlerType m_fontHandlerType;
const EGpInputDriverType *m_inputDriverTypes;
size_t m_numInputDrivers;
IGpLogDriver *m_logger;
void *m_osGlobals;
};
extern GpGlobalConfig g_gpGlobalConfig;

View File

@@ -0,0 +1,23 @@
#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];

View File

@@ -0,0 +1,18 @@
#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];
};

133
GpShell/GpMain.cpp Normal file
View File

@@ -0,0 +1,133 @@
#include "GpMain.h"
#include "GpAudioDriverFactory.h"
#include "GpAudioDriverProperties.h"
#include "GpDisplayDriverFactory.h"
#include "GpDisplayDriverProperties.h"
#include "GpDisplayDriverTickStatus.h"
#include "GpFontHandlerFactory.h"
#include "GpFontHandlerProperties.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));
GpFontHandlerProperties fontProps;
memset(&fontProps, 0, sizeof(fontProps));
fontProps.m_type = g_gpGlobalConfig.m_fontHandlerType;
// 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::CreateFontHandler(fontProps);
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;
}

6
GpShell/GpMain.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
namespace GpMain
{
int Run();
}

View File

@@ -0,0 +1,49 @@
#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;
}

21
GpShell/GpMemoryBuffer.h Normal file
View File

@@ -0,0 +1,21 @@
#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;
};

147
GpShell/GpShell.vcxproj Normal file
View File

@@ -0,0 +1,147 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{10CF9B5F-61D0-4B5B-89F4-810B58FC053D}</ProjectGuid>
<RootNamespace>GpShell</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Common.props" />
<Import Project="..\GpCommon.props" />
<Import Project="..\PortabilityLayer.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" />
<Import Project="..\Common.props" />
<Import Project="..\GpCommon.props" />
<Import Project="..\PortabilityLayer.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" />
<Import Project="..\Common.props" />
<Import Project="..\GpCommon.props" />
<Import Project="..\PortabilityLayer.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" />
<Import Project="..\Common.props" />
<Import Project="..\GpCommon.props" />
<Import Project="..\PortabilityLayer.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="GpAppEnvironment.cpp" />
<ClCompile Include="GpAudioDriverFactory.cpp" />
<ClCompile Include="GpDisplayDriverFactory.cpp" />
<ClCompile Include="GpFontHandlerFactory.cpp" />
<ClCompile Include="GpGlobalConfig.cpp" />
<ClCompile Include="GpInputDriverFactory.cpp" />
<ClCompile Include="GpMain.cpp" />
<ClCompile Include="GpMemoryBuffer.cpp" />
<ClCompile Include="GpVOSEventQueue.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\GpCommon\EGpFontHandlerType.h" />
<ClInclude Include="GpFontHandlerProperties.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="GpAppEnvironment.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpAudioDriverFactory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpDisplayDriverFactory.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="GpMemoryBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GpVOSEventQueue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="GpFontHandlerProperties.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\GpCommon\EGpFontHandlerType.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,45 @@
#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;
}

25
GpShell/GpVOSEventQueue.h Normal file
View File

@@ -0,0 +1,25 @@
#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;
};