Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
467fa86f59 | ||
|
|
608509aa22 | ||
|
|
9aa488e100 |
Binary file not shown.
Binary file not shown.
@@ -17,6 +17,29 @@ extern std::unique_ptr<MonitorManager> g_manager;
|
||||
extern std::queue<Message> g_messages;
|
||||
|
||||
|
||||
void OutputWindowsInformation()
|
||||
{
|
||||
const auto hModule = ::LoadLibrary(TEXT("ntdll.dll"));
|
||||
if (!hModule) return;
|
||||
|
||||
ScopedReleaser freeModule([&] { ::FreeLibrary(hModule); });
|
||||
|
||||
if (const auto address = ::GetProcAddress(hModule, "RtlGetVersion"))
|
||||
{
|
||||
using RtlGetVersionType = NTSTATUS(WINAPI *)(OSVERSIONINFOEXW*);
|
||||
const auto RtlGetVersion = reinterpret_cast<RtlGetVersionType>(address);
|
||||
|
||||
OSVERSIONINFOEXW os = { sizeof(os) };
|
||||
if (!FAILED(RtlGetVersion(&os)))
|
||||
{
|
||||
Debug::Log("OS Version : ", os.dwMajorVersion, ".", os.dwMinorVersion);
|
||||
Debug::Log("Build Number : ", os.dwBuildNumber);
|
||||
Debug::Log("Service Pack : ", os.szCSDVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IUnityInterfaces* GetUnity()
|
||||
{
|
||||
return g_unity;
|
||||
@@ -37,7 +60,9 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
||||
|
||||
LUID GetUnityAdapterLuid()
|
||||
{
|
||||
const auto device = GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto device = GetDevice();
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
||||
if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgiDevice)))){
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
|
||||
|
||||
// Output windows version
|
||||
void OutputWindowsInformation();
|
||||
|
||||
// Unity interface getter
|
||||
struct IUnityInterfaces;
|
||||
IUnityInterfaces* GetUnity();
|
||||
|
||||
@@ -21,6 +21,8 @@ Cursor::~Cursor()
|
||||
|
||||
void Cursor::UpdateBuffer(Duplicator* duplicator, const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (frameInfo.LastMouseUpdateTime.QuadPart == 0)
|
||||
{
|
||||
return;
|
||||
@@ -66,6 +68,8 @@ void Cursor::UpdateTexture(
|
||||
Duplicator* duplicator,
|
||||
const ComPtr<ID3D11Texture2D>& desktopTexture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
auto monitor = duplicator->GetMonitor();
|
||||
|
||||
// Check desktop texure
|
||||
@@ -369,6 +373,8 @@ void Cursor::UpdateTexture(
|
||||
|
||||
void Cursor::Draw(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (texture == nullptr)
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => Desktop texture is null.");
|
||||
@@ -384,6 +390,8 @@ void Cursor::Draw(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture)
|
||||
|
||||
void Cursor::GetTexture(ID3D11Texture2D* texture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!bgraBuffer_)
|
||||
{
|
||||
Debug::Error("Cursor::GetTexture() => bgra32Buffer is null.");
|
||||
|
||||
@@ -39,4 +39,18 @@ void Debug::Finalize()
|
||||
}
|
||||
Debug::SetLogFunc(nullptr);
|
||||
Debug::SetErrorFunc(nullptr);
|
||||
}
|
||||
|
||||
|
||||
decltype(DebugFunctionScopedTimer::currentId) DebugFunctionScopedTimer::currentId = 0;
|
||||
|
||||
|
||||
DebugFunctionScopedTimer::DebugFunctionScopedTimer(const char* name)
|
||||
: ScopedTimer([this](std::chrono::microseconds us) {
|
||||
Debug::Log("<< [", id_, "]", name_, " : ", us.count(), "[us]");
|
||||
})
|
||||
, name_(name)
|
||||
, id_(currentId++)
|
||||
{
|
||||
Debug::Log(">> [", id_, "]", name_);
|
||||
}
|
||||
@@ -10,7 +10,9 @@
|
||||
|
||||
|
||||
// Debug flag
|
||||
#ifdef _DEBUG
|
||||
#define UDD_DEBUG_ON
|
||||
#endif
|
||||
|
||||
|
||||
// Logging
|
||||
@@ -40,12 +42,24 @@ private:
|
||||
};
|
||||
|
||||
template <class T>
|
||||
static void Output(T&& arg)
|
||||
static void Output(const T& arg)
|
||||
{
|
||||
if (mode_ == Mode::None) return;
|
||||
if (ss_.good())
|
||||
{
|
||||
ss_ << std::forward<T>(arg);
|
||||
ss_ << arg;
|
||||
}
|
||||
}
|
||||
|
||||
static void Output(const WCHAR* arg)
|
||||
{
|
||||
if (mode_ == Mode::None) return;
|
||||
if (ss_.good())
|
||||
{
|
||||
char buf[256];
|
||||
size_t size;
|
||||
wcstombs_s(&size, buf, arg, 256);
|
||||
ss_ << buf;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,10 +103,10 @@ private:
|
||||
}
|
||||
|
||||
template <class Arg, class... RestArgs>
|
||||
static void _Log(Level level, Arg&& arg, RestArgs&&... restArgs)
|
||||
static void _Log(Level level, const Arg& arg, const RestArgs&... restArgs)
|
||||
{
|
||||
Output(std::forward<Arg>(arg));
|
||||
_Log(level, std::forward<RestArgs>(restArgs)...);
|
||||
Output(arg);
|
||||
_Log(level, restArgs...);
|
||||
}
|
||||
|
||||
static void _Log(Level level)
|
||||
@@ -144,16 +158,25 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class DebugFunctionScopedTimer : public ScopedTimer
|
||||
{
|
||||
public:
|
||||
explicit DebugFunctionScopedTimer(const char* name);
|
||||
|
||||
private:
|
||||
static unsigned int currentId;
|
||||
const char* const name_;
|
||||
const unsigned int id_;
|
||||
};
|
||||
|
||||
|
||||
#ifdef UDD_DEBUG_ON
|
||||
#define UDD_FUNCTION_SCOPE_TIMER \
|
||||
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
||||
{ \
|
||||
Debug::Log(__FUNCTION__, "@", __FILE__, ":", __LINE__, " => ", us.count(), " [us]"); \
|
||||
});
|
||||
DebugFunctionScopedTimer _timer_##__COUNTER__(__FUNCTION__);
|
||||
#define UDD_SCOPE_TIMER(Name) \
|
||||
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
||||
{ \
|
||||
Debug::Log(#Name, " => ", us.count(), " [us]"); \
|
||||
Debug::Log(#Name, " : ", us.count(), " [us]"); \
|
||||
});
|
||||
#else
|
||||
#define UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
@@ -27,6 +27,8 @@ IsolatedD3D11Device::~IsolatedD3D11Device()
|
||||
|
||||
HRESULT IsolatedD3D11Device::Create(const ComPtr<IDXGIAdapter>& adapter)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto driverType = adapter ?
|
||||
D3D_DRIVER_TYPE_UNKNOWN :
|
||||
D3D_DRIVER_TYPE_HARDWARE;
|
||||
@@ -68,6 +70,8 @@ ComPtr<ID3D11Device> IsolatedD3D11Device::GetDevice()
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> IsolatedD3D11Device::GetCompatibleSharedTexture(
|
||||
const ComPtr<ID3D11Texture2D>& src)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
D3D11_TEXTURE2D_DESC srcDesc;
|
||||
src->GetDesc(&srcDesc);
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ Duplicator::~Duplicator()
|
||||
|
||||
void Duplicator::InitializeDevice()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
device_ = std::make_shared<IsolatedD3D11Device>();
|
||||
|
||||
if (FAILED(device_->Create(monitor_->GetAdapter())))
|
||||
@@ -45,6 +47,8 @@ void Duplicator::InitializeDevice()
|
||||
|
||||
void Duplicator::InitializeDuplication()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
ComPtr<IDXGIOutput1> output1;
|
||||
if (FAILED(monitor_->GetOutput().As(&output1)))
|
||||
{
|
||||
@@ -57,17 +61,7 @@ void Duplicator::InitializeDuplication()
|
||||
case S_OK:
|
||||
{
|
||||
state_ = State::Ready;
|
||||
const auto rot = static_cast<DXGI_MODE_ROTATION>(monitor_->GetRotation());
|
||||
Debug::Log("Duplicator::Initialize() => OK.");
|
||||
Debug::Log(" ID : ", monitor_->GetId());
|
||||
Debug::Log(" Size : (", monitor_->GetWidth(), ", ", monitor_->GetHeight(), ")");
|
||||
Debug::Log(" DPI : (", monitor_->GetDpiX(), ", ", monitor_->GetDpiY(), ")");
|
||||
Debug::Log(" Rot : ",
|
||||
rot == DXGI_MODE_ROTATION_IDENTITY ? "Landscape" :
|
||||
rot == DXGI_MODE_ROTATION_ROTATE90 ? "Portrait" :
|
||||
rot == DXGI_MODE_ROTATION_ROTATE180 ? "Landscape (flipped)" :
|
||||
rot == DXGI_MODE_ROTATION_ROTATE270 ? "Portrait (flipped)" :
|
||||
"Unspecified");
|
||||
break;
|
||||
}
|
||||
case E_INVALIDARG:
|
||||
@@ -117,6 +111,8 @@ void Duplicator::InitializeDuplication()
|
||||
|
||||
void Duplicator::CheckUnityAdapter()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
monitor_->GetAdapter()->GetDesc(&desc);
|
||||
|
||||
@@ -135,6 +131,8 @@ void Duplicator::CheckUnityAdapter()
|
||||
|
||||
void Duplicator::Start()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (state_ != State::Ready) return;
|
||||
|
||||
Stop();
|
||||
@@ -180,6 +178,8 @@ void Duplicator::Start()
|
||||
|
||||
void Duplicator::Stop()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
shouldRun_ = false;
|
||||
|
||||
if (thread_.joinable())
|
||||
@@ -236,6 +236,8 @@ const Duplicator::Frame& Duplicator::GetLastFrame() const
|
||||
|
||||
void Duplicator::Duplicate(UINT timeout)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!dupl_ || !device_) return;
|
||||
|
||||
Release();
|
||||
@@ -322,6 +324,8 @@ void Duplicator::Duplicate(UINT timeout)
|
||||
|
||||
void Duplicator::Release()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!isFrameAcquired_) return;
|
||||
|
||||
const auto hr = dupl_->ReleaseFrame();
|
||||
@@ -357,6 +361,8 @@ void Duplicator::UpdateCursor(
|
||||
const ComPtr<ID3D11Texture2D>& texture,
|
||||
const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
auto& manager = GetMonitorManager();
|
||||
|
||||
if (frameInfo.PointerPosition.Visible)
|
||||
@@ -375,6 +381,8 @@ void Duplicator::UpdateCursor(
|
||||
|
||||
void Duplicator::UpdateMetadata(UINT totalBufferSize)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
metaData_.buffer.ExpandIfNeeded(totalBufferSize);
|
||||
if (!metaData_.buffer.Empty())
|
||||
{
|
||||
@@ -386,6 +394,8 @@ void Duplicator::UpdateMetadata(UINT totalBufferSize)
|
||||
|
||||
void Duplicator::UpdateMoveRects()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto hr = dupl_->GetFrameMoveRects(
|
||||
metaData_.buffer.Size(),
|
||||
metaData_.buffer.As<DXGI_OUTDUPL_MOVE_RECT>(),
|
||||
@@ -428,6 +438,8 @@ void Duplicator::UpdateMoveRects()
|
||||
|
||||
void Duplicator::UpdateDirtyRects()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto hr = dupl_->GetFrameDirtyRects(
|
||||
metaData_.buffer.Size() - metaData_.moveRectSize,
|
||||
metaData_.buffer.As<RECT>(metaData_.moveRectSize /* offset */),
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
void UpdateMoveRects();
|
||||
void UpdateDirtyRects();
|
||||
|
||||
Monitor* monitor_ = nullptr;
|
||||
Monitor* const monitor_ = nullptr;
|
||||
std::atomic<State> state_ = State::Ready;
|
||||
|
||||
std::shared_ptr<class IsolatedD3D11Device> device_;
|
||||
|
||||
@@ -21,7 +21,6 @@ Monitor::Monitor(int id)
|
||||
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
duplicator_->Stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +29,8 @@ void Monitor::Initialize(
|
||||
const ComPtr<IDXGIOutput> &output
|
||||
)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
adapter_ = adapter;
|
||||
output_ = output;
|
||||
|
||||
@@ -58,18 +59,34 @@ void Monitor::Initialize(
|
||||
// DPI is set as -1, so the application has to use the appropriate value.
|
||||
}
|
||||
|
||||
const auto rot = outputDesc_.Rotation;
|
||||
Debug::Log("Monitor::Initialized() =>");
|
||||
Debug::Log(" ID : ", id_);
|
||||
Debug::Log(" Size : (", width_, ", ", height_, ")");
|
||||
Debug::Log(" DPI : (", dpiX_, ", ", dpiY_, ")");
|
||||
Debug::Log(" Rot : ",
|
||||
rot == DXGI_MODE_ROTATION_IDENTITY ? "Landscape" :
|
||||
rot == DXGI_MODE_ROTATION_ROTATE90 ? "Portrait" :
|
||||
rot == DXGI_MODE_ROTATION_ROTATE180 ? "Landscape (flipped)" :
|
||||
rot == DXGI_MODE_ROTATION_ROTATE270 ? "Portrait (flipped)" :
|
||||
"Unspecified");
|
||||
|
||||
duplicator_ = std::make_shared<Duplicator>(this);
|
||||
}
|
||||
|
||||
|
||||
void Monitor::Finalize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
StopCapture();
|
||||
}
|
||||
|
||||
|
||||
void Monitor::Render()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto& frame = duplicator_->GetLastFrame();
|
||||
|
||||
if (frame.id == lastFrameId_) return;
|
||||
@@ -122,6 +139,8 @@ void Monitor::Render()
|
||||
|
||||
void Monitor::StartCapture()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (duplicator_->GetState() == DuplicatorState::Ready)
|
||||
{
|
||||
duplicator_->Start();
|
||||
@@ -131,6 +150,8 @@ void Monitor::StartCapture()
|
||||
|
||||
void Monitor::StopCapture()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
duplicator_->Stop();
|
||||
}
|
||||
|
||||
@@ -291,6 +312,8 @@ bool Monitor::UseGetPixels() const
|
||||
|
||||
void Monitor::CopyTextureFromGpuToCpu(ID3D11Texture2D* texture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto monitorRot = static_cast<DXGI_MODE_ROTATION>(GetRotation());
|
||||
const auto monitorWidth = GetWidth();
|
||||
const auto monitorHeight = GetHeight();
|
||||
@@ -356,6 +379,8 @@ void Monitor::CopyTextureFromGpuToCpu(ID3D11Texture2D* texture)
|
||||
|
||||
bool Monitor::GetPixels(BYTE* output, int x, int y, int width, int height)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!UseGetPixels())
|
||||
{
|
||||
Debug::Error("Monitor::GetPixels() => UseGetPixels(true) must have been called when you want to use GetPixels().");
|
||||
|
||||
@@ -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,23 +18,20 @@ using namespace Microsoft::WRL;
|
||||
|
||||
|
||||
|
||||
MonitorManager::MonitorManager(LUID unityAdapterLuid)
|
||||
: unityAdapterLuid_(unityAdapterLuid)
|
||||
MonitorManager::MonitorManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MonitorManager::~MonitorManager()
|
||||
{
|
||||
Finalize();
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::Initialize()
|
||||
{
|
||||
Finalize();
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
// Get factory
|
||||
ComPtr<IDXGIFactory1> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||
{
|
||||
@@ -42,27 +39,40 @@ void MonitorManager::Initialize()
|
||||
return;
|
||||
}
|
||||
|
||||
// Check all display adapters
|
||||
int id = 0;
|
||||
std::vector<std::pair<ComPtr<IDXGIAdapter1>, ComPtr<IDXGIOutput>>> outputs;
|
||||
|
||||
ComPtr<IDXGIAdapter1> adapter;
|
||||
for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i)
|
||||
{
|
||||
// Search the main monitor from all outputs
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
if (FAILED(adapter->GetDesc(&desc))) continue;
|
||||
Debug::Log("Graphics Card [", i, "] : ", desc.Description);
|
||||
|
||||
ComPtr<IDXGIOutput> output;
|
||||
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);
|
||||
DXGI_OUTPUT_DESC desc;
|
||||
if (FAILED(output->GetDesc(&desc))) continue;
|
||||
Debug::Log(" > Monitor[", j, "] : ", desc.DeviceName);
|
||||
outputs.emplace_back(adapter, output);
|
||||
}
|
||||
}
|
||||
|
||||
for (int id = 0; id < static_cast<int>(outputs.size()); ++id)
|
||||
{
|
||||
const auto& pair = outputs.at(id);
|
||||
auto monitor = std::make_shared<Monitor>(id);
|
||||
monitor->Initialize(pair.first, pair.second);
|
||||
monitor->StartCapture();
|
||||
monitors_.push_back(monitor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::Finalize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
for (const auto& monitor : monitors_)
|
||||
{
|
||||
monitor->Finalize();
|
||||
@@ -74,6 +84,8 @@ void MonitorManager::Finalize()
|
||||
|
||||
void MonitorManager::Update()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (isReinitializationRequired_)
|
||||
{
|
||||
Reinitialize();
|
||||
@@ -91,7 +103,10 @@ void MonitorManager::RequireReinitilization()
|
||||
|
||||
void MonitorManager::Reinitialize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
Debug::Log("MonitorManager::Reinitialize()");
|
||||
Finalize();
|
||||
Initialize();
|
||||
SendMessageToUnity(Message::Reinitialized);
|
||||
}
|
||||
@@ -99,6 +114,8 @@ void MonitorManager::Reinitialize()
|
||||
|
||||
bool MonitorManager::HasMonitorCountChanged() const
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
ComPtr<IDXGIFactory1> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||
{
|
||||
|
||||
@@ -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,24 @@ 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);
|
||||
OutputWindowsInformation();
|
||||
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