Allocator refactor

This commit is contained in:
elasota
2021-04-28 01:46:07 -04:00
parent 472462c535
commit a2d374f650
75 changed files with 473 additions and 253 deletions

View File

@@ -43,6 +43,7 @@
<Import Project="..\GpMainApp.props" /> <Import Project="..\GpMainApp.props" />
<Import Project="..\GpShell.props" /> <Import Project="..\GpShell.props" />
<Import Project="..\Debug.props" /> <Import Project="..\Debug.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -52,6 +53,7 @@
<Import Project="..\GpMainApp.props" /> <Import Project="..\GpMainApp.props" />
<Import Project="..\Release.props" /> <Import Project="..\Release.props" />
<Import Project="..\GpShell.props" /> <Import Project="..\GpShell.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup />
@@ -82,6 +84,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="GpBWCursor_Win32.cpp" /> <ClCompile Include="GpBWCursor_Win32.cpp" />
<ClCompile Include="GpColorCursor_Win32.cpp" /> <ClCompile Include="GpColorCursor_Win32.cpp" />
<ClCompile Include="GpFileStream_Win32.cpp" /> <ClCompile Include="GpFileStream_Win32.cpp" />

View File

@@ -28,6 +28,9 @@
<ClCompile Include="GpBWCursor_Win32.cpp"> <ClCompile Include="GpBWCursor_Win32.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\GpCommon\EGpInputDriverType.h"> <ClInclude Include="..\GpCommon\EGpInputDriverType.h">

View File

@@ -21,6 +21,7 @@
#include "GpBWCursor_Win32.h" #include "GpBWCursor_Win32.h"
#include "GpWindows.h" #include "GpWindows.h"
#include "IGpAllocator.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@@ -34,19 +35,19 @@ void GpBWCursor_Win32::Destroy()
this->DecRef(); this->DecRef();
} }
IGpCursor_Win32 *GpBWCursor_Win32::Create(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY) IGpCursor_Win32 *GpBWCursor_Win32::Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY)
{ {
size_t numBits = width * height; size_t numBits = width * height;
size_t numBytes = (width * height + 7) / 8; size_t numBytes = (numBits + 7) / 8;
uint8_t *convertedAndData = static_cast<uint8_t*>(malloc(numBytes)); uint8_t *convertedAndData = static_cast<uint8_t*>(alloc->Alloc(numBytes));
uint8_t *convertedXorData = static_cast<uint8_t*>(malloc(numBytes)); uint8_t *convertedXorData = static_cast<uint8_t*>(alloc->Alloc(numBytes));
if (!convertedAndData || !convertedXorData) if (!convertedAndData || !convertedXorData)
{ {
if (convertedAndData) if (convertedAndData)
free(convertedAndData); alloc->Release(convertedAndData);
if (convertedXorData) if (convertedXorData)
free(convertedXorData); alloc->Release(convertedXorData);
return nullptr; return nullptr;
} }
@@ -62,25 +63,26 @@ IGpCursor_Win32 *GpBWCursor_Win32::Create(size_t width, size_t height, const voi
HCURSOR hcursor = CreateCursor(g_gpWindowsGlobals.m_hInstance, static_cast<int>(hotSpotX), static_cast<int>(hotSpotY), static_cast<int>(width), static_cast<int>(height), convertedAndData, convertedXorData); HCURSOR hcursor = CreateCursor(g_gpWindowsGlobals.m_hInstance, static_cast<int>(hotSpotX), static_cast<int>(hotSpotY), static_cast<int>(width), static_cast<int>(height), convertedAndData, convertedXorData);
free(convertedAndData); alloc->Release(convertedAndData);
free(convertedXorData); alloc->Release(convertedXorData);
if (!hcursor) if (!hcursor)
return nullptr; return nullptr;
void *storage = malloc(sizeof(GpBWCursor_Win32)); void *storage = alloc->Alloc(sizeof(GpBWCursor_Win32));
if (!storage) if (!storage)
{ {
DestroyCursor(hcursor); DestroyCursor(hcursor);
return nullptr; return nullptr;
} }
return new (storage) GpBWCursor_Win32(hcursor); return new (storage) GpBWCursor_Win32(hcursor, alloc);
} }
GpBWCursor_Win32::GpBWCursor_Win32(HCURSOR cursor) GpBWCursor_Win32::GpBWCursor_Win32(HCURSOR cursor, IGpAllocator *alloc)
: m_cursor(cursor) : m_cursor(cursor)
, m_refCount(1) , m_refCount(1)
, m_alloc(alloc)
{ {
} }
@@ -104,7 +106,8 @@ void GpBWCursor_Win32::DecRef()
m_refCount--; m_refCount--;
if (m_refCount == 0) if (m_refCount == 0)
{ {
IGpAllocator *alloc = m_alloc;
this->~GpBWCursor_Win32(); this->~GpBWCursor_Win32();
free(this); alloc->Release(this);
} }
} }

View File

@@ -3,6 +3,8 @@
#include "IGpCursor_Win32.h" #include "IGpCursor_Win32.h"
#include "GpWindows.h" #include "GpWindows.h"
struct IGpAllocator;
class GpBWCursor_Win32 final : public IGpCursor_Win32 class GpBWCursor_Win32 final : public IGpCursor_Win32
{ {
public: public:
@@ -13,12 +15,13 @@ public:
void IncRef() override; void IncRef() override;
void DecRef() override; void DecRef() override;
static IGpCursor_Win32 *Create(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY); static IGpCursor_Win32 *Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
private: private:
GpBWCursor_Win32(HCURSOR cursor); GpBWCursor_Win32(HCURSOR cursor, IGpAllocator *alloc);
~GpBWCursor_Win32(); ~GpBWCursor_Win32();
HCURSOR m_cursor; HCURSOR m_cursor;
int m_refCount; int m_refCount;
IGpAllocator *m_alloc;
}; };

View File

@@ -20,6 +20,7 @@
*/ */
#include "GpColorCursor_Win32.h" #include "GpColorCursor_Win32.h"
#include "IGpAllocator.h"
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@@ -31,7 +32,7 @@ void GpColorCursor_Win32::Destroy()
this->DecRef(); this->DecRef();
} }
IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY) IGpCursor_Win32 *GpColorCursor_Win32::Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY)
{ {
const size_t paddingBits = (sizeof(void*) * 8); const size_t paddingBits = (sizeof(void*) * 8);
@@ -52,7 +53,7 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
size_t maskPitch = width + paddingBits - 1; size_t maskPitch = width + paddingBits - 1;
maskPitch -= maskPitch % paddingBits; maskPitch -= maskPitch % paddingBits;
LPVOID maskBits = malloc(maskPitch * height); LPVOID maskBits = alloc->Alloc(maskPitch * height);
if (!maskBits) if (!maskBits)
return nullptr; return nullptr;
@@ -71,6 +72,8 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
ii.hbmMask = CreateBitmap(width, height, 1, 1, maskBits); ii.hbmMask = CreateBitmap(width, height, 1, 1, maskBits);
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
alloc->Release(maskBits);
size_t cursorPitch = width * 4; size_t cursorPitch = width * 4;
size_t numPixels = width * height; size_t numPixels = width * height;
@@ -90,19 +93,20 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
if (!hicon) if (!hicon)
return nullptr; return nullptr;
void *storage = malloc(sizeof(GpColorCursor_Win32)); void *storage = alloc->Alloc(sizeof(GpColorCursor_Win32));
if (!storage) if (!storage)
{ {
DestroyIcon(hicon); DestroyIcon(hicon);
return nullptr; return nullptr;
} }
return new (storage) GpColorCursor_Win32(reinterpret_cast<HCURSOR>(hicon)); return new (storage) GpColorCursor_Win32(alloc, reinterpret_cast<HCURSOR>(hicon));
} }
GpColorCursor_Win32::GpColorCursor_Win32(HCURSOR cursor) GpColorCursor_Win32::GpColorCursor_Win32(IGpAllocator *alloc, HCURSOR cursor)
: m_cursor(cursor) : m_cursor(cursor)
, m_refCount(1) , m_refCount(1)
, m_alloc(alloc)
{ {
} }
@@ -126,7 +130,8 @@ void GpColorCursor_Win32::DecRef()
m_refCount--; m_refCount--;
if (m_refCount == 0) if (m_refCount == 0)
{ {
IGpAllocator *alloc = m_alloc;
this->~GpColorCursor_Win32(); this->~GpColorCursor_Win32();
free(this); alloc->Release(this);
} }
} }

View File

@@ -3,6 +3,7 @@
#include "IGpCursor_Win32.h" #include "IGpCursor_Win32.h"
#include "GpWindows.h" #include "GpWindows.h"
struct IGpAllocator;
class GpColorCursor_Win32 final : public IGpCursor_Win32 class GpColorCursor_Win32 final : public IGpCursor_Win32
{ {
@@ -14,12 +15,13 @@ public:
void IncRef() override; void IncRef() override;
void DecRef() override; void DecRef() override;
static IGpCursor_Win32 *Create(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY); static IGpCursor_Win32 *Create(IGpAllocator *alloc, size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
private: private:
GpColorCursor_Win32(HCURSOR cursor); GpColorCursor_Win32(IGpAllocator *alloc, HCURSOR cursor);
~GpColorCursor_Win32(); ~GpColorCursor_Win32();
HCURSOR m_cursor; HCURSOR m_cursor;
int m_refCount; int m_refCount;
IGpAllocator *m_alloc;
}; };

View File

@@ -1,8 +1,10 @@
#include "GpFileSystem_Win32.h" #include "GpFileSystem_Win32.h"
#include "GpAllocator_C.h"
#include "GpApplicationName.h" #include "GpApplicationName.h"
#include "GpFileStream_Win32.h" #include "GpFileStream_Win32.h"
#include "GpWindows.h" #include "GpWindows.h"
#include "IGpAllocator.h"
#include "IGpDirectoryCursor.h" #include "IGpDirectoryCursor.h"
#include <string> #include <string>
@@ -12,33 +14,36 @@
#include <assert.h> #include <assert.h>
struct IGpAllocator;
extern GpWindowsGlobals g_gpWindowsGlobals; extern GpWindowsGlobals g_gpWindowsGlobals;
class GpDirectoryCursor_Win32 final : public IGpDirectoryCursor class GpDirectoryCursor_Win32 final : public IGpDirectoryCursor
{ {
public: public:
static GpDirectoryCursor_Win32 *Create(const HANDLE &handle, const WIN32_FIND_DATAW &findData); static GpDirectoryCursor_Win32 *Create(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData);
bool GetNext(const char *&outFileName) override; bool GetNext(const char *&outFileName) override;
void Destroy() override; void Destroy() override;
private: private:
GpDirectoryCursor_Win32(const HANDLE &handle, const WIN32_FIND_DATAW &findData); GpDirectoryCursor_Win32(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData);
~GpDirectoryCursor_Win32(); ~GpDirectoryCursor_Win32();
IGpAllocator *m_alloc;
HANDLE m_handle; HANDLE m_handle;
WIN32_FIND_DATAW m_findData; WIN32_FIND_DATAW m_findData;
char m_chars[MAX_PATH + 1]; char m_chars[MAX_PATH + 1];
bool m_haveNext; bool m_haveNext;
}; };
GpDirectoryCursor_Win32 *GpDirectoryCursor_Win32::Create(const HANDLE &handle, const WIN32_FIND_DATAW &findData) GpDirectoryCursor_Win32 *GpDirectoryCursor_Win32::Create(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData)
{ {
void *storage = malloc(sizeof(GpDirectoryCursor_Win32)); void *storage = alloc->Alloc(sizeof(GpDirectoryCursor_Win32));
if (!storage) if (!storage)
return nullptr; return nullptr;
return new (storage) GpDirectoryCursor_Win32(handle, findData); return new (storage) GpDirectoryCursor_Win32(alloc, handle, findData);
} }
bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName) bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName)
@@ -82,14 +87,16 @@ bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName)
void GpDirectoryCursor_Win32::Destroy() void GpDirectoryCursor_Win32::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpDirectoryCursor_Win32(); this->~GpDirectoryCursor_Win32();
free(this); alloc->Release(this);
} }
GpDirectoryCursor_Win32::GpDirectoryCursor_Win32(const HANDLE &handle, const WIN32_FIND_DATAW &findData) GpDirectoryCursor_Win32::GpDirectoryCursor_Win32(IGpAllocator *alloc, const HANDLE &handle, const WIN32_FIND_DATAW &findData)
: m_handle(handle) : m_handle(handle)
, m_findData(findData) , m_findData(findData)
, m_haveNext(true) , m_haveNext(true)
, m_alloc(alloc)
{ {
} }
@@ -99,6 +106,7 @@ GpDirectoryCursor_Win32::~GpDirectoryCursor_Win32()
} }
GpFileSystem_Win32::GpFileSystem_Win32() GpFileSystem_Win32::GpFileSystem_Win32()
: m_alloc(GpAllocator_C::GetInstance())
{ {
// GP TODO: This shouldn't be static init since it allocates memory // GP TODO: This shouldn't be static init since it allocates memory
m_executablePath[0] = 0; m_executablePath[0] = 0;
@@ -277,7 +285,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
{ {
wchar_t winPath[MAX_PATH + 2]; wchar_t winPath[MAX_PATH + 2];
const char **expandedPaths = static_cast<const char**>(malloc(sizeof(const char*) * (numPaths + 1))); const char **expandedPaths = static_cast<const char**>(m_alloc->Alloc(sizeof(const char*) * (numPaths + 1)));
if (!expandedPaths) if (!expandedPaths)
return nullptr; return nullptr;
@@ -286,7 +294,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
expandedPaths[numPaths] = "*"; expandedPaths[numPaths] = "*";
const bool isPathResolved = ResolvePath(virtualDirectory, expandedPaths, numPaths + 1, winPath); const bool isPathResolved = ResolvePath(virtualDirectory, expandedPaths, numPaths + 1, winPath);
free(expandedPaths); m_alloc->Release(expandedPaths);
if (!isPathResolved) if (!isPathResolved)
return nullptr; return nullptr;
@@ -297,7 +305,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
if (ff == INVALID_HANDLE_VALUE) if (ff == INVALID_HANDLE_VALUE)
return nullptr; return nullptr;
return GpDirectoryCursor_Win32::Create(ff, findData); return GpDirectoryCursor_Win32::Create(m_alloc, ff, findData);
} }
bool GpFileSystem_Win32::ValidateFilePathUnicodeChar(uint32_t c) const bool GpFileSystem_Win32::ValidateFilePathUnicodeChar(uint32_t c) const

View File

@@ -41,5 +41,7 @@ private:
std::wstring m_fontCacheDir; std::wstring m_fontCacheDir;
wchar_t m_executablePath[MAX_PATH]; wchar_t m_executablePath[MAX_PATH];
IGpAllocator *m_alloc;
static GpFileSystem_Win32 ms_instance; static GpFileSystem_Win32 ms_instance;
}; };

