mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 06:53:43 +00:00
Allocator refactor
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
<Import Project="..\GpMainApp.props" />
|
||||
<Import Project="..\GpShell.props" />
|
||||
<Import Project="..\Debug.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -52,6 +53,7 @@
|
||||
<Import Project="..\GpMainApp.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="..\GpShell.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
@@ -82,6 +84,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
|
||||
<ClCompile Include="GpBWCursor_Win32.cpp" />
|
||||
<ClCompile Include="GpColorCursor_Win32.cpp" />
|
||||
<ClCompile Include="GpFileStream_Win32.cpp" />
|
||||
|
@@ -28,6 +28,9 @@
|
||||
<ClCompile Include="GpBWCursor_Win32.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\GpCommon\EGpInputDriverType.h">
|
||||
|
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "GpBWCursor_Win32.h"
|
||||
#include "GpWindows.h"
|
||||
#include "IGpAllocator.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -34,19 +35,19 @@ void GpBWCursor_Win32::Destroy()
|
||||
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 numBytes = (width * height + 7) / 8;
|
||||
uint8_t *convertedAndData = static_cast<uint8_t*>(malloc(numBytes));
|
||||
uint8_t *convertedXorData = static_cast<uint8_t*>(malloc(numBytes));
|
||||
size_t numBytes = (numBits + 7) / 8;
|
||||
uint8_t *convertedAndData = static_cast<uint8_t*>(alloc->Alloc(numBytes));
|
||||
uint8_t *convertedXorData = static_cast<uint8_t*>(alloc->Alloc(numBytes));
|
||||
|
||||
if (!convertedAndData || !convertedXorData)
|
||||
{
|
||||
if (convertedAndData)
|
||||
free(convertedAndData);
|
||||
alloc->Release(convertedAndData);
|
||||
if (convertedXorData)
|
||||
free(convertedXorData);
|
||||
alloc->Release(convertedXorData);
|
||||
|
||||
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);
|
||||
|
||||
free(convertedAndData);
|
||||
free(convertedXorData);
|
||||
alloc->Release(convertedAndData);
|
||||
alloc->Release(convertedXorData);
|
||||
|
||||
if (!hcursor)
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(sizeof(GpBWCursor_Win32));
|
||||
void *storage = alloc->Alloc(sizeof(GpBWCursor_Win32));
|
||||
if (!storage)
|
||||
{
|
||||
DestroyCursor(hcursor);
|
||||
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_refCount(1)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -104,7 +106,8 @@ void GpBWCursor_Win32::DecRef()
|
||||
m_refCount--;
|
||||
if (m_refCount == 0)
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpBWCursor_Win32();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include "IGpCursor_Win32.h"
|
||||
#include "GpWindows.h"
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpBWCursor_Win32 final : public IGpCursor_Win32
|
||||
{
|
||||
public:
|
||||
@@ -13,12 +15,13 @@ public:
|
||||
void IncRef() 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:
|
||||
GpBWCursor_Win32(HCURSOR cursor);
|
||||
GpBWCursor_Win32(HCURSOR cursor, IGpAllocator *alloc);
|
||||
~GpBWCursor_Win32();
|
||||
|
||||
HCURSOR m_cursor;
|
||||
int m_refCount;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "GpColorCursor_Win32.h"
|
||||
#include "IGpAllocator.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -31,7 +32,7 @@ void GpColorCursor_Win32::Destroy()
|
||||
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);
|
||||
|
||||
@@ -52,7 +53,7 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
|
||||
size_t maskPitch = width + paddingBits - 1;
|
||||
maskPitch -= maskPitch % paddingBits;
|
||||
|
||||
LPVOID maskBits = malloc(maskPitch * height);
|
||||
LPVOID maskBits = alloc->Alloc(maskPitch * height);
|
||||
if (!maskBits)
|
||||
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);
|
||||
ReleaseDC(NULL, hdc);
|
||||
|
||||
alloc->Release(maskBits);
|
||||
|
||||
size_t cursorPitch = width * 4;
|
||||
|
||||
size_t numPixels = width * height;
|
||||
@@ -90,19 +93,20 @@ IGpCursor_Win32 *GpColorCursor_Win32::Create(size_t width, size_t height, const
|
||||
if (!hicon)
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(sizeof(GpColorCursor_Win32));
|
||||
void *storage = alloc->Alloc(sizeof(GpColorCursor_Win32));
|
||||
if (!storage)
|
||||
{
|
||||
DestroyIcon(hicon);
|
||||
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_refCount(1)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -126,7 +130,8 @@ void GpColorCursor_Win32::DecRef()
|
||||
m_refCount--;
|
||||
if (m_refCount == 0)
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpColorCursor_Win32();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "IGpCursor_Win32.h"
|
||||
#include "GpWindows.h"
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpColorCursor_Win32 final : public IGpCursor_Win32
|
||||
{
|
||||
@@ -14,12 +15,13 @@ public:
|
||||
void IncRef() 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:
|
||||
GpColorCursor_Win32(HCURSOR cursor);
|
||||
GpColorCursor_Win32(IGpAllocator *alloc, HCURSOR cursor);
|
||||
~GpColorCursor_Win32();
|
||||
|
||||
HCURSOR m_cursor;
|
||||
int m_refCount;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include "GpFileSystem_Win32.h"
|
||||
|
||||
#include "GpAllocator_C.h"
|
||||
#include "GpApplicationName.h"
|
||||
#include "GpFileStream_Win32.h"
|
||||
#include "GpWindows.h"
|
||||
#include "IGpAllocator.h"
|
||||
#include "IGpDirectoryCursor.h"
|
||||
|
||||
#include <string>
|
||||
@@ -12,33 +14,36 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
extern GpWindowsGlobals g_gpWindowsGlobals;
|
||||
|
||||
class GpDirectoryCursor_Win32 final : public IGpDirectoryCursor
|
||||
{
|
||||
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;
|
||||
void Destroy() override;
|
||||
|
||||
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();
|
||||
|
||||
IGpAllocator *m_alloc;
|
||||
HANDLE m_handle;
|
||||
WIN32_FIND_DATAW m_findData;
|
||||
char m_chars[MAX_PATH + 1];
|
||||
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)
|
||||
return nullptr;
|
||||
|
||||
return new (storage) GpDirectoryCursor_Win32(handle, findData);
|
||||
return new (storage) GpDirectoryCursor_Win32(alloc, handle, findData);
|
||||
}
|
||||
|
||||
bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName)
|
||||
@@ -82,14 +87,16 @@ bool GpDirectoryCursor_Win32::GetNext(const char *&outFileName)
|
||||
|
||||
void GpDirectoryCursor_Win32::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
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_findData(findData)
|
||||
, m_haveNext(true)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -99,6 +106,7 @@ GpDirectoryCursor_Win32::~GpDirectoryCursor_Win32()
|
||||
}
|
||||
|
||||
GpFileSystem_Win32::GpFileSystem_Win32()
|
||||
: m_alloc(GpAllocator_C::GetInstance())
|
||||
{
|
||||
// GP TODO: This shouldn't be static init since it allocates memory
|
||||
m_executablePath[0] = 0;
|
||||
@@ -277,7 +285,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
|
||||
{
|
||||
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)
|
||||
return nullptr;
|
||||
|
||||
@@ -286,7 +294,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
|
||||
expandedPaths[numPaths] = "*";
|
||||
|
||||
const bool isPathResolved = ResolvePath(virtualDirectory, expandedPaths, numPaths + 1, winPath);
|
||||
free(expandedPaths);
|
||||
m_alloc->Release(expandedPaths);
|
||||
|
||||
if (!isPathResolved)
|
||||
return nullptr;
|
||||
@@ -297,7 +305,7 @@ IGpDirectoryCursor *GpFileSystem_Win32::ScanDirectoryNested(PortabilityLayer::Vi
|
||||
if (ff == INVALID_HANDLE_VALUE)
|
||||
return nullptr;
|
||||
|
||||
return GpDirectoryCursor_Win32::Create(ff, findData);
|
||||
return GpDirectoryCursor_Win32::Create(m_alloc, ff, findData);
|
||||
}
|
||||
|
||||
bool GpFileSystem_Win32::ValidateFilePathUnicodeChar(uint32_t c) const
|
||||
|
@@ -41,5 +41,7 @@ private:
|
||||
std::wstring m_fontCacheDir;
|
||||
wchar_t m_executablePath[MAX_PATH];
|
||||
|
||||
IGpAllocator *m_alloc;
|
||||
|
||||
static GpFileSystem_Win32 ms_instance;
|
||||
};
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#include "GpAllocator_C.h"
|
||||
#include "GpLogDriver_Win32.h"
|
||||
#include "GpFileSystem_Win32.h"
|
||||
|
||||
@@ -7,6 +8,7 @@
|
||||
GpLogDriver_Win32::GpLogDriver_Win32()
|
||||
: m_stream(nullptr)
|
||||
, 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)
|
||||
return;
|
||||
|
||||
char *charBuff = static_cast<char*>(malloc(formattedSize + 1));
|
||||
char *charBuff = static_cast<char*>(m_alloc->Alloc(formattedSize + 1));
|
||||
if (!charBuff)
|
||||
return;
|
||||
|
||||
vsnprintf(charBuff, formattedSize + 1, fmt, args);
|
||||
|
||||
m_stream->Write(charBuff, formattedSize);
|
||||
free(charBuff);
|
||||
m_alloc->Release(charBuff);
|
||||
}
|
||||
|
||||
m_stream->Write("\n", 1);
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "IGpLogDriver.h"
|
||||
|
||||
class GpIOStream;
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpLogDriver_Win32 : public IGpLogDriver
|
||||
{
|
||||
@@ -20,6 +21,7 @@ private:
|
||||
void InitInternal();
|
||||
|
||||
GpIOStream *m_stream;
|
||||
IGpAllocator *m_alloc;
|
||||
bool m_isInitialized;
|
||||
|
||||
static GpLogDriver_Win32 ms_instance;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "GpMain.h"
|
||||
#include "GpAllocator_C.h"
|
||||
#include "GpAudioDriverFactory.h"
|
||||
#include "GpBWCursor_Win32.h"
|
||||
#include "GpColorCursor_Win32.h"
|
||||
@@ -410,12 +411,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
|
||||
IGpLogDriver *logger = GpLogDriver_Win32::GetInstance();
|
||||
IGpAllocator *alloc = GpAllocator_C::GetInstance();
|
||||
IGpSystemServices *sysServices = GpSystemServices_Win32::GetInstance();
|
||||
|
||||
GpDriverCollection *drivers = GpAppInterface_Get()->PL_GetDriverCollection();
|
||||
|
||||
drivers->SetDriver<GpDriverIDs::kFileSystem>(GpFileSystem_Win32::GetInstance());
|
||||
drivers->SetDriver<GpDriverIDs::kSystemServices>(GpSystemServices_Win32::GetInstance());
|
||||
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance());
|
||||
drivers->SetDriver<GpDriverIDs::kSystemServices>(sysServices);
|
||||
drivers->SetDriver<GpDriverIDs::kLog>(logger);
|
||||
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
|
||||
|
||||
g_gpWindowsGlobals.m_hInstance = hInstance;
|
||||
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_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);
|
||||
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_XAudio2, GpDriver_CreateAudioDriver_XAudio2);
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "GpMutex_Win32.h"
|
||||
|
||||
#include "IGpAllocator.h"
|
||||
#include "GpWindows.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -7,8 +8,9 @@
|
||||
|
||||
void GpMutex_Win32::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpMutex_Win32();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@
|
||||
|
||||
#include "GpWindows.h"
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpMutex_Win32 final : public IGpMutex
|
||||
{
|
||||
public:
|
||||
@@ -11,11 +13,12 @@ public:
|
||||
void Lock() override;
|
||||
void Unlock() override;
|
||||
|
||||
static GpMutex_Win32 *Create();
|
||||
static GpMutex_Win32 *Create(IGpAllocator *alloc);
|
||||
|
||||
private:
|
||||
const GpMutex_Win32();
|
||||
explicit GpMutex_Win32(IGpAllocator *alloc);
|
||||
~GpMutex_Win32();
|
||||
|
||||
CRITICAL_SECTION m_critSection;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "GpMutex_Win32.h"
|
||||
#include "GpThreadEvent_Win32.h"
|
||||
#include "GpWindows.h"
|
||||
#include "GpAllocator_C.h"
|
||||
|
||||
#include "IGpClipboardContents.h"
|
||||
|
||||
@@ -133,6 +134,7 @@ static DWORD WINAPI StaticStartThread(LPVOID lpThreadParameter)
|
||||
|
||||
GpSystemServices_Win32::GpSystemServices_Win32()
|
||||
: 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()
|
||||
{
|
||||
return GpMutex_Win32::Create();
|
||||
return GpMutex_Win32::Create(m_alloc);
|
||||
}
|
||||
|
||||
IGpMutex *GpSystemServices_Win32::CreateRecursiveMutex()
|
||||
{
|
||||
return GpMutex_Win32::Create();
|
||||
return GpMutex_Win32::Create(m_alloc);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@@ -48,6 +48,8 @@ public:
|
||||
private:
|
||||
bool m_isTouchscreenSimulation;
|
||||
|
||||
IGpAllocator *m_alloc;
|
||||
|
||||
static GpSystemServices_Win32 ms_instance;
|
||||
};
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "GpThreadEvent_Win32.h"
|
||||
#include "IGpAllocator.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -20,28 +21,30 @@ void GpThreadEvent_Win32::Signal()
|
||||
|
||||
void GpThreadEvent_Win32::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
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);
|
||||
if (handle == nullptr)
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(sizeof(GpThreadEvent_Win32));
|
||||
void *storage = alloc->Alloc(sizeof(GpThreadEvent_Win32));
|
||||
if (!storage)
|
||||
{
|
||||
CloseHandle(handle);
|
||||
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_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -12,11 +12,12 @@ public:
|
||||
void Signal() override;
|
||||
void Destroy() override;
|
||||
|
||||
static GpThreadEvent_Win32 *Create(bool autoReset, bool startSignaled);
|
||||
static GpThreadEvent_Win32 *Create(IGpAllocator *alloc, bool autoReset, bool startSignaled);
|
||||
|
||||
private:
|
||||
explicit GpThreadEvent_Win32(const HANDLE &handle);
|
||||
explicit GpThreadEvent_Win32(IGpAllocator *alloc, const HANDLE &handle);
|
||||
~GpThreadEvent_Win32();
|
||||
|
||||
HANDLE m_event;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -2,7 +2,9 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<PropertyGroup>
|
||||
<IncludePath>$(SolutionDir)AerofoilPortable;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup />
|
||||
<ItemGroup />
|
||||
</Project>
|
115
AerofoilPortable/GpAllocator_C.cpp
Normal file
115
AerofoilPortable/GpAllocator_C.cpp
Normal 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;
|
17
AerofoilPortable/GpAllocator_C.h
Normal file
17
AerofoilPortable/GpAllocator_C.h
Normal 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;
|
||||
};
|
@@ -84,6 +84,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
|
||||
<ClCompile Include="..\Aerofoil\GpColorCursor_Win32.cpp" />
|
||||
<ClCompile Include="..\Aerofoil\GpFileStream_Win32.cpp" />
|
||||
<ClCompile Include="..\Aerofoil\GpFileSystem_Win32.cpp" />
|
||||
|
@@ -66,6 +66,9 @@
|
||||
<ClCompile Include="GpInputDriver_SDL_Gamepad.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ShaderCode\Functions.h">
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#include "SDL.h"
|
||||
|
||||
#include "GpMain.h"
|
||||
#include "GpAllocator_C.h"
|
||||
#include "GpAudioDriverFactory.h"
|
||||
#include "GpDisplayDriverFactory.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::kSystemServices>(GpSystemServices_Win32::GetInstance());
|
||||
drivers->SetDriver<GpDriverIDs::kLog>(GpLogDriver_Win32::GetInstance());
|
||||
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
|
||||
|
||||
g_gpWindowsGlobals.m_hInstance = hInstance;
|
||||
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_logger = logger;
|
||||
g_gpGlobalConfig.m_systemServices = GpSystemServices_Win32::GetInstance();
|
||||
g_gpGlobalConfig.m_allocator = GpAllocator_C::GetInstance();
|
||||
|
||||
GpDisplayDriverFactory::RegisterDisplayDriverFactory(EGpDisplayDriverType_SDL_GL2, GpDriver_CreateDisplayDriver_SDL_GL2);
|
||||
GpAudioDriverFactory::RegisterAudioDriverFactory(EGpAudioDriverType_SDL2, GpDriver_CreateAudioDriver_SDL);
|
||||
|
@@ -1,11 +1,13 @@
|
||||
#include "CFileStream.h"
|
||||
#include "BMPFormat.h"
|
||||
#include "GpAllocator_C.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "ResourceCompiledTypeList.h"
|
||||
#include "ResourceFile.h"
|
||||
#include "SharedTypes.h"
|
||||
#include "QDStandardPalette.h"
|
||||
#include "PLBigEndian.h"
|
||||
#include "PLDrivers.h"
|
||||
#include <assert.h>
|
||||
|
||||
#include <string>
|
||||
@@ -141,6 +143,9 @@ int main(int argc, const char **argv)
|
||||
|
||||
PortabilityLayer::CFileStream stream(f);
|
||||
|
||||
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
|
||||
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
|
||||
|
||||
PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create();
|
||||
if (!resFile->Load(&stream))
|
||||
return -1;
|
||||
|
@@ -42,6 +42,7 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\stb.props" />
|
||||
<Import Project="..\Debug.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -50,6 +51,7 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\stb.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
@@ -81,6 +83,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
|
||||
<ClCompile Include="..\stb\stb_image_write.c" />
|
||||
<ClCompile Include="ConvertColorCursors.cpp" />
|
||||
</ItemGroup>
|
||||
|
@@ -21,5 +21,8 @@
|
||||
<ClCompile Include="..\stb\stb_image_write.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -3,6 +3,7 @@
|
||||
#include "FontRenderer.h"
|
||||
#include "IGpFont.h"
|
||||
#include "IGpFontHandler.h"
|
||||
#include "GpAllocator_C.h"
|
||||
#include "GpAppInterface.h"
|
||||
#include "GpDriverIndex.h"
|
||||
#include "GpFontHandlerProperties.h"
|
||||
@@ -167,8 +168,14 @@ bool KnownFontSpec::operator!=(const KnownFontSpec &other) const
|
||||
|
||||
int toolMain(int argc, const char **argv)
|
||||
{
|
||||
IGpAllocator *alloc = GpAllocator_C::GetInstance();
|
||||
|
||||
GpFontHandlerProperties fhProperties;
|
||||
fhProperties.m_type = EGpFontHandlerType_FreeType2;
|
||||
fhProperties.m_alloc = alloc;
|
||||
|
||||
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
|
||||
drivers->SetDriver<GpDriverIDs::kAlloc>(alloc);
|
||||
|
||||
IGpFontHandler *ft2Handler = GpDriver_CreateFontHandler_FreeType2(fhProperties);
|
||||
|
||||
|
@@ -43,6 +43,7 @@
|
||||
<Import Project="..\AerofoilWin.props" />
|
||||
<Import Project="..\Debug.props" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -52,6 +53,7 @@
|
||||
<Import Project="..\AerofoilWin.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
@@ -93,6 +95,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
|
||||
<ClCompile Include="GenerateFonts.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@@ -18,5 +18,8 @@
|
||||
<ClCompile Include="GenerateFonts.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -1,12 +1,12 @@
|
||||
#include "GpAudioBufferXAudio2.h"
|
||||
#include "CoreDefs.h"
|
||||
#include "GpWindows.h"
|
||||
#include "IGpAllocator.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#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);
|
||||
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;
|
||||
|
||||
void *storage = _aligned_malloc(totalSize, GP_SYSTEM_MEMORY_ALIGNMENT);
|
||||
void *storage = alloc->Realloc(nullptr, totalSize);
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
void *dataPos = static_cast<uint8_t*>(storage) + baseSize;
|
||||
|
||||
memcpy(dataPos, buffer, size);
|
||||
return new (storage) GpAudioBufferXAudio2(dataPos, size);
|
||||
return new (storage) GpAudioBufferXAudio2(alloc, dataPos, size);
|
||||
}
|
||||
|
||||
void GpAudioBufferXAudio2::AddRef()
|
||||
@@ -40,8 +40,9 @@ const XAUDIO2_BUFFER *GpAudioBufferXAudio2::GetXA2Buffer() const
|
||||
return &m_xa2Buffer;
|
||||
}
|
||||
|
||||
GpAudioBufferXAudio2::GpAudioBufferXAudio2(const void *data, size_t size)
|
||||
: m_data(data)
|
||||
GpAudioBufferXAudio2::GpAudioBufferXAudio2(IGpAllocator *alloc, const void *data, size_t size)
|
||||
: m_alloc(alloc)
|
||||
, m_data(data)
|
||||
, m_size(size)
|
||||
, m_count(1)
|
||||
{
|
||||
@@ -62,6 +63,7 @@ GpAudioBufferXAudio2::~GpAudioBufferXAudio2()
|
||||
|
||||
void GpAudioBufferXAudio2::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpAudioBufferXAudio2();
|
||||
_aligned_free(this);
|
||||
m_alloc->Realloc(this, 0);
|
||||
}
|
||||
|
@@ -4,10 +4,12 @@
|
||||
|
||||
#include <xaudio2.h>
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpAudioBufferXAudio2 final : public IGpAudioBuffer
|
||||
{
|
||||
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 Release() override;
|
||||
@@ -15,13 +17,14 @@ public:
|
||||
const XAUDIO2_BUFFER *GetXA2Buffer() const;
|
||||
|
||||
private:
|
||||
GpAudioBufferXAudio2(const void *data, size_t size);
|
||||
GpAudioBufferXAudio2(IGpAllocator *alloc, const void *data, size_t size);
|
||||
~GpAudioBufferXAudio2();
|
||||
|
||||
void Destroy();
|
||||
|
||||
const void *m_data;
|
||||
size_t m_size;
|
||||
IGpAllocator *m_alloc;
|
||||
|
||||
XAUDIO2_BUFFER m_xa2Buffer;
|
||||
|
||||
|
@@ -1,26 +1,27 @@
|
||||
#include "GpAudioBufferXAudio2.h"
|
||||
#include "GpAudioChannelXAudio2.h"
|
||||
#include "GpAudioDriverXAudio2.h"
|
||||
#include "IGpAllocator.h"
|
||||
#include "IGpAudioChannelCallbacks.h"
|
||||
#include "IGpLogDriver.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
|
||||
GpAudioChannelXAudio2 *GpAudioChannelXAudio2::Create(GpAudioDriverXAudio2 *driver)
|
||||
GpAudioChannelXAudio2 *GpAudioChannelXAudio2::Create(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver)
|
||||
{
|
||||
IGpLogDriver *logger = driver->GetProperties().m_logger;
|
||||
|
||||
void *storage = malloc(sizeof(GpAudioChannelXAudio2));
|
||||
void *storage = alloc->Realloc(nullptr, sizeof(GpAudioChannelXAudio2));
|
||||
if (!storage)
|
||||
{
|
||||
if (!logger)
|
||||
logger->Printf(IGpLogDriver::Category_Error, "GpAudioChannelXAudio2::Create failed, malloc failed");
|
||||
logger->Printf(IGpLogDriver::Category_Error, "GpAudioChannelXAudio2::Create failed, alloc failed");
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GpAudioChannelXAudio2 *channel = new (storage) GpAudioChannelXAudio2(driver);
|
||||
GpAudioChannelXAudio2 *channel = new (storage) GpAudioChannelXAudio2(alloc, driver);
|
||||
if (!channel->Init())
|
||||
{
|
||||
if (!logger)
|
||||
@@ -110,8 +111,9 @@ void GpAudioChannelXAudio2::Stop()
|
||||
|
||||
void GpAudioChannelXAudio2::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpAudioChannelXAudio2();
|
||||
free(this);
|
||||
alloc->Realloc(this, 0);
|
||||
}
|
||||
|
||||
void GpAudioChannelXAudio2::OnBufferEnd()
|
||||
@@ -120,12 +122,13 @@ void GpAudioChannelXAudio2::OnBufferEnd()
|
||||
m_contextCallbacks->NotifyBufferFinished();
|
||||
}
|
||||
|
||||
GpAudioChannelXAudio2::GpAudioChannelXAudio2(GpAudioDriverXAudio2 *driver)
|
||||
GpAudioChannelXAudio2::GpAudioChannelXAudio2(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver)
|
||||
: m_driver(driver)
|
||||
, m_xAudioCallbacks(this)
|
||||
, m_sourceVoice(nullptr)
|
||||
, m_contextCallbacks(nullptr)
|
||||
, m_voiceState(VoiceState_Idle)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -7,13 +7,14 @@
|
||||
class GpAudioDriverXAudio2;
|
||||
class GpAudioChannelXAudio2Callbacks;
|
||||
struct IXAudio2SourceVoice;
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpAudioChannelXAudio2 final : public IGpAudioChannel
|
||||
{
|
||||
public:
|
||||
friend class GpAudioChannelXAudio2Callbacks;
|
||||
|
||||
static GpAudioChannelXAudio2 *Create(GpAudioDriverXAudio2 *driver);
|
||||
static GpAudioChannelXAudio2 *Create(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver);
|
||||
|
||||
void SetAudioChannelContext(IGpAudioChannelCallbacks *callbacks) override;
|
||||
bool PostBuffer(IGpAudioBuffer *buffer) override;
|
||||
@@ -32,12 +33,13 @@ private:
|
||||
VoiceState_Active,
|
||||
};
|
||||
|
||||
explicit GpAudioChannelXAudio2(GpAudioDriverXAudio2 *driver);
|
||||
explicit GpAudioChannelXAudio2(IGpAllocator *alloc, GpAudioDriverXAudio2 *driver);
|
||||
~GpAudioChannelXAudio2();
|
||||
|
||||
GpAudioDriverXAudio2 *m_driver;
|
||||
IXAudio2SourceVoice *m_sourceVoice;
|
||||
GpAudioChannelXAudio2Callbacks m_xAudioCallbacks;
|
||||
IGpAudioChannelCallbacks *m_contextCallbacks;
|
||||
IGpAllocator *m_alloc;
|
||||
VoiceState m_voiceState;
|
||||
};
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include "CoreDefs.h"
|
||||
|
||||
#include <xaudio2.h>
|
||||
#include <malloc.h>
|
||||
|
||||
void GpAudioDriverXAudio2::Shutdown()
|
||||
{
|
||||
@@ -101,12 +100,12 @@ GpAudioDriverXAudio2 *GpAudioDriverXAudio2::Create(const GpAudioDriverProperties
|
||||
|
||||
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()
|
||||
{
|
||||
return GpAudioChannelXAudio2::Create(this);
|
||||
return GpAudioChannelXAudio2::Create(m_properties.m_alloc, this);
|
||||
}
|
||||
|
||||
void GpAudioDriverXAudio2::SetMasterVolume(uint32_t vol, uint32_t maxVolume)
|
||||
|
@@ -5,6 +5,7 @@
|
||||
struct IGpSystemServices;
|
||||
struct IGpAudioDriver;
|
||||
struct IGpLogDriver;
|
||||
struct IGpAllocator;
|
||||
|
||||
struct GpAudioDriverProperties
|
||||
{
|
||||
@@ -15,4 +16,5 @@ struct GpAudioDriverProperties
|
||||
|
||||
IGpLogDriver *m_logger;
|
||||
IGpSystemServices *m_systemServices;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -10,6 +10,7 @@ struct IGpFiber;
|
||||
struct IGpVOSEventQueue;
|
||||
struct IGpLogDriver;
|
||||
struct IGpSystemServices;
|
||||
struct IGpAllocator;
|
||||
|
||||
struct GpDisplayDriverProperties
|
||||
{
|
||||
@@ -43,4 +44,5 @@ struct GpDisplayDriverProperties
|
||||
IGpVOSEventQueue *m_eventQueue;
|
||||
IGpLogDriver *m_logger;
|
||||
IGpSystemServices *m_systemServices;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -16,6 +16,7 @@ namespace GpDriverIDs
|
||||
kSystemServices,
|
||||
kFont,
|
||||
kEventQueue,
|
||||
kAlloc,
|
||||
|
||||
kCount
|
||||
};
|
||||
@@ -54,6 +55,7 @@ GP_DEFINE_MULTI_DRIVER(kInput, IGpInputDriver);
|
||||
GP_DEFINE_DRIVER(kSystemServices, IGpSystemServices);
|
||||
GP_DEFINE_DRIVER(kFont, IGpFontHandler);
|
||||
GP_DEFINE_DRIVER(kEventQueue, IGpVOSEventQueue);
|
||||
GP_DEFINE_DRIVER(kAlloc, IGpAllocator);
|
||||
|
||||
struct GpDriverCollection
|
||||
{
|
||||
|
@@ -2,7 +2,11 @@
|
||||
|
||||
#include "EGpFontHandlerType.h"
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
struct GpFontHandlerProperties
|
||||
{
|
||||
EGpFontHandlerType m_type;
|
||||
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -4,10 +4,12 @@
|
||||
|
||||
struct IGpAudioDriver;
|
||||
struct IGpVOSEventQueue;
|
||||
struct IGpAllocator;
|
||||
|
||||
struct GpInputDriverProperties
|
||||
{
|
||||
EGpInputDriverType m_type;
|
||||
|
||||
IGpVOSEventQueue *m_eventQueue;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
struct IGpBWCursor_Win32;
|
||||
struct IGpCursor_Win32;
|
||||
struct IGpAllocator;
|
||||
struct IGpVOSEventQueue;
|
||||
|
||||
struct GpWindowsGlobals
|
||||
@@ -28,7 +29,7 @@ struct GpWindowsGlobals
|
||||
HICON m_hIconSm;
|
||||
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_createBWCursorFunc)(size_t width, size_t height, const void *pixelData, const void *maskData, 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)(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);
|
||||
};
|
||||
|
12
GpCommon/IGpAllocator.h
Normal file
12
GpCommon/IGpAllocator.h
Normal 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); }
|
||||
};
|
@@ -1,8 +1,10 @@
|
||||
#include "GpApplicationName.h"
|
||||
#include "GpDisplayDriverD3D11.h"
|
||||
#include "GpDisplayDriverProperties.h"
|
||||
#include "GpDisplayDriverSurfaceD3D11.h"
|
||||
#include "GpVOSEvent.h"
|
||||
#include "GpWindows.h"
|
||||
#include "IGpAllocator.h"
|
||||
#include "IGpCursor_Win32.h"
|
||||
#include "IGpVOSEventQueue.h"
|
||||
|
||||
@@ -1243,8 +1245,9 @@ void GpDisplayDriverD3D11::ServeTicks(int tickCount)
|
||||
|
||||
void GpDisplayDriverD3D11::Shutdown()
|
||||
{
|
||||
IGpAllocator *alloc = m_properties.m_alloc;
|
||||
this->~GpDisplayDriverD3D11();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
@@ -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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
@@ -1507,7 +1510,7 @@ bool GpDisplayDriverD3D11::SavePrefs(void *context, IGpPrefsHandler::WritePrefsF
|
||||
|
||||
GpDisplayDriverD3D11 *GpDisplayDriverD3D11::Create(const GpDisplayDriverProperties &properties)
|
||||
{
|
||||
void *storage = malloc(sizeof(GpDisplayDriverD3D11));
|
||||
void *storage = properties.m_alloc->Alloc(sizeof(GpDisplayDriverD3D11));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "GpDisplayDriverSurfaceD3D11.h"
|
||||
#include "GpComPtr.h"
|
||||
#include "IGpAllocator.h"
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <emmintrin.h>
|
||||
@@ -55,8 +56,9 @@ void GpDisplayDriverSurfaceD3D11::UploadEntire(const void *data, size_t pitch)
|
||||
|
||||
void GpDisplayDriverSurfaceD3D11::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpDisplayDriverSurfaceD3D11();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
|
||||
ID3D11ShaderResourceView *GpDisplayDriverSurfaceD3D11::GetSRV() const
|
||||
@@ -79,7 +81,7 @@ size_t GpDisplayDriverSurfaceD3D11::GetHeight() const
|
||||
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;
|
||||
|
||||
@@ -127,17 +129,17 @@ GpDisplayDriverSurfaceD3D11 *GpDisplayDriverSurfaceD3D11::Create(ID3D11Device *d
|
||||
if (device->CreateShaderResourceView(texture, &srvDesc, srv.GetMutablePtr()) != S_OK)
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(sizeof(GpDisplayDriverSurfaceD3D11));
|
||||
void *storage = alloc->Alloc(sizeof(GpDisplayDriverSurfaceD3D11));
|
||||
if (!storage)
|
||||
{
|
||||
texture->Release();
|
||||
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_height(height)
|
||||
, m_pixelFormat(pixelFormat)
|
||||
@@ -145,6 +147,7 @@ GpDisplayDriverSurfaceD3D11::GpDisplayDriverSurfaceD3D11(ID3D11Device *device, I
|
||||
, m_deviceContext(deviceContext)
|
||||
, m_texture(texture)
|
||||
, m_srv(srv)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@ struct ID3D11Device;
|
||||
struct ID3D11DeviceContext;
|
||||
struct ID3D11ShaderResourceView;
|
||||
struct ID3D11Texture2D;
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpDisplayDriverSurfaceD3D11 final : public IGpDisplayDriverSurface
|
||||
{
|
||||
@@ -21,10 +22,10 @@ public:
|
||||
size_t GetWidth() 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:
|
||||
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();
|
||||
|
||||
size_t m_width;
|
||||
@@ -32,6 +33,7 @@ private:
|
||||
GpPixelFormat_t m_pixelFormat;
|
||||
ID3D11Device *m_device;
|
||||
ID3D11DeviceContext *m_deviceContext;
|
||||
IGpAllocator *m_alloc;
|
||||
|
||||
GpComPtr<ID3D11Texture2D> m_texture;
|
||||
GpComPtr<ID3D11ShaderResourceView> m_srv;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "CoreDefs.h"
|
||||
#include "GpIOStream.h"
|
||||
#include "IGpAllocator.h"
|
||||
#include "IGpFont.h"
|
||||
#include "IGpFontRenderedGlyph.h"
|
||||
#include "GpRenderedGlyphMetrics.h"
|
||||
@@ -17,6 +18,8 @@
|
||||
#include <new>
|
||||
#include <assert.h>
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
class GpFontRenderedGlyph_FreeType2 final : public IGpFontRenderedGlyph
|
||||
{
|
||||
public:
|
||||
@@ -24,14 +27,15 @@ public:
|
||||
const void *GetData() const 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();
|
||||
|
||||
private:
|
||||
GpFontRenderedGlyph_FreeType2(void *data, const GpRenderedGlyphMetrics &metrics);
|
||||
GpFontRenderedGlyph_FreeType2(IGpAllocator *alloc, void *data, const GpRenderedGlyphMetrics &metrics);
|
||||
~GpFontRenderedGlyph_FreeType2();
|
||||
|
||||
IGpAllocator *m_alloc;
|
||||
void *m_data;
|
||||
GpRenderedGlyphMetrics m_metrics;
|
||||
};
|
||||
@@ -44,17 +48,18 @@ public:
|
||||
bool GetLineSpacing(unsigned int size, int32_t &outSpacing) 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);
|
||||
|
||||
private:
|
||||
explicit GpFont_FreeType2(const FT_StreamRec_ &streamRec, GpIOStream *stream);
|
||||
GpFont_FreeType2(IGpAllocator *alloc, const FT_StreamRec_ &streamRec, GpIOStream *stream);
|
||||
~GpFont_FreeType2();
|
||||
|
||||
FT_StreamRec_ m_ftStream;
|
||||
FT_Face m_face;
|
||||
GpIOStream *m_stream;
|
||||
IGpAllocator *m_alloc;
|
||||
unsigned int m_currentSize;
|
||||
};
|
||||
|
||||
@@ -70,20 +75,21 @@ const void *GpFontRenderedGlyph_FreeType2::GetData() const
|
||||
|
||||
void GpFontRenderedGlyph_FreeType2::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
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);
|
||||
alignedPrefixSize -= alignedPrefixSize % GP_SYSTEM_MEMORY_ALIGNMENT;
|
||||
|
||||
void *storage = malloc(alignedPrefixSize + dataSize);
|
||||
void *storage = alloc->Alloc(alignedPrefixSize + dataSize);
|
||||
if (!storage)
|
||||
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()
|
||||
@@ -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_data(data)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -104,8 +111,9 @@ GpFontRenderedGlyph_FreeType2::~GpFontRenderedGlyph_FreeType2()
|
||||
|
||||
void GpFont_FreeType2::Destroy()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
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)
|
||||
@@ -190,7 +198,7 @@ IGpFontRenderedGlyph *GpFont_FreeType2::Render(uint32_t unicodeCodePoint, unsign
|
||||
|
||||
metrics.m_glyphDataPitch = pitchRequired;
|
||||
|
||||
GpFontRenderedGlyph_FreeType2 *renderedGlyph = GpFontRenderedGlyph_FreeType2::Create(glyphDataSize, metrics);
|
||||
GpFontRenderedGlyph_FreeType2 *renderedGlyph = GpFontRenderedGlyph_FreeType2::Create(m_alloc, glyphDataSize, metrics);
|
||||
if (!renderedGlyph)
|
||||
return nullptr;
|
||||
|
||||
@@ -263,13 +271,13 @@ bool GpFont_FreeType2::SupportScaling() const
|
||||
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)
|
||||
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)
|
||||
@@ -288,11 +296,12 @@ bool GpFont_FreeType2::FTLoad(const FT_Library &library, int typeFaceIndex)
|
||||
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_ftStream(streamRec)
|
||||
, m_stream(stream)
|
||||
, m_currentSize(0)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
assert(stream);
|
||||
}
|
||||
@@ -305,13 +314,13 @@ GpFont_FreeType2::~GpFont_FreeType2()
|
||||
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)
|
||||
return nullptr;
|
||||
|
||||
GpFontHandler_FreeType2 *fh = new (storage) GpFontHandler_FreeType2();
|
||||
GpFontHandler_FreeType2 *fh = new (storage) GpFontHandler_FreeType2(alloc);
|
||||
if (!fh->Init())
|
||||
{
|
||||
fh->Shutdown();
|
||||
@@ -331,7 +340,7 @@ IGpFont *GpFontHandler_FreeType2::LoadFont(GpIOStream *stream, int typeFaceIndex
|
||||
ftStream.read = FTStreamIo;
|
||||
ftStream.close = FTStreamClose;
|
||||
|
||||
GpFont_FreeType2 *font = GpFont_FreeType2::Create(ftStream, stream);
|
||||
GpFont_FreeType2 *font = GpFont_FreeType2::Create(m_alloc, ftStream, stream);
|
||||
if (!font)
|
||||
{
|
||||
stream->Close();
|
||||
@@ -354,14 +363,16 @@ bool GpFontHandler_FreeType2::KeepStreamOpen() const
|
||||
|
||||
void GpFontHandler_FreeType2::Shutdown()
|
||||
{
|
||||
IGpAllocator *alloc = m_alloc;
|
||||
this->~GpFontHandler_FreeType2();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
|
||||
GpFontHandler_FreeType2::GpFontHandler_FreeType2()
|
||||
GpFontHandler_FreeType2::GpFontHandler_FreeType2(IGpAllocator *alloc)
|
||||
: m_ftIsInitialized(false)
|
||||
, m_library(nullptr)
|
||||
, m_currentSize(0)
|
||||
, m_alloc(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -411,18 +422,18 @@ void GpFontHandler_FreeType2::FTStreamClose(FT_Stream stream)
|
||||
|
||||
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)
|
||||
{
|
||||
free(block);
|
||||
m_alloc->Release(block);
|
||||
}
|
||||
|
||||
void *GpFontHandler_FreeType2::FTRealloc(long curSize, long newSize, void *block)
|
||||
{
|
||||
(void)curSize;
|
||||
return realloc(block, static_cast<size_t>(newSize));
|
||||
return m_alloc->Realloc(block, static_cast<size_t>(newSize));
|
||||
}
|
||||
|
||||
bool GpFontHandler_FreeType2::Init()
|
||||
@@ -448,5 +459,5 @@ __declspec(dllexport)
|
||||
#endif
|
||||
IGpFontHandler *GpDriver_CreateFontHandler_FreeType2(const GpFontHandlerProperties &properties)
|
||||
{
|
||||
return GpFontHandler_FreeType2::Create();
|
||||
return GpFontHandler_FreeType2::Create(properties.m_alloc);
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
class GpIOStream;
|
||||
struct IGpAllocator;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
@@ -21,10 +22,10 @@ public:
|
||||
|
||||
bool KeepStreamOpen() const override;
|
||||
|
||||
static GpFontHandler_FreeType2 *Create();
|
||||
static GpFontHandler_FreeType2 *Create(IGpAllocator *alloc);
|
||||
|
||||
private:
|
||||
GpFontHandler_FreeType2();
|
||||
explicit GpFontHandler_FreeType2(IGpAllocator *alloc);
|
||||
~GpFontHandler_FreeType2();
|
||||
|
||||
static void *FTAllocThunk(FT_Memory memory, long size);
|
||||
@@ -44,4 +45,5 @@ private:
|
||||
FT_Library m_library;
|
||||
unsigned int m_currentSize;
|
||||
bool m_ftIsInitialized;
|
||||
IGpAllocator *m_alloc;
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "GpVOSEvent.h"
|
||||
#include "GpWindows.h"
|
||||
#include "IGpVOSEventQueue.h"
|
||||
#include "IGpAllocator.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -72,8 +73,9 @@ void GpInputDriverXInput::ProcessInput()
|
||||
|
||||
void GpInputDriverXInput::Shutdown()
|
||||
{
|
||||
IGpAllocator *alloc = m_properties.m_alloc;
|
||||
this->~GpInputDriverXInput();
|
||||
free(this);
|
||||
alloc->Release(this);
|
||||
}
|
||||
|
||||
IGpPrefsHandler *GpInputDriverXInput::GetPrefsHandler() const
|
||||
@@ -83,7 +85,7 @@ IGpPrefsHandler *GpInputDriverXInput::GetPrefsHandler() const
|
||||
|
||||
GpInputDriverXInput *GpInputDriverXInput::Create(const GpInputDriverProperties &props)
|
||||
{
|
||||
void *storage = malloc(sizeof(GpInputDriverXInput));
|
||||
void *storage = props.m_alloc->Alloc(sizeof(GpInputDriverXInput));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
struct IGpLogDriver;
|
||||
struct IGpSystemServices;
|
||||
struct IGpAllocator;
|
||||
|
||||
struct GpGlobalConfig
|
||||
{
|
||||
@@ -22,6 +23,7 @@ struct GpGlobalConfig
|
||||
|
||||
IGpLogDriver *m_logger;
|
||||
IGpSystemServices *m_systemServices;
|
||||
IGpAllocator *m_allocator;
|
||||
void *m_osGlobals;
|
||||
};
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "GpInputDriverProperties.h"
|
||||
#include "GpGlobalConfig.h"
|
||||
#include "GpAppEnvironment.h"
|
||||
#include "IGpAllocator.h"
|
||||
#include "IGpAudioDriver.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpFontHandler.h"
|
||||
@@ -36,6 +37,7 @@ int GpMain::Run()
|
||||
{
|
||||
GpVOSEventQueue *eventQueue = new GpVOSEventQueue();
|
||||
GpAppEnvironment *appEnvironment = new GpAppEnvironment();
|
||||
IGpAllocator *alloc = g_gpGlobalConfig.m_allocator;
|
||||
|
||||
GpDisplayDriverProperties ddProps;
|
||||
memset(&ddProps, 0, sizeof(ddProps));
|
||||
@@ -60,6 +62,7 @@ int GpMain::Run()
|
||||
ddProps.m_eventQueue = eventQueue;
|
||||
ddProps.m_logger = g_gpGlobalConfig.m_logger;
|
||||
ddProps.m_systemServices = g_gpGlobalConfig.m_systemServices;
|
||||
ddProps.m_alloc = g_gpGlobalConfig.m_allocator;
|
||||
|
||||
GpAudioDriverProperties adProps;
|
||||
memset(&adProps, 0, sizeof(adProps));
|
||||
@@ -68,6 +71,7 @@ int GpMain::Run()
|
||||
memset(&fontProps, 0, sizeof(fontProps));
|
||||
|
||||
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
|
||||
// This appears to be the "standard" Mac sample rate, probably rounded from 244800/11.
|
||||
@@ -80,8 +84,9 @@ int GpMain::Run()
|
||||
#endif
|
||||
adProps.m_logger = g_gpGlobalConfig.m_logger;
|
||||
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;
|
||||
if (inputDrivers)
|
||||
@@ -93,6 +98,7 @@ int GpMain::Run()
|
||||
|
||||
inputProps.m_type = g_gpGlobalConfig.m_inputDriverTypes[i];
|
||||
inputProps.m_eventQueue = eventQueue;
|
||||
inputProps.m_alloc = g_gpGlobalConfig.m_allocator;
|
||||
|
||||
if (IGpInputDriver *driver = GpInputDriverFactory::CreateInputDriver(inputProps))
|
||||
inputDrivers[numCreatedInputDrivers++] = driver;
|
||||
@@ -123,7 +129,7 @@ int GpMain::Run()
|
||||
for (size_t i = 0; i < numCreatedInputDrivers; i++)
|
||||
inputDrivers[i]->Shutdown();
|
||||
|
||||
free(inputDrivers);
|
||||
alloc->Release(inputDrivers);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include "DeflateCodec.h"
|
||||
#include "MacFileInfo.h"
|
||||
#include "ZipFile.h"
|
||||
#include "GpAllocator_C.h"
|
||||
#include "PLDrivers.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
@@ -12,6 +14,9 @@
|
||||
|
||||
int toolMain(int argc, const char **argv)
|
||||
{
|
||||
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
|
||||
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: MergeGPF <file.gpf>");
|
||||
|
@@ -42,6 +42,7 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\Debug.props" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -50,6 +51,7 @@
|
||||
<Import Project="..\Common.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="..\GpCommon.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
@@ -84,6 +86,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
|
||||
<ClCompile Include="MergeGPF.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@@ -18,5 +18,8 @@
|
||||
<ClCompile Include="MergeGPF.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@@ -3,6 +3,7 @@
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpLogDriver.h"
|
||||
#include "IGpSystemServices.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "QDPixMap.h"
|
||||
#include "Rect2i.h"
|
||||
@@ -361,7 +362,7 @@ namespace PortabilityLayer
|
||||
void DialogTemplate::Destroy()
|
||||
{
|
||||
this->~DialogTemplate();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
ArrayView<const DialogTemplateItem> DialogTemplate::GetItems() const
|
||||
@@ -374,7 +375,7 @@ namespace PortabilityLayer
|
||||
PortabilityLayer::WindowManager::GetInstance()->DestroyWindow(m_window);
|
||||
|
||||
this->~DialogImpl();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
Window *DialogImpl::GetWindow() const
|
||||
@@ -646,7 +647,7 @@ namespace PortabilityLayer
|
||||
|
||||
const size_t itemsSize = sizeof(DialogItem) * numItems;
|
||||
|
||||
void *storage = malloc(alignedSize + itemsSize);
|
||||
void *storage = NewPtr(alignedSize + itemsSize);
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
@@ -882,7 +883,7 @@ namespace PortabilityLayer
|
||||
|
||||
const size_t dtlItemSize = sizeof(DialogTemplateItem) * numItems;
|
||||
|
||||
void *storage = malloc(dtlAlignedSize + dtlItemSize);
|
||||
void *storage = NewPtr(dtlAlignedSize + dtlItemSize);
|
||||
if (!storage)
|
||||
{
|
||||
dtemplateH.Dispose();
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "ResTypeID.h"
|
||||
#include "ZipFileProxy.h"
|
||||
|
||||
#include "PLCore.h"
|
||||
#include "PLDrivers.h"
|
||||
#include "PLPasStr.h"
|
||||
#include "PLErrorCodes.h"
|
||||
@@ -474,12 +475,12 @@ namespace PortabilityLayer
|
||||
void CompositeFileImpl::Close()
|
||||
{
|
||||
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)
|
||||
{
|
||||
void *storage = malloc(sizeof(CompositeFileImpl));
|
||||
void *storage = NewPtr(sizeof(CompositeFileImpl));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include "FileSectionStream.h"
|
||||
#include "PLCore.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -151,7 +152,7 @@ namespace PortabilityLayer
|
||||
void FileSectionStreamImpl::GP_ASYNCIFY_PARANOID_NAMED(Close)()
|
||||
{
|
||||
this->~FileSectionStreamImpl();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
void FileSectionStreamImpl::Flush()
|
||||
@@ -161,7 +162,7 @@ namespace PortabilityLayer
|
||||
|
||||
GpIOStream *FileSectionStream::Create(GpIOStream *stream, GpUFilePos_t start, GpUFilePos_t size)
|
||||
{
|
||||
void *storage = malloc(sizeof(FileSectionStreamImpl));
|
||||
void *storage = NewPtr(sizeof(FileSectionStreamImpl));
|
||||
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "MemReaderStream.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "PLCore.h"
|
||||
#include "PLDrivers.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -158,7 +159,7 @@ namespace PortabilityLayer
|
||||
|
||||
FontFamily *FontFamily::Create(FontFamilyID_t familyID)
|
||||
{
|
||||
void *storage = malloc(sizeof(FontFamily));
|
||||
void *storage = NewPtr(sizeof(FontFamily));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
@@ -168,7 +169,7 @@ namespace PortabilityLayer
|
||||
void FontFamily::Destroy()
|
||||
{
|
||||
this->~FontFamily();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
FontFamily::FontFamily(FontFamilyID_t familyID)
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "GpRenderedGlyphMetrics.h"
|
||||
|
||||
#include "PLBigEndian.h"
|
||||
#include "PLCore.h"
|
||||
#include "PLDrivers.h"
|
||||
#include "PLPasStr.h"
|
||||
#include "DeflateCodec.h"
|
||||
@@ -166,7 +167,7 @@ namespace PortabilityLayer
|
||||
void RenderedFontImpl::Destroy()
|
||||
{
|
||||
this->~RenderedFontImpl();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
void *storage = malloc(allocSize);
|
||||
void *storage = NewPtr(allocSize);
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "InflateStream.h"
|
||||
#include "DeflateCodec.h"
|
||||
#include "PLCore.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -225,7 +226,7 @@ namespace PortabilityLayer
|
||||
void InflateStreamImpl::GP_ASYNCIFY_PARANOID_NAMED(Close)()
|
||||
{
|
||||
this->~InflateStreamImpl();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
void InflateStreamImpl::Flush()
|
||||
@@ -238,7 +239,7 @@ namespace PortabilityLayer
|
||||
if (!inflateContext)
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(sizeof(InflateStreamImpl));
|
||||
void *storage = NewPtr(sizeof(InflateStreamImpl));
|
||||
if (!storage)
|
||||
{
|
||||
inflateContext->Destroy();
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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
|
@@ -1,8 +1,9 @@
|
||||
#include "MemoryManager.h"
|
||||
#include "MMBlock.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "IGpAllocator.h"
|
||||
#include "PLDrivers.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
@@ -28,7 +29,6 @@ namespace PortabilityLayer
|
||||
static MemoryManagerImpl *GetInstance();
|
||||
|
||||
private:
|
||||
|
||||
static MemoryManagerImpl ms_instance;
|
||||
};
|
||||
|
||||
@@ -42,75 +42,17 @@ namespace PortabilityLayer
|
||||
|
||||
void *MemoryManagerImpl::Realloc(void *buf, size_t newSize)
|
||||
{
|
||||
assert(buf != nullptr);
|
||||
|
||||
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();
|
||||
return PLDrivers::GetAlloc()->Realloc(buf, newSize);
|
||||
}
|
||||
|
||||
void *MemoryManagerImpl::Alloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
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();
|
||||
return PLDrivers::GetAlloc()->Realloc(nullptr, size);
|
||||
}
|
||||
|
||||
void MemoryManagerImpl::Release(void *buf)
|
||||
{
|
||||
if (!buf)
|
||||
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);
|
||||
PLDrivers::GetAlloc()->Realloc(buf, 0);
|
||||
}
|
||||
|
||||
MMHandleBlock *MemoryManagerImpl::AllocHandle(size_t size)
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#ifndef __PL_MEMORY_MANAGER_H__
|
||||
#define __PL_MEMORY_MANAGER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct IGpAllocator;
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
struct MMHandleBlock;
|
||||
@@ -50,5 +50,3 @@ namespace PortabilityLayer
|
||||
return objectHdl;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -288,7 +288,7 @@ namespace PortabilityLayer
|
||||
if (m_iconGraphic)
|
||||
{
|
||||
m_iconGraphic->~SimpleGraphic();
|
||||
free(m_iconGraphic);
|
||||
DisposePtr(m_iconGraphic);
|
||||
}
|
||||
|
||||
// GP TODO: Dispose of menus properly
|
||||
@@ -834,7 +834,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
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)
|
||||
{
|
||||
memcpy(m_iconMask, static_cast<const uint8_t*>(*icsHandle) + 32, 32);
|
||||
|
@@ -50,4 +50,10 @@ IGpVOSEventQueue *PLDrivers::GetVOSEventQueue()
|
||||
return ms_drivers.GetDriver<GpDriverIDs::kEventQueue>();
|
||||
}
|
||||
|
||||
IGpAllocator *PLDrivers::GetAlloc()
|
||||
{
|
||||
return ms_drivers.GetDriver<GpDriverIDs::kAlloc>();
|
||||
}
|
||||
|
||||
|
||||
GpDriverCollection PLDrivers::ms_drivers;
|
||||
|
@@ -16,6 +16,7 @@ public:
|
||||
static IGpSystemServices *GetSystemServices();
|
||||
static IGpFontHandler *GetFontHandler();
|
||||
static IGpVOSEventQueue *GetVOSEventQueue();
|
||||
static IGpAllocator *GetAlloc();
|
||||
|
||||
private:
|
||||
static GpDriverCollection ms_drivers;
|
||||
|
@@ -124,7 +124,6 @@
|
||||
<ClInclude Include="MacRsrcMap.h" />
|
||||
<ClInclude Include="MemoryManager.h" />
|
||||
<ClInclude Include="MemReaderStream.h" />
|
||||
<ClInclude Include="MMBlock.h" />
|
||||
<ClInclude Include="MMHandleBlock.h" />
|
||||
<ClInclude Include="PascalStr.h" />
|
||||
<ClInclude Include="PascalStrLiteral.h" />
|
||||
@@ -250,7 +249,6 @@
|
||||
<ClCompile Include="MemoryManager.cpp" />
|
||||
<ClCompile Include="MemReaderStream.cpp" />
|
||||
<ClCompile Include="MenuManager.cpp" />
|
||||
<ClCompile Include="MMBlock.cpp" />
|
||||
<ClCompile Include="MMHandleBlock.cpp" />
|
||||
<ClCompile Include="PLApplication.cpp" />
|
||||
<ClCompile Include="PLButtonWidget.cpp" />
|
||||
|
@@ -132,9 +132,6 @@
|
||||
<ClInclude Include="MMHandleBlock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MMBlock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DisplayDeviceManager.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@@ -494,9 +491,6 @@
|
||||
<ClCompile Include="MemoryManager.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MMBlock.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MMHandleBlock.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#include "MemoryManager.cpp"
|
||||
#include "MemReaderStream.cpp"
|
||||
#include "MenuManager.cpp"
|
||||
#include "MMBlock.cpp"
|
||||
#include "MMHandleBlock.cpp"
|
||||
#include "PLApplication.cpp"
|
||||
#include "PLButtonWidget.cpp"
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include "ScanlineMaskBuilder.h"
|
||||
#include "ScanlineMaskIterator.h"
|
||||
|
||||
#include "PLCore.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
|
||||
@@ -11,7 +13,7 @@ namespace PortabilityLayer
|
||||
void ScanlineMask::Destroy()
|
||||
{
|
||||
this->~ScanlineMask();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
const Rect &ScanlineMask::GetRect() const
|
||||
@@ -50,7 +52,7 @@ namespace PortabilityLayer
|
||||
else
|
||||
return nullptr;
|
||||
|
||||
void *storage = malloc(alignedPrefixSize + storageSize);
|
||||
void *storage = NewPtr(alignedPrefixSize + storageSize);
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "LinePlotter.h"
|
||||
#include "ScanlineMaskBuilder.h"
|
||||
#include "IPlotter.h"
|
||||
#include "PLCore.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
@@ -135,7 +136,7 @@ namespace PortabilityLayer
|
||||
#else
|
||||
const size_t storageSize = (numElements * 2 + 7) / 8;
|
||||
#endif
|
||||
void *storage = malloc(storageSize);
|
||||
void *storage = NewPtr(storageSize);
|
||||
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
@@ -250,7 +251,7 @@ namespace PortabilityLayer
|
||||
stbi_write_png(path, width, height, 4, flagBits, width * 4);
|
||||
#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);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "IGpThreadEvent.h"
|
||||
#include "IGpSystemServices.h"
|
||||
|
||||
#include "PLCore.h"
|
||||
#include "PLDrivers.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -39,7 +40,7 @@ namespace PortabilityLayer
|
||||
void PortabilityLayer::WorkerThreadImpl::Destroy()
|
||||
{
|
||||
this->~WorkerThreadImpl();
|
||||
free(this);
|
||||
DisposePtr(this);
|
||||
}
|
||||
|
||||
void PortabilityLayer::WorkerThreadImpl::AsyncExecuteTask(PortabilityLayer::WorkerThread::Callback_t callback, void *context)
|
||||
@@ -139,7 +140,7 @@ PortabilityLayer::WorkerThread::~WorkerThread()
|
||||
|
||||
PortabilityLayer::WorkerThread *PortabilityLayer::WorkerThread::Create()
|
||||
{
|
||||
void *storage = malloc(sizeof(PortabilityLayer::WorkerThreadImpl));
|
||||
void *storage = NewPtr(sizeof(PortabilityLayer::WorkerThreadImpl));
|
||||
if (!storage)
|
||||
return nullptr;
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "CFileStream.h"
|
||||
#include "CombinedTimestamp.h"
|
||||
#include "GPArchive.h"
|
||||
#include "GpAllocator_C.h"
|
||||
#include "MacRomanConversion.h"
|
||||
#include "MemReaderStream.h"
|
||||
#include "QDPictDecoder.h"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "ZipFile.h"
|
||||
#include "WaveFormat.h"
|
||||
#include "GpUnicode.h"
|
||||
#include "PLDrivers.h"
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
@@ -1431,6 +1433,9 @@ int ConvertSingleFile(const char *resPath, const PortabilityLayer::CombinedTimes
|
||||
|
||||
PortabilityLayer::CFileStream cfs(inF);
|
||||
|
||||
GpDriverCollection *drivers = PLDrivers::GetDriverCollection();
|
||||
drivers->SetDriver<GpDriverIDs::kAlloc>(GpAllocator_C::GetInstance());
|
||||
|
||||
PortabilityLayer::ResourceFile *resFile = PortabilityLayer::ResourceFile::Create();
|
||||
resFile->Load(&cfs);
|
||||
cfs.Close();
|
||||
|
@@ -45,6 +45,7 @@
|
||||
<Import Project="..\RapidJSON.props" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\Debug.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
@@ -56,6 +57,7 @@
|
||||
<Import Project="..\RapidJSON.props" />
|
||||
<Import Project="..\WindowsUnicodeToolShim.props" />
|
||||
<Import Project="..\Release.props" />
|
||||
<Import Project="..\AerofoilPortable.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
@@ -95,6 +97,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp" />
|
||||
<ClCompile Include="gpr2gpa.cpp" />
|
||||
<ClCompile Include="macedec.cpp" />
|
||||
</ItemGroup>
|
||||
|
@@ -21,6 +21,9 @@
|
||||
<ClCompile Include="macedec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\AerofoilPortable\GpAllocator_C.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="macedec.h">
|
||||
|
Reference in New Issue
Block a user