mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 20:19:38 +00:00
Add some initial widget functionality (prefs partly working)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
#include "MemoryManager.h"
|
||||
#include "MMBlock.h"
|
||||
#include "MMHandleBlock.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceCompiledRef.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <new>
|
||||
#include <assert.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace PortabilityLayer
|
||||
@@ -16,10 +16,10 @@ namespace PortabilityLayer
|
||||
public:
|
||||
void Init() override;
|
||||
void Shutdown() override;
|
||||
|
||||
void *Alloc(size_t size) override;
|
||||
|
||||
void *Alloc(size_t size) override;
|
||||
void *Realloc(void *buf, size_t newSize) override;
|
||||
void Release(void *buf) override;
|
||||
void Release(void *buf) override;
|
||||
|
||||
MMHandleBlock *AllocHandle(size_t size) override;
|
||||
bool ResizeHandle(MMHandleBlock *hdl, size_t newSize) override;
|
||||
@@ -38,40 +38,40 @@ namespace PortabilityLayer
|
||||
|
||||
void MemoryManagerImpl::Shutdown()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void *MemoryManagerImpl::Realloc(void *buf, size_t newSize)
|
||||
{
|
||||
assert(buf != nullptr);
|
||||
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 MMBlock *oldBufMMBlock = reinterpret_cast<const MMBlock*>(oldBufBytes - MMBlock::AlignedSize());
|
||||
|
||||
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + PL_SYSTEM_MEMORY_ALIGNMENT - 1;
|
||||
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;
|
||||
return nullptr;
|
||||
|
||||
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(newBuffer) & static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT - 1);
|
||||
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>(PL_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);
|
||||
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);
|
||||
|
||||
MMBlock *newMMBlock = reinterpret_cast<MMBlock*>(newBuffer + alignPadding);
|
||||
newMMBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
|
||||
|
||||
return newBuffer + alignPadding + MMBlock::AlignedSize();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace PortabilityLayer
|
||||
if (size == 0)
|
||||
return nullptr;
|
||||
|
||||
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + PL_SYSTEM_MEMORY_ALIGNMENT - 1;
|
||||
const size_t mmBlockSizeWithMaxPadding = MMBlock::AlignedSize() + GP_SYSTEM_MEMORY_ALIGNMENT - 1;
|
||||
if (SIZE_MAX - size < mmBlockSizeWithMaxPadding)
|
||||
return nullptr;
|
||||
|
||||
@@ -88,13 +88,13 @@ namespace PortabilityLayer
|
||||
if (!buffer)
|
||||
return nullptr;
|
||||
|
||||
const intptr_t offsetFromAlignPoint = reinterpret_cast<intptr_t>(buffer) & static_cast<intptr_t>(PL_SYSTEM_MEMORY_ALIGNMENT - 1);
|
||||
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>(PL_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
|
||||
alignPadding = static_cast<intptr_t>(GP_SYSTEM_MEMORY_ALIGNMENT) - offsetFromAlignPoint;
|
||||
|
||||
MMBlock *mmBlock = reinterpret_cast<MMBlock*>(buffer + alignPadding);
|
||||
mmBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<PL_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
|
||||
mmBlock->m_offsetFromAllocLocation = static_cast<SmallestUInt<GP_SYSTEM_MEMORY_ALIGNMENT>::ValueType_t>(alignPadding);
|
||||
|
||||
return buffer + alignPadding + MMBlock::AlignedSize();
|
||||
}
|
||||
@@ -118,23 +118,23 @@ namespace PortabilityLayer
|
||||
MMHandleBlock *handleBlock = static_cast<MMHandleBlock*>(Alloc(sizeof(MMHandleBlock)));
|
||||
|
||||
return new (handleBlock) MMHandleBlock(contents, size);
|
||||
}
|
||||
}
|
||||
|
||||
bool MemoryManagerImpl::ResizeHandle(MMHandleBlock *hdl, size_t newSize)
|
||||
{
|
||||
if (hdl->m_contents == nullptr)
|
||||
return false;
|
||||
|
||||
if (newSize != hdl->m_size)
|
||||
bool MemoryManagerImpl::ResizeHandle(MMHandleBlock *hdl, size_t newSize)
|
||||
{
|
||||
if (hdl->m_contents == nullptr)
|
||||
return false;
|
||||
|
||||
if (newSize != hdl->m_size)
|
||||
{
|
||||
void *newBuf = Realloc(hdl->m_contents, newSize);
|
||||
if (!newBuf)
|
||||
return false;
|
||||
|
||||
hdl->m_contents = newBuf;
|
||||
hdl->m_size = newSize;
|
||||
}
|
||||
|
||||
void *newBuf = Realloc(hdl->m_contents, newSize);
|
||||
if (!newBuf)
|
||||
return false;
|
||||
|
||||
hdl->m_contents = newBuf;
|
||||
hdl->m_size = newSize;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -142,8 +142,8 @@ namespace PortabilityLayer
|
||||
{
|
||||
if (!hdl)
|
||||
return;
|
||||
|
||||
if (hdl->m_rmSelfRef)
|
||||
|
||||
if (hdl->m_rmSelfRef)
|
||||
PortabilityLayer::ResourceManager::GetInstance()->DissociateHandle(hdl);
|
||||
|
||||
if (hdl->m_contents)
|
||||
|
||||
Reference in New Issue
Block a user