From bbb0de6e9abee4446c2232ab6914ac3f9f1c34a0 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 12 Jun 2025 22:51:52 +0200 Subject: [PATCH] Implement full screen (#290) --- ISLE/isleapp.cpp | 14 ++++++-- miniwin/include/miniwin/miniwindevice.h | 1 + miniwin/src/d3drm/d3drmdevice.cpp | 5 +++ miniwin/src/ddraw/ddraw.cpp | 5 +++ miniwin/src/ddraw/ddsurface.cpp | 46 ++++++++++++++++++++----- miniwin/src/internal/d3drmdevice_impl.h | 1 + miniwin/src/internal/d3drmrenderer.h | 6 ++++ miniwin/src/internal/ddraw_impl.h | 3 ++ 8 files changed, 70 insertions(+), 11 deletions(-) diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index 7377e94e..6a8068f2 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -88,7 +88,7 @@ IsleApp::IsleApp() m_cdPath = NULL; m_deviceId = NULL; m_savePath = NULL; - m_fullScreen = FALSE; + m_fullScreen = TRUE; m_flipSurfaces = FALSE; m_backBuffersInVram = TRUE; m_using8bit = FALSE; @@ -355,9 +355,19 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) // [library:window] // Remaining functionality to be implemented: - // Full screen - crashes when minimizing/maximizing, but this will probably be fixed once DirectDraw is replaced // WM_TIMER - use SDL_Timer functionality instead + switch (event->type) { + case SDL_EVENT_MOUSE_MOTION: + case SDL_EVENT_MOUSE_BUTTON_DOWN: + case SDL_EVENT_MOUSE_BUTTON_UP: + IDirect3DRMMiniwinDevice* device = GetD3DRMMiniwinDevice(); + if (device && !device->ConvertEventToRenderCoordinates(event)) { + SDL_Log("Failed to convert event coordinates: %s", SDL_GetError()); + } + break; + } + switch (event->type) { case SDL_EVENT_WINDOW_FOCUS_GAINED: if (!IsleDebug_Enabled()) { diff --git a/miniwin/include/miniwin/miniwindevice.h b/miniwin/include/miniwin/miniwindevice.h index 032e776d..2434175f 100644 --- a/miniwin/include/miniwin/miniwindevice.h +++ b/miniwin/include/miniwin/miniwindevice.h @@ -3,6 +3,7 @@ DEFINE_GUID(IID_IDirect3DRMMiniwinDevice, 0x6eb09673, 0x8d30, 0x4d8a, 0x8d, 0x81, 0x34, 0xea, 0x69, 0x30, 0x12, 0x01); struct IDirect3DRMMiniwinDevice : virtual public IUnknown { + virtual bool ConvertEventToRenderCoordinates(SDL_Event* event) = 0; virtual float GetShininessFactor() = 0; virtual HRESULT SetShininessFactor(float factor) = 0; }; diff --git a/miniwin/src/d3drm/d3drmdevice.cpp b/miniwin/src/d3drm/d3drmdevice.cpp index 2000cf56..58ff7c2c 100644 --- a/miniwin/src/d3drm/d3drmdevice.cpp +++ b/miniwin/src/d3drm/d3drmdevice.cpp @@ -144,6 +144,11 @@ float Direct3DRMDevice2Impl::GetShininessFactor() return m_renderer->GetShininessFactor(); } +bool Direct3DRMDevice2Impl::ConvertEventToRenderCoordinates(SDL_Event* event) +{ + return m_renderer->ConvertEventToRenderCoordinates(event); +} + HRESULT Direct3DRMDevice2Impl::SetShininessFactor(float factor) { return m_renderer->SetShininessFactor(factor); diff --git a/miniwin/src/ddraw/ddraw.cpp b/miniwin/src/ddraw/ddraw.cpp index 8ac249f1..aeba3972 100644 --- a/miniwin/src/ddraw/ddraw.cpp +++ b/miniwin/src/ddraw/ddraw.cpp @@ -17,6 +17,9 @@ SDL_Window* DDWindow; SDL_Surface* DDBackBuffer; +SDL_Texture* HWBackBuffer; +SDL_PixelFormat HWBackBufferFormat; +SDL_Renderer* DDRenderer; HRESULT DirectDrawImpl::QueryInterface(const GUID& riid, void** ppvObject) { @@ -296,6 +299,8 @@ HRESULT DirectDrawImpl::SetCooperativeLevel(HWND hWnd, DDSCLFlags dwFlags) return DDERR_GENERIC; } DDWindow = sdlWindow; + DDRenderer = SDL_CreateRenderer(DDWindow, NULL); + SDL_SetRenderLogicalPresentation(DDRenderer, 640, 480, SDL_LOGICAL_PRESENTATION_LETTERBOX); } return DD_OK; } diff --git a/miniwin/src/ddraw/ddsurface.cpp b/miniwin/src/ddraw/ddsurface.cpp index 5c8ee6db..7a767e87 100644 --- a/miniwin/src/ddraw/ddsurface.cpp +++ b/miniwin/src/ddraw/ddsurface.cpp @@ -55,6 +55,31 @@ static SDL_Rect ConvertRect(const RECT* r) return {r->left, r->top, r->right - r->left, r->bottom - r->top}; } +bool SetupHWBackBuffer() +{ + HWBackBuffer = SDL_CreateTextureFromSurface(DDRenderer, DDBackBuffer); + if (!HWBackBuffer) { + return false; + } + + SDL_PropertiesID props = SDL_GetTextureProperties(HWBackBuffer); + if (!props) { + SDL_DestroyTexture(HWBackBuffer); + HWBackBuffer = nullptr; + return false; + } + + HWBackBufferFormat = + (SDL_PixelFormat) SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PIXELFORMAT_UNKNOWN); + if (HWBackBufferFormat == SDL_PIXELFORMAT_UNKNOWN) { + SDL_DestroyTexture(HWBackBuffer); + HWBackBuffer = nullptr; + return false; + } + + return true; +} + HRESULT DirectDrawSurfaceImpl::Blt( LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpDDSrcSurface, @@ -69,6 +94,9 @@ HRESULT DirectDrawSurfaceImpl::Blt( } if (m_autoFlip) { DDBackBuffer = srcSurface->m_surface; + if (!HWBackBuffer && !SetupHWBackBuffer()) { + return DDERR_GENERIC; + } return Flip(nullptr, DDFLIP_WAIT); } @@ -126,18 +154,15 @@ HRESULT DirectDrawSurfaceImpl::BltFast( HRESULT DirectDrawSurfaceImpl::Flip(LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DDFlipFlags dwFlags) { - if (!DDBackBuffer) { + if (!DDBackBuffer || !DDRenderer) { return DDERR_GENERIC; } - SDL_Surface* windowSurface = SDL_GetWindowSurface(DDWindow); - if (!windowSurface) { - return DDERR_GENERIC; - } - SDL_Rect srcRect{0, 0, DDBackBuffer->w, DDBackBuffer->h}; - SDL_Surface* copy = SDL_ConvertSurface(DDBackBuffer, windowSurface->format); - SDL_BlitSurface(copy, &srcRect, windowSurface, &srcRect); + + SDL_Surface* copy = SDL_ConvertSurface(DDBackBuffer, HWBackBufferFormat); + SDL_UpdateTexture(HWBackBuffer, nullptr, copy->pixels, copy->pitch); SDL_DestroySurface(copy); - SDL_UpdateWindowSurface(DDWindow); + SDL_RenderTexture(DDRenderer, HWBackBuffer, nullptr, nullptr); + SDL_RenderPresent(DDRenderer); return DD_OK; } @@ -147,6 +172,9 @@ HRESULT DirectDrawSurfaceImpl::GetAttachedSurface(LPDDSCAPS lpDDSCaps, LPDIRECTD return DDERR_INVALIDPARAMS; } DDBackBuffer = m_surface; + if (!SetupHWBackBuffer()) { + return DDERR_GENERIC; + } *lplpDDAttachedSurface = static_cast(this); return DD_OK; } diff --git a/miniwin/src/internal/d3drmdevice_impl.h b/miniwin/src/internal/d3drmdevice_impl.h index e96bcd43..5b902ef6 100644 --- a/miniwin/src/internal/d3drmdevice_impl.h +++ b/miniwin/src/internal/d3drmdevice_impl.h @@ -33,6 +33,7 @@ struct Direct3DRMDevice2Impl : public Direct3DRMObjectBaseImpl