remove useThread flag #10
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "IUnityInterface.h"
|
||||
#include "IUnityGraphicsD3D11.h"
|
||||
#include "Common.h"
|
||||
#include "Debug.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
@@ -33,6 +34,29 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
||||
}
|
||||
|
||||
|
||||
LUID GetUnityAdapterLuid()
|
||||
{
|
||||
const auto device = GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
||||
if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgiDevice)))){
|
||||
Debug::Error("QueryInterface from IUnityGraphicsD3D11 to IDXGIDevice1 failed.");
|
||||
return LUID();
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
if (FAILED(dxgiDevice->GetAdapter(&dxgiAdapter))) {
|
||||
Debug::Error("QueryInterface from IDXGIDevice1 to IDXGIAdapter failed.");
|
||||
return LUID();
|
||||
}
|
||||
|
||||
DXGI_ADAPTER_DESC adapterDesc;
|
||||
dxgiAdapter->GetDesc(&adapterDesc);
|
||||
|
||||
return adapterDesc.AdapterLuid;
|
||||
}
|
||||
|
||||
|
||||
void SendMessageToUnity(Message message)
|
||||
{
|
||||
g_messages.push(message);
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <wrl/client.h>
|
||||
|
||||
|
||||
// Unity interface and ID3D11Device getters
|
||||
// Unity interface getter
|
||||
struct IUnityInterfaces;
|
||||
IUnityInterfaces* GetUnity();
|
||||
|
||||
// ID3D11Device (in Unity) getter
|
||||
struct ID3D11Device;
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> GetDevice();
|
||||
|
||||
|
||||
// Manager getter
|
||||
class MonitorManager;
|
||||
const std::unique_ptr<MonitorManager>& GetMonitorManager();
|
||||
|
||||
// Get adapter LUID to check the adapter of the monitor is same as Unity one.
|
||||
LUID GetUnityAdapterLuid();
|
||||
|
||||
|
||||
// Message is pooled and fetch from Unity.
|
||||
enum class Message
|
||||
|
||||
@@ -29,7 +29,7 @@ MonitorManager::~MonitorManager()
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::Initialize(LUID unityAdapterLuid, bool useThread)
|
||||
void MonitorManager::Initialize()
|
||||
{
|
||||
Finalize();
|
||||
|
||||
@@ -54,15 +54,11 @@ void MonitorManager::Initialize(LUID unityAdapterLuid, bool useThread)
|
||||
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
|
||||
{
|
||||
auto monitor = std::make_shared<Monitor>(id++);
|
||||
if (useThread) {
|
||||
monitor->InitializeThreaded(adapter
|
||||
, desc.AdapterLuid.HighPart == unityAdapterLuid.HighPart
|
||||
&& desc.AdapterLuid.LowPart == unityAdapterLuid.LowPart
|
||||
, output);
|
||||
}
|
||||
else {
|
||||
monitor->Initialize(output.Get());
|
||||
}
|
||||
const auto unityAdapterLuid = GetUnityAdapterLuid();
|
||||
monitor->InitializeThreaded(adapter
|
||||
, desc.AdapterLuid.HighPart == unityAdapterLuid.HighPart
|
||||
&& desc.AdapterLuid.LowPart == unityAdapterLuid.LowPart
|
||||
, output);
|
||||
monitors_.push_back(monitor);
|
||||
}
|
||||
}
|
||||
@@ -81,9 +77,8 @@ void MonitorManager::RequireReinitilization()
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::Reinitialize(bool useThread)
|
||||
void MonitorManager::Reinitialize()
|
||||
{
|
||||
useThread_ = useThread;
|
||||
Debug::Log("MonitorManager::Reinitialize()");
|
||||
Initialize();
|
||||
SendMessageToUnity(Message::Reinitialized);
|
||||
@@ -137,7 +132,7 @@ void MonitorManager::Update()
|
||||
{
|
||||
if (isReinitializationRequired_)
|
||||
{
|
||||
Reinitialize(useThread_);
|
||||
Reinitialize();
|
||||
isReinitializationRequired_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class MonitorManager
|
||||
public:
|
||||
explicit MonitorManager(LUID unityAdapterLuid_);
|
||||
~MonitorManager();
|
||||
void Reinitialize(bool useThread);
|
||||
void Reinitialize();
|
||||
bool HasMonitorCountChanged() const;
|
||||
void RequireReinitilization();
|
||||
void SetCursorMonitorId(int id) { cursorMonitorId_ = id; }
|
||||
@@ -24,8 +24,7 @@ public:
|
||||
std::shared_ptr<Cursor> GetCursor() const;
|
||||
|
||||
private:
|
||||
void Initialize(){ Initialize(unityAdapterLuid_, useThread_); }
|
||||
void Initialize(LUID unityAdapterLuid, bool useThread);
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
|
||||
// Setters from Unity
|
||||
@@ -39,11 +38,9 @@ public:
|
||||
int GetMonitorCount() const;
|
||||
int GetTotalWidth() const;
|
||||
int GetTotalHeight() const;
|
||||
bool UseThread()const { return useThread_; }
|
||||
|
||||
private:
|
||||
LUID unityAdapterLuid_;
|
||||
bool useThread_ = false;
|
||||
|
||||
int timeout_ = 10;
|
||||
bool enableTextureCopyFromGpuToCpu_ = false;
|
||||
|
||||
@@ -106,12 +106,7 @@ extern "C"
|
||||
if (!g_manager) return;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
if (g_manager->UseThread()) {
|
||||
monitor->CopyTextureFromThread();
|
||||
}
|
||||
else {
|
||||
monitor->Render(g_manager->GetTimeout());
|
||||
}
|
||||
monitor->CopyTextureFromThread();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +115,10 @@ extern "C"
|
||||
return OnRenderEvent;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Reinitialize(int useThread)
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Reinitialize()
|
||||
{
|
||||
if (!g_manager) return;
|
||||
return g_manager->Reinitialize(useThread);
|
||||
return g_manager->Reinitialize();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Update()
|
||||
|
||||
Reference in New Issue
Block a user