View File

@@ -1,3 +1,4 @@
#include "GpAllocator_C.h"
#include "GpLogDriver_Win32.h" #include "GpLogDriver_Win32.h"
#include "GpFileSystem_Win32.h" #include "GpFileSystem_Win32.h"
@@ -7,6 +8,7 @@
GpLogDriver_Win32::GpLogDriver_Win32() GpLogDriver_Win32::GpLogDriver_Win32()
: m_stream(nullptr) : m_stream(nullptr)
, m_isInitialized(false) , m_isInitialized(false)
, m_alloc(GpAllocator_C::GetInstance())
{ {
} }
@@ -58,14 +60,14 @@ void GpLogDriver_Win32::VPrintf(Category category, const char *fmt, va_list args
if (formattedSize <= 0) if (formattedSize <= 0)
return; return;
char *charBuff = static_cast<char*>(malloc(formattedSize + 1)); char *charBuff = static_cast<char*>(m_alloc->Alloc(formattedSize + 1));
if (!charBuff) if (!charBuff)
return; return;
vsnprintf(charBuff, formattedSize + 1, fmt, args); vsnprintf(charBuff, formattedSize + 1, fmt, args);
m_stream->Write(charBuff, formattedSize); m_stream->Write(charBuff, formattedSize);
free(charBuff); m_alloc->Release(charBuff);
} }
m_stream->Write("\n", 1); m_stream->Write("\n", 1);

View File

@@ -3,6 +3,7 @@
#include "IGpLogDriver.h" #include "IGpLogDriver.h"
class GpIOStream; class GpIOStream;
struct IGpAllocator;
class GpLogDriver_Win32 : public IGpLogDriver class GpLogDriver_Win32 : public IGpLogDriver
{ {
@@ -20,6 +21,7 @@ private:
void InitInternal(); void InitInternal();
GpIOStream *m_stream; GpIOStream *m_stream;
IGpAllocator *m_alloc;
bool m_isInitialized; bool m_isInitialized;
static GpLogDriver_Win32 ms_instance; static GpLogDriver_Win32 ms_instance;

View File

@@ -1,4 +1,5 @@
#include "GpMain.h" #include "GpMain.h"
#include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h" #include "GpAudioDriverFactory.h"
#include "GpBWCursor_Win32.h" #include "GpBWCursor_Win32.h"
#include "GpColorCursor_Win32.h" #include "GpColorCursor_Win32.h"
@@ -410,12 +411,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
} }
IGpLogDriver *logger = GpLogDriver_Win32::GetInstance(); IGpLogDriver *logger = GpLogDriver_Win32::GetInstance();
IGpAllocator *alloc = GpAllocator_C::GetInstance();
IGpSystemServices *sysServices = GpSystemServices_Win32::GetInstance();
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection(); GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance()); drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Win32::GetInstance()); drivers->SetDriver<GpDriverIDs::kSystemServices>(sysServices);
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance()); drivers->SetDriver<GpDriverIDs::kLog>(logger);
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
g_gpWindowsGlobals.m_hInstance = hInstance; g_gpWindowsGlobals.m_hInstance = hInstance;
g_gpWindowsGlobals.m_hPrevInstance = hPrevInstance; g_gpWindowsGlobals.m_hPrevInstance = hPrevInstance;
@@ -448,7 +452,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpGlobalConfig.m_osGlobals = &g_gpWindowsGlobals; g_gpGlobalConfig.m_osGlobals = &g_gpWindowsGlobals;
g_gpGlobalConfig.m_logger = logger; g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_Win32::GetInstance(); g_gpGlobalConfig.m_systemServices = sysServices;
g_gpGlobalConfig.m_allocator = alloc;
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_D3D11, GpDriver_CreateDisplayDriver_D3D11); GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_D3D11, GpDriver_CreateDisplayDriver_D3D11);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_XAudio2, GpDriver_CreateAudioDriver_XAudio2); GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_XAudio2, GpDriver_CreateAudioDriver_XAudio2);

View File

@@ -1,5 +1,6 @@
#include "GpMutex_Win32.h" #include "GpMutex_Win32.h"
#include "IGpAllocator.h"
#include "GpWindows.h" #include "GpWindows.h"
#include <stdlib.h> #include <stdlib.h>
@@ -7,8 +8,9 @@
void GpMutex_Win32::Destroy() void GpMutex_Win32::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpMutex_Win32(); this->~GpMutex_Win32();
free(this); alloc->Release(this);
} }
void GpMutex_Win32::Lock() void GpMutex_Win32::Lock()
@@ -22,16 +24,17 @@ void GpMutex_Win32::Unlock()
} }
GpMutex_Win32 *GpMutex_Win32::Create() GpMutex_Win32 *GpMutex_Win32::Create(IGpAllocator *alloc)
{ {
void *storage = malloc(sizeof(GpMutex_Win32)); void *storage = alloc->Alloc(sizeof(GpMutex_Win32));
if (!storage) if (!storage)
return nullptr; return nullptr;
return new (storage) GpMutex_Win32(); return new (storage) GpMutex_Win32(alloc);
} }
GpMutex_Win32::GpMutex_Win32() GpMutex_Win32::GpMutex_Win32(IGpAllocator *alloc)
: m_alloc(alloc)
{ {
InitializeCriticalSection(&m_critSection); InitializeCriticalSection(&m_critSection);
} }

View File

@@ -4,6 +4,8 @@
#include "GpWindows.h" #include "GpWindows.h"
struct IGpAllocator;
class GpMutex_Win32 final : public IGpMutex class GpMutex_Win32 final : public IGpMutex
{ {
public: public:
@@ -11,11 +13,12 @@ public:
void Lock() override; void Lock() override;
void Unlock() override; void Unlock() override;
static GpMutex_Win32 *Create(); static GpMutex_Win32 *Create(IGpAllocator *alloc);
private: private:
const GpMutex_Win32(); explicit GpMutex_Win32(IGpAllocator *alloc);
~GpMutex_Win32(); ~GpMutex_Win32();
CRITICAL_SECTION m_critSection; CRITICAL_SECTION m_critSection;
IGpAllocator *m_alloc;
}; };

View File

@@ -2,6 +2,7 @@
#include "GpMutex_Win32.h" #include "GpMutex_Win32.h"
#include "GpThreadEvent_Win32.h" #include "GpThreadEvent_Win32.h"
#include "GpWindows.h" #include "GpWindows.h"
#include "GpAllocator_C.h"
#include "IGpClipboardContents.h" #include "IGpClipboardContents.h"
@@ -133,6 +134,7 @@ static DWORD WINAPI StaticStartThread(LPVOID lpThreadParameter)
GpSystemServices_Win32::GpSystemServices_Win32() GpSystemServices_Win32::GpSystemServices_Win32()
: m_isTouchscreenSimulation(false) : m_isTouchscreenSimulation(false)
, m_alloc(GpAllocator_C::GetInstance())
{ {
} }
@@ -180,17 +182,17 @@ void GpSystemServices_Win32::GetLocalDateTime(unsigned int &year, unsigned int &
IGpMutex *GpSystemServices_Win32::CreateMutex() IGpMutex *GpSystemServices_Win32::CreateMutex()
{ {
return GpMutex_Win32::Create(); return GpMutex_Win32::Create(m_alloc);
} }
IGpMutex *GpSystemServices_Win32::CreateRecursiveMutex() IGpMutex *GpSystemServices_Win32::CreateRecursiveMutex()
{ {
return GpMutex_Win32::Create(); return GpMutex_Win32::Create(m_alloc);
} }
IGpThreadEvent *GpSystemServices_Win32::CreateThreadEvent(bool autoReset, bool startSignaled) IGpThreadEvent *GpSystemServices_Win32::CreateThreadEvent(bool autoReset, bool startSignaled)
{ {
return GpThreadEvent_Win32::Create(autoReset, startSignaled); return GpThreadEvent_Win32::Create(m_alloc, autoReset, startSignaled);
} }
void *GpSystemServices_Win32::CreateThread(ThreadFunc_t threadFunc, void *context) void *GpSystemServices_Win32::CreateThread(ThreadFunc_t threadFunc, void *context)

View File

@@ -48,6 +48,8 @@ public:
private: private:
bool m_isTouchscreenSimulation; bool m_isTouchscreenSimulation;
IGpAllocator *m_alloc;
static GpSystemServices_Win32 ms_instance; static GpSystemServices_Win32 ms_instance;
}; };

View File

@@ -1,4 +1,5 @@
#include "GpThreadEvent_Win32.h" #include "GpThreadEvent_Win32.h"
#include "IGpAllocator.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
@@ -20,28 +21,30 @@ void GpThreadEvent_Win32::Signal()
void GpThreadEvent_Win32::Destroy() void GpThreadEvent_Win32::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpThreadEvent_Win32(); this->~GpThreadEvent_Win32();
free(this); alloc->Release(this);
} }
GpThreadEvent_Win32 *GpThreadEvent_Win32::Create(bool autoReset, bool startSignaled) GpThreadEvent_Win32 *GpThreadEvent_Win32::Create(IGpAllocator *alloc, bool autoReset, bool startSignaled)
{ {
HANDLE handle = CreateEventA(nullptr, autoReset ? FALSE : TRUE, startSignaled ? TRUE : FALSE, nullptr); HANDLE handle = CreateEventA(nullptr, autoReset ? FALSE : TRUE, startSignaled ? TRUE : FALSE, nullptr);
if (handle == nullptr) if (handle == nullptr)
return nullptr; return nullptr;
void *storage = malloc(sizeof(GpThreadEvent_Win32)); void *storage = alloc->Alloc(sizeof(GpThreadEvent_Win32));
if (!storage) if (!storage)
{ {
CloseHandle(handle); CloseHandle(handle);
return nullptr; return nullptr;
} }
return new (storage) GpThreadEvent_Win32(handle); return new (storage) GpThreadEvent_Win32(alloc, handle);
} }
GpThreadEvent_Win32::GpThreadEvent_Win32(const HANDLE &handle) GpThreadEvent_Win32::GpThreadEvent_Win32(IGpAllocator *alloc, const HANDLE &handle)
: m_event(handle) : m_event(handle)
, m_alloc(alloc)
{ {
} }

View File

@@ -12,11 +12,12 @@ public:
void Signal() override; void Signal() override;
void Destroy() override; void Destroy() override;
static GpThreadEvent_Win32 *Create(bool autoReset, bool startSignaled); static GpThreadEvent_Win32 *Create(IGpAllocator *alloc, bool autoReset, bool startSignaled);
private: private:
explicit GpThreadEvent_Win32(const HANDLE &handle); explicit GpThreadEvent_Win32(IGpAllocator *alloc, const HANDLE &handle);
~GpThreadEvent_Win32(); ~GpThreadEvent_Win32();
HANDLE m_event; HANDLE m_event;
IGpAllocator *m_alloc;
}; };

View File

@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" /> <ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup>
<IncludePath>$(SolutionDir)AerofoilPortable;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup /> <ItemDefinitionGroup />
<ItemGroup /> <ItemGroup />
</Project> </Project>

View File

