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