Move DirectDraw entry functions to backends (#178)

This commit is contained in:
Anonymous Maarten 2025-05-26 03:33:39 +02:00 committed by GitHub
parent 3df6be1122
commit e1cddc5c0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 109 additions and 81 deletions

View File

@ -1,6 +1,8 @@
#include "miniwin_config.h"
#include "miniwin_d3drm.h"
#include "miniwin_d3drm_sdl3gpu.h"
#include "miniwin_ddraw_sdl3gpu.h"
#include "miniwin_p.h"
#define RGBA_MAKE(r, g, b, a) ((D3DCOLOR) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
@ -17,9 +19,9 @@ void Miniwin_ConfigureBackend(MiniwinBackendType type)
MiniwinBackendType Miniwin_StringToBackendType(const char* str)
{
if (SDL_strcasecmp(str, "sdl3gpu") == 0) {
return MiniwinBackendType ::eSDL3GPU;
return MiniwinBackendType::eSDL3GPU;
}
return MiniwinBackendType ::eInvalid;
return MiniwinBackendType::eInvalid;
}
std::string Miniwin_BackendTypeToString(MiniwinBackendType type)
@ -48,3 +50,27 @@ D3DCOLOR D3DRMCreateColorRGBA(D3DVALUE red, D3DVALUE green, D3DVALUE blue, D3DVA
{
return RGBA_MAKE((int) (255.f * red), (int) (255.f * green), (int) (255.f * blue), (int) (255.f * alpha));
}
HRESULT DirectDrawCreate(LPGUID lpGuid, LPDIRECTDRAW* lplpDD, IUnknown* pUnkOuter)
{
if (lpGuid) {
MINIWIN_NOT_IMPLEMENTED();
}
switch (g_backendType) {
case MiniwinBackendType::eSDL3GPU:
return DirectDrawCreate_SDL3GPU(lpGuid, lplpDD, pUnkOuter);
default:
*lplpDD = nullptr;
return DDERR_GENERIC;
}
}
HRESULT DirectDrawEnumerate(LPDDENUMCALLBACKA cb, void* context)
{
switch (g_backendType) {
case MiniwinBackendType::eSDL3GPU:
return DirectDrawEnumerate_SDL3GPU(cb, context);
default:
return DDERR_GENERIC;
}
}

View File

@ -1,5 +1,6 @@
#include "miniwin.h"
#include "miniwin_ddraw.h"
#include "miniwin_p.h"
#include <SDL3/SDL.h>
@ -27,6 +28,11 @@ HRESULT IUnknown::QueryInterface(const GUID& riid, void** ppvObject)
return E_NOINTERFACE;
}
HRESULT IDirectDrawClipper::SetHWnd(DWORD unnamedParam1, HWND hWnd)
{
return DD_OK;
}
BOOL SetWindowPos(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
{
if (!hWnd) {
@ -257,3 +263,34 @@ intptr_t _spawnl(
MINIWIN_NOT_IMPLEMENTED();
return 0;
}
UINT WINAPI GetSystemPaletteEntries(HDC hdc, UINT iStart, UINT cEntries, LPPALETTEENTRY pPalEntries)
{
MINIWIN_NOT_IMPLEMENTED();
for (UINT i = 0; i < cEntries; i++) {
UINT val = iStart + i;
pPalEntries[i].peRed = val;
pPalEntries[i].peGreen = val;
pPalEntries[i].peBlue = val;
pPalEntries[i].peFlags = PC_NONE;
}
return cEntries;
}
HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette)
{
MINIWIN_NOT_IMPLEMENTED();
return nullptr;
}
int SelectPalette(HDC hdc, HPALETTE hpal, BOOL bForceBackground)
{
MINIWIN_NOT_IMPLEMENTED();
return 0;
}
int RealizePalette(HDC hdc)
{
MINIWIN_NOT_IMPLEMENTED();
return 0;
}

View File

@ -103,9 +103,6 @@
DEFINE_GUID(IID_IDirectDraw2, 0xB3A6F3E0, 0x2B43, 0x11CF, 0xA2, 0xDE, 0x00, 0xAA, 0x00, 0xB9, 0x33, 0x56);
DEFINE_GUID(IID_IDirectDrawSurface3, 0xDA044E00, 0x69B2, 0x11D0, 0xA1, 0xD5, 0x00, 0xAA, 0x00, 0xB8, 0xDF, 0xBB);
extern SDL_Window* DDWindow;
extern SDL_Surface* DDBackBuffer;
// --- Enums ---
#define DDCKEY_SRCBLT DDColorKeyFlags::SRCBLT
enum class DDColorKeyFlags : uint32_t {

View File

@ -6,6 +6,9 @@
#include <algorithm>
#include <vector>
extern SDL_Window* DDWindow_SDL3GPU;
extern SDL_Surface* DDBackBuffer_SDL3GPU;
struct Direct3DRM_SDL3GPUImpl : virtual public IDirect3DRM2 {
// IUnknown interface
HRESULT QueryInterface(const GUID& riid, void** ppvObject) override;

View File

@ -33,3 +33,7 @@ struct DirectDraw_SDL3GPUImpl : public IDirectDraw2, public IDirect3D2 {
HRESULT CreateDevice(const GUID& guid, void* pBackBuffer, IDirect3DDevice2** ppDirect3DDevice) override;
HRESULT EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx) override;
};
HRESULT DirectDrawEnumerate_SDL3GPU(LPDDENUMCALLBACKA cb, void* context);
HRESULT DirectDrawCreate_SDL3GPU(LPGUID lpGuid, LPDIRECTDRAW* lplpDD, IUnknown* pUnkOuter);

View File

@ -169,10 +169,10 @@ HRESULT Direct3DRM_SDL3GPUImpl::CreateDevice(IDirect3DRMDevice2** outDevice, DWO
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_CreateGPUDevice failed (%s)", SDL_GetError());
return DDERR_GENERIC;
}
if (DDWindow == NULL) {
if (DDWindow_SDL3GPU == NULL) {
return DDERR_GENERIC;
}
if (!SDL_ClaimWindowForGPUDevice(device, DDWindow)) {
if (!SDL_ClaimWindowForGPUDevice(device, DDWindow_SDL3GPU)) {
SDL_LogError(LOG_CATEGORY_MINIWIN, "SDL_ClaimWindowForGPUDevice failed (%s)", SDL_GetError());
return DDERR_GENERIC;
}

View File

@ -22,7 +22,7 @@ Direct3DRMDevice2_SDL3GPUImpl::~Direct3DRMDevice2_SDL3GPUImpl()
}
m_viewports->Release();
SDL_ReleaseWindowFromGPUDevice(m_device, DDWindow);
SDL_ReleaseWindowFromGPUDevice(m_device, DDWindow_SDL3GPU);
SDL_DestroyGPUDevice(m_device);
}

View File

@ -298,8 +298,8 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::Render(IDirect3DRMFrame* group)
SDL_GPUCopyPass* copyPass = SDL_BeginGPUCopyPass(cmdbuf);
SDL_GPUTextureRegion region = {};
region.texture = m_transferTexture;
region.w = DDBackBuffer->w;
region.h = DDBackBuffer->h;
region.w = DDBackBuffer_SDL3GPU->w;
region.h = DDBackBuffer_SDL3GPU->h;
region.d = 1;
SDL_GPUTextureTransferInfo transferInfo = {};
transferInfo.transfer_buffer = m_downloadTransferBuffer;
@ -318,11 +318,11 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::Render(IDirect3DRMFrame* group)
SDL_DestroySurface(m_renderedImage);
m_renderedImage = SDL_CreateSurfaceFrom(
DDBackBuffer->w,
DDBackBuffer->h,
DDBackBuffer_SDL3GPU->w,
DDBackBuffer_SDL3GPU->h,
SDL_PIXELFORMAT_ABGR8888,
downloadedData,
DDBackBuffer->w * 4
DDBackBuffer_SDL3GPU->w * 4
);
SDL_Surface* convertedRender = SDL_ConvertSurface(m_renderedImage, SDL_PIXELFORMAT_RGBA8888);
@ -330,7 +330,7 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::Render(IDirect3DRMFrame* group)
SDL_UnmapGPUTransferBuffer(m_device, m_downloadTransferBuffer);
m_renderedImage = convertedRender;
return ForceUpdate(0, 0, DDBackBuffer->w, DDBackBuffer->h);
return ForceUpdate(0, 0, DDBackBuffer_SDL3GPU->w, DDBackBuffer_SDL3GPU->h);
}
HRESULT Direct3DRMViewport_SDL3GPUImpl::ForceUpdate(int x, int y, int w, int h)
@ -339,37 +339,37 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::ForceUpdate(int x, int y, int w, int h)
return DDERR_GENERIC;
}
// Blit the render back to our backbuffer
SDL_Rect srcRect{0, 0, DDBackBuffer->w, DDBackBuffer->h};
SDL_Rect srcRect{0, 0, DDBackBuffer_SDL3GPU->w, DDBackBuffer_SDL3GPU->h};
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(DDBackBuffer->format);
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(DDBackBuffer_SDL3GPU->format);
if (details->Amask != 0) {
// Backbuffer supports transparnacy
SDL_Surface* convertedRender = SDL_ConvertSurface(m_renderedImage, DDBackBuffer->format);
SDL_Surface* convertedRender = SDL_ConvertSurface(m_renderedImage, DDBackBuffer_SDL3GPU->format);
SDL_DestroySurface(m_renderedImage);
m_renderedImage = convertedRender;
return DD_OK;
}
if (m_renderedImage->format == DDBackBuffer->format) {
if (m_renderedImage->format == DDBackBuffer_SDL3GPU->format) {
// No conversion needed
SDL_BlitSurface(m_renderedImage, &srcRect, DDBackBuffer, &srcRect);
SDL_BlitSurface(m_renderedImage, &srcRect, DDBackBuffer_SDL3GPU, &srcRect);
return DD_OK;
}
// Convert backbuffer to a format that supports transparancy
SDL_Surface* tempBackbuffer = SDL_ConvertSurface(DDBackBuffer, m_renderedImage->format);
SDL_Surface* tempBackbuffer = SDL_ConvertSurface(DDBackBuffer_SDL3GPU, m_renderedImage->format);
SDL_BlitSurface(m_renderedImage, &srcRect, tempBackbuffer, &srcRect);
// Then convert the result back to the backbuffer format and write it back
SDL_Surface* newBackBuffer = SDL_ConvertSurface(tempBackbuffer, DDBackBuffer->format);
SDL_Surface* newBackBuffer = SDL_ConvertSurface(tempBackbuffer, DDBackBuffer_SDL3GPU->format);
SDL_DestroySurface(tempBackbuffer);
SDL_BlitSurface(newBackBuffer, &srcRect, DDBackBuffer, &srcRect);
SDL_BlitSurface(newBackBuffer, &srcRect, DDBackBuffer_SDL3GPU, &srcRect);
SDL_DestroySurface(newBackBuffer);
return DD_OK;
}
HRESULT Direct3DRMViewport_SDL3GPUImpl::Clear()
{
if (!DDBackBuffer) {
if (!DDBackBuffer_SDL3GPU) {
return DDERR_GENERIC;
}
@ -377,8 +377,8 @@ HRESULT Direct3DRMViewport_SDL3GPUImpl::Clear()
uint8_t g = (m_backgroundColor >> 8) & 0xFF;
uint8_t b = m_backgroundColor & 0xFF;
Uint32 color = SDL_MapRGB(SDL_GetPixelFormatDetails(DDBackBuffer->format), nullptr, r, g, b);
SDL_FillSurfaceRect(DDBackBuffer, NULL, color);
Uint32 color = SDL_MapRGB(SDL_GetPixelFormatDetails(DDBackBuffer_SDL3GPU->format), nullptr, r, g, b);
SDL_FillSurfaceRect(DDBackBuffer_SDL3GPU, NULL, color);
return DD_OK;
}

View File

@ -11,13 +11,8 @@
#include <cstdlib>
#include <cstring>
SDL_Window* DDWindow;
SDL_Surface* DDBackBuffer;
HRESULT IDirectDrawClipper::SetHWnd(DWORD unnamedParam1, HWND hWnd)
{
return DD_OK;
}
SDL_Window* DDWindow_SDL3GPU;
SDL_Surface* DDBackBuffer_SDL3GPU;
HRESULT DirectDraw_SDL3GPUImpl::QueryInterface(const GUID& riid, void** ppvObject)
{
@ -92,12 +87,12 @@ HRESULT DirectDraw_SDL3GPUImpl::CreateSurface(
return DD_OK;
}
if ((lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) == DDSCAPS_PRIMARYSURFACE) {
SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow);
SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow_SDL3GPU);
if (!windowSurface) {
return DDERR_GENERIC;
}
int width, height;
SDL_GetWindowSize(DDWindow, &width, &height);
SDL_GetWindowSize(DDWindow_SDL3GPU, &width, &height);
bool implicitFlip = (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_FLIP) != DDSCAPS_FLIP;
auto frontBuffer = new DirectDrawSurface_SDL3GPUImpl(width, height, windowSurface->format);
frontBuffer->SetAutoFlip(implicitFlip);
@ -328,7 +323,7 @@ HRESULT DirectDraw_SDL3GPUImpl::SetCooperativeLevel(HWND hWnd, DDSCLFlags dwFlag
if (!SDL_SetWindowFullscreen(hWnd, fullscreen)) {
return DDERR_GENERIC;
}
DDWindow = hWnd;
DDWindow_SDL3GPU = hWnd;
}
return DD_OK;
}
@ -346,18 +341,7 @@ HRESULT DirectDraw_SDL3GPUImpl::CreateDevice(const GUID& guid, void* pBackBuffer
return DD_OK;
}
HRESULT DirectDrawCreate(LPGUID lpGuid, LPDIRECTDRAW* lplpDD, IUnknown* pUnkOuter)
{
if (lpGuid) {
MINIWIN_NOT_IMPLEMENTED();
}
*lplpDD = new DirectDraw_SDL3GPUImpl;
return DD_OK;
}
HRESULT DirectDrawEnumerate(LPDDENUMCALLBACKA cb, void* context)
HRESULT DirectDrawEnumerate_SDL3GPU(LPDDENUMCALLBACKA cb, void* context)
{
int numDrivers = SDL_GetNumVideoDrivers();
@ -374,32 +358,8 @@ HRESULT DirectDrawEnumerate(LPDDENUMCALLBACKA cb, void* context)
return DD_OK;
}
UINT WINAPI GetSystemPaletteEntries(HDC hdc, UINT iStart, UINT cEntries, LPPALETTEENTRY pPalEntries)
HRESULT DirectDrawCreate_SDL3GPU(LPGUID lpGuid, LPDIRECTDRAW* lplpDD, IUnknown* pUnkOuter)
{
for (UINT i = 0; i < cEntries; i++) {
UINT val = iStart + i;
pPalEntries[i].peRed = val;
pPalEntries[i].peGreen = val;
pPalEntries[i].peBlue = val;
pPalEntries[i].peFlags = PC_NONE;
}
return cEntries;
}
HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette)
{
MINIWIN_NOT_IMPLEMENTED();
return nullptr;
}
int SelectPalette(HDC hdc, HPALETTE hpal, BOOL bForceBackground)
{
MINIWIN_NOT_IMPLEMENTED();
return 0;
}
int RealizePalette(HDC hdc)
{
MINIWIN_NOT_IMPLEMENTED();
return 0;
*lplpDD = new DirectDraw_SDL3GPUImpl;
return DD_OK;
}

View File

@ -1,3 +1,4 @@
#include "miniwin_d3drm_sdl3gpu.h"
#include "miniwin_ddpalette_sdl3gpu.h"
#include "miniwin_ddraw_sdl3gpu.h"
#include "miniwin_ddsurface_sdl3gpu.h"
@ -68,7 +69,7 @@ HRESULT DirectDrawSurface_SDL3GPUImpl::Blt(
return DDERR_GENERIC;
}
if (m_autoFlip) {
DDBackBuffer = srcSurface->m_surface;
DDBackBuffer_SDL3GPU = srcSurface->m_surface;
return Flip(nullptr, DDFLIP_WAIT);
}
@ -129,18 +130,18 @@ HRESULT DirectDrawSurface_SDL3GPUImpl::BltFast(
HRESULT DirectDrawSurface_SDL3GPUImpl::Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags)
{
if (!DDBackBuffer) {
if (!DDBackBuffer_SDL3GPU) {
return DDERR_GENERIC;
}
SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow);
SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow_SDL3GPU);
if (!windowSurface) {
return DDERR_GENERIC;
}
SDL_Rect srcRect{0, 0, DDBackBuffer->w, DDBackBuffer->h};
SDL_Surface* copy = SDL_ConvertSurface(DDBackBuffer, windowSurface->format);
SDL_Rect srcRect{0, 0, DDBackBuffer_SDL3GPU->w, DDBackBuffer_SDL3GPU->h};
SDL_Surface* copy = SDL_ConvertSurface(DDBackBuffer_SDL3GPU, windowSurface->format);
SDL_BlitSurface(copy, &srcRect, windowSurface, &srcRect);
SDL_DestroySurface(copy);
SDL_UpdateWindowSurface(DDWindow);
SDL_UpdateWindowSurface(DDWindow_SDL3GPU);
return DD_OK;
}
@ -152,7 +153,7 @@ HRESULT DirectDrawSurface_SDL3GPUImpl::GetAttachedSurface(
if ((lpDDSCaps->dwCaps & DDSCAPS_BACKBUFFER) != DDSCAPS_BACKBUFFER) {
return DDERR_INVALIDPARAMS;
}
DDBackBuffer = m_surface;
DDBackBuffer_SDL3GPU = m_surface;
*lplpDDAttachedSurface = static_cast<IDirectDrawSurface*>(this);
return DD_OK;
}