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