code cleanups.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -37,7 +37,7 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
|||||||
|
|
||||||
LUID GetUnityAdapterLuid()
|
LUID GetUnityAdapterLuid()
|
||||||
{
|
{
|
||||||
const auto device = GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
const auto device = GetDevice();
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
||||||
if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgiDevice)))){
|
if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgiDevice)))){
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ Monitor::Monitor(int id)
|
|||||||
|
|
||||||
Monitor::~Monitor()
|
Monitor::~Monitor()
|
||||||
{
|
{
|
||||||
duplicator_->Stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
|
|
||||||
|
class MonitorManager;
|
||||||
enum class DuplicatorState;
|
enum class DuplicatorState;
|
||||||
|
|
||||||
|
|
||||||
@@ -56,11 +57,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
void CopyTextureFromGpuToCpu(ID3D11Texture2D* texture);
|
void CopyTextureFromGpuToCpu(ID3D11Texture2D* texture);
|
||||||
|
|
||||||
int id_ = -1;
|
MonitorManager* manager_ = nullptr;
|
||||||
|
const int id_;
|
||||||
UINT dpiX_ = -1, dpiY_ = -1;
|
UINT dpiX_ = -1, dpiY_ = -1;
|
||||||
int width_ = -1, height_ = -1;
|
int width_ = -1, height_ = -1;
|
||||||
|
|
||||||
bool hasBeenUpdated_ = false;
|
bool hasBeenUpdated_ = false;
|
||||||
bool useGetPixels_ = false;
|
bool useGetPixels_ = false;
|
||||||
|
|
||||||
|
|||||||
@@ -18,22 +18,18 @@ using namespace Microsoft::WRL;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
MonitorManager::MonitorManager(LUID unityAdapterLuid)
|
MonitorManager::MonitorManager()
|
||||||
: unityAdapterLuid_(unityAdapterLuid)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MonitorManager::~MonitorManager()
|
MonitorManager::~MonitorManager()
|
||||||
{
|
{
|
||||||
Finalize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MonitorManager::Initialize()
|
void MonitorManager::Initialize()
|
||||||
{
|
{
|
||||||
Finalize();
|
|
||||||
|
|
||||||
// Get factory
|
// Get factory
|
||||||
ComPtr<IDXGIFactory1> factory;
|
ComPtr<IDXGIFactory1> factory;
|
||||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||||
@@ -52,7 +48,6 @@ void MonitorManager::Initialize()
|
|||||||
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
|
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
|
||||||
{
|
{
|
||||||
auto monitor = std::make_shared<Monitor>(id++);
|
auto monitor = std::make_shared<Monitor>(id++);
|
||||||
const auto unityAdapterLuid = GetUnityAdapterLuid();
|
|
||||||
monitor->Initialize(adapter, output);
|
monitor->Initialize(adapter, output);
|
||||||
monitor->StartCapture();
|
monitor->StartCapture();
|
||||||
monitors_.push_back(monitor);
|
monitors_.push_back(monitor);
|
||||||
@@ -92,6 +87,7 @@ void MonitorManager::RequireReinitilization()
|
|||||||
void MonitorManager::Reinitialize()
|
void MonitorManager::Reinitialize()
|
||||||
{
|
{
|
||||||
Debug::Log("MonitorManager::Reinitialize()");
|
Debug::Log("MonitorManager::Reinitialize()");
|
||||||
|
Finalize();
|
||||||
Initialize();
|
Initialize();
|
||||||
SendMessageToUnity(Message::Reinitialized);
|
SendMessageToUnity(Message::Reinitialized);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Cursor;
|
|||||||
class MonitorManager
|
class MonitorManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit MonitorManager(LUID unityAdapterLuid_);
|
MonitorManager();
|
||||||
~MonitorManager();
|
~MonitorManager();
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Finalize();
|
void Finalize();
|
||||||
@@ -34,7 +34,6 @@ public:
|
|||||||
int GetTotalHeight() const;
|
int GetTotalHeight() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LUID unityAdapterLuid_;
|
|
||||||
UINT frameRate_ = 60;
|
UINT frameRate_ = 60;
|
||||||
bool enableTextureCopyFromGpuToCpu_ = false;
|
bool enableTextureCopyFromGpuToCpu_ = false;
|
||||||
std::vector<std::shared_ptr<Monitor>> monitors_;
|
std::vector<std::shared_ptr<Monitor>> monitors_;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
IUnityInterfaces* g_unity = nullptr;
|
IUnityInterfaces* g_unity = nullptr;
|
||||||
std::unique_ptr<MonitorManager> g_manager;
|
std::unique_ptr<MonitorManager> g_manager;
|
||||||
std::queue<Message> g_messages;
|
std::queue<Message> g_messages;
|
||||||
ID3D11DeviceContext* g_deviceContextForMainThread = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -35,40 +34,23 @@ extern "C"
|
|||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Initialize()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Initialize()
|
||||||
{
|
{
|
||||||
if (g_unity && !g_manager)
|
if (!g_unity) return;
|
||||||
|
|
||||||
|
if (!g_manager)
|
||||||
{
|
{
|
||||||
Debug::Initialize();
|
Debug::Initialize();
|
||||||
|
g_manager = std::make_unique<MonitorManager>();
|
||||||
auto device = g_unity->Get<IUnityGraphicsD3D11>()->GetDevice();
|
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
|
||||||
if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgiDevice))))
|
|
||||||
{
|
|
||||||
Debug::Error("Initialize() => device->QueryInterface() failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
|
|
||||||
if (FAILED(dxgiDevice->GetAdapter(&dxgiAdapter)))
|
|
||||||
{
|
|
||||||
Debug::Error("Initialize() => dxgiDevice->GetAdapter() failed.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC desc;
|
|
||||||
dxgiAdapter->GetDesc(&desc);
|
|
||||||
|
|
||||||
g_manager = std::make_unique<MonitorManager>(desc.AdapterLuid);
|
|
||||||
g_manager->Initialize();
|
g_manager->Initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Finalize()
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Finalize()
|
||||||
{
|
{
|
||||||
if (!g_manager) return;
|
if (g_manager)
|
||||||
|
{
|
||||||
g_manager->Finalize();
|
g_manager->Finalize();
|
||||||
g_manager.reset();
|
g_manager.reset();
|
||||||
|
}
|
||||||
|
|
||||||
std::queue<Message> empty;
|
std::queue<Message> empty;
|
||||||
g_messages.swap(empty);
|
g_messages.swap(empty);
|
||||||
|
|||||||
Reference in New Issue
Block a user