mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-14 20:19:38 +00:00
Refactoring. Add line drawing.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "DisplayDeviceManager.h"
|
||||
|
||||
#include "HostDisplayDriver.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "PLQDraw.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "QDStandardPalette.h"
|
||||
@@ -15,8 +16,8 @@ namespace PortabilityLayer
|
||||
void Init() override;
|
||||
void Shutdown() override;
|
||||
|
||||
GDevice **GetMainDevice() override;
|
||||
|
||||
GpPixelFormat_t GetPixelFormat() const override;
|
||||
void SyncPalette(IGpDisplayDriver *displayDriver) override;
|
||||
|
||||
void IncrementTickCount(uint32_t count) override;
|
||||
uint32_t GetTickCount() override;
|
||||
@@ -24,50 +25,62 @@ namespace PortabilityLayer
|
||||
static DisplayDeviceManagerImpl *GetInstance();
|
||||
|
||||
private:
|
||||
GDHandle m_mainDevice;
|
||||
uint32_t m_tickCount;
|
||||
GpPixelFormat_t m_pixelFormat;
|
||||
bool m_paletteIsDirty;
|
||||
|
||||
PortabilityLayer::RGBAColor *m_palette;
|
||||
uint8_t m_paletteStorage[256 * sizeof(PortabilityLayer::RGBAColor) + PL_SYSTEM_MEMORY_ALIGNMENT];
|
||||
|
||||
static DisplayDeviceManagerImpl ms_instance;
|
||||
};
|
||||
|
||||
DisplayDeviceManagerImpl::DisplayDeviceManagerImpl()
|
||||
: m_mainDevice(nullptr)
|
||||
, m_tickCount(1)
|
||||
: m_tickCount(1)
|
||||
, m_paletteIsDirty(true)
|
||||
, m_pixelFormat(GpPixelFormats::k8BitStandard)
|
||||
{
|
||||
uint8_t *paletteStorage = m_paletteStorage;
|
||||
while (reinterpret_cast<intptr_t>(paletteStorage) % PL_SYSTEM_MEMORY_ALIGNMENT != 0)
|
||||
paletteStorage++;
|
||||
|
||||
m_palette = reinterpret_cast<PortabilityLayer::RGBAColor*>(paletteStorage);
|
||||
|
||||
for (size_t i = 0; i < 256; i++)
|
||||
{
|
||||
PortabilityLayer::RGBAColor &color = m_palette[i];
|
||||
color.r = color.g = color.b = i;
|
||||
color.a = 255;
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayDeviceManagerImpl::Init()
|
||||
{
|
||||
m_mainDevice = MemoryManager::GetInstance()->NewHandle<GDevice>();
|
||||
if (m_mainDevice)
|
||||
{
|
||||
GDevice *device = *m_mainDevice;
|
||||
HostDisplayDriver::GetInstance()->GetDisplayResolution(nullptr, nullptr, &m_pixelFormat);
|
||||
|
||||
HostDisplayDriver::GetInstance()->GetDisplayResolution(nullptr, nullptr, &device->pixelFormat);
|
||||
const PortabilityLayer::RGBAColor *spColors = StandardPalette::GetInstance()->GetColors();
|
||||
for (size_t i = 0; i < 256; i++)
|
||||
m_palette[i] = spColors[i];
|
||||
|
||||
uint8_t *paletteStorage = device->paletteStorage;
|
||||
while (reinterpret_cast<intptr_t>(paletteStorage) % PL_SYSTEM_MEMORY_ALIGNMENT != 0)
|
||||
paletteStorage++;
|
||||
|
||||
PortabilityLayer::RGBAColor *paletteData = reinterpret_cast<PortabilityLayer::RGBAColor*>(paletteStorage);
|
||||
device->paletteDataOffset = static_cast<uint8_t>(paletteStorage - device->paletteStorage);
|
||||
|
||||
const PortabilityLayer::RGBAColor *spColors = StandardPalette::GetInstance()->GetColors();
|
||||
for (size_t i = 0; i < 256; i++)
|
||||
paletteData[i] = spColors[i];
|
||||
|
||||
device->paletteIsDirty = true;
|
||||
}
|
||||
m_paletteIsDirty = true;
|
||||
}
|
||||
|
||||
void DisplayDeviceManagerImpl::Shutdown()
|
||||
{
|
||||
MemoryManager::GetInstance()->ReleaseHandle(reinterpret_cast<MMHandleBlock*>(m_mainDevice));
|
||||
}
|
||||
|
||||
GDevice **DisplayDeviceManagerImpl::GetMainDevice()
|
||||
GpPixelFormat_t DisplayDeviceManagerImpl::GetPixelFormat() const
|
||||
{
|
||||
return m_mainDevice;
|
||||
return m_pixelFormat;
|
||||
}
|
||||
|
||||
void DisplayDeviceManagerImpl::SyncPalette(IGpDisplayDriver *displayDriver)
|
||||
{
|
||||
if (m_paletteIsDirty)
|
||||
{
|
||||
displayDriver->UpdatePalette(m_palette);
|
||||
m_paletteIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayDeviceManagerImpl::IncrementTickCount(uint32_t count)
|
||||
|
||||
Reference in New Issue
Block a user