diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index 5bac2b9..c5723ac 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -4,7 +4,7 @@ #include "DDraw/DirectDraw.h" #include "DDraw/DirectDrawSurface.h" #include "DDraw/DisplayMode.h" -#include "DDraw/IReleaseNotifier.h" +#include "DDraw/Surfaces/FullScreenTagSurface.h" #include "DDraw/Surfaces/PrimarySurface.h" #include "DDraw/Surfaces/Surface.h" @@ -23,32 +23,6 @@ namespace DirectDrawInterface* g_fullScreenDirectDraw = nullptr; CompatWeakPtr g_fullScreenTagSurface; - void onReleaseFullScreenTagSurface(); - - DDraw::IReleaseNotifier g_fullScreenTagSurfaceReleaseNotifier(&onReleaseFullScreenTagSurface); - - CompatPtr createFullScreenTagSurface(CompatRef dd) - { - DDSURFACEDESC desc = {}; - desc.dwSize = sizeof(desc); - desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - desc.dwWidth = 1; - desc.dwHeight = 1; - desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - - CompatPtr tagSurface; - dd->CreateSurface(&dd, &desc, &tagSurface.getRef(), nullptr); - if (tagSurface) - { - CompatPtr tagSurface7(tagSurface); - tagSurface7->SetPrivateData( - tagSurface7, IID_IReleaseNotifier, &g_fullScreenTagSurfaceReleaseNotifier, - sizeof(&g_fullScreenTagSurfaceReleaseNotifier), DDSPD_IUNKNOWNPOINTER); - } - - return tagSurface; - } - bool isFullScreenDirectDraw(void* dd) { return dd && g_fullScreenDirectDraw && @@ -65,7 +39,8 @@ namespace void setFullScreenDirectDraw(CompatRef dd) { g_fullScreenTagSurface.release(); - g_fullScreenTagSurface = createFullScreenTagSurface(dd).detach(); + DDraw::FullScreenTagSurface::create( + dd, g_fullScreenTagSurface.getRef(), &onReleaseFullScreenTagSurface); /* IDirectDraw interfaces don't conform to the COM rule about object identity: diff --git a/DDrawCompat/DDraw/Surfaces/FullScreenTagSurface.cpp b/DDrawCompat/DDraw/Surfaces/FullScreenTagSurface.cpp new file mode 100644 index 0000000..599a681 --- /dev/null +++ b/DDrawCompat/DDraw/Surfaces/FullScreenTagSurface.cpp @@ -0,0 +1,35 @@ +#include "DDraw/Surfaces/SurfaceImpl.h" +#include "DDraw/Surfaces/FullScreenTagSurface.h" + +namespace DDraw +{ + FullScreenTagSurface::FullScreenTagSurface(const std::function& releaseHandler) + : m_releaseHandler(releaseHandler) + { + } + + FullScreenTagSurface::~FullScreenTagSurface() + { + m_releaseHandler(); + } + + HRESULT FullScreenTagSurface::create(CompatRef dd, IDirectDrawSurface*& surface, + const std::function& releaseHandler) + { + DDSURFACEDESC desc = {}; + desc.dwSize = sizeof(desc); + desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; + desc.dwWidth = 1; + desc.dwHeight = 1; + desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + + HRESULT result = Surface::create(dd, desc, surface); + if (SUCCEEDED(result)) + { + CompatPtr surface7(Compat::queryInterface(surface)); + std::unique_ptr privateData(new FullScreenTagSurface(releaseHandler)); + attach(*surface7, privateData); + } + return result; + } +} diff --git a/DDrawCompat/DDraw/Surfaces/FullScreenTagSurface.h b/DDrawCompat/DDraw/Surfaces/FullScreenTagSurface.h new file mode 100644 index 0000000..64557d5 --- /dev/null +++ b/DDrawCompat/DDraw/Surfaces/FullScreenTagSurface.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +#include "Common/CompatPtr.h" +#include "DDraw/Surfaces/Surface.h" + +namespace DDraw +{ + class FullScreenTagSurface : public Surface + { + public: + FullScreenTagSurface(const std::function& releaseHandler); + virtual ~FullScreenTagSurface(); + + static HRESULT create(CompatRef dd, IDirectDrawSurface*& surface, + const std::function& releaseHandler); + + private: + std::function m_releaseHandler; + }; +} diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index dc65910..55fe89a 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -178,6 +178,7 @@ + @@ -229,6 +230,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 8ff12cb..5c32915 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -255,6 +255,9 @@ Header Files\DDraw\Surfaces + + Header Files\DDraw\Surfaces + @@ -383,6 +386,9 @@ Source Files\DDraw\Surfaces + + Source Files\DDraw\Surfaces +