mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
113 lines
2.1 KiB
C++
113 lines
2.1 KiB
C++
#include "QDManager.h"
|
|
|
|
#include "MemoryManager.h"
|
|
#include "PLCore.h"
|
|
#include "PLQDOffscreen.h"
|
|
#include "QDGraf.h"
|
|
#include "QDState.h"
|
|
|
|
namespace PortabilityLayer
|
|
{
|
|
class QDManagerImpl final : public QDManager
|
|
{
|
|
public:
|
|
QDManagerImpl();
|
|
|
|
void Init() override;
|
|
void GetPort(QDPort **port, GDevice ***gdHandle) override;
|
|
void SetPort(QDPort *gw, GDevice **gdHandle) override;
|
|
int NewGWorld(CGraf **gw, int depth, const Rect &bounds, ColorTable **colorTable, GDevice **device, int flags) override;
|
|
QDState *GetState() override;
|
|
|
|
static QDManagerImpl *GetInstance();
|
|
|
|
private:
|
|
QDPort *m_port;
|
|
GDHandle m_gdHandle;
|
|
|
|
static QDManagerImpl ms_instance;
|
|
};
|
|
|
|
QDManagerImpl::QDManagerImpl()
|
|
: m_port(nullptr)
|
|
, m_gdHandle(nullptr)
|
|
{
|
|
}
|
|
|
|
void QDManagerImpl::Init()
|
|
{
|
|
}
|
|
|
|
void QDManagerImpl::GetPort(QDPort **port, GDevice ***gdHandle)
|
|
{
|
|
if (port)
|
|
*port = m_port;
|
|
if (gdHandle)
|
|
*gdHandle = m_gdHandle;
|
|
}
|
|
|
|
void QDManagerImpl::SetPort(QDPort *gw, GDevice **gdHandle)
|
|
{
|
|
m_port = gw;
|
|
m_gdHandle = gdHandle;
|
|
}
|
|
|
|
int QDManagerImpl::NewGWorld(CGraf **gw, int depth, const Rect &bounds, ColorTable **colorTable, GDevice **device, int flags)
|
|
{
|
|
GpPixelFormat_t pixelFormat;
|
|
|
|
switch (depth)
|
|
{
|
|
case 8:
|
|
pixelFormat = (colorTable == nullptr) ? GpPixelFormats::k8BitStandard : GpPixelFormats::k8BitCustom;
|
|
break;
|
|
case 16:
|
|
pixelFormat = GpPixelFormats::kRGB555;
|
|
break;
|
|
case 32:
|
|
pixelFormat = GpPixelFormats::kRGB32;
|
|
break;
|
|
default:
|
|
return genericErr;
|
|
}
|
|
|
|
if (depth != 8)
|
|
return genericErr;
|
|
|
|
void *grafStorage = MemoryManager::GetInstance()->Alloc(sizeof(CGraf));
|
|
if (!grafStorage)
|
|
return mFulErr;
|
|
|
|
if (!bounds.IsValid())
|
|
return genericErr;
|
|
|
|
CGraf *graf = new (grafStorage) CGraf();
|
|
int initError = graf->Init(bounds, pixelFormat);
|
|
if (initError)
|
|
{
|
|
DisposeGWorld(graf);
|
|
return initError;
|
|
}
|
|
|
|
*gw = graf;
|
|
return noErr;
|
|
}
|
|
|
|
QDState *QDManagerImpl::GetState()
|
|
{
|
|
return m_port->GetState();
|
|
}
|
|
|
|
QDManagerImpl *QDManagerImpl::GetInstance()
|
|
{
|
|
return &ms_instance;
|
|
}
|
|
|
|
QDManagerImpl QDManagerImpl::ms_instance;
|
|
|
|
QDManager *QDManager::GetInstance()
|
|
{
|
|
return QDManagerImpl::GetInstance();
|
|
}
|
|
}
|