mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 12:09:36 +00:00
More work. Audio driver works enough to play music now.
This commit is contained in:
112
PortabilityLayer/QDManager.cpp
Normal file
112
PortabilityLayer/QDManager.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#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)
|
||||
{
|
||||
PixelFormat pixelFormat;
|
||||
|
||||
switch (depth)
|
||||
{
|
||||
case 8:
|
||||
pixelFormat = (colorTable == nullptr) ? PixelFormat_8BitStandard : PixelFormat_8BitCustom;
|
||||
break;
|
||||
case 16:
|
||||
pixelFormat = PixelFormat_RGB555;
|
||||
break;
|
||||
case 32:
|
||||
pixelFormat = PixelFormat_RGB32;
|
||||
break;
|
||||
default:
|
||||
return genericErr;
|
||||
}
|
||||
|
||||
if (depth != 8)
|
||||
return genericErr;
|
||||
|
||||
void *grafStorage = MemoryManager::GetInstance()->Alloc(sizeof(CGrafImpl));
|
||||
if (!grafStorage)
|
||||
return mFulErr;
|
||||
|
||||
if (!bounds.IsValid())
|
||||
return genericErr;
|
||||
|
||||
CGrafImpl *graf = new (grafStorage) CGrafImpl();
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user