diff --git a/DDrawCompat/CompatDirectDraw.cpp b/DDrawCompat/CompatDirectDraw.cpp index e719b39..72c1d55 100644 --- a/DDrawCompat/CompatDirectDraw.cpp +++ b/DDrawCompat/CompatDirectDraw.cpp @@ -220,11 +220,6 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw::SetDisplayMode( return CompatDisplayMode::setDisplayMode(*dd, dwWidth, dwHeight, dwBPP, params...); } -template <> const IID& CompatDirectDraw::s_iid = IID_IDirectDraw; -template <> const IID& CompatDirectDraw::s_iid = IID_IDirectDraw2; -template <> const IID& CompatDirectDraw::s_iid = IID_IDirectDraw4; -template <> const IID& CompatDirectDraw::s_iid = IID_IDirectDraw7; - template CompatDirectDraw; template CompatDirectDraw; template CompatDirectDraw; diff --git a/DDrawCompat/CompatDirectDraw.h b/DDrawCompat/CompatDirectDraw.h index 0e37fc8..a6886e6 100644 --- a/DDrawCompat/CompatDirectDraw.h +++ b/DDrawCompat/CompatDirectDraw.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "CompatVtable.h" #include "DDrawTypes.h" #include "DirectDrawVtblVisitor.h" @@ -32,42 +30,4 @@ public: DWORD dwHeight, DWORD dwBPP, Params... params); - - static const IID& s_iid; }; - -namespace Compat -{ - template - struct IsDirectDrawIntf : std::false_type {}; - - template<> struct IsDirectDrawIntf : std::true_type {}; - template<> struct IsDirectDrawIntf : std::true_type {}; - template<> struct IsDirectDrawIntf : std::true_type {}; - template<> struct IsDirectDrawIntf : std::true_type {}; - - template - std::enable_if_t::value && IsDirectDrawIntf::value> - queryInterface(OrigIntf& origIntf, NewIntf*& newIntf) - { - CompatDirectDraw::s_origVtable.QueryInterface( - &origIntf, CompatDirectDraw::s_iid, reinterpret_cast(&newIntf)); - } - - template - std::enable_if_t::value> - queryInterface(IUnknown& origIntf, NewIntf*& newIntf) - { - CompatDirectDraw::s_origVtable.QueryInterface( - reinterpret_cast(&origIntf), - CompatDirectDraw::s_iid, reinterpret_cast(&newIntf)); - } - - template - std::enable_if_t::value> - queryInterface(OrigIntf& origIntf, IUnknown*& newIntf) - { - CompatDirectDraw::s_origVtable.QueryInterface( - &origIntf, IID_IUnknown, reinterpret_cast(&newIntf)); - } -} diff --git a/DDrawCompat/CompatDirectDrawSurface.cpp b/DDrawCompat/CompatDirectDrawSurface.cpp index 527d4ef..2a8f07a 100644 --- a/DDrawCompat/CompatDirectDrawSurface.cpp +++ b/DDrawCompat/CompatDirectDrawSurface.cpp @@ -531,12 +531,6 @@ void CompatDirectDrawSurface::restorePrimaryCaps(TDdsCaps& caps) caps.dwCaps |= DDSCAPS_PRIMARYSURFACE | DDSCAPS_VISIBLE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM; } -template <> const IID& CompatDirectDrawSurface::s_iid = IID_IDirectDrawSurface; -template <> const IID& CompatDirectDrawSurface::s_iid = IID_IDirectDrawSurface2; -template <> const IID& CompatDirectDrawSurface::s_iid = IID_IDirectDrawSurface3; -template <> const IID& CompatDirectDrawSurface::s_iid = IID_IDirectDrawSurface4; -template <> const IID& CompatDirectDrawSurface::s_iid = IID_IDirectDrawSurface7; - template CompatDirectDrawSurface; template CompatDirectDrawSurface; template CompatDirectDrawSurface; diff --git a/DDrawCompat/CompatDirectDrawSurface.h b/DDrawCompat/CompatDirectDrawSurface.h index 18f4948..eacad43 100644 --- a/DDrawCompat/CompatDirectDrawSurface.h +++ b/DDrawCompat/CompatDirectDrawSurface.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "CompatRef.h" #include "CompatVtable.h" #include "DDrawTypes.h" @@ -64,45 +62,6 @@ public: static HRESULT STDMETHODCALLTYPE SetPalette(TSurface* This, LPDIRECTDRAWPALETTE lpDDPalette); static HRESULT STDMETHODCALLTYPE Unlock(TSurface* This, TUnlockParam lpRect); - static const IID& s_iid; - private: static void restorePrimaryCaps(TDdsCaps& caps); }; - -namespace Compat -{ - template - struct IsDirectDrawSurfaceIntf : std::false_type {}; - - template<> struct IsDirectDrawSurfaceIntf : std::true_type {}; - template<> struct IsDirectDrawSurfaceIntf : std::true_type {}; - template<> struct IsDirectDrawSurfaceIntf : std::true_type {}; - template<> struct IsDirectDrawSurfaceIntf : std::true_type {}; - template<> struct IsDirectDrawSurfaceIntf : std::true_type {}; - - template - std::enable_if_t::value && IsDirectDrawSurfaceIntf::value> - queryInterface(OrigIntf& origIntf, NewIntf*& newIntf) - { - CompatDirectDrawSurface::s_origVtable.QueryInterface( - &origIntf, CompatDirectDrawSurface::s_iid, reinterpret_cast(&newIntf)); - } - - template - std::enable_if_t::value> - queryInterface(IUnknown& origIntf, NewIntf*& newIntf) - { - CompatDirectDrawSurface::s_origVtable.QueryInterface( - reinterpret_cast(&origIntf), - CompatDirectDrawSurface::s_iid, reinterpret_cast(&newIntf)); - } - - template - std::enable_if_t::value> - queryInterface(OrigIntf& origIntf, IUnknown*& newIntf) - { - CompatDirectDrawSurface::s_origVtable.QueryInterface( - &origIntf, IID_IUnknown, reinterpret_cast(&newIntf)); - } -} diff --git a/DDrawCompat/CompatQueryInterface.h b/DDrawCompat/CompatQueryInterface.h index d387e14..0fb9da3 100644 --- a/DDrawCompat/CompatQueryInterface.h +++ b/DDrawCompat/CompatQueryInterface.h @@ -1,9 +1,52 @@ #pragma once -struct IUnknown; +#include + +#include "CompatVtable.h" namespace Compat { + template + struct GetBaseIntf + { + typedef Intf Type; + }; + +#define DEFINE_BASE_INTF(Intf, BaseIntf) \ + template<> struct GetBaseIntf { typedef BaseIntf Type; } + + DEFINE_BASE_INTF(IDirectDraw2, IDirectDraw); + DEFINE_BASE_INTF(IDirectDraw4, IDirectDraw); + DEFINE_BASE_INTF(IDirectDraw7, IDirectDraw); + DEFINE_BASE_INTF(IDirectDrawSurface2, IDirectDrawSurface); + DEFINE_BASE_INTF(IDirectDrawSurface3, IDirectDrawSurface); + DEFINE_BASE_INTF(IDirectDrawSurface4, IDirectDrawSurface); + DEFINE_BASE_INTF(IDirectDrawSurface7, IDirectDrawSurface); + +#undef DEFINE_BASE_INTF + + template + const IID& getIntfId(); + +#define DEFINE_INTF_ID(Intf) \ + template<> inline const IID& getIntfId() { return IID_##Intf; } + + DEFINE_INTF_ID(IDirectDraw); + DEFINE_INTF_ID(IDirectDraw2); + DEFINE_INTF_ID(IDirectDraw4); + DEFINE_INTF_ID(IDirectDraw7); + DEFINE_INTF_ID(IDirectDrawSurface); + DEFINE_INTF_ID(IDirectDrawSurface2); + DEFINE_INTF_ID(IDirectDrawSurface3); + DEFINE_INTF_ID(IDirectDrawSurface4); + DEFINE_INTF_ID(IDirectDrawSurface7); + DEFINE_INTF_ID(IDirectDrawPalette); + DEFINE_INTF_ID(IDirectDrawClipper); + DEFINE_INTF_ID(IDirectDrawColorControl); + DEFINE_INTF_ID(IDirectDrawGammaControl); + +#undef DEFINE_INTF_ID + template void queryInterface(Intf& origIntf, Intf*& newIntf) { @@ -11,7 +54,31 @@ namespace Compat newIntf->lpVtbl->AddRef(newIntf); } - void queryInterface(IUnknown&, IUnknown*&) = delete; + template + void queryInterface(IUnknown& origIntf, NewIntf*& newIntf) + { + CompatVtableBase::getOrigVtable(reinterpret_cast(origIntf)).QueryInterface( + reinterpret_cast(&origIntf), + getIntfId(), + reinterpret_cast(&newIntf)); + } + + template + void queryInterface(OrigIntf& origIntf, IUnknown*& newIntf) + { + CompatVtableBase::getOrigVtable(origIntf).QueryInterface( + &origIntf, IID_IUnknown, reinterpret_cast(&newIntf)); + } + + template + std::enable_if_t::Type, + typename GetBaseIntf::Type>::value> + queryInterface(OrigIntf& origIntf, NewIntf*& newIntf) + { + CompatVtableBase::getOrigVtable(origIntf).QueryInterface( + &origIntf, getIntfId(), reinterpret_cast(&newIntf)); + } template NewIntf* queryInterface(OrigIntf* origIntf)