LibraryHook classes self-register, without library name

* The libName parameter to CreateHooks isn't yet deleted since it's used as a
  hack in the GL hooks to have multiple paths through a function.
This commit is contained in:
baldurk
2018-06-26 12:29:37 +01:00
parent 9ecad14932
commit 6a30e63a46
12 changed files with 22 additions and 47 deletions
-1
View File
@@ -113,7 +113,6 @@ class D3D11Hook : LibraryHook
public:
D3D11Hook()
{
LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this);
m_HasHooks = false;
m_InsideCreate = false;
}
-1
View File
@@ -90,7 +90,6 @@ class D3D12Hook : LibraryHook
public:
D3D12Hook()
{
LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this);
m_HasHooks = false;
m_InsideCreate = false;
}
+1 -6
View File
@@ -33,12 +33,7 @@ typedef IDirect3D8 *(WINAPI *PFN_D3D8_CREATE)(UINT);
class D3D8Hook : LibraryHook
{
public:
D3D8Hook()
{
LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this);
m_HasHooks = false;
}
D3D8Hook() { m_HasHooks = false; }
bool CreateHooks(const char *libName)
{
bool success = true;
+1 -6
View File
@@ -42,12 +42,7 @@ typedef IDirect3D9 *(WINAPI *PFN_D3D9_CREATE)(UINT);
class D3D9Hook : LibraryHook
{
public:
D3D9Hook()
{
LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this);
m_HasHooks = false;
}
D3D9Hook() { m_HasHooks = false; }
bool CreateHooks(const char *libName)
{
bool success = true;
-1
View File
@@ -74,7 +74,6 @@ struct RenderDocAnalysis : IDXGraphicsAnalysis
class DXGIHook : LibraryHook
{
public:
DXGIHook() { LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this); }
bool CreateHooks(const char *libName)
{
bool success = true;
-2
View File
@@ -37,8 +37,6 @@ class EGLHook : LibraryHook, public GLPlatform
public:
EGLHook()
{
LibraryHooks::GetInstance().RegisterHook("libEGL.so", this);
m_HasHooks = false;
m_GLDriver = NULL;
-2
View File
@@ -49,8 +49,6 @@ class OpenGLHook : LibraryHook, public GLPlatform
public:
OpenGLHook()
{
LibraryHooks::GetInstance().RegisterHook("libGL.so", this);
m_HasHooks = false;
m_GLDriver = NULL;
-2
View File
@@ -667,8 +667,6 @@ class OpenGLHook : LibraryHook, public GLPlatform
public:
OpenGLHook()
{
LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this);
m_GLDriver = NULL;
m_HasHooks = false;
+3 -3
View File
@@ -47,7 +47,7 @@
// set environment variables
class VulkanHook : LibraryHook
{
VulkanHook() { LibraryHooks::GetInstance().RegisterHook(VulkanLibraryName, this); }
VulkanHook() {}
bool CreateHooks(const char *libName)
{
// we assume the implicit layer is registered - the UI will prompt the user about installing it.
@@ -55,12 +55,12 @@ class VulkanHook : LibraryHook
EnvMod::Set, EnvSep::NoSep, "ENABLE_VULKAN_RENDERDOC_CAPTURE", "1"));
// check options to set further variables, and apply
OptionsUpdated(libName);
OptionsUpdated();
return true;
}
void OptionsUpdated(const char *libName)
void OptionsUpdated()
{
if(RenderDoc::Inst().GetCaptureOptions().apiValidation)
{
+6 -11
View File
@@ -32,21 +32,16 @@ LibraryHooks &LibraryHooks::GetInstance()
return instance;
}
void LibraryHooks::RegisterHook(const char *libName, LibraryHook *hook)
void LibraryHooks::RegisterLibrary(LibraryHook *lib)
{
m_Hooks[libName] = hook;
m_Libraries.push_back(lib);
}
void LibraryHooks::CreateHooks()
{
HOOKS_BEGIN();
for(auto it = m_Hooks.begin(); it != m_Hooks.end(); ++it)
{
RDCDEBUG("Hooking %s", it->first);
if(!it->second->CreateHooks(it->first))
RDCWARN("Couldn't hook into %s", it->first);
}
for(LibraryHook *lib : m_Libraries)
lib->CreateHooks("dummy");
HOOKS_END();
}
@@ -60,6 +55,6 @@ void LibraryHooks::RemoveHooks()
void LibraryHooks::OptionsUpdated()
{
for(auto it = m_Hooks.begin(); it != m_Hooks.end(); ++it)
it->second->OptionsUpdated(it->first);
for(LibraryHook *lib : m_Libraries)
lib->OptionsUpdated();
}
+11 -11
View File
@@ -78,13 +78,7 @@ private:
#endif
// defines the interface that a library hooking class will implement.
// the libName is the name they used when registering
struct LibraryHook
{
virtual bool CreateHooks(const char *libName) = 0;
virtual void OptionsUpdated(const char *libName) {}
};
struct LibraryHook;
// this singleton allows you to compile in code that defines a hook for a given library
// (and it will be registered). Then when the renderdoc library is initialised in the target
@@ -94,15 +88,21 @@ class LibraryHooks
public:
LibraryHooks() : m_HooksRemoved(false) {}
static LibraryHooks &GetInstance();
void RegisterHook(const char *libName, LibraryHook *hook);
void RegisterLibrary(LibraryHook *lib);
void CreateHooks();
void OptionsUpdated();
void RemoveHooks();
private:
typedef map<const char *, LibraryHook *> HookMap;
bool m_HooksRemoved;
HookMap m_Hooks;
std::vector<LibraryHook *> m_Libraries;
};
// defines the interface that a library hooking class will implement.
struct LibraryHook
{
LibraryHook() { LibraryHooks::GetInstance().RegisterLibrary(this); }
virtual bool CreateHooks(const char *dummy) = 0;
virtual void OptionsUpdated() {}
};
-1
View File
@@ -75,7 +75,6 @@ class SysHook : LibraryHook
public:
SysHook()
{
LibraryHooks::GetInstance().RegisterHook(DLL_NAME, this);
m_HasHooks = false;
m_WSARefCount = 1;
}