mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
94 lines
1.8 KiB
C++
94 lines
1.8 KiB
C++
#include "QDManager.h"
|
|
|
|
#include "MemoryManager.h"
|
|
#include "PLCore.h"
|
|
#include "PLQDOffscreen.h"
|
|
#include "QDGraf.h"
|
|
|
|
#include <assert.h>
|
|
|
|
namespace PortabilityLayer
|
|
{
|
|
class QDManagerImpl final : public QDManager
|
|
{
|
|
public:
|
|
QDManagerImpl();
|
|
|
|
void Init() override;
|
|
DrawSurface *GetPort() const override;
|
|
void SetPort(DrawSurface *gw) override;
|
|
PLError_t NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable) override;
|
|
void DisposeGWorld(DrawSurface *gw) override;
|
|
|
|
static QDManagerImpl *GetInstance();
|
|
|
|
private:
|
|
DrawSurface *m_port;
|
|
|
|
static QDManagerImpl ms_instance;
|
|
};
|
|
|
|
QDManagerImpl::QDManagerImpl()
|
|
: m_port(nullptr)
|
|
{
|
|
}
|
|
|
|
void QDManagerImpl::Init()
|
|
{
|
|
}
|
|
|
|
DrawSurface *QDManagerImpl::GetPort() const
|
|
{
|
|
return m_port;
|
|
}
|
|
|
|
void QDManagerImpl::SetPort(DrawSurface *gw)
|
|
{
|
|
#if GP_DEBUG_CONFIG
|
|
if (gw)
|
|
gw->m_port.CheckPortSentinel();
|
|
#endif
|
|
|
|
m_port = gw;
|
|
}
|
|
|
|
PLError_t QDManagerImpl::NewGWorld(DrawSurface **gw, GpPixelFormat_t pixelFormat, const Rect &bounds, ColorTable **colorTable)
|
|
{
|
|
void *grafStorage = MemoryManager::GetInstance()->Alloc(sizeof(DrawSurface));
|
|
if (!grafStorage)
|
|
return PLErrors::kOutOfMemory;
|
|
|
|
if (!bounds.IsValid())
|
|
return PLErrors::kInvalidParameter;
|
|
|
|
DrawSurface *graf = new (grafStorage) DrawSurface();
|
|
PLError_t initError = graf->Init(bounds, pixelFormat);
|
|
if (initError)
|
|
{
|
|
DisposeGWorld(graf);
|
|
return initError;
|
|
}
|
|
|
|
*gw = graf;
|
|
return PLErrors::kNone;
|
|
}
|
|
|
|
void QDManagerImpl::DisposeGWorld(DrawSurface *gw)
|
|
{
|
|
gw->~DrawSurface();
|
|
MemoryManager::GetInstance()->Release(gw);
|
|
}
|
|
|
|
QDManagerImpl *QDManagerImpl::GetInstance()
|
|
{
|
|
return &ms_instance;
|
|
}
|
|
|
|
QDManagerImpl QDManagerImpl::ms_instance;
|
|
|
|
QDManager *QDManager::GetInstance()
|
|
{
|
|
return QDManagerImpl::GetInstance();
|
|
}
|
|
}
|