mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Use types and constants from ddrawi.h
This commit is contained in:
parent
726f237724
commit
641df63f14
@ -20,8 +20,6 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const DWORD SURFACE_LOST_FLAG = 0x10000000;
|
|
||||||
|
|
||||||
template <typename TDirectDraw, typename TSurfaceDesc, typename TSurface>
|
template <typename TDirectDraw, typename TSurfaceDesc, typename TSurface>
|
||||||
HRESULT STDMETHODCALLTYPE CreateSurface(
|
HRESULT STDMETHODCALLTYPE CreateSurface(
|
||||||
TDirectDraw* This, TSurfaceDesc* lpDDSurfaceDesc, TSurface** lplpDDSurface, IUnknown* pUnkOuter)
|
TDirectDraw* This, TSurfaceDesc* lpDDSurfaceDesc, TSurface** lplpDDSurface, IUnknown* pUnkOuter)
|
||||||
@ -110,12 +108,12 @@ namespace
|
|||||||
HRESULT WINAPI restoreSurfaceLostFlag(
|
HRESULT WINAPI restoreSurfaceLostFlag(
|
||||||
LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 /*lpDDSurfaceDesc*/, LPVOID lpContext)
|
LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 /*lpDDSurfaceDesc*/, LPVOID lpContext)
|
||||||
{
|
{
|
||||||
auto& surfacesToRestore = *static_cast<std::set<void*>*>(lpContext);
|
auto& surfacesToRestore = *static_cast<std::set<DDRAWI_DDRAWSURFACE_LCL*>*>(lpContext);
|
||||||
auto it = surfacesToRestore.find(DDraw::DirectDrawSurface::getSurfaceObject(*lpDDSurface));
|
auto lcl = DDraw::DirectDrawSurface::getInt(*lpDDSurface).lpLcl;
|
||||||
|
auto it = surfacesToRestore.find(lcl);
|
||||||
if (it != surfacesToRestore.end())
|
if (it != surfacesToRestore.end())
|
||||||
{
|
{
|
||||||
DWORD& flags = DDraw::DirectDrawSurface::getFlags(*lpDDSurface);
|
lcl->dwFlags &= ~DDRAWISURF_INVALID;
|
||||||
flags &= ~SURFACE_LOST_FLAG;
|
|
||||||
surfacesToRestore.erase(it);
|
surfacesToRestore.erase(it);
|
||||||
}
|
}
|
||||||
return DDENUMRET_OK;
|
return DDENUMRET_OK;
|
||||||
@ -125,14 +123,14 @@ namespace
|
|||||||
LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 /*lpDDSurfaceDesc*/, LPVOID lpContext)
|
LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 /*lpDDSurfaceDesc*/, LPVOID lpContext)
|
||||||
{
|
{
|
||||||
auto& surfacesToRestore = *static_cast<std::set<void*>*>(lpContext);
|
auto& surfacesToRestore = *static_cast<std::set<void*>*>(lpContext);
|
||||||
DWORD& flags = DDraw::DirectDrawSurface::getFlags(*lpDDSurface);
|
auto lcl = DDraw::DirectDrawSurface::getInt(*lpDDSurface).lpLcl;
|
||||||
if (!(flags & SURFACE_LOST_FLAG))
|
if (!(lcl->dwFlags & DDRAWISURF_INVALID))
|
||||||
{
|
{
|
||||||
auto resource = D3dDdi::Device::findResource(DDraw::DirectDrawSurface::getDriverResourceHandle(*lpDDSurface));
|
auto resource = D3dDdi::Device::findResource(DDraw::DirectDrawSurface::getDriverResourceHandle(*lpDDSurface));
|
||||||
if (resource && !resource->getOrigDesc().Flags.MatchGdiPrimary)
|
if (resource && !resource->getOrigDesc().Flags.MatchGdiPrimary)
|
||||||
{
|
{
|
||||||
flags |= SURFACE_LOST_FLAG;
|
lcl->dwFlags |= DDRAWISURF_INVALID;
|
||||||
surfacesToRestore.insert(DDraw::DirectDrawSurface::getSurfaceObject(*lpDDSurface));
|
surfacesToRestore.insert(lcl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DDENUMRET_OK;
|
return DDENUMRET_OK;
|
||||||
@ -212,7 +210,7 @@ namespace DDraw
|
|||||||
}
|
}
|
||||||
|
|
||||||
DDraw::ScopedThreadLock lock;
|
DDraw::ScopedThreadLock lock;
|
||||||
std::set<void*> surfacesToRestore;
|
std::set<DDRAWI_DDRAWSURFACE_LCL*> surfacesToRestore;
|
||||||
TagSurface::forEachDirectDraw([&](CompatRef<IDirectDraw7> dd)
|
TagSurface::forEachDirectDraw([&](CompatRef<IDirectDraw7> dd)
|
||||||
{
|
{
|
||||||
dd->EnumSurfaces(&dd, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, nullptr,
|
dd->EnumSurfaces(&dd, DDENUMSURFACES_DOESEXIST | DDENUMSURFACES_ALL, nullptr,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <ddraw.h>
|
#include <ddraw.h>
|
||||||
|
#include <ddrawi.h>
|
||||||
|
|
||||||
#include <Common/CompatPtr.h>
|
#include <Common/CompatPtr.h>
|
||||||
#include <Common/CompatRef.h>
|
#include <Common/CompatRef.h>
|
||||||
@ -18,15 +19,15 @@ namespace DDraw
|
|||||||
void suppressEmulatedDirectDraw(GUID*& guid);
|
void suppressEmulatedDirectDraw(GUID*& guid);
|
||||||
|
|
||||||
template <typename TDirectDraw>
|
template <typename TDirectDraw>
|
||||||
void* getDdObject(TDirectDraw& dd)
|
DDRAWI_DIRECTDRAW_INT& getInt(TDirectDraw& dd)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<void**>(&dd)[1];
|
return reinterpret_cast<DDRAWI_DIRECTDRAW_INT&>(dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TDirectDraw>
|
template <typename TDirectDraw>
|
||||||
HWND* getDeviceWindowPtr(TDirectDraw& dd)
|
HWND* getDeviceWindowPtr(TDirectDraw& dd)
|
||||||
{
|
{
|
||||||
return &reinterpret_cast<HWND**>(&dd)[1][8];
|
return &reinterpret_cast<HWND>(getInt(dd).lpLcl->hWnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Vtable>
|
template <typename Vtable>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <ddrawi.h>
|
||||||
|
|
||||||
#include <Common/CompatPtr.h>
|
#include <Common/CompatPtr.h>
|
||||||
#include <Common/CompatRef.h>
|
#include <Common/CompatRef.h>
|
||||||
@ -14,21 +15,15 @@ namespace DDraw
|
|||||||
std::vector<CompatPtr<IDirectDrawSurface7>> getAllAttachedSurfaces(CompatRef<IDirectDrawSurface7> surface);
|
std::vector<CompatPtr<IDirectDrawSurface7>> getAllAttachedSurfaces(CompatRef<IDirectDrawSurface7> surface);
|
||||||
|
|
||||||
template <typename TSurface>
|
template <typename TSurface>
|
||||||
void* getSurfaceObject(TSurface& surface)
|
DDRAWI_DDRAWSURFACE_INT& getInt(TSurface& surface)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<void**>(&surface)[1];
|
return reinterpret_cast<DDRAWI_DDRAWSURFACE_INT&>(surface);
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TSurface>
|
|
||||||
DWORD& getFlags(TSurface& surface)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<DWORD**>(&surface)[1][7];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TSurface>
|
template <typename TSurface>
|
||||||
HANDLE getRuntimeResourceHandle(TSurface& surface)
|
HANDLE getRuntimeResourceHandle(TSurface& surface)
|
||||||
{
|
{
|
||||||
return reinterpret_cast<HANDLE**>(&surface)[1][2];
|
return reinterpret_cast<HANDLE>(getInt(surface).lpLcl->hDDSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TSurface>
|
template <typename TSurface>
|
||||||
|
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::map<void*, DDraw::TagSurface*> g_ddObjects;
|
std::map<DDRAWI_DIRECTDRAW_LCL*, DDraw::TagSurface*> g_ddObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace DDraw
|
namespace DDraw
|
||||||
{
|
{
|
||||||
TagSurface::TagSurface(DWORD origCaps, void* ddObject)
|
TagSurface::TagSurface(DWORD origCaps, DDRAWI_DIRECTDRAW_LCL* ddLcl)
|
||||||
: Surface(origCaps)
|
: Surface(origCaps)
|
||||||
, m_ddObject(ddObject)
|
, m_ddLcl(ddLcl)
|
||||||
, m_fullscreenWindow(nullptr)
|
, m_fullscreenWindow(nullptr)
|
||||||
, m_fullscreenWindowStyle(0)
|
, m_fullscreenWindowStyle(0)
|
||||||
, m_fullscreenWindowExStyle(0)
|
, m_fullscreenWindowExStyle(0)
|
||||||
@ -23,7 +23,7 @@ namespace DDraw
|
|||||||
TagSurface::~TagSurface()
|
TagSurface::~TagSurface()
|
||||||
{
|
{
|
||||||
setFullscreenWindow(nullptr);
|
setFullscreenWindow(nullptr);
|
||||||
g_ddObjects.erase(m_ddObject);
|
g_ddObjects.erase(m_ddLcl);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT TagSurface::create(CompatRef<IDirectDraw> dd)
|
HRESULT TagSurface::create(CompatRef<IDirectDraw> dd)
|
||||||
@ -35,9 +35,9 @@ namespace DDraw
|
|||||||
desc.dwHeight = 1;
|
desc.dwHeight = 1;
|
||||||
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
|
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
|
||||||
|
|
||||||
auto ddObject = DDraw::DirectDraw::getDdObject(dd.get());
|
auto ddLcl = DDraw::DirectDraw::getInt(dd.get()).lpLcl;
|
||||||
auto privateData(std::make_unique<TagSurface>(desc.ddsCaps.dwCaps, ddObject));
|
auto privateData(std::make_unique<TagSurface>(desc.ddsCaps.dwCaps, ddLcl));
|
||||||
g_ddObjects[ddObject] = privateData.get();
|
g_ddObjects[ddLcl] = privateData.get();
|
||||||
|
|
||||||
IDirectDrawSurface* surface = nullptr;
|
IDirectDrawSurface* surface = nullptr;
|
||||||
return Surface::create(dd, desc, surface, std::move(privateData));
|
return Surface::create(dd, desc, surface, std::move(privateData));
|
||||||
@ -57,25 +57,20 @@ namespace DDraw
|
|||||||
|
|
||||||
void TagSurface::forEachDirectDraw(std::function<void(CompatRef<IDirectDraw7>)> callback)
|
void TagSurface::forEachDirectDraw(std::function<void(CompatRef<IDirectDraw7>)> callback)
|
||||||
{
|
{
|
||||||
struct DirectDrawInterface
|
for (auto& ddObj : g_ddObjects)
|
||||||
{
|
{
|
||||||
const void* vtable;
|
DDRAWI_DIRECTDRAW_INT intf = {};
|
||||||
void* ddObject;
|
intf.lpVtbl = &CompatVtable<IDirectDraw7Vtbl>::s_origVtable;
|
||||||
DirectDrawInterface* next;
|
intf.lpLcl = ddObj.first;
|
||||||
DWORD refCount;
|
intf.dwIntRefCnt = 1;
|
||||||
};
|
|
||||||
|
|
||||||
for (auto ddObj : g_ddObjects)
|
|
||||||
{
|
|
||||||
DirectDrawInterface intf = { &CompatVtable<IDirectDraw7Vtbl>::s_origVtable, ddObj.first, nullptr, 1 };
|
|
||||||
callback(CompatRef<IDirectDraw7>(reinterpret_cast<IDirectDraw7&>(intf)));
|
callback(CompatRef<IDirectDraw7>(reinterpret_cast<IDirectDraw7&>(intf)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TagSurface* TagSurface::get(CompatRef<IDirectDraw> dd)
|
TagSurface* TagSurface::get(CompatRef<IDirectDraw> dd)
|
||||||
{
|
{
|
||||||
auto ddObject = DDraw::DirectDraw::getDdObject(dd.get());
|
auto ddLcl = DDraw::DirectDraw::getInt(dd.get()).lpLcl;
|
||||||
auto it = g_ddObjects.find(ddObject);
|
auto it = g_ddObjects.find(ddLcl);
|
||||||
if (it != g_ddObjects.end())
|
if (it != g_ddObjects.end())
|
||||||
{
|
{
|
||||||
return it->second;
|
return it->second;
|
||||||
@ -85,7 +80,7 @@ namespace DDraw
|
|||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return g_ddObjects[ddObject];
|
return g_ddObjects[ddLcl];
|
||||||
}
|
}
|
||||||
|
|
||||||
void TagSurface::setFullscreenWindow(HWND hwnd)
|
void TagSurface::setFullscreenWindow(HWND hwnd)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ddraw.h>
|
#include <ddraw.h>
|
||||||
|
#include <ddrawi.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <Common/CompatRef.h>
|
#include <Common/CompatRef.h>
|
||||||
@ -11,7 +12,7 @@ namespace DDraw
|
|||||||
class TagSurface : public Surface
|
class TagSurface : public Surface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TagSurface(DWORD origCaps, void* ddObject);
|
TagSurface(DWORD origCaps, DDRAWI_DIRECTDRAW_LCL* ddLcl);
|
||||||
virtual ~TagSurface() override;
|
virtual ~TagSurface() override;
|
||||||
|
|
||||||
static TagSurface* get(CompatRef<IDirectDraw> dd);
|
static TagSurface* get(CompatRef<IDirectDraw> dd);
|
||||||
@ -26,7 +27,7 @@ namespace DDraw
|
|||||||
private:
|
private:
|
||||||
static HRESULT create(CompatRef<IDirectDraw> dd);
|
static HRESULT create(CompatRef<IDirectDraw> dd);
|
||||||
|
|
||||||
void* m_ddObject;
|
DDRAWI_DIRECTDRAW_LCL* m_ddLcl;
|
||||||
HWND m_fullscreenWindow;
|
HWND m_fullscreenWindow;
|
||||||
LONG m_fullscreenWindowStyle;
|
LONG m_fullscreenWindowStyle;
|
||||||
LONG m_fullscreenWindowExStyle;
|
LONG m_fullscreenWindowExStyle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user