@@ -0,0 +1,115 @@
#include "GpAllocator_C.h"
#include "CoreDefs.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
struct GpAllocator_C_MMBlock
{
uint8_t m_offsetFromAllocLocation;
static size_t AlignedSize();
};
size_t GpAllocator_C_MMBlock::AlignedSize()
{
const size_t paddedSize = sizeof(GpAllocator_C_MMBlock) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t paddedSizeTruncated = paddedSize - (paddedSize % GP_SYSTEM_MEMORY_ALIGNMENT);
return paddedSizeTruncated;
}
void *GpAllocator_C::Realloc(void *buf, size_t newSize)
{
if (buf == nullptr)
{
if (newSize == 0)
return nullptr;
return this->Alloc(newSize);
}
if (newSize == 0)
{
this->Free(buf);
return nullptr;
}
assert(buf != nullptr);
const size_t mmBlockSize = GpAllocator_C_MMBlock::AlignedSize();
uint8_t *oldBufBytes = static_cast<uint8_t*>(buf);
const GpAllocator_C_MMBlock *oldBufMMBlock = reinterpret_cast<const GpAllocator_C_MMBlock*>(oldBufBytes - GpAllocator_C_MMBlock::AlignedSize());
const size_t oldBufOffsetFromAlignLoc = oldBufMMBlock->m_offsetFromAllocLocation;
uint8_t *oldBufBase = oldBufBytes - GpAllocator_C_MMBlock::AlignedSize() - oldBufOffsetFromAlignLoc;
const size_t mmBlockSizeWithMaxPadding = GpAllocator_C_MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - newSize < mmBlockSizeWithMaxPadding)
return nullptr;
const size_t newBufferSize = newSize + mmBlockSizeWithMaxPadding;
uint8_t *newBuffer = static_cast<uint8_t*>(realloc(oldBufBase, newSize + mmBlockSizeWithMaxPadding));
if (!newBuffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(newBuffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
// Check if the alignment changed, if so relocate
if (static_cast<size_t>(alignPadding) != oldBufOffsetFromAlignLoc)
memmove(newBuffer + alignPadding, newBuffer + oldBufOffsetFromAlignLoc, GpAllocator_C_MMBlock::AlignedSize() + newSize);
GpAllocator_C_MMBlock *newMMBlock = reinterpret_cast<GpAllocator_C_MMBlock*>(newBuffer + alignPadding);
newMMBlock->m_offsetFromAllocLocation = static_cast<uint8_t>(alignPadding);
return newBuffer + alignPadding + GpAllocator_C_MMBlock::AlignedSize();
}
void *GpAllocator_C::Alloc(size_t size)
{
if (size == 0)
return nullptr;
const size_t mmBlockSizeWithMaxPadding = GpAllocator_C_MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - size < mmBlockSizeWithMaxPadding)
return nullptr;
uint8_t *buffer = static_cast<uint8_t*>(realloc(nullptr, size + mmBlockSizeWithMaxPadding));
if (!buffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
GpAllocator_C_MMBlock *mmBlock = reinterpret_cast<GpAllocator_C_MMBlock*>(buffer + alignPadding);
mmBlock->m_offsetFromAllocLocation = static_cast<uint8_t>(alignPadding);
return buffer + alignPadding + GpAllocator_C_MMBlock::AlignedSize();
}
void GpAllocator_C::Free(void *buf)
{
if (!buf)
return;
const size_t mmBlockSize = GpAllocator_C_MMBlock::AlignedSize();
uint8_t *bytes = static_cast<uint8_t*>(buf);
const GpAllocator_C_MMBlock *mmBlock = reinterpret_cast<const GpAllocator_C_MMBlock*>(bytes - GpAllocator_C_MMBlock::AlignedSize());
void *freeLoc = bytes - GpAllocator_C_MMBlock::AlignedSize() - mmBlock->m_offsetFromAllocLocation;
realloc(freeLoc, 0);
}
GpAllocator_C *GpAllocator_C::GetInstance()
{
return &ms_instance;
}
GpAllocator_C GpAllocator_C::ms_instance;

View File

@@ -0,0 +1,17 @@
#pragma once
#include "IGpAllocator.h"
class GpAllocator_C final : public IGpAllocator
{
public:
void *Realloc(void *buf, size_t newSize) override;
static GpAllocator_C *GetInstance();
private:
void *Alloc(size_t size);
void Free(void *ptr);
static GpAllocator_C ms_instance;
};

View File

@@ -84,6 +84,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="..\Aerofoil\GpColorCursor_Win32.cpp" /> <ClCompile Include="..\Aerofoil\GpColorCursor_Win32.cpp" />
<ClCompile Include="..\Aerofoil\GpFileStream_Win32.cpp" /> <ClCompile Include="..\Aerofoil\GpFileStream_Win32.cpp" />
<ClCompile Include="..\Aerofoil\GpFileSystem_Win32.cpp" /> <ClCompile Include="..\Aerofoil\GpFileSystem_Win32.cpp" />

View File

@@ -66,6 +66,9 @@
<ClCompile Include="GpInputDriver_SDL_Gamepad.cpp"> <ClCompile Include="GpInputDriver_SDL_Gamepad.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ShaderCode\Functions.h"> <ClInclude Include="ShaderCode\Functions.h">

View File

@@ -1,6 +1,7 @@
#include "SDL.h" #include "SDL.h"
#include "GpMain.h" #include "GpMain.h"
#include "GpAllocator_C.h"
#include "GpAudioDriverFactory.h" #include "GpAudioDriverFactory.h"
#include "GpDisplayDriverFactory.h" #include "GpDisplayDriverFactory.h"
#include "GpGlobalConfig.h" #include "GpGlobalConfig.h"
@@ -59,6 +60,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance()); drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Win32::GetInstance()); drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance()); drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance());
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
g_gpWindowsGlobals.m_hInstance = hInstance; g_gpWindowsGlobals.m_hInstance = hInstance;
g_gpWindowsGlobals.m_hPrevInstance = hPrevInstance; g_gpWindowsGlobals.m_hPrevInstance = hPrevInstance;
@@ -86,6 +88,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
g_gpGlobalConfig.m_osGlobals = &g_gpWindowsGlobals; g_gpGlobalConfig.m_osGlobals = &g_gpWindowsGlobals;
g_gpGlobalConfig.m_logger = logger; g_gpGlobalConfig.m_logger = logger;
g_gpGlobalConfig.m_systemServices = GpSystemServices_Win32::GetInstance(); g_gpGlobalConfig.m_systemServices = GpSystemServices_Win32::GetInstance();
g_gpGlobalConfig.m_allocator = GpAllocator_C::GetInstance();
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2); GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL); GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);

View File

@@ -1,11 +1,13 @@
#include "CFileStream.h" #include "CFileStream.h"
#include "BMPFormat.h" #include "BMPFormat.h"
#include "GpAllocator_C.h"
#include "MMHandleBlock.h" #include "MMHandleBlock.h"
#include "ResourceCompiledTypeList.h" #include "ResourceCompiledTypeList.h"
#include "ResourceFile.h" #include "ResourceFile.h"
#include "SharedTypes.h" #include "SharedTypes.h"
#include "QDStandardPalette.h" #include "QDStandardPalette.h"
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "PLDrivers.h"
#include <assert.h> #include <assert.h>
#include <string> #include <string>
@@ -141,6 +143,9 @@ int main(int argc, const char **argv)
PortabilityLayer::CFileStream stream(f); PortabilityLayer::CFileStream stream(f);
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create(); PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create();
if (!resFile->Load(&stream)) if (!resFile->Load(&stream))
return -1; return -1;

View File

@@ -42,6 +42,7 @@
<Import Project="..\Common.props" /> <Import Project="..\Common.props" />
<Import Project="..\stb.props" /> <Import Project="..\stb.props" />
<Import Project="..\Debug.props" /> <Import Project="..\Debug.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -50,6 +51,7 @@
<Import Project="..\Common.props" /> <Import Project="..\Common.props" />
<Import Project="..\stb.props" /> <Import Project="..\stb.props" />
<Import Project="..\Release.props" /> <Import Project="..\Release.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup />
@@ -81,6 +83,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="..\stb\stb_image_write.c" /> <ClCompile Include="..\stb\stb_image_write.c" />
<ClCompile Include="ConvertColorCursors.cpp" /> <ClCompile Include="ConvertColorCursors.cpp" />
</ItemGroup> </ItemGroup>

View File

@@ -21,5 +21,8 @@
<ClCompile Include="..\stb\stb_image_write.c"> <ClCompile Include="..\stb\stb_image_write.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -3,6 +3,7 @@
#include "FontRenderer.h" #include "FontRenderer.h"
#include "IGpFont.h" #include "IGpFont.h"
#include "IGpFontHandler.h" #include "IGpFontHandler.h"
#include "GpAllocator_C.h"
#include "GpAppInterface.h" #include "GpAppInterface.h"
#include "GpDriverIndex.h" #include "GpDriverIndex.h"
#include "GpFontHandlerProperties.h" #include "GpFontHandlerProperties.h"
@@ -167,8 +168,14 @@ bool KnownFontSpec::operator!=(const KnownFontSpec &other) const
int toolMain(int argc, const char **argv) int toolMain(int argc, const char **argv)
{ {
IGpAllocator *alloc = GpAllocator_C::GetInstance();
GpFontHandlerProperties fhProperties; GpFontHandlerProperties fhProperties;
fhProperties.m_type = EGpFontHandlerType_FreeType2; fhProperties.m_type = EGpFontHandlerType_FreeType2;
fhProperties.m_alloc = alloc;
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
IGpFontHandler *ft2Handler = GpDriver_CreateFontHandler_FreeType2(fhProperties); IGpFontHandler *ft2Handler = GpDriver_CreateFontHandler_FreeType2(fhProperties);

View File

@@ -43,6 +43,7 @@
<Import Project="..\AerofoilWin.props" /> <Import Project="..\AerofoilWin.props" />
<Import Project="..\Debug.props" /> <Import Project="..\Debug.props" />
<Import Project="..\WindowsUnicodeToolShim.props" /> <Import Project="..\WindowsUnicodeToolShim.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -52,6 +53,7 @@
<Import Project="..\AerofoilWin.props" /> <Import Project="..\AerofoilWin.props" />
<Import Project="..\Release.props" /> <Import Project="..\Release.props" />
<Import Project="..\WindowsUnicodeToolShim.props" /> <Import Project="..\WindowsUnicodeToolShim.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup />
@@ -93,6 +95,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="GenerateFonts.cpp" /> <ClCompile Include="GenerateFonts.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -18,5 +18,8 @@
<ClCompile Include="GenerateFonts.cpp"> <ClCompile Include="GenerateFonts.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,12 +1,12 @@
#include "GpAudioBufferXAudio2.h" #include "GpAudioBufferXAudio2.h"
#include "CoreDefs.h" #include "CoreDefs.h"
#include "GpWindows.h" #include "GpWindows.h"
#include "IGpAllocator.h"
#include <malloc.h>
#include <string.h> #include <string.h>
#include <new> #include <new>
GpAudioBufferXAudio2 *GpAudioBufferXAudio2::Create(const void *buffer, size_t size) GpAudioBufferXAudio2 *GpAudioBufferXAudio2::Create(IGpAllocator *alloc, const void *buffer, size_t size)
{ {
size_t baseSize = sizeof(GpAudioBufferXAudio2); size_t baseSize = sizeof(GpAudioBufferXAudio2);
baseSize = baseSize + GP_SYSTEM_MEMORY_ALIGNMENT - 1; baseSize = baseSize + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
@@ -14,14 +14,14 @@ GpAudioBufferXAudio2 *GpAudioBufferXAudio2::Create(const void *buffer, size_t si
size_t totalSize = baseSize + size; size_t totalSize = baseSize + size;
void *storage = _aligned_malloc(totalSize, GP_SYSTEM_MEMORY_ALIGNMENT); void *storage = alloc->Realloc(nullptr, totalSize);
if (!storage) if (!storage)
return nullptr; return nullptr;
void *dataPos = static_cast<uint8_t*>(storage) + baseSize; void *dataPos = static_cast<uint8_t*>(storage) + baseSize;
memcpy(dataPos, buffer, size); memcpy(dataPos, buffer, size);
return new (storage) GpAudioBufferXAudio2(dataPos, size); return new (storage) GpAudioBufferXAudio2(alloc, dataPos, size);
} }
void GpAudioBufferXAudio2::AddRef() void GpAudioBufferXAudio2::AddRef()
@@ -40,8 +40,9 @@ const XAUDIO2_BUFFER *GpAudioBufferXAudio2::GetXA2Buffer() const
return &m_xa2Buffer; return &m_xa2Buffer;
} }
GpAudioBufferXAudio2::GpAudioBufferXAudio2(const void *data, size_t size) GpAudioBufferXAudio2::GpAudioBufferXAudio2(IGpAllocator *alloc, const void *data, size_t size)
: m_data(data) : m_alloc(alloc)
, m_data(data)
, m_size(size) , m_size(size)
, m_count(1) , m_count(1)
{ {
@@ -62,6 +63,7 @@ GpAudioBufferXAudio2::~GpAudioBufferXAudio2()
void GpAudioBufferXAudio2::Destroy() void GpAudioBufferXAudio2::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpAudioBufferXAudio2(); this->~GpAudioBufferXAudio2();
_aligned_free(this); m_alloc->Realloc(this, 0);
} }

View File

@@ -4,10 +4,12 @@
#include <xaudio2.h> #include <xaudio2.h>
struct IGpAllocator;
class GpAudioBufferXAudio2 final : public IGpAudioBuffer class GpAudioBufferXAudio2 final : public IGpAudioBuffer
{ {
public: public:
static GpAudioBufferXAudio2 *Create(const void *buffer, size_t size); static GpAudioBufferXAudio2 *Create(IGpAllocator *alloc, const void *buffer, size_t size);
void AddRef() override; void AddRef() override;
void Release() override; void Release() override;
@@ -15,13 +17,14 @@ public:
const XAUDIO2_BUFFER *GetXA2Buffer() const; const XAUDIO2_BUFFER *GetXA2Buffer() const;
private: private:
GpAudioBufferXAudio2(const void *data, size_t size); GpAudioBufferXAudio2(IGpAllocator *alloc, const void *data, size_t size);
~GpAudioBufferXAudio2(); ~GpAudioBufferXAudio2();
void Destroy(); void Destroy();
const void *m_data; const void *m_data;
size_t m_size; size_t m_size;
IGpAllocator *m_alloc;
XAUDIO2_BUFFER m_xa2Buffer; XAUDIO2_BUFFER m_xa2Buffer;

View File

@@ -1,26 +1,27 @@
#include "GpAudioBufferXAudio2.h" #include "GpAudioBufferXAudio2.h"
#include "GpAudioChannelXAudio2.h" #include "GpAudioChannelXAudio2.h"
#include "GpAudioDriverXAudio2.h" #include "GpAudioDriverXAudio2.h"
#include "IGpAllocator.h"
#include "IGpAudioChannelCallbacks.h" #include "IGpAudioChannelCallbacks.h"
#include "IGpLogDriver.h" #include "IGpLogDriver.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
GpAudioChannelXAudio2 *GpAudioChannelXAudio2::Create(GpAudioDriverXAudio2 *driver) GpAudioChannelXAudio2 *GpAudioChannelXAudio2::Create(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver)
{ {
IGpLogDriver *logger = driver->GetProperties().m_logger; IGpLogDriver *logger = driver->GetProperties().m_logger;
void *storage = malloc(sizeof(GpAudioChannelXAudio2)); void *storage = alloc->Realloc(nullptr, sizeof(GpAudioChannelXAudio2));
if (!storage) if (!storage)
{ {
if (!logger) if (!logger)
logger->Printf(IGpLogDriver::Category_Error, "GpAudioChannelXAudio2::Create failed, malloc failed"); logger->Printf(IGpLogDriver::Category_Error, "GpAudioChannelXAudio2::Create failed, alloc failed");
return nullptr; return nullptr;
} }
GpAudioChannelXAudio2 *channel = new (storage) GpAudioChannelXAudio2(driver); GpAudioChannelXAudio2 *channel = new (storage) GpAudioChannelXAudio2(alloc, driver);
if (!channel->Init()) if (!channel->Init())
{ {
if (!logger) if (!logger)
@@ -110,8 +111,9 @@ void GpAudioChannelXAudio2::Stop()
void GpAudioChannelXAudio2::Destroy() void GpAudioChannelXAudio2::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpAudioChannelXAudio2(); this->~GpAudioChannelXAudio2();
free(this); alloc->Realloc(this, 0);
} }
void GpAudioChannelXAudio2::OnBufferEnd() void GpAudioChannelXAudio2::OnBufferEnd()
@@ -120,12 +122,13 @@ void GpAudioChannelXAudio2::OnBufferEnd()
m_contextCallbacks->NotifyBufferFinished(); m_contextCallbacks->NotifyBufferFinished();
} }
GpAudioChannelXAudio2::GpAudioChannelXAudio2(GpAudioDriverXAudio2 *driver) GpAudioChannelXAudio2::GpAudioChannelXAudio2(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver)
: m_driver(driver) : m_driver(driver)
, m_xAudioCallbacks(this) , m_xAudioCallbacks(this)
, m_sourceVoice(nullptr) , m_sourceVoice(nullptr)
, m_contextCallbacks(nullptr) , m_contextCallbacks(nullptr)
, m_voiceState(VoiceState_Idle) , m_voiceState(VoiceState_Idle)
, m_alloc(alloc)
{ {
} }

View File

@@ -7,13 +7,14 @@
class GpAudioDriverXAudio2; class GpAudioDriverXAudio2;
class GpAudioChannelXAudio2Callbacks; class GpAudioChannelXAudio2Callbacks;
struct IXAudio2SourceVoice; struct IXAudio2SourceVoice;
struct IGpAllocator;
class GpAudioChannelXAudio2 final : public IGpAudioChannel class GpAudioChannelXAudio2 final : public IGpAudioChannel
{ {
public: public:
friend class GpAudioChannelXAudio2Callbacks; friend class GpAudioChannelXAudio2Callbacks;
static GpAudioChannelXAudio2 *Create(GpAudioDriverXAudio2 *driver); static GpAudioChannelXAudio2 *Create(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver);
void SetAudioChannelContext(IGpAudioChannelCallbacks *callbacks) override; void SetAudioChannelContext(IGpAudioChannelCallbacks *callbacks) override;
bool PostBuffer(IGpAudioBuffer *buffer) override; bool PostBuffer(IGpAudioBuffer *buffer) override;
@@ -32,12 +33,13 @@ private:
VoiceState_Active, VoiceState_Active,
}; };
explicit GpAudioChannelXAudio2(GpAudioDriverXAudio2 *driver); explicit GpAudioChannelXAudio2(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver);
~GpAudioChannelXAudio2(); ~GpAudioChannelXAudio2();
GpAudioDriverXAudio2 *m_driver; GpAudioDriverXAudio2 *m_driver;
IXAudio2SourceVoice *m_sourceVoice; IXAudio2SourceVoice *m_sourceVoice;
GpAudioChannelXAudio2Callbacks m_xAudioCallbacks; GpAudioChannelXAudio2Callbacks m_xAudioCallbacks;
IGpAudioChannelCallbacks *m_contextCallbacks; IGpAudioChannelCallbacks *m_contextCallbacks;
IGpAllocator *m_alloc;
VoiceState m_voiceState; VoiceState m_voiceState;
}; };

View File

@@ -6,7 +6,6 @@
#include "CoreDefs.h" #include "CoreDefs.h"
#include <xaudio2.h> #include <xaudio2.h>
#include <malloc.h>
void GpAudioDriverXAudio2::Shutdown() void GpAudioDriverXAudio2::Shutdown()
{ {
@@ -101,12 +100,12 @@ GpAudioDriverXAudio2 *GpAudioDriverXAudio2::Create(const GpAudioDriverProperties
IGpAudioBuffer *GpAudioDriverXAudio2::CreateBuffer(const void *buffer, size_t bufferSize) IGpAudioBuffer *GpAudioDriverXAudio2::CreateBuffer(const void *buffer, size_t bufferSize)
{ {
return GpAudioBufferXAudio2::Create(buffer, bufferSize); return GpAudioBufferXAudio2::Create(m_properties.m_alloc, buffer, bufferSize);
} }
IGpAudioChannel *GpAudioDriverXAudio2::CreateChannel() IGpAudioChannel *GpAudioDriverXAudio2::CreateChannel()
{ {
return GpAudioChannelXAudio2::Create(this); return GpAudioChannelXAudio2::Create(m_properties.m_alloc, this);
} }
void GpAudioDriverXAudio2::SetMasterVolume(uint32_t vol, uint32_t maxVolume) void GpAudioDriverXAudio2::SetMasterVolume(uint32_t vol, uint32_t maxVolume)

View File

@@ -5,6 +5,7 @@
struct IGpSystemServices; struct IGpSystemServices;
struct IGpAudioDriver; struct IGpAudioDriver;
struct IGpLogDriver; struct IGpLogDriver;
struct IGpAllocator;
struct GpAudioDriverProperties struct GpAudioDriverProperties
{ {
@@ -15,4 +16,5 @@ struct GpAudioDriverProperties
IGpLogDriver *m_logger; IGpLogDriver *m_logger;
IGpSystemServices *m_systemServices; IGpSystemServices *m_systemServices;
IGpAllocator *m_alloc;
}; };

View File

@@ -10,6 +10,7 @@ struct IGpFiber;
struct IGpVOSEventQueue; struct IGpVOSEventQueue;
struct IGpLogDriver; struct IGpLogDriver;
struct IGpSystemServices; struct IGpSystemServices;
struct IGpAllocator;
struct GpDisplayDriverProperties struct GpDisplayDriverProperties
{ {
@@ -43,4 +44,5 @@ struct GpDisplayDriverProperties
IGpVOSEventQueue *m_eventQueue; IGpVOSEventQueue *m_eventQueue;
IGpLogDriver *m_logger; IGpLogDriver *m_logger;
IGpSystemServices *m_systemServices; IGpSystemServices *m_systemServices;
IGpAllocator *m_alloc;
}; };

View File

@@ -16,6 +16,7 @@ namespace GpDriverIDs
kSystemServices, kSystemServices,
kFont, kFont,
kEventQueue, kEventQueue,
kAlloc,
kCount kCount
}; };
@@ -54,6 +55,7 @@ GP_DEFINE_MULTI_DRIVER(kInput, IGpInputDriver);
GP_DEFINE_DRIVER(kSystemServices, IGpSystemServices); GP_DEFINE_DRIVER(kSystemServices, IGpSystemServices);
GP_DEFINE_DRIVER(kFont, IGpFontHandler); GP_DEFINE_DRIVER(kFont, IGpFontHandler);
GP_DEFINE_DRIVER(kEventQueue, IGpVOSEventQueue); GP_DEFINE_DRIVER(kEventQueue, IGpVOSEventQueue);
GP_DEFINE_DRIVER(kAlloc, IGpAllocator);
struct GpDriverCollection struct GpDriverCollection
{ {

View File

@@ -2,7 +2,11 @@
#include "EGpFontHandlerType.h" #include "EGpFontHandlerType.h"
struct IGpAllocator;
struct GpFontHandlerProperties struct GpFontHandlerProperties
{ {
EGpFontHandlerType m_type; EGpFontHandlerType m_type;
IGpAllocator *m_alloc;
}; };

View File

@@ -4,10 +4,12 @@
struct IGpAudioDriver; struct IGpAudioDriver;
struct IGpVOSEventQueue; struct IGpVOSEventQueue;
struct IGpAllocator;
struct GpInputDriverProperties struct GpInputDriverProperties
{ {
EGpInputDriverType m_type; EGpInputDriverType m_type;
IGpVOSEventQueue *m_eventQueue; IGpVOSEventQueue *m_eventQueue;
IGpAllocator *m_alloc;
}; };

View File

@@ -13,6 +13,7 @@
struct IGpBWCursor_Win32; struct IGpBWCursor_Win32;
struct IGpCursor_Win32; struct IGpCursor_Win32;
struct IGpAllocator;
struct IGpVOSEventQueue; struct IGpVOSEventQueue;
struct GpWindowsGlobals struct GpWindowsGlobals
@@ -28,7 +29,7 @@ struct GpWindowsGlobals
HICON m_hIconSm; HICON m_hIconSm;
int m_nCmdShow; int m_nCmdShow;
IGpCursor_Win32 *(*m_createColorCursorFunc)(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY); IGpCursor_Win32 *(*m_createColorCursorFunc)(IGpAllocator *alloc, size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY);
IGpCursor_Win32 *(*m_createBWCursorFunc)(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY); IGpCursor_Win32 *(*m_createBWCursorFunc)(IGpAllocator *alloc, size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY);
void (*m_translateWindowsMessageFunc)(const MSG *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY); void (*m_translateWindowsMessageFunc)(const MSG *msg, IGpVOSEventQueue *eventQueue, float pixelScaleX, float pixelScaleY);
}; };

12
GpCommon/IGpAllocator.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
struct IGpAllocator
{
virtual void *Realloc(void *buf, size_t newSize) = 0;
inline void *Alloc(size_t size) { return this->Realloc(nullptr, size); }
inline void Release(void *ptr) { this->Realloc(ptr, 0); }
};

View File

@@ -1,8 +1,10 @@
#include "GpApplicationName.h" #include "GpApplicationName.h"
#include "GpDisplayDriverD3D11.h" #include "GpDisplayDriverD3D11.h"
#include "GpDisplayDriverProperties.h"
#include "GpDisplayDriverSurfaceD3D11.h" #include "GpDisplayDriverSurfaceD3D11.h"
#include "GpVOSEvent.h" #include "GpVOSEvent.h"
#include "GpWindows.h" #include "GpWindows.h"
#include "IGpAllocator.h"
#include "IGpCursor_Win32.h" #include "IGpCursor_Win32.h"
#include "IGpVOSEventQueue.h" #include "IGpVOSEventQueue.h"
@@ -1243,8 +1245,9 @@ void GpDisplayDriverD3D11::ServeTicks(int tickCount)
void GpDisplayDriverD3D11::Shutdown() void GpDisplayDriverD3D11::Shutdown()
{ {
IGpAllocator *alloc = m_properties.m_alloc;
this->~GpDisplayDriverD3D11(); this->~GpDisplayDriverD3D11();
free(this); alloc->Release(this);
} }
void GpDisplayDriverD3D11::GetInitialDisplayResolution(unsigned int *width, unsigned int *height) void GpDisplayDriverD3D11::GetInitialDisplayResolution(unsigned int *width, unsigned int *height)
@@ -1257,7 +1260,7 @@ void GpDisplayDriverD3D11::GetInitialDisplayResolution(unsigned int *width, unsi
IGpDisplayDriverSurface *GpDisplayDriverD3D11::CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, IGpDisplayDriver::SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) IGpDisplayDriverSurface *GpDisplayDriverD3D11::CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, IGpDisplayDriver::SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext)
{ {
return GpDisplayDriverSurfaceD3D11::Create(m_device, m_deviceContext, width, height, pixelFormat); return GpDisplayDriverSurfaceD3D11::Create(m_device, m_deviceContext, width, height, pixelFormat, m_properties.m_alloc);
} }
void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects)
@@ -1385,12 +1388,12 @@ void GpDisplayDriverD3D11::DrawSurface(IGpDisplayDriverSurface *surface, int32_t
IGpCursor *GpDisplayDriverD3D11::CreateColorCursor(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY) IGpCursor *GpDisplayDriverD3D11::CreateColorCursor(size_t width, size_t height, const void *pixelDataRGBA, size_t hotSpotX, size_t hotSpotY)
{ {
return m_osGlobals->m_createColorCursorFunc(width, height, pixelDataRGBA, hotSpotX, hotSpotY); return m_osGlobals->m_createColorCursorFunc(m_properties.m_alloc, width, height, pixelDataRGBA, hotSpotX, hotSpotY);
} }
IGpCursor *GpDisplayDriverD3D11::CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY) IGpCursor *GpDisplayDriverD3D11::CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY)
{ {
return m_osGlobals->m_createBWCursorFunc(width, height, pixelData, maskData, hotSpotX, hotSpotY); return m_osGlobals->m_createBWCursorFunc(m_properties.m_alloc, width, height, pixelData, maskData, hotSpotX, hotSpotY);
} }
// We can't just set the cursor because we want to post WM_SETCURSOR to keep it limited // We can't just set the cursor because we want to post WM_SETCURSOR to keep it limited
@@ -1507,7 +1510,7 @@ bool GpDisplayDriverD3D11::SavePrefs(void *context, IGpPrefsHandler::WritePrefsF
GpDisplayDriverD3D11 *GpDisplayDriverD3D11::Create(const GpDisplayDriverProperties &properties) GpDisplayDriverD3D11 *GpDisplayDriverD3D11::Create(const GpDisplayDriverProperties &properties)
{ {
void *storage = malloc(sizeof(GpDisplayDriverD3D11)); void *storage = properties.m_alloc->Alloc(sizeof(GpDisplayDriverD3D11));
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -1,5 +1,6 @@
#include "GpDisplayDriverSurfaceD3D11.h" #include "GpDisplayDriverSurfaceD3D11.h"
#include "GpComPtr.h" #include "GpComPtr.h"
#include "IGpAllocator.h"
#include <d3d11.h> #include <d3d11.h>
#include <emmintrin.h> #include <emmintrin.h>
@@ -55,8 +56,9 @@ void GpDisplayDriverSurfaceD3D11::UploadEntire(const void *data, size_t pitch)
void GpDisplayDriverSurfaceD3D11::Destroy() void GpDisplayDriverSurfaceD3D11::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpDisplayDriverSurfaceD3D11(); this->~GpDisplayDriverSurfaceD3D11();
free(this); alloc->Release(this);
} }
ID3D11ShaderResourceView *GpDisplayDriverSurfaceD3D11::GetSRV() const ID3D11ShaderResourceView *GpDisplayDriverSurfaceD3D11::GetSRV() const
@@ -79,7 +81,7 @@ size_t GpDisplayDriverSurfaceD3D11::GetHeight() const
return m_height; return m_height;
} }
GpDisplayDriverSurfaceD3D11 *GpDisplayDriverSurfaceD3D11::Create(ID3D11Device *device, ID3D11DeviceContext *deviceContext, size_t width, size_t height, GpPixelFormat_t pixelFormat) GpDisplayDriverSurfaceD3D11 *GpDisplayDriverSurfaceD3D11::Create(ID3D11Device *device, ID3D11DeviceContext *deviceContext, size_t width, size_t height, GpPixelFormat_t pixelFormat, IGpAllocator *alloc)
{ {
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8_UNORM; DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8_UNORM;
@@ -127,17 +129,17 @@ GpDisplayDriverSurfaceD3D11 *GpDisplayDriverSurfaceD3D11::Create(ID3D11Device *d
if (device->CreateShaderResourceView(texture, &srvDesc, srv.GetMutablePtr()) != S_OK) if (device->CreateShaderResourceView(texture, &srvDesc, srv.GetMutablePtr()) != S_OK)
return nullptr; return nullptr;
void *storage = malloc(sizeof(GpDisplayDriverSurfaceD3D11)); void *storage = alloc->Alloc(sizeof(GpDisplayDriverSurfaceD3D11));
if (!storage) if (!storage)
{ {
texture->Release(); texture->Release();
return nullptr; return nullptr;
} }
return new (storage) GpDisplayDriverSurfaceD3D11(device, deviceContext, texture, srv, width, height, pixelFormat); return new (storage) GpDisplayDriverSurfaceD3D11(device, deviceContext, texture, srv, width, height, pixelFormat, alloc);
} }
GpDisplayDriverSurfaceD3D11::GpDisplayDriverSurfaceD3D11(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *texture, ID3D11ShaderResourceView *srv, size_t width, size_t height, GpPixelFormat_t pixelFormat) GpDisplayDriverSurfaceD3D11::GpDisplayDriverSurfaceD3D11(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *texture, ID3D11ShaderResourceView *srv, size_t width, size_t height, GpPixelFormat_t pixelFormat, IGpAllocator *alloc)
: m_width(width) : m_width(width)
, m_height(height) , m_height(height)
, m_pixelFormat(pixelFormat) , m_pixelFormat(pixelFormat)
@@ -145,6 +147,7 @@ GpDisplayDriverSurfaceD3D11::GpDisplayDriverSurfaceD3D11(ID3D11Device *device, I
, m_deviceContext(deviceContext) , m_deviceContext(deviceContext)
, m_texture(texture) , m_texture(texture)
, m_srv(srv) , m_srv(srv)
, m_alloc(alloc)
{ {
} }

View File

@@ -8,6 +8,7 @@ struct ID3D11Device;
struct ID3D11DeviceContext; struct ID3D11DeviceContext;
struct ID3D11ShaderResourceView; struct ID3D11ShaderResourceView;
struct ID3D11Texture2D; struct ID3D11Texture2D;
struct IGpAllocator;
class GpDisplayDriverSurfaceD3D11 final : public IGpDisplayDriverSurface class GpDisplayDriverSurfaceD3D11 final : public IGpDisplayDriverSurface
{ {
@@ -21,10 +22,10 @@ public:
size_t GetWidth() const; size_t GetWidth() const;
size_t GetHeight() const; size_t GetHeight() const;
static GpDisplayDriverSurfaceD3D11 *Create(ID3D11Device *device, ID3D11DeviceContext *deviceContext, size_t width, size_t height, GpPixelFormat_t pixelFormat); static GpDisplayDriverSurfaceD3D11 *Create(ID3D11Device *device, ID3D11DeviceContext *deviceContext, size_t width, size_t height, GpPixelFormat_t pixelFormat, IGpAllocator *alloc);
private: private:
GpDisplayDriverSurfaceD3D11(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *texture, ID3D11ShaderResourceView *srv, size_t width, size_t height, GpPixelFormat_t pixelFormat); GpDisplayDriverSurfaceD3D11(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Texture2D *texture, ID3D11ShaderResourceView *srv, size_t width, size_t height, GpPixelFormat_t pixelFormat, IGpAllocator *alloc);
~GpDisplayDriverSurfaceD3D11(); ~GpDisplayDriverSurfaceD3D11();
size_t m_width; size_t m_width;
@@ -32,6 +33,7 @@ private:
GpPixelFormat_t m_pixelFormat; GpPixelFormat_t m_pixelFormat;
ID3D11Device *m_device; ID3D11Device *m_device;
ID3D11DeviceContext *m_deviceContext; ID3D11DeviceContext *m_deviceContext;
IGpAllocator *m_alloc;
GpComPtr<ID3D11Texture2D> m_texture; GpComPtr<ID3D11Texture2D> m_texture;
GpComPtr<ID3D11ShaderResourceView> m_srv; GpComPtr<ID3D11ShaderResourceView> m_srv;

View File

@@ -3,6 +3,7 @@
#include "CoreDefs.h" #include "CoreDefs.h"
#include "GpIOStream.h" #include "GpIOStream.h"
#include "IGpAllocator.h"
#include "IGpFont.h" #include "IGpFont.h"
#include "IGpFontRenderedGlyph.h" #include "IGpFontRenderedGlyph.h"
#include "GpRenderedGlyphMetrics.h" #include "GpRenderedGlyphMetrics.h"
@@ -17,6 +18,8 @@
#include <new> #include <new>
#include <assert.h> #include <assert.h>
struct IGpAllocator;
class GpFontRenderedGlyph_FreeType2 final : public IGpFontRenderedGlyph class GpFontRenderedGlyph_FreeType2 final : public IGpFontRenderedGlyph
{ {
public: public:
@@ -24,14 +27,15 @@ public:
const void *GetData() const override; const void *GetData() const override;
void Destroy() override; void Destroy() override;
static GpFontRenderedGlyph_FreeType2 *Create(size_t dataSize, const GpRenderedGlyphMetrics &metrics); static GpFontRenderedGlyph_FreeType2 *Create(IGpAllocator *alloc, size_t dataSize, const GpRenderedGlyphMetrics &metrics);
void *GetMutableData(); void *GetMutableData();
private: private:
GpFontRenderedGlyph_FreeType2(void *data, const GpRenderedGlyphMetrics &metrics); GpFontRenderedGlyph_FreeType2(IGpAllocator *alloc, void *data, const GpRenderedGlyphMetrics &metrics);
~GpFontRenderedGlyph_FreeType2(); ~GpFontRenderedGlyph_FreeType2();
IGpAllocator *m_alloc;
void *m_data; void *m_data;
GpRenderedGlyphMetrics m_metrics; GpRenderedGlyphMetrics m_metrics;
}; };
@@ -44,17 +48,18 @@ public:
bool GetLineSpacing(unsigned int size, int32_t &outSpacing) override; bool GetLineSpacing(unsigned int size, int32_t &outSpacing) override;
bool SupportScaling() const override; bool SupportScaling() const override;
static GpFont_FreeType2 *Create(const FT_StreamRec_ &streamRec, GpIOStream *stream); static GpFont_FreeType2 *Create(IGpAllocator *alloc, const FT_StreamRec_ &streamRec, GpIOStream *stream);
bool FTLoad(const FT_Library &library, int typeFaceIndex); bool FTLoad(const FT_Library &library, int typeFaceIndex);
private: private:
explicit GpFont_FreeType2(const FT_StreamRec_ &streamRec, GpIOStream *stream); GpFont_FreeType2(IGpAllocator *alloc, const FT_StreamRec_ &streamRec, GpIOStream *stream);
~GpFont_FreeType2(); ~GpFont_FreeType2();
FT_StreamRec_ m_ftStream; FT_StreamRec_ m_ftStream;
FT_Face m_face; FT_Face m_face;
GpIOStream *m_stream; GpIOStream *m_stream;
IGpAllocator *m_alloc;
unsigned int m_currentSize; unsigned int m_currentSize;
}; };
@@ -70,20 +75,21 @@ const void *GpFontRenderedGlyph_FreeType2::GetData() const
void GpFontRenderedGlyph_FreeType2::Destroy() void GpFontRenderedGlyph_FreeType2::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpFontRenderedGlyph_FreeType2(); this->~GpFontRenderedGlyph_FreeType2();
free(this); alloc->Release(this);
} }
GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(size_t dataSize, const GpRenderedGlyphMetrics &metrics) GpFontRenderedGlyph_FreeType2 *GpFontRenderedGlyph_FreeType2::Create(IGpAllocator *alloc, size_t dataSize, const GpRenderedGlyphMetrics &metrics)
{ {
size_t alignedPrefixSize = (sizeof(GpFontRenderedGlyph_FreeType2) + GP_SYSTEM_MEMORY_ALIGNMENT - 1); size_t alignedPrefixSize = (sizeof(GpFontRenderedGlyph_FreeType2) + GP_SYSTEM_MEMORY_ALIGNMENT - 1);
alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT; alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT;
void *storage = malloc(alignedPrefixSize + dataSize); void *storage = alloc->Alloc(alignedPrefixSize + dataSize);
if (!storage) if (!storage)
return nullptr; return nullptr;
return new (storage) GpFontRenderedGlyph_FreeType2(static_cast<uint8_t*>(storage) + alignedPrefixSize, metrics); return new (storage) GpFontRenderedGlyph_FreeType2(alloc, static_cast<uint8_t*>(storage) + alignedPrefixSize, metrics);
} }
void *GpFontRenderedGlyph_FreeType2::GetMutableData() void *GpFontRenderedGlyph_FreeType2::GetMutableData()
@@ -92,9 +98,10 @@ void *GpFontRenderedGlyph_FreeType2::GetMutableData()
} }
GpFontRenderedGlyph_FreeType2::GpFontRenderedGlyph_FreeType2(void *data, const GpRenderedGlyphMetrics &metrics) GpFontRenderedGlyph_FreeType2::GpFontRenderedGlyph_FreeType2(IGpAllocator *alloc, void *data, const GpRenderedGlyphMetrics &metrics)
: m_metrics(metrics) : m_metrics(metrics)
, m_data(data) , m_data(data)
, m_alloc(alloc)
{ {
} }
@@ -104,8 +111,9 @@ GpFontRenderedGlyph_FreeType2::~GpFontRenderedGlyph_FreeType2()
void GpFont_FreeType2::Destroy() void GpFont_FreeType2::Destroy()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpFont_FreeType2(); this->~GpFont_FreeType2();
free(this); alloc->Release(this);
} }
IGpFontRenderedGlyph *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsigned int size, unsigned int xScale, unsigned int yScale, bool aa) IGpFontRenderedGlyph *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsigned int size, unsigned int xScale, unsigned int yScale, bool aa)
@@ -190,7 +198,7 @@ IGpFontRenderedGlyph *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsign
metrics.m_glyphDataPitch = pitchRequired; metrics.m_glyphDataPitch = pitchRequired;
GpFontRenderedGlyph_FreeType2 *renderedGlyph = GpFontRenderedGlyph_FreeType2::Create(glyphDataSize, metrics); GpFontRenderedGlyph_FreeType2 *renderedGlyph = GpFontRenderedGlyph_FreeType2::Create(m_alloc, glyphDataSize, metrics);
if (!renderedGlyph) if (!renderedGlyph)
return nullptr; return nullptr;
@@ -263,13 +271,13 @@ bool GpFont_FreeType2::SupportScaling() const
return true; return true;
} }
GpFont_FreeType2 *GpFont_FreeType2::Create(const FT_StreamRec_ &streamRec, GpIOStream *stream) GpFont_FreeType2 *GpFont_FreeType2::Create(IGpAllocator *alloc, const FT_StreamRec_ &streamRec, GpIOStream *stream)
{ {
void *storage = malloc(sizeof(GpFont_FreeType2)); void *storage = alloc->Alloc(sizeof(GpFont_FreeType2));
if (!storage) if (!storage)
return nullptr; return nullptr;
return new (storage) GpFont_FreeType2(streamRec, stream); return new (storage) GpFont_FreeType2(alloc, streamRec, stream);
} }
bool GpFont_FreeType2::FTLoad(const FT_Library &library, int typeFaceIndex) bool GpFont_FreeType2::FTLoad(const FT_Library &library, int typeFaceIndex)
@@ -288,11 +296,12 @@ bool GpFont_FreeType2::FTLoad(const FT_Library &library, int typeFaceIndex)
return true; return true;
} }
GpFont_FreeType2::GpFont_FreeType2(const FT_StreamRec_ &streamRec, GpIOStream *stream) GpFont_FreeType2::GpFont_FreeType2(IGpAllocator *alloc, const FT_StreamRec_ &streamRec, GpIOStream *stream)
: m_face(nullptr) : m_face(nullptr)
, m_ftStream(streamRec) , m_ftStream(streamRec)
, m_stream(stream) , m_stream(stream)
, m_currentSize(0) , m_currentSize(0)
, m_alloc(alloc)
{ {
assert(stream); assert(stream);
} }
@@ -305,13 +314,13 @@ GpFont_FreeType2::~GpFont_FreeType2()
m_stream->Close(); m_stream->Close();
} }
GpFontHandler_FreeType2 *GpFontHandler_FreeType2::Create() GpFontHandler_FreeType2 *GpFontHandler_FreeType2::Create(IGpAllocator *alloc)
{ {
void *storage = malloc(sizeof(GpFontHandler_FreeType2)); void *storage = alloc->Alloc(sizeof(GpFontHandler_FreeType2));
if (!storage) if (!storage)
return nullptr; return nullptr;
GpFontHandler_FreeType2 *fh = new (storage) GpFontHandler_FreeType2(); GpFontHandler_FreeType2 *fh = new (storage) GpFontHandler_FreeType2(alloc);
if (!fh->Init()) if (!fh->Init())
{ {
fh->Shutdown(); fh->Shutdown();
@@ -331,7 +340,7 @@ IGpFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream, int typeFaceIndex
ftStream.read = FTStreamIo; ftStream.read = FTStreamIo;
ftStream.close = FTStreamClose; ftStream.close = FTStreamClose;
GpFont_FreeType2 *font = GpFont_FreeType2::Create(ftStream, stream); GpFont_FreeType2 *font = GpFont_FreeType2::Create(m_alloc, ftStream, stream);
if (!font) if (!font)
{ {
stream->Close(); stream->Close();
@@ -354,14 +363,16 @@ bool GpFontHandler_FreeType2::KeepStreamOpen() const
void GpFontHandler_FreeType2::Shutdown() void GpFontHandler_FreeType2::Shutdown()
{ {
IGpAllocator *alloc = m_alloc;
this->~GpFontHandler_FreeType2(); this->~GpFontHandler_FreeType2();
free(this); alloc->Release(this);
} }
GpFontHandler_FreeType2::GpFontHandler_FreeType2() GpFontHandler_FreeType2::GpFontHandler_FreeType2(IGpAllocator *alloc)
: m_ftIsInitialized(false) : m_ftIsInitialized(false)
, m_library(nullptr) , m_library(nullptr)
, m_currentSize(0) , m_currentSize(0)
, m_alloc(alloc)
{ {
} }
@@ -411,18 +422,18 @@ void GpFontHandler_FreeType2::FTStreamClose(FT_Stream stream)
void *GpFontHandler_FreeType2::FTAlloc(long size) void *GpFontHandler_FreeType2::FTAlloc(long size)
{ {
return malloc(static_cast<size_t>(size)); return m_alloc->Alloc(static_cast<size_t>(size));
} }
void GpFontHandler_FreeType2::FTFree(void* block) void GpFontHandler_FreeType2::FTFree(void* block)
{ {
free(block); m_alloc->Release(block);
} }
void *GpFontHandler_FreeType2::FTRealloc(long curSize, long newSize, void *block) void *GpFontHandler_FreeType2::FTRealloc(long curSize, long newSize, void *block)
{ {
(void)curSize; (void)curSize;
return realloc(block, static_cast<size_t>(newSize)); return m_alloc->Realloc(block, static_cast<size_t>(newSize));
} }
bool GpFontHandler_FreeType2::Init() bool GpFontHandler_FreeType2::Init()
@@ -448,5 +459,5 @@ __declspec(dllexport)
#endif #endif
IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties) IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties)
{ {
return GpFontHandler_FreeType2::Create(); return GpFontHandler_FreeType2::Create(properties.m_alloc);
} }

View File

@@ -7,6 +7,7 @@
#include FT_FREETYPE_H #include FT_FREETYPE_H
class GpIOStream; class GpIOStream;
struct IGpAllocator;
namespace PortabilityLayer namespace PortabilityLayer
{ {
@@ -21,10 +22,10 @@ public:
bool KeepStreamOpen() const override; bool KeepStreamOpen() const override;
static GpFontHandler_FreeType2 *Create(); static GpFontHandler_FreeType2 *Create(IGpAllocator *alloc);
private: private:
GpFontHandler_FreeType2(); explicit GpFontHandler_FreeType2(IGpAllocator *alloc);
~GpFontHandler_FreeType2(); ~GpFontHandler_FreeType2();
static void *FTAllocThunk(FT_Memory memory, long size); static void *FTAllocThunk(FT_Memory memory, long size);
@@ -44,4 +45,5 @@ private:
FT_Library m_library; FT_Library m_library;
unsigned int m_currentSize; unsigned int m_currentSize;
bool m_ftIsInitialized; bool m_ftIsInitialized;
IGpAllocator *m_alloc;
}; };

View File

@@ -2,6 +2,7 @@
#include "GpVOSEvent.h" #include "GpVOSEvent.h"
#include "GpWindows.h" #include "GpWindows.h"
#include "IGpVOSEventQueue.h" #include "IGpVOSEventQueue.h"
#include "IGpAllocator.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
@@ -72,8 +73,9 @@ void GpInputDriverXInput::ProcessInput()
void GpInputDriverXInput::Shutdown() void GpInputDriverXInput::Shutdown()
{ {
IGpAllocator *alloc = m_properties.m_alloc;
this->~GpInputDriverXInput(); this->~GpInputDriverXInput();
free(this); alloc->Release(this);
} }
IGpPrefsHandler *GpInputDriverXInput::GetPrefsHandler() const IGpPrefsHandler *GpInputDriverXInput::GetPrefsHandler() const
@@ -83,7 +85,7 @@ IGpPrefsHandler *GpInputDriverXInput::GetPrefsHandler() const
GpInputDriverXInput *GpInputDriverXInput::Create(const GpInputDriverProperties &props) GpInputDriverXInput *GpInputDriverXInput::Create(const GpInputDriverProperties &props)
{ {
void *storage = malloc(sizeof(GpInputDriverXInput)); void *storage = props.m_alloc->Alloc(sizeof(GpInputDriverXInput));
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -10,6 +10,7 @@
struct IGpLogDriver; struct IGpLogDriver;
struct IGpSystemServices; struct IGpSystemServices;
struct IGpAllocator;
struct GpGlobalConfig struct GpGlobalConfig
{ {
@@ -22,6 +23,7 @@ struct GpGlobalConfig
IGpLogDriver *m_logger; IGpLogDriver *m_logger;
IGpSystemServices *m_systemServices; IGpSystemServices *m_systemServices;
IGpAllocator *m_allocator;
void *m_osGlobals; void *m_osGlobals;
}; };

View File

@@ -11,6 +11,7 @@
#include "GpInputDriverProperties.h" #include "GpInputDriverProperties.h"
#include "GpGlobalConfig.h" #include "GpGlobalConfig.h"
#include "GpAppEnvironment.h" #include "GpAppEnvironment.h"
#include "IGpAllocator.h"
#include "IGpAudioDriver.h" #include "IGpAudioDriver.h"
#include "IGpDisplayDriver.h" #include "IGpDisplayDriver.h"
#include "IGpFontHandler.h" #include "IGpFontHandler.h"
@@ -36,6 +37,7 @@ int GpMain::Run()
{ {
GpVOSEventQueue *eventQueue = new GpVOSEventQueue(); GpVOSEventQueue *eventQueue = new GpVOSEventQueue();
GpAppEnvironment *appEnvironment = new GpAppEnvironment(); GpAppEnvironment *appEnvironment = new GpAppEnvironment();
IGpAllocator *alloc = g_gpGlobalConfig.m_allocator;
GpDisplayDriverProperties ddProps; GpDisplayDriverProperties ddProps;
memset(&ddProps, 0, sizeof(ddProps)); memset(&ddProps, 0, sizeof(ddProps));
@@ -60,6 +62,7 @@ int GpMain::Run()
ddProps.m_eventQueue = eventQueue; ddProps.m_eventQueue = eventQueue;
ddProps.m_logger = g_gpGlobalConfig.m_logger; ddProps.m_logger = g_gpGlobalConfig.m_logger;
ddProps.m_systemServices = g_gpGlobalConfig.m_systemServices; ddProps.m_systemServices = g_gpGlobalConfig.m_systemServices;
ddProps.m_alloc = g_gpGlobalConfig.m_allocator;
GpAudioDriverProperties adProps; GpAudioDriverProperties adProps;
memset(&adProps, 0, sizeof(adProps)); memset(&adProps, 0, sizeof(adProps));
@@ -68,6 +71,7 @@ int GpMain::Run()
memset(&fontProps, 0, sizeof(fontProps)); memset(&fontProps, 0, sizeof(fontProps));
fontProps.m_type = g_gpGlobalConfig.m_fontHandlerType; fontProps.m_type = g_gpGlobalConfig.m_fontHandlerType;
fontProps.m_alloc = g_gpGlobalConfig.m_allocator;
// The sample rate used in all of Glider PRO's sound is 0x56ee8ba3 // 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. // This appears to be the "standard" Mac sample rate, probably rounded from 244800/11.
@@ -80,8 +84,9 @@ int GpMain::Run()
#endif #endif
adProps.m_logger = g_gpGlobalConfig.m_logger; adProps.m_logger = g_gpGlobalConfig.m_logger;
adProps.m_systemServices = g_gpGlobalConfig.m_systemServices; adProps.m_systemServices = g_gpGlobalConfig.m_systemServices;
adProps.m_alloc = g_gpGlobalConfig.m_allocator;
IGpInputDriver **inputDrivers = static_cast<IGpInputDriver**>(malloc(sizeof(IGpInputDriver*) * g_gpGlobalConfig.m_numInputDrivers)); IGpInputDriver **inputDrivers = static_cast<IGpInputDriver**>(alloc->Alloc(sizeof(IGpInputDriver*) * g_gpGlobalConfig.m_numInputDrivers));
size_t numCreatedInputDrivers = 0; size_t numCreatedInputDrivers = 0;
if (inputDrivers) if (inputDrivers)
@@ -93,6 +98,7 @@ int GpMain::Run()
inputProps.m_type = g_gpGlobalConfig.m_inputDriverTypes[i]; inputProps.m_type = g_gpGlobalConfig.m_inputDriverTypes[i];
inputProps.m_eventQueue = eventQueue; inputProps.m_eventQueue = eventQueue;
inputProps.m_alloc = g_gpGlobalConfig.m_allocator;
if (IGpInputDriver *driver = GpInputDriverFactory::CreateInputDriver(inputProps)) if (IGpInputDriver *driver = GpInputDriverFactory::CreateInputDriver(inputProps))
inputDrivers[numCreatedInputDrivers++] = driver; inputDrivers[numCreatedInputDrivers++] = driver;
@@ -123,7 +129,7 @@ int GpMain::Run()
for (size_t i = 0; i < numCreatedInputDrivers; i++) for (size_t i = 0; i < numCreatedInputDrivers; i++)
inputDrivers[i]->Shutdown(); inputDrivers[i]->Shutdown();
free(inputDrivers); alloc->Release(inputDrivers);
} }
return 0; return 0;

View File

@@ -5,6 +5,8 @@
#include "DeflateCodec.h" #include "DeflateCodec.h"
#include "MacFileInfo.h" #include "MacFileInfo.h"
#include "ZipFile.h" #include "ZipFile.h"
#include "GpAllocator_C.h"
#include "PLDrivers.h"
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
@@ -12,6 +14,9 @@
int toolMain(int argc, const char **argv) int toolMain(int argc, const char **argv)
{ {
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
if (argc != 2) if (argc != 2)
{ {
fprintf(stderr, "Usage: MergeGPF <file.gpf>"); fprintf(stderr, "Usage: MergeGPF <file.gpf>");

View File

@@ -42,6 +42,7 @@
<Import Project="..\Common.props" /> <Import Project="..\Common.props" />
<Import Project="..\Debug.props" /> <Import Project="..\Debug.props" />
<Import Project="..\GpCommon.props" /> <Import Project="..\GpCommon.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -50,6 +51,7 @@
<Import Project="..\Common.props" /> <Import Project="..\Common.props" />
<Import Project="..\Release.props" /> <Import Project="..\Release.props" />
<Import Project="..\GpCommon.props" /> <Import Project="..\GpCommon.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup />
@@ -84,6 +86,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="MergeGPF.cpp" /> <ClCompile Include="MergeGPF.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -18,5 +18,8 @@
<ClCompile Include="MergeGPF.cpp"> <ClCompile Include="MergeGPF.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -371,6 +371,6 @@ uint32_t PortabilityLayer::DeflateContext::CRC32(uint32_t inputValue, const void
PortabilityLayer::InflateContext *PortabilityLayer::InflateContext::Create() PortabilityLayer::InflateContext *PortabilityLayer::InflateContext::Create()
{ {
return InflateContextImpl::Create(); return InflateContextImpl::Create();
} }

View File

@@ -3,6 +3,7 @@
#include "IGpDisplayDriver.h" #include "IGpDisplayDriver.h"
#include "IGpLogDriver.h" #include "IGpLogDriver.h"
#include "IGpSystemServices.h" #include "IGpSystemServices.h"
#include "MemoryManager.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "QDPixMap.h" #include "QDPixMap.h"
#include "Rect2i.h" #include "Rect2i.h"
@@ -361,7 +362,7 @@ namespace PortabilityLayer
void DialogTemplate::Destroy() void DialogTemplate::Destroy()
{ {
this->~DialogTemplate(); this->~DialogTemplate();
free(this); DisposePtr(this);
} }
ArrayView<const DialogTemplateItem> DialogTemplate::GetItems() const ArrayView<const DialogTemplateItem> DialogTemplate::GetItems() const
@@ -374,7 +375,7 @@ namespace PortabilityLayer
PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(m_window); PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(m_window);
this->~DialogImpl(); this->~DialogImpl();
free(this); DisposePtr(this);
} }
Window *DialogImpl::GetWindow() const Window *DialogImpl::GetWindow() const
@@ -646,7 +647,7 @@ namespace PortabilityLayer
const size_t itemsSize = sizeof(DialogItem) * numItems; const size_t itemsSize = sizeof(DialogItem) * numItems;
void *storage = malloc(alignedSize + itemsSize); void *storage = NewPtr(alignedSize + itemsSize);
if (!storage) if (!storage)
return nullptr; return nullptr;
@@ -882,7 +883,7 @@ namespace PortabilityLayer
const size_t dtlItemSize = sizeof(DialogTemplateItem) * numItems; const size_t dtlItemSize = sizeof(DialogTemplateItem) * numItems;
void *storage = malloc(dtlAlignedSize + dtlItemSize); void *storage = NewPtr(dtlAlignedSize + dtlItemSize);
if (!storage) if (!storage)
{ {
dtemplateH.Dispose(); dtemplateH.Dispose();

View File

@@ -10,6 +10,7 @@
#include "ResTypeID.h" #include "ResTypeID.h"
#include "ZipFileProxy.h" #include "ZipFileProxy.h"
#include "PLCore.h"
#include "PLDrivers.h" #include "PLDrivers.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "PLErrorCodes.h" #include "PLErrorCodes.h"
@@ -474,12 +475,12 @@ namespace PortabilityLayer
void CompositeFileImpl::Close() void CompositeFileImpl::Close()
{ {
this->~CompositeFileImpl(); this->~CompositeFileImpl();
free(this); DisposePtr(this);
} }
CompositeFileImpl *CompositeFileImpl::Create(VirtualDirectory_t dirID, const PLPasStr &filename, GpIOStream *stream, ZipFileProxy *zipFile, const MacFileProperties &mfp, bool resInline, bool dataInline, size_t inlineDataIndex) CompositeFileImpl *CompositeFileImpl::Create(VirtualDirectory_t dirID, const PLPasStr &filename, GpIOStream *stream, ZipFileProxy *zipFile, const MacFileProperties &mfp, bool resInline, bool dataInline, size_t inlineDataIndex)
{ {
void *storage = malloc(sizeof(CompositeFileImpl)); void *storage = NewPtr(sizeof(CompositeFileImpl));
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -1,4 +1,5 @@
#include "FileSectionStream.h" #include "FileSectionStream.h"
#include "PLCore.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
@@ -151,7 +152,7 @@ namespace PortabilityLayer
void FileSectionStreamImpl::GP_ASYNCIFY_PARANOID_NAMED(Close)() void FileSectionStreamImpl::GP_ASYNCIFY_PARANOID_NAMED(Close)()
{ {
this->~FileSectionStreamImpl(); this->~FileSectionStreamImpl();
free(this); DisposePtr(this);
} }
void FileSectionStreamImpl::Flush() void FileSectionStreamImpl::Flush()
@@ -161,7 +162,7 @@ namespace PortabilityLayer
GpIOStream *FileSectionStream::Create(GpIOStream *stream, GpUFilePos_t start, GpUFilePos_t size) GpIOStream *FileSectionStream::Create(GpIOStream *stream, GpUFilePos_t start, GpUFilePos_t size)
{ {
void *storage = malloc(sizeof(FileSectionStreamImpl)); void *storage = NewPtr(sizeof(FileSectionStreamImpl));
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -7,6 +7,7 @@
#include "MemReaderStream.h" #include "MemReaderStream.h"
#include "MemoryManager.h" #include "MemoryManager.h"
#include "PLCore.h"
#include "PLDrivers.h" #include "PLDrivers.h"
#include <stdlib.h> #include <stdlib.h>
@@ -158,7 +159,7 @@ namespace PortabilityLayer
FontFamily *FontFamily::Create(FontFamilyID_t familyID) FontFamily *FontFamily::Create(FontFamilyID_t familyID)
{ {
void *storage = malloc(sizeof(FontFamily)); void *storage = NewPtr(sizeof(FontFamily));
if (!storage) if (!storage)
return nullptr; return nullptr;
@@ -168,7 +169,7 @@ namespace PortabilityLayer
void FontFamily::Destroy() void FontFamily::Destroy()
{ {
this->~FontFamily(); this->~FontFamily();
free(this); DisposePtr(this);
} }
FontFamily::FontFamily(FontFamilyID_t familyID) FontFamily::FontFamily(FontFamilyID_t familyID)

View File

@@ -11,6 +11,7 @@
#include "GpRenderedGlyphMetrics.h" #include "GpRenderedGlyphMetrics.h"
#include "PLBigEndian.h" #include "PLBigEndian.h"
#include "PLCore.h"
#include "PLDrivers.h" #include "PLDrivers.h"
#include "PLPasStr.h" #include "PLPasStr.h"
#include "DeflateCodec.h" #include "DeflateCodec.h"
@@ -166,7 +167,7 @@ namespace PortabilityLayer
void RenderedFontImpl::Destroy() void RenderedFontImpl::Destroy()
{ {
this->~RenderedFontImpl(); this->~RenderedFontImpl();
free(this); DisposePtr(this);
} }
void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const GpRenderedGlyphMetrics &metrics) void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const GpRenderedGlyphMetrics &metrics)
@@ -251,7 +252,7 @@ namespace PortabilityLayer
const size_t allocSize = alignedPrefixSize + glyphDataSize; const size_t allocSize = alignedPrefixSize + glyphDataSize;
void *storage = malloc(allocSize); void *storage = NewPtr(allocSize);
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -1,5 +1,6 @@
#include "InflateStream.h" #include "InflateStream.h"
#include "DeflateCodec.h" #include "DeflateCodec.h"
#include "PLCore.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
@@ -225,7 +226,7 @@ namespace PortabilityLayer
void InflateStreamImpl::GP_ASYNCIFY_PARANOID_NAMED(Close)() void InflateStreamImpl::GP_ASYNCIFY_PARANOID_NAMED(Close)()
{ {
this->~InflateStreamImpl(); this->~InflateStreamImpl();
free(this); DisposePtr(this);
} }
void InflateStreamImpl::Flush() void InflateStreamImpl::Flush()
@@ -238,7 +239,7 @@ namespace PortabilityLayer
if (!inflateContext) if (!inflateContext)
return nullptr; return nullptr;
void *storage = malloc(sizeof(InflateStreamImpl)); void *storage = NewPtr(sizeof(InflateStreamImpl));
if (!storage) if (!storage)
{ {
inflateContext->Destroy(); inflateContext->Destroy();

View File

@@ -1,12 +0,0 @@
#include "MMBlock.h"
namespace PortabilityLayer
{
size_t MMBlock::AlignedSize()
{
const size_t paddedSize = sizeof(MMBlock) + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
const size_t paddedSizeTruncated = paddedSize - (paddedSize % GP_SYSTEM_MEMORY_ALIGNMENT);
return paddedSizeTruncated;
}
}

View File

@@ -1,20 +0,0 @@
#pragma once
#ifndef __PL_MM_BLOCK_H__
#define __PL_MM_BLOCK_H__
#include <stdint.h>
#include "CoreDefs.h"
#include "SmallestInt.h"
namespace PortabilityLayer
{
struct MMBlock
{
SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t m_offsetFromAllocLocation;
static size_t AlignedSize();
};
}
#endif

View File

@@ -1,8 +1,9 @@
#include "MemoryManager.h" #include "MemoryManager.h"
#include "MMBlock.h"
#include "MMHandleBlock.h" #include "MMHandleBlock.h"
#include "ResourceCompiledRef.h" #include "ResourceCompiledRef.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "IGpAllocator.h"
#include "PLDrivers.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
@@ -28,7 +29,6 @@ namespace PortabilityLayer
static MemoryManagerImpl *GetInstance(); static MemoryManagerImpl *GetInstance();
private: private:
static MemoryManagerImpl ms_instance; static MemoryManagerImpl ms_instance;
}; };
@@ -42,75 +42,17 @@ namespace PortabilityLayer
void *MemoryManagerImpl::Realloc(void *buf, size_t newSize) void *MemoryManagerImpl::Realloc(void *buf, size_t newSize)
{ {
assert(buf != nullptr); return PLDrivers::GetAlloc()->Realloc(buf, newSize);
const size_t mmBlockSize = MMBlock::AlignedSize();
uint8_t *oldBufBytes = static_cast<uint8_t*>(buf);
const MMBlock *oldBufMMBlock = reinterpret_cast<const MMBlock*>(oldBufBytes - MMBlock::AlignedSize());
const size_t oldBufOffsetFromAlignLoc = oldBufMMBlock->m_offsetFromAllocLocation;
uint8_t *oldBufBase = oldBufBytes - MMBlock::AlignedSize() - oldBufOffsetFromAlignLoc;
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - newSize < mmBlockSizeWithMaxPadding)
return nullptr;
const size_t newBufferSize = newSize + mmBlockSizeWithMaxPadding;
uint8_t *newBuffer = static_cast<uint8_t*>(realloc(oldBufBase, newSize + mmBlockSizeWithMaxPadding));
if (!newBuffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(newBuffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
// Check if the alignment changed, if so relocate
if (static_cast<size_t>(alignPadding) != oldBufOffsetFromAlignLoc)
memmove(newBuffer + alignPadding, newBuffer + oldBufOffsetFromAlignLoc, MMBlock::AlignedSize() + newSize);
MMBlock *newMMBlock = reinterpret_cast<MMBlock*>(newBuffer + alignPadding);
newMMBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
return newBuffer + alignPadding + MMBlock::AlignedSize();
} }
void *MemoryManagerImpl::Alloc(size_t size) void *MemoryManagerImpl::Alloc(size_t size)
{ {
if (size == 0) return PLDrivers::GetAlloc()->Realloc(nullptr, size);
return nullptr;
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
if (SIZE_MAX - size < mmBlockSizeWithMaxPadding)
return nullptr;
uint8_t *buffer = static_cast<uint8_t*>(malloc(size + mmBlockSizeWithMaxPadding));
if (!buffer)
return nullptr;
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT - 1);
intptr_t alignPadding = 0;
if (offsetFromAlignPoint != 0)
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
MMBlock *mmBlock = reinterpret_cast<MMBlock*>(buffer + alignPadding);
mmBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
return buffer + alignPadding + MMBlock::AlignedSize();
} }
void MemoryManagerImpl::Release(void *buf) void MemoryManagerImpl::Release(void *buf)
{ {
if (!buf) PLDrivers::GetAlloc()->Realloc(buf, 0);
return;
const size_t mmBlockSize = MMBlock::AlignedSize();
uint8_t *bytes = static_cast<uint8_t*>(buf);
const MMBlock *mmBlock = reinterpret_cast<const MMBlock*>(bytes - MMBlock::AlignedSize());
void *freeLoc = bytes - MMBlock::AlignedSize() - mmBlock->m_offsetFromAllocLocation;
free(freeLoc);
} }
MMHandleBlock *MemoryManagerImpl::AllocHandle(size_t size) MMHandleBlock *MemoryManagerImpl::AllocHandle(size_t size)

View File

@@ -1,10 +1,10 @@
#pragma once #pragma once
#ifndef __PL_MEMORY_MANAGER_H__
#define __PL_MEMORY_MANAGER_H__
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
struct IGpAllocator;
namespace PortabilityLayer namespace PortabilityLayer
{ {
struct MMHandleBlock; struct MMHandleBlock;
@@ -50,5 +50,3 @@ namespace PortabilityLayer
return objectHdl; return objectHdl;
} }
} }
#endif

View File

@@ -288,7 +288,7 @@ namespace PortabilityLayer
if (m_iconGraphic) if (m_iconGraphic)
{ {
m_iconGraphic->~SimpleGraphic(); m_iconGraphic->~SimpleGraphic();
free(m_iconGraphic); DisposePtr(m_iconGraphic);
} }
// GP TODO: Dispose of menus properly // GP TODO: Dispose of menus properly
@@ -834,7 +834,7 @@ namespace PortabilityLayer
{ {
typedef SimpleGraphicInstanceStandardPalette<16, 16> GraphicType_t; typedef SimpleGraphicInstanceStandardPalette<16, 16> GraphicType_t;
void *storage = static_cast<GraphicType_t*>(malloc(sizeof(GraphicType_t))); void *storage = static_cast<GraphicType_t*>(NewPtr(sizeof(GraphicType_t)));
if (storage) if (storage)
{ {
memcpy(m_iconMask, static_cast<const uint8_t*>(*icsHandle) + 32, 32); memcpy(m_iconMask, static_cast<const uint8_t*>(*icsHandle) + 32, 32);

View File

@@ -50,4 +50,10 @@ IGpVOSEventQueue *PLDrivers::GetVOSEventQueue()
return ms_drivers.GetDriver<GpDriverIDs::kEventQueue>(); return ms_drivers.GetDriver<GpDriverIDs::kEventQueue>();
} }
IGpAllocator *PLDrivers::GetAlloc()
{
return ms_drivers.GetDriver<GpDriverIDs::kAlloc>();
}
GpDriverCollection PLDrivers::ms_drivers; GpDriverCollection PLDrivers::ms_drivers;

View File

@@ -16,6 +16,7 @@ public:
static IGpSystemServices *GetSystemServices(); static IGpSystemServices *GetSystemServices();
static IGpFontHandler *GetFontHandler(); static IGpFontHandler *GetFontHandler();
static IGpVOSEventQueue *GetVOSEventQueue(); static IGpVOSEventQueue *GetVOSEventQueue();
static IGpAllocator *GetAlloc();
private: private:
static GpDriverCollection ms_drivers; static GpDriverCollection ms_drivers;

View File

@@ -124,7 +124,6 @@
<ClInclude Include="MacRsrcMap.h" /> <ClInclude Include="MacRsrcMap.h" />
<ClInclude Include="MemoryManager.h" /> <ClInclude Include="MemoryManager.h" />
<ClInclude Include="MemReaderStream.h" /> <ClInclude Include="MemReaderStream.h" />
<ClInclude Include="MMBlock.h" />
<ClInclude Include="MMHandleBlock.h" /> <ClInclude Include="MMHandleBlock.h" />
<ClInclude Include="PascalStr.h" /> <ClInclude Include="PascalStr.h" />
<ClInclude Include="PascalStrLiteral.h" /> <ClInclude Include="PascalStrLiteral.h" />
@@ -250,7 +249,6 @@
<ClCompile Include="MemoryManager.cpp" /> <ClCompile Include="MemoryManager.cpp" />
<ClCompile Include="MemReaderStream.cpp" /> <ClCompile Include="MemReaderStream.cpp" />
<ClCompile Include="MenuManager.cpp" /> <ClCompile Include="MenuManager.cpp" />
<ClCompile Include="MMBlock.cpp" />
<ClCompile Include="MMHandleBlock.cpp" /> <ClCompile Include="MMHandleBlock.cpp" />
<ClCompile Include="PLApplication.cpp" /> <ClCompile Include="PLApplication.cpp" />
<ClCompile Include="PLButtonWidget.cpp" /> <ClCompile Include="PLButtonWidget.cpp" />

View File

@@ -132,9 +132,6 @@
<ClInclude Include="MMHandleBlock.h"> <ClInclude Include="MMHandleBlock.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="MMBlock.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DisplayDeviceManager.h"> <ClInclude Include="DisplayDeviceManager.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -494,9 +491,6 @@
<ClCompile Include="MemoryManager.cpp"> <ClCompile Include="MemoryManager.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="MMBlock.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MMHandleBlock.cpp"> <ClCompile Include="MMHandleBlock.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>

View File

@@ -26,7 +26,6 @@
#include "MemoryManager.cpp" #include "MemoryManager.cpp"
#include "MemReaderStream.cpp" #include "MemReaderStream.cpp"
#include "MenuManager.cpp" #include "MenuManager.cpp"
#include "MMBlock.cpp"
#include "MMHandleBlock.cpp" #include "MMHandleBlock.cpp"
#include "PLApplication.cpp" #include "PLApplication.cpp"
#include "PLButtonWidget.cpp" #include "PLButtonWidget.cpp"

View File

@@ -3,6 +3,8 @@
#include "ScanlineMaskBuilder.h" #include "ScanlineMaskBuilder.h"
#include "ScanlineMaskIterator.h" #include "ScanlineMaskIterator.h"
#include "PLCore.h"
#include <stdlib.h> #include <stdlib.h>
#include <new> #include <new>
@@ -11,7 +13,7 @@ namespace PortabilityLayer
void ScanlineMask::Destroy() void ScanlineMask::Destroy()
{ {
this->~ScanlineMask(); this->~ScanlineMask();
free(this); DisposePtr(this);
} }
const Rect &ScanlineMask::GetRect() const const Rect &ScanlineMask::GetRect() const
@@ -50,7 +52,7 @@ namespace PortabilityLayer
else else
return nullptr; return nullptr;
void *storage = malloc(alignedPrefixSize + storageSize); void *storage = NewPtr(alignedPrefixSize + storageSize);
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -7,6 +7,7 @@
#include "LinePlotter.h" #include "LinePlotter.h"
#include "ScanlineMaskBuilder.h" #include "ScanlineMaskBuilder.h"
#include "IPlotter.h" #include "IPlotter.h"
#include "PLCore.h"
#include <assert.h> #include <assert.h>
#include <algorithm> #include <algorithm>
@@ -135,7 +136,7 @@ namespace PortabilityLayer
#else #else
const size_t storageSize = (numElements * 2 + 7) / 8; const size_t storageSize = (numElements * 2 + 7) / 8;
#endif #endif
void *storage = malloc(storageSize); void *storage = NewPtr(storageSize);
if (!storage) if (!storage)
return nullptr; return nullptr;
@@ -250,7 +251,7 @@ namespace PortabilityLayer
stbi_write_png(path, width, height, 4, flagBits, width * 4); stbi_write_png(path, width, height, 4, flagBits, width * 4);
#endif #endif
free(storage); DisposePtr(storage);
return ScanlineMask::Create(Rect::Create(minPoint.m_y, minPoint.m_x, minPoint.m_y + static_cast<int16_t>(height), minPoint.m_x + static_cast<int16_t>(width)), maskBuilder); return ScanlineMask::Create(Rect::Create(minPoint.m_y, minPoint.m_x, minPoint.m_y + static_cast<int16_t>(height), minPoint.m_x + static_cast<int16_t>(width)), maskBuilder);
} }

View File

@@ -2,6 +2,7 @@
#include "IGpThreadEvent.h" #include "IGpThreadEvent.h"
#include "IGpSystemServices.h" #include "IGpSystemServices.h"
#include "PLCore.h"
#include "PLDrivers.h" #include "PLDrivers.h"
#include <stdlib.h> #include <stdlib.h>
@@ -39,7 +40,7 @@ namespace PortabilityLayer
void PortabilityLayer::WorkerThreadImpl::Destroy() void PortabilityLayer::WorkerThreadImpl::Destroy()
{ {
this->~WorkerThreadImpl(); this->~WorkerThreadImpl();
free(this); DisposePtr(this);
} }
void PortabilityLayer::WorkerThreadImpl::AsyncExecuteTask(PortabilityLayer::WorkerThread::Callback_t callback, void *context) void PortabilityLayer::WorkerThreadImpl::AsyncExecuteTask(PortabilityLayer::WorkerThread::Callback_t callback, void *context)
@@ -139,7 +140,7 @@ PortabilityLayer::WorkerThread::~WorkerThread()
PortabilityLayer::WorkerThread *PortabilityLayer::WorkerThread::Create() PortabilityLayer::WorkerThread *PortabilityLayer::WorkerThread::Create()
{ {
void *storage = malloc(sizeof(PortabilityLayer::WorkerThreadImpl)); void *storage = NewPtr(sizeof(PortabilityLayer::WorkerThreadImpl));
if (!storage) if (!storage)
return nullptr; return nullptr;

View File

@@ -2,6 +2,7 @@
#include "CFileStream.h" #include "CFileStream.h"
#include "CombinedTimestamp.h" #include "CombinedTimestamp.h"
#include "GPArchive.h" #include "GPArchive.h"
#include "GpAllocator_C.h"
#include "MacRomanConversion.h" #include "MacRomanConversion.h"
#include "MemReaderStream.h" #include "MemReaderStream.h"
#include "QDPictDecoder.h" #include "QDPictDecoder.h"
@@ -15,6 +16,7 @@
#include "ZipFile.h" #include "ZipFile.h"
#include "WaveFormat.h" #include "WaveFormat.h"
#include "GpUnicode.h" #include "GpUnicode.h"
#include "PLDrivers.h"
#include "zlib.h" #include "zlib.h"
@@ -1431,6 +1433,9 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
PortabilityLayer::CFileStream cfs(inF); PortabilityLayer::CFileStream cfs(inF);
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create(); PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create();
resFile->Load(&cfs); resFile->Load(&cfs);
cfs.Close(); cfs.Close();

View File

@@ -45,6 +45,7 @@
<Import Project="..\RapidJSON.props" /> <Import Project="..\RapidJSON.props" />
<Import Project="..\WindowsUnicodeToolShim.props" /> <Import Project="..\WindowsUnicodeToolShim.props" />
<Import Project="..\Debug.props" /> <Import Project="..\Debug.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
@@ -56,6 +57,7 @@
<Import Project="..\RapidJSON.props" /> <Import Project="..\RapidJSON.props" />
<Import Project="..\WindowsUnicodeToolShim.props" /> <Import Project="..\WindowsUnicodeToolShim.props" />
<Import Project="..\Release.props" /> <Import Project="..\Release.props" />
<Import Project="..\AerofoilPortable.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup /> <PropertyGroup />
@@ -95,6 +97,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
<ClCompile Include="gpr2gpa.cpp" /> <ClCompile Include="gpr2gpa.cpp" />
<ClCompile Include="macedec.cpp" /> <ClCompile Include="macedec.cpp" />
</ItemGroup> </ItemGroup>

View File

@@ -21,6 +21,9 @@
<ClCompile Include="macedec.cpp"> <ClCompile Include="macedec.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="macedec.h"> <ClInclude Include="macedec.h">