mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Refactored the queryInterface implementation
This commit is contained in:
parent
d9e095f75d
commit
923912d3af
@ -220,11 +220,6 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw<TDirectDraw>::SetDisplayMode(
|
||||
return CompatDisplayMode::setDisplayMode(*dd, dwWidth, dwHeight, dwBPP, params...);
|
||||
}
|
||||
|
||||
template <> const IID& CompatDirectDraw<IDirectDraw>::s_iid = IID_IDirectDraw;
|
||||
template <> const IID& CompatDirectDraw<IDirectDraw2>::s_iid = IID_IDirectDraw2;
|
||||
template <> const IID& CompatDirectDraw<IDirectDraw4>::s_iid = IID_IDirectDraw4;
|
||||
template <> const IID& CompatDirectDraw<IDirectDraw7>::s_iid = IID_IDirectDraw7;
|
||||
|
||||
template CompatDirectDraw<IDirectDraw>;
|
||||
template CompatDirectDraw<IDirectDraw2>;
|
||||
template CompatDirectDraw<IDirectDraw4>;
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#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 <typename Intf>
|
||||
struct IsDirectDrawIntf : std::false_type {};
|
||||
|
||||
template<> struct IsDirectDrawIntf<IDirectDraw> : std::true_type {};
|
||||
template<> struct IsDirectDrawIntf<IDirectDraw2> : std::true_type {};
|
||||
template<> struct IsDirectDrawIntf<IDirectDraw4> : std::true_type {};
|
||||
template<> struct IsDirectDrawIntf<IDirectDraw7> : std::true_type {};
|
||||
|
||||
template <typename NewIntf, typename OrigIntf>
|
||||
std::enable_if_t<IsDirectDrawIntf<NewIntf>::value && IsDirectDrawIntf<OrigIntf>::value>
|
||||
queryInterface(OrigIntf& origIntf, NewIntf*& newIntf)
|
||||
{
|
||||
CompatDirectDraw<OrigIntf>::s_origVtable.QueryInterface(
|
||||
&origIntf, CompatDirectDraw<NewIntf>::s_iid, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename NewIntf>
|
||||
std::enable_if_t<IsDirectDrawIntf<NewIntf>::value>
|
||||
queryInterface(IUnknown& origIntf, NewIntf*& newIntf)
|
||||
{
|
||||
CompatDirectDraw<IDirectDraw>::s_origVtable.QueryInterface(
|
||||
reinterpret_cast<IDirectDraw*>(&origIntf),
|
||||
CompatDirectDraw<NewIntf>::s_iid, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename OrigIntf>
|
||||
std::enable_if_t<IsDirectDrawIntf<OrigIntf>::value>
|
||||
queryInterface(OrigIntf& origIntf, IUnknown*& newIntf)
|
||||
{
|
||||
CompatDirectDraw<OrigIntf>::s_origVtable.QueryInterface(
|
||||
&origIntf, IID_IUnknown, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
}
|
||||
|
@ -531,12 +531,6 @@ void CompatDirectDrawSurface<TSurface>::restorePrimaryCaps(TDdsCaps& caps)
|
||||
caps.dwCaps |= DDSCAPS_PRIMARYSURFACE | DDSCAPS_VISIBLE | DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM;
|
||||
}
|
||||
|
||||
template <> const IID& CompatDirectDrawSurface<IDirectDrawSurface>::s_iid = IID_IDirectDrawSurface;
|
||||
template <> const IID& CompatDirectDrawSurface<IDirectDrawSurface2>::s_iid = IID_IDirectDrawSurface2;
|
||||
template <> const IID& CompatDirectDrawSurface<IDirectDrawSurface3>::s_iid = IID_IDirectDrawSurface3;
|
||||
template <> const IID& CompatDirectDrawSurface<IDirectDrawSurface4>::s_iid = IID_IDirectDrawSurface4;
|
||||
template <> const IID& CompatDirectDrawSurface<IDirectDrawSurface7>::s_iid = IID_IDirectDrawSurface7;
|
||||
|
||||
template CompatDirectDrawSurface<IDirectDrawSurface>;
|
||||
template CompatDirectDrawSurface<IDirectDrawSurface2>;
|
||||
template CompatDirectDrawSurface<IDirectDrawSurface3>;
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#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 <typename Intf>
|
||||
struct IsDirectDrawSurfaceIntf : std::false_type {};
|
||||
|
||||
template<> struct IsDirectDrawSurfaceIntf<IDirectDrawSurface> : std::true_type {};
|
||||
template<> struct IsDirectDrawSurfaceIntf<IDirectDrawSurface2> : std::true_type {};
|
||||
template<> struct IsDirectDrawSurfaceIntf<IDirectDrawSurface3> : std::true_type {};
|
||||
template<> struct IsDirectDrawSurfaceIntf<IDirectDrawSurface4> : std::true_type {};
|
||||
template<> struct IsDirectDrawSurfaceIntf<IDirectDrawSurface7> : std::true_type {};
|
||||
|
||||
template <typename NewIntf, typename OrigIntf>
|
||||
std::enable_if_t<IsDirectDrawSurfaceIntf<NewIntf>::value && IsDirectDrawSurfaceIntf<OrigIntf>::value>
|
||||
queryInterface(OrigIntf& origIntf, NewIntf*& newIntf)
|
||||
{
|
||||
CompatDirectDrawSurface<OrigIntf>::s_origVtable.QueryInterface(
|
||||
&origIntf, CompatDirectDrawSurface<NewIntf>::s_iid, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename NewIntf>
|
||||
std::enable_if_t<IsDirectDrawSurfaceIntf<NewIntf>::value>
|
||||
queryInterface(IUnknown& origIntf, NewIntf*& newIntf)
|
||||
{
|
||||
CompatDirectDrawSurface<IDirectDrawSurface>::s_origVtable.QueryInterface(
|
||||
reinterpret_cast<IDirectDrawSurface*>(&origIntf),
|
||||
CompatDirectDrawSurface<NewIntf>::s_iid, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename OrigIntf>
|
||||
std::enable_if_t<IsDirectDrawSurfaceIntf<OrigIntf>::value>
|
||||
queryInterface(OrigIntf& origIntf, IUnknown*& newIntf)
|
||||
{
|
||||
CompatDirectDrawSurface<OrigIntf>::s_origVtable.QueryInterface(
|
||||
&origIntf, IID_IUnknown, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
struct IUnknown;
|
||||
#include <type_traits>
|
||||
|
||||
#include "CompatVtable.h"
|
||||
|
||||
namespace Compat
|
||||
{
|
||||
template <typename Intf>
|
||||
struct GetBaseIntf
|
||||
{
|
||||
typedef Intf Type;
|
||||
};
|
||||
|
||||
#define DEFINE_BASE_INTF(Intf, BaseIntf) \
|
||||
template<> struct GetBaseIntf<Intf> { 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 <typename Intf>
|
||||
const IID& getIntfId();
|
||||
|
||||
#define DEFINE_INTF_ID(Intf) \
|
||||
template<> inline const IID& getIntfId<Intf>() { 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 <typename Intf>
|
||||
void queryInterface(Intf& origIntf, Intf*& newIntf)
|
||||
{
|
||||
@ -11,7 +54,31 @@ namespace Compat
|
||||
newIntf->lpVtbl->AddRef(newIntf);
|
||||
}
|
||||
|
||||
void queryInterface(IUnknown&, IUnknown*&) = delete;
|
||||
template <typename NewIntf>
|
||||
void queryInterface(IUnknown& origIntf, NewIntf*& newIntf)
|
||||
{
|
||||
CompatVtableBase<NewIntf>::getOrigVtable(reinterpret_cast<NewIntf&>(origIntf)).QueryInterface(
|
||||
reinterpret_cast<NewIntf*>(&origIntf),
|
||||
getIntfId<NewIntf>(),
|
||||
reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename OrigIntf>
|
||||
void queryInterface(OrigIntf& origIntf, IUnknown*& newIntf)
|
||||
{
|
||||
CompatVtableBase<OrigIntf>::getOrigVtable(origIntf).QueryInterface(
|
||||
&origIntf, IID_IUnknown, reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename NewIntf, typename OrigIntf>
|
||||
std::enable_if_t<std::is_same<
|
||||
typename GetBaseIntf<NewIntf>::Type,
|
||||
typename GetBaseIntf<OrigIntf>::Type>::value>
|
||||
queryInterface(OrigIntf& origIntf, NewIntf*& newIntf)
|
||||
{
|
||||
CompatVtableBase<OrigIntf>::getOrigVtable(origIntf).QueryInterface(
|
||||
&origIntf, getIntfId<NewIntf>(), reinterpret_cast<void**>(&newIntf));
|
||||
}
|
||||
|
||||
template <typename NewIntf, typename OrigIntf>
|
||||
NewIntf* queryInterface(OrigIntf* origIntf)
|
||||
|
Loading…
x
Reference in New Issue
Block a user