add logs.
This commit is contained in:
Binary file not shown.
@@ -29,6 +29,14 @@ public class UddSceneManager : MonoBehaviour
|
|||||||
} else if (Input.GetKeyDown(KeyCode.LeftArrow)) {
|
} else if (Input.GetKeyDown(KeyCode.LeftArrow)) {
|
||||||
Prev();
|
Prev();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.R) && (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) {
|
||||||
|
uDesktopDuplication.Manager.instance.Reinitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKeyDown(KeyCode.Escape)) {
|
||||||
|
Application.Quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Next()
|
void Next()
|
||||||
@@ -45,6 +53,6 @@ public class UddSceneManager : MonoBehaviour
|
|||||||
|
|
||||||
void Load()
|
void Load()
|
||||||
{
|
{
|
||||||
SceneManager.LoadScene(scenes[sceneNo]);
|
SceneManager.LoadScene(scenes[Mathf.Clamp(sceneNo, 0, scenes.Length - 1)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -9,6 +9,7 @@ public enum Message
|
|||||||
{
|
{
|
||||||
None = -1,
|
None = -1,
|
||||||
Reinitialized = 0,
|
Reinitialized = 0,
|
||||||
|
TextureSizeChanged = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CursorShapeType
|
public enum CursorShapeType
|
||||||
@@ -36,7 +37,8 @@ public enum MonitorState
|
|||||||
Unsupported = 3,
|
Unsupported = 3,
|
||||||
CurrentlyNotAvailable = 4,
|
CurrentlyNotAvailable = 4,
|
||||||
SessionDisconnected = 5,
|
SessionDisconnected = 5,
|
||||||
AccessLost = 6,
|
AccessLost = 6,
|
||||||
|
TextureSizeInconsistent = 7,
|
||||||
Unknown = 999,
|
Unknown = 999,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
@@ -113,7 +112,7 @@ public class Manager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ContextMenu("Reinitialize")]
|
[ContextMenu("Reinitialize")]
|
||||||
void Reinitialize()
|
public void Reinitialize()
|
||||||
{
|
{
|
||||||
Debug.Log("[uDD] Reinitialize");
|
Debug.Log("[uDD] Reinitialize");
|
||||||
Lib.Reinitialize();
|
Lib.Reinitialize();
|
||||||
@@ -152,10 +151,14 @@ public class Manager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
var message = Lib.PopMessage();
|
var message = Lib.PopMessage();
|
||||||
while (message != Message.None) {
|
while (message != Message.None) {
|
||||||
|
Debug.Log("[uDD] " + message);
|
||||||
switch (message) {
|
switch (message) {
|
||||||
case Message.Reinitialized:
|
case Message.Reinitialized:
|
||||||
ReinitializeMonitors();
|
ReinitializeMonitors();
|
||||||
break;
|
break;
|
||||||
|
case Message.TextureSizeChanged:
|
||||||
|
RecreateTextures();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -195,15 +198,11 @@ public class Manager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitThenDo(System.Action func, float sec)
|
void RecreateTextures()
|
||||||
{
|
{
|
||||||
StartCoroutine(_WaitThenDo(func, sec));
|
for (int i = 0; i < monitorCount; ++i) {
|
||||||
}
|
monitors[i].CreateTexture();
|
||||||
|
}
|
||||||
IEnumerator _WaitThenDo(System.Action func, float sec)
|
|
||||||
{
|
|
||||||
yield return new WaitForSeconds(sec);
|
|
||||||
func();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
@@ -204,13 +203,17 @@ public class Monitor
|
|||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Texture2D errorTexture_;
|
||||||
|
private static readonly string errorTexturePath = "uDesktopDuplication/Textures/NotAvailable";
|
||||||
|
|
||||||
private Texture2D texture_;
|
private Texture2D texture_;
|
||||||
public Texture2D texture
|
public Texture2D texture
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!available) {
|
if (!available) {
|
||||||
return Resources.Load<Texture2D>("uDesktopDuplication/Textures/NotAvailable");
|
return errorTexture_ ??
|
||||||
|
(errorTexture_ = Resources.Load<Texture2D>(errorTexturePath));
|
||||||
}
|
}
|
||||||
if (texture_ == null) {
|
if (texture_ == null) {
|
||||||
CreateTexture();
|
CreateTexture();
|
||||||
@@ -242,7 +245,10 @@ public class Monitor
|
|||||||
|
|
||||||
if (texture_) {
|
if (texture_) {
|
||||||
if (texture_.width != w || texture_.height != h) {
|
if (texture_.width != w || texture_.height != h) {
|
||||||
if (texture_) Object.DestroyImmediate(texture_);
|
if (texture_) {
|
||||||
|
Object.Destroy(texture_);
|
||||||
|
texture_ = null;
|
||||||
|
}
|
||||||
shouldCreate = true;
|
shouldCreate = true;
|
||||||
} else {
|
} else {
|
||||||
shouldCreate = false;
|
shouldCreate = false;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
@@ -25,6 +26,17 @@ public static class Utility
|
|||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void WaitThenDo(System.Action func, float sec)
|
||||||
|
{
|
||||||
|
Manager.instance.StartCoroutine(_WaitThenDo(func, sec));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerator _WaitThenDo(System.Action func, float sec)
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(sec);
|
||||||
|
func();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <unordered_map>
|
|
||||||
#include <iostream>
|
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
|
||||||
#include "IUnityInterface.h"
|
#include "IUnityInterface.h"
|
||||||
#include "IUnityGraphicsD3D11.h"
|
#include "IUnityGraphicsD3D11.h"
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
|
using namespace Microsoft::WRL;
|
||||||
|
|
||||||
|
|
||||||
extern IUnityInterfaces* g_unity;
|
extern IUnityInterfaces* g_unity;
|
||||||
extern std::unique_ptr<MonitorManager> g_manager;
|
extern std::unique_ptr<MonitorManager> g_manager;
|
||||||
@@ -21,7 +21,7 @@ IUnityInterfaces* GetUnity()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ID3D11Device* GetDevice()
|
ComPtr<ID3D11Device> GetDevice()
|
||||||
{
|
{
|
||||||
return GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
return GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <wrl/client.h>
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
|
|
||||||
// Unity interface and ID3D11Device getters
|
// Unity interface and ID3D11Device getters
|
||||||
@@ -10,7 +9,7 @@ struct IUnityInterfaces;
|
|||||||
IUnityInterfaces* GetUnity();
|
IUnityInterfaces* GetUnity();
|
||||||
|
|
||||||
struct ID3D11Device;
|
struct ID3D11Device;
|
||||||
ID3D11Device* GetDevice();
|
Microsoft::WRL::ComPtr<ID3D11Device> GetDevice();
|
||||||
|
|
||||||
|
|
||||||
// Manager getter
|
// Manager getter
|
||||||
@@ -23,6 +22,7 @@ enum class Message
|
|||||||
{
|
{
|
||||||
None = -1,
|
None = -1,
|
||||||
Reinitialized = 0,
|
Reinitialized = 0,
|
||||||
|
TextureSizeChanged = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
void SendMessageToUnity(Message message);
|
void SendMessageToUnity(Message message);
|
||||||
@@ -58,13 +58,12 @@ void Cursor::UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
|||||||
// Get mouse pointer information
|
// Get mouse pointer information
|
||||||
UINT bufferSize;
|
UINT bufferSize;
|
||||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo;
|
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo;
|
||||||
const auto hr = monitor_->GetDeskDupl()->GetFramePointerShape(
|
if (FAILED(
|
||||||
apiBufferSize_,
|
monitor_->GetDeskDupl()->GetFramePointerShape(
|
||||||
reinterpret_cast<void*>(apiBuffer_.get()),
|
apiBufferSize_,
|
||||||
&bufferSize,
|
reinterpret_cast<void*>(apiBuffer_.get()),
|
||||||
&shapeInfo);
|
&bufferSize,
|
||||||
|
&shapeInfo)))
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
Debug::Error("Cursor::UpdateBuffer() => GetFramePointerShape() failed.");
|
Debug::Error("Cursor::UpdateBuffer() => GetFramePointerShape() failed.");
|
||||||
apiBuffer_.reset();
|
apiBuffer_.reset();
|
||||||
@@ -105,8 +104,6 @@ void Cursor::UpdateTexture()
|
|||||||
// If masked, copy the desktop image and merge it with masked image.
|
// If masked, copy the desktop image and merge it with masked image.
|
||||||
if (isMono || isColorMask)
|
if (isMono || isColorMask)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
const auto mw = monitor_->GetWidth();
|
const auto mw = monitor_->GetWidth();
|
||||||
const auto mh = monitor_->GetHeight();
|
const auto mh = monitor_->GetHeight();
|
||||||
auto x = x_;
|
auto x = x_;
|
||||||
@@ -153,8 +150,7 @@ void Cursor::UpdateTexture()
|
|||||||
desc.MiscFlags = 0;
|
desc.MiscFlags = 0;
|
||||||
|
|
||||||
ComPtr<ID3D11Texture2D> texture;
|
ComPtr<ID3D11Texture2D> texture;
|
||||||
hr = GetDevice()->CreateTexture2D(&desc, nullptr, &texture);
|
if (FAILED(GetDevice()->CreateTexture2D(&desc, nullptr, &texture)))
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
Debug::Error("Cursor::UpdateTexture() => GetDevice()->CreateTexture2D() failed.");
|
Debug::Error("Cursor::UpdateTexture() => GetDevice()->CreateTexture2D() failed.");
|
||||||
return;
|
return;
|
||||||
@@ -174,23 +170,19 @@ void Cursor::UpdateTexture()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
ComPtr<ID3D11DeviceContext> context;
|
||||||
ComPtr<ID3D11DeviceContext> context;
|
GetDevice()->GetImmediateContext(&context);
|
||||||
GetDevice()->GetImmediateContext(&context);
|
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, monitor_->GetUnityTexture(), 0, &box);
|
||||||
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, monitor_->GetUnityTexture(), 0, &box);
|
|
||||||
}
|
|
||||||
|
|
||||||
ComPtr<IDXGISurface> surface;
|
ComPtr<IDXGISurface> surface;
|
||||||
hr = texture.As<IDXGISurface>(&surface);
|
if (FAILED(texture.As<IDXGISurface>(&surface)))
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
Debug::Error("Cursor::UpdateTexture() => texture->QueryInterface() failed.");
|
Debug::Error("Cursor::UpdateTexture() => texture->QueryInterface() failed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGI_MAPPED_RECT mappedSurface;
|
DXGI_MAPPED_RECT mappedSurface;
|
||||||
hr = surface->Map(&mappedSurface, DXGI_MAP_READ);
|
if (FAILED(surface->Map(&mappedSurface, DXGI_MAP_READ)))
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
Debug::Error("Cursor::UpdateTexture() => surface->Map() failed.");
|
Debug::Error("Cursor::UpdateTexture() => surface->Map() failed.");
|
||||||
return;
|
return;
|
||||||
@@ -243,8 +235,7 @@ void Cursor::UpdateTexture()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = surface->Unmap();
|
if (FAILED(surface->Unmap()))
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,4 +28,6 @@ void Debug::Finalize()
|
|||||||
Debug::Log("Stop");
|
Debug::Log("Stop");
|
||||||
fs_.close();
|
fs_.close();
|
||||||
}
|
}
|
||||||
|
Debug::SetLogFunc(nullptr);
|
||||||
|
Debug::SetErrorFunc(nullptr);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <time.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "IUnityInterface.h"
|
#include "IUnityInterface.h"
|
||||||
@@ -86,18 +87,34 @@ private:
|
|||||||
Flush(level);
|
Flush(level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void OutputTime()
|
||||||
|
{
|
||||||
|
auto t = time(nullptr);
|
||||||
|
tm tm;
|
||||||
|
localtime_s(&tm, &t);
|
||||||
|
char buf[64];
|
||||||
|
strftime(buf, 64, "%F %T", &tm);
|
||||||
|
Output("[");;
|
||||||
|
Output(buf);
|
||||||
|
Output("]");
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
template <class Arg, class... RestArgs>
|
template <class Arg, class... RestArgs>
|
||||||
static void Log(Arg&& arg, RestArgs&&... restArgs)
|
static void Log(Arg&& arg, RestArgs&&... restArgs)
|
||||||
{
|
{
|
||||||
Output("[uDD::Log] ");
|
Output("[uDD::Log]");
|
||||||
|
OutputTime();
|
||||||
|
Output(" ");
|
||||||
_Log(Level::Log, std::forward<Arg>(arg), std::forward<RestArgs>(restArgs)...);
|
_Log(Level::Log, std::forward<Arg>(arg), std::forward<RestArgs>(restArgs)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Arg, class... RestArgs>
|
template <class Arg, class... RestArgs>
|
||||||
static void Error(Arg&& arg, RestArgs&&... restArgs)
|
static void Error(Arg&& arg, RestArgs&&... restArgs)
|
||||||
{
|
{
|
||||||
Output("[uDD::Err] ");
|
Output("[uDD::Err]");
|
||||||
|
OutputTime();
|
||||||
|
Output(" ");
|
||||||
_Log(Level::Error, std::forward<Arg>(arg), std::forward<RestArgs>(restArgs)...);
|
_Log(Level::Error, std::forward<Arg>(arg), std::forward<RestArgs>(restArgs)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,54 +23,84 @@ Monitor::~Monitor()
|
|||||||
|
|
||||||
void Monitor::Initialize(IDXGIOutput* output)
|
void Monitor::Initialize(IDXGIOutput* output)
|
||||||
{
|
{
|
||||||
output->GetDesc(&outputDesc_);
|
if (FAILED(output->GetDesc(&outputDesc_)))
|
||||||
monitorInfo_.cbSize = sizeof(MONITORINFOEX);
|
{
|
||||||
GetMonitorInfo(outputDesc_.Monitor, &monitorInfo_);
|
Debug::Error("Monitor::Initialize() => IDXGIOutput::GetDesc() failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
GetDpiForMonitor(outputDesc_.Monitor, MDT_RAW_DPI, &dpiX_, &dpiY_);
|
monitorInfo_.cbSize = sizeof(MONITORINFOEX);
|
||||||
|
if (!GetMonitorInfo(outputDesc_.Monitor, &monitorInfo_))
|
||||||
|
{
|
||||||
|
Debug::Error("Monitor::Initialize() => GetMonitorInfo() failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto rect = monitorInfo_.rcMonitor;
|
||||||
|
width_ = rect.right - rect.left;
|
||||||
|
height_ = rect.bottom - rect.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(GetDpiForMonitor(outputDesc_.Monitor, MDT_RAW_DPI, &dpiX_, &dpiY_)))
|
||||||
|
{
|
||||||
|
Debug::Error("Monitor::Initialize() => GetDpiForMonitor() failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);
|
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);
|
||||||
const auto hr = output1->DuplicateOutput(GetDevice(), &deskDupl_);
|
switch (output1->DuplicateOutput(GetDevice().Get(), &deskDupl_))
|
||||||
|
|
||||||
// TODO: error check
|
|
||||||
switch (hr)
|
|
||||||
{
|
{
|
||||||
case S_OK:
|
case S_OK:
|
||||||
state_ = State::Available;
|
{
|
||||||
Debug::Log("Monitor::Initialize() => OK.");
|
state_ = State::Available;
|
||||||
Debug::Log(" ID : ", GetId());
|
Debug::Log("Monitor::Initialize() => OK.");
|
||||||
Debug::Log(" Size : (", GetWidth(), ", ", GetHeight(), ")");
|
Debug::Log(" ID : ", GetId());
|
||||||
Debug::Log(" DPI : (", GetDpiX(), ", ", GetDpiY(), ")");
|
Debug::Log(" Size : (", GetWidth(), ", ", GetHeight(), ")");
|
||||||
break;
|
Debug::Log(" DPI : (", GetDpiX(), ", ", GetDpiY(), ")");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case E_INVALIDARG:
|
case E_INVALIDARG:
|
||||||
state_ = State::InvalidArg;
|
{
|
||||||
Debug::Error("Monitor::Initialize() => Invalid arguments.");
|
state_ = State::InvalidArg;
|
||||||
break;
|
Debug::Error("Monitor::Initialize() => Invalid arguments.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case E_ACCESSDENIED:
|
case E_ACCESSDENIED:
|
||||||
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
{
|
||||||
// switches to admin screen, this error occurs.
|
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
||||||
state_ = State::AccessDenied;
|
// switches to admin screen, this error occurs.
|
||||||
Debug::Error("Monitor::Initialize() => Access denied.");
|
state_ = State::AccessDenied;
|
||||||
break;
|
Debug::Error("Monitor::Initialize() => Access denied.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DXGI_ERROR_UNSUPPORTED:
|
case DXGI_ERROR_UNSUPPORTED:
|
||||||
// If the display adapter on the computer is running under the Microsoft Hybrid system,
|
{
|
||||||
// this error occurs.
|
// If the display adapter on the computer is running under the Microsoft Hybrid system,
|
||||||
state_ = State::Unsupported;
|
// this error occurs.
|
||||||
Debug::Error("Monitor::Initialize() => Unsupported display.");
|
state_ = State::Unsupported;
|
||||||
break;
|
Debug::Error("Monitor::Initialize() => Unsupported display.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
||||||
// When other application use Desktop Duplication API, this error occurs.
|
{
|
||||||
state_ = State::CurrentlyNotAvailable;
|
// When other application use Desktop Duplication API, this error occurs.
|
||||||
Debug::Error("Monitor::Initialize() => Currently not available.");
|
state_ = State::CurrentlyNotAvailable;
|
||||||
break;
|
Debug::Error("Monitor::Initialize() => Currently not available.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DXGI_ERROR_SESSION_DISCONNECTED:
|
case DXGI_ERROR_SESSION_DISCONNECTED:
|
||||||
|
{
|
||||||
state_ = State::SessionDisconnected;
|
state_ = State::SessionDisconnected;
|
||||||
Debug::Error("Monitor::Initialize() => Session disconnected.");
|
Debug::Error("Monitor::Initialize() => Session disconnected.");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
state_ = State::Unknown;
|
{
|
||||||
Debug::Error("Monitor::Render() => Unknown Error.");
|
state_ = State::Unknown;
|
||||||
break;
|
Debug::Error("Monitor::Render() => Unknown Error.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,9 +111,8 @@ void Monitor::Render(UINT timeout)
|
|||||||
|
|
||||||
ComPtr<IDXGIResource> resource;
|
ComPtr<IDXGIResource> resource;
|
||||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
hr = deskDupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
|
const auto hr = deskDupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
{
|
{
|
||||||
switch (hr)
|
switch (hr)
|
||||||
@@ -115,17 +144,26 @@ void Monitor::Render(UINT timeout)
|
|||||||
if (unityTexture_)
|
if (unityTexture_)
|
||||||
{
|
{
|
||||||
ComPtr<ID3D11Texture2D> texture;
|
ComPtr<ID3D11Texture2D> texture;
|
||||||
resource.As<ID3D11Texture2D>(&texture);
|
if (FAILED(resource.As<ID3D11Texture2D>(&texture)))
|
||||||
|
{
|
||||||
|
Debug::Error("Monitor::Render() => resource.As() failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
D3D11_TEXTURE2D_DESC srcDesc, dstDesc;
|
D3D11_TEXTURE2D_DESC srcDesc, dstDesc;
|
||||||
texture->GetDesc(&srcDesc);
|
texture->GetDesc(&srcDesc);
|
||||||
texture->GetDesc(&dstDesc);
|
unityTexture_->GetDesc(&dstDesc);
|
||||||
if (srcDesc.Width != dstDesc.Width ||
|
if (srcDesc.Width != dstDesc.Width ||
|
||||||
srcDesc.Height != dstDesc.Height)
|
srcDesc.Height != dstDesc.Height)
|
||||||
{
|
{
|
||||||
Debug::Error("Monitor::Render() => Texture sizes are defferent.");
|
Debug::Error("Monitor::Render() => Texture sizes are defferent.");
|
||||||
Debug::Error(" Source : (", srcDesc.Width, ", ", srcDesc.Height, ")");
|
Debug::Error(" Source : (", srcDesc.Width, ", ", srcDesc.Height, ")");
|
||||||
Debug::Error(" Dest : (", dstDesc.Width, ", ", dstDesc.Height, ")");
|
Debug::Error(" Dest : (", dstDesc.Width, ", ", dstDesc.Height, ")");
|
||||||
|
Debug::Log(" => Try modifying width/height using reported value from DDA.");
|
||||||
|
width_ = srcDesc.Width;
|
||||||
|
height_ = srcDesc.Height;
|
||||||
|
state_ = MonitorState::TextureSizeInconsistent;
|
||||||
|
SendMessageToUnity(Message::TextureSizeChanged);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -138,8 +176,7 @@ void Monitor::Render(UINT timeout)
|
|||||||
cursor_->UpdateBuffer(frameInfo);
|
cursor_->UpdateBuffer(frameInfo);
|
||||||
cursor_->UpdateTexture();
|
cursor_->UpdateTexture();
|
||||||
|
|
||||||
hr = deskDupl_->ReleaseFrame();
|
if (FAILED(deskDupl_->ReleaseFrame()))
|
||||||
if (FAILED(hr))
|
|
||||||
{
|
{
|
||||||
Debug::Error("Monitor::Render() => ReleaseFrame() failed.");
|
Debug::Error("Monitor::Render() => ReleaseFrame() failed.");
|
||||||
}
|
}
|
||||||
@@ -244,13 +281,11 @@ int Monitor::GetDpiY() const
|
|||||||
|
|
||||||
int Monitor::GetWidth() const
|
int Monitor::GetWidth() const
|
||||||
{
|
{
|
||||||
const auto rect = monitorInfo_.rcMonitor;
|
return width_;
|
||||||
return rect.right - rect.left;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Monitor::GetHeight() const
|
int Monitor::GetHeight() const
|
||||||
{
|
{
|
||||||
const auto rect = monitorInfo_.rcMonitor;
|
return height_;
|
||||||
return rect.bottom - rect.top;
|
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ enum class MonitorState
|
|||||||
CurrentlyNotAvailable = 4,
|
CurrentlyNotAvailable = 4,
|
||||||
SessionDisconnected = 5,
|
SessionDisconnected = 5,
|
||||||
AccessLost = 6,
|
AccessLost = 6,
|
||||||
|
TextureSizeInconsistent = 7,
|
||||||
Unknown = 999,
|
Unknown = 999,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
int id_ = -1;
|
int id_ = -1;
|
||||||
UINT dpiX_ = -1, dpiY_ = -1;
|
UINT dpiX_ = -1, dpiY_ = -1;
|
||||||
|
int width_ = -1, height_ = -1;
|
||||||
State state_ = State::NotSet;
|
State state_ = State::NotSet;
|
||||||
std::unique_ptr<Cursor> cursor_;
|
std::unique_ptr<Cursor> cursor_;
|
||||||
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> deskDupl_;
|
Microsoft::WRL::ComPtr<IDXGIOutputDuplication> deskDupl_;
|
||||||
|
|||||||
@@ -33,17 +33,22 @@ void MonitorManager::Initialize()
|
|||||||
{
|
{
|
||||||
Finalize();
|
Finalize();
|
||||||
|
|
||||||
// Get factory
|
|
||||||
ComPtr<IDXGIFactory1> factory;
|
ComPtr<IDXGIFactory1> factory;
|
||||||
CreateDXGIFactory1(IID_PPV_ARGS(&factory));
|
ComPtr<IDXGIAdapter1> adapter;
|
||||||
|
ComPtr<IDXGIOutput> output;
|
||||||
|
|
||||||
|
// Get factory
|
||||||
|
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||||
|
{
|
||||||
|
Debug::Error("MonitorManager::Initialize() => CreateDXGIFactory1() failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check all display adapters
|
// Check all display adapters
|
||||||
int id = 0;
|
int id = 0;
|
||||||
ComPtr<IDXGIAdapter1> adapter;
|
|
||||||
for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i)
|
for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i)
|
||||||
{
|
{
|
||||||
// Search the main monitor from all outputs
|
// Search the main monitor from all outputs
|
||||||
ComPtr<IDXGIOutput> output;
|
|
||||||
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++);
|
||||||
@@ -77,13 +82,18 @@ void MonitorManager::Reinitialize()
|
|||||||
void MonitorManager::CheckMonitorNumbers()
|
void MonitorManager::CheckMonitorNumbers()
|
||||||
{
|
{
|
||||||
ComPtr<IDXGIFactory1> factory;
|
ComPtr<IDXGIFactory1> factory;
|
||||||
CreateDXGIFactory1(IID_PPV_ARGS(&factory));
|
ComPtr<IDXGIAdapter1> adapter;
|
||||||
|
ComPtr<IDXGIOutput> output;
|
||||||
|
|
||||||
|
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||||
|
{
|
||||||
|
Debug::Error("MonitorManager::CheckMonitorNumbers() => CreateDXGIFactory1() failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int id = 0;
|
int id = 0;
|
||||||
ComPtr<IDXGIAdapter1> adapter;
|
|
||||||
for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i)
|
for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i)
|
||||||
{
|
{
|
||||||
ComPtr<IDXGIOutput> output;
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
id++;
|
id++;
|
||||||
@@ -92,7 +102,6 @@ void MonitorManager::CheckMonitorNumbers()
|
|||||||
|
|
||||||
if (GetMonitorCount() != id)
|
if (GetMonitorCount() != id)
|
||||||
{
|
{
|
||||||
Debug::Log("Monitor number changed: ", GetMonitorCount(), " => ", id);
|
|
||||||
RequireReinitilization();
|
RequireReinitilization();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ extern "C"
|
|||||||
std::queue<Message> empty;
|
std::queue<Message> empty;
|
||||||
g_messages.swap(empty);
|
g_messages.swap(empty);
|
||||||
|
|
||||||
Debug::SetLogFunc(nullptr);
|
|
||||||
Debug::SetErrorFunc(nullptr);
|
|
||||||
Debug::Finalize();
|
Debug::Finalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
|||||||
m_EditorVersion: 5.4.1f1
|
m_EditorVersion: 5.4.2f2
|
||||||
m_StandardAssetsVersion: 0
|
m_StandardAssetsVersion: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user