diff --git a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs index d960bb0..184493e 100644 --- a/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs +++ b/Assets/uDesktopDuplication/Examples/Scripts/MultipleMonitorCreator.cs @@ -9,6 +9,8 @@ public class MultipleMonitorCreator : MonoBehaviour void Start() { var monitors = uDesktopDuplication.Manager.monitors; + monitors.Sort((a, b) => a.left - b.left); + var n = monitors.Count; var totalWidth = 0f; @@ -24,6 +26,7 @@ public class MultipleMonitorCreator : MonoBehaviour totalWidth += width * scaleX; } + totalWidth += margin * (n - 1); var x = -totalWidth / 2; for (int i = 0 ; i < n; ++i) { diff --git a/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll b/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll index 80e7005..dd700b5 100644 Binary files a/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll and b/Assets/uDesktopDuplication/Plugins/uDesktopDuplication.dll differ diff --git a/Assets/uDesktopDuplication/Scripts/Lib.cs b/Assets/uDesktopDuplication/Scripts/Lib.cs index be67491..149dd5a 100644 --- a/Assets/uDesktopDuplication/Scripts/Lib.cs +++ b/Assets/uDesktopDuplication/Scripts/Lib.cs @@ -18,6 +18,15 @@ public enum CursorShapeType MaskedColor = 4, } +public enum MonitorRotation +{ + Unspecified = 0, + Identity = 1, + Rotate90 = 2, + Rotate180 = 3, + Rotate270 = 4 +} + public static class Lib { public delegate void MessageHandler(Message message); @@ -33,16 +42,30 @@ public static class Lib [DllImport("uDesktopDuplication")] public static extern int GetMonitorCount(); [DllImport("uDesktopDuplication")] + public static extern int GetTotalWidth(); + [DllImport("uDesktopDuplication")] + public static extern int GetTotalHeight(); + [DllImport("uDesktopDuplication")] public static extern void SetTimeout(int timeout); [DllImport("uDesktopDuplication")] public static extern IntPtr GetRenderEventFunc(); [DllImport("uDesktopDuplication")] public static extern void GetName(int id, StringBuilder buf, int len); [DllImport("uDesktopDuplication")] + public static extern int GetLeft(int id); + [DllImport("uDesktopDuplication")] + public static extern int GetRight(int id); + [DllImport("uDesktopDuplication")] + public static extern int GetTop(int id); + [DllImport("uDesktopDuplication")] + public static extern int GetBottom(int id); + [DllImport("uDesktopDuplication")] public static extern int GetWidth(int id); [DllImport("uDesktopDuplication")] public static extern int GetHeight(int id); [DllImport("uDesktopDuplication")] + public static extern MonitorRotation GetRotation(int id); + [DllImport("uDesktopDuplication")] public static extern bool IsPrimary(int id); [DllImport("uDesktopDuplication")] public static extern bool IsCursorVisible(int id); diff --git a/Assets/uDesktopDuplication/Scripts/Monitor.cs b/Assets/uDesktopDuplication/Scripts/Monitor.cs index 9ee82d4..39e0dfd 100644 --- a/Assets/uDesktopDuplication/Scripts/Monitor.cs +++ b/Assets/uDesktopDuplication/Scripts/Monitor.cs @@ -31,6 +31,26 @@ public class Monitor get { return Lib.IsPrimary(id); } } + public int left + { + get { return Lib.GetLeft(id); } + } + + public int right + { + get { return Lib.GetRight(id); } + } + + public int top + { + get { return Lib.GetTop(id); } + } + + public int bottom + { + get { return Lib.GetBottom(id); } + } + public int width { get { return Lib.GetWidth(id); } @@ -41,6 +61,11 @@ public class Monitor get { return Lib.GetHeight(id); } } + public MonitorRotation rotation + { + get { return Lib.GetRotation(id); } + } + public float aspect { get { return (float)width / height; } diff --git a/Assets/uDesktopDuplication/Scripts/Texture.cs b/Assets/uDesktopDuplication/Scripts/Texture.cs index e1ba444..c36ce6a 100644 --- a/Assets/uDesktopDuplication/Scripts/Texture.cs +++ b/Assets/uDesktopDuplication/Scripts/Texture.cs @@ -52,6 +52,7 @@ public class Texture : MonoBehaviour { monitor.shouldBeUpdated = true; UpdateMaterial(); + Debug.Log(Lib.GetTotalWidth() + " " + Lib.GetTotalHeight()); } void UpdateMaterial() diff --git a/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader b/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader index bea41f3..cb04b23 100644 --- a/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader +++ b/Assets/uDesktopDuplication/Shaders/uDD_Unlit.shader @@ -49,9 +49,9 @@ Pass CGPROGRAM #pragma vertex vert #pragma fragment frag - #pragma shader_feature ___ INVERT_X - #pragma shader_feature ___ INVERT_Y - #pragma shader_feature ___ VERTICAL + #pragma multi_compile ___ INVERT_X + #pragma multi_compile ___ INVERT_Y + #pragma multi_compile ___ VERTICAL #pragma shader_feature ___ USE_BEND ENDCG } diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp index bff7928..a7c6ac1 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.cpp @@ -141,6 +141,36 @@ bool Monitor::IsPrimary() const } +int Monitor::GetLeft() const +{ + return outputDesc_.DesktopCoordinates.left; +} + + +int Monitor::GetRight() const +{ + return outputDesc_.DesktopCoordinates.right; +} + + +int Monitor::GetTop() const +{ + return outputDesc_.DesktopCoordinates.top; +} + + +int Monitor::GetBottom() const +{ + return outputDesc_.DesktopCoordinates.bottom; +} + + +int Monitor::GetRotation() const +{ + return static_cast(outputDesc_.Rotation); +} + + int Monitor::GetWidth() const { const auto rect = monitorInfo_.rcMonitor; diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.h b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.h index e3066ef..92168df 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.h +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/Monitor.h @@ -18,8 +18,13 @@ public: ID3D11Texture2D* GetUnityTexture() const; void GetName(char* buf, int len) const; bool IsPrimary() const; + int GetLeft() const; + int GetRight() const; + int GetTop() const; + int GetBottom() const; int GetWidth() const; int GetHeight() const; + int GetRotation() const; IDXGIOutputDuplication* GetDeskDupl(); const std::unique_ptr& GetCursor(); diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.cpp index 3208956..b898958 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "IUnityInterface.h" #include "IUnityGraphicsD3D11.h" @@ -129,6 +130,32 @@ int MonitorManager::GetMonitorCount() const return static_cast(monitors_.size()); } +int MonitorManager::GetTotalWidth() const +{ + std::vector lefts, rights; + for (const auto& monitor : monitors_) + { + lefts.push_back(monitor->GetLeft()); + rights.push_back(monitor->GetRight()); + } + const auto minLeft = *std::min_element(lefts.begin(), lefts.end()); + const auto maxRight = *std::max_element(rights.begin(), rights.end()); + return maxRight - minLeft; +} + +int MonitorManager::GetTotalHeight() const +{ + std::vector tops, bottoms; + for (const auto& monitor : monitors_) + { + tops.push_back(monitor->GetTop()); + bottoms.push_back(monitor->GetBottom()); + } + const auto minTop = *std::min_element(tops.begin(), tops.end()); + const auto maxBottom = *std::max_element(bottoms.begin(), bottoms.end()); + return maxBottom - minTop; +} + void MonitorManager::GetName(int id, char* buf, int len) const { @@ -149,6 +176,46 @@ bool MonitorManager::IsPrimary(int id) const } +int MonitorManager::GetLeft(int id) const +{ + if (auto monitor = GetMonitor(id)) + { + return monitor->GetLeft(); + } + return 0; +} + + +int MonitorManager::GetRight(int id) const +{ + if (auto monitor = GetMonitor(id)) + { + return monitor->GetRight(); + } + return 0; +} + + +int MonitorManager::GetTop(int id) const +{ + if (auto monitor = GetMonitor(id)) + { + return monitor->GetTop(); + } + return 0; +} + + +int MonitorManager::GetBottom(int id) const +{ + if (auto monitor = GetMonitor(id)) + { + return monitor->GetBottom(); + } + return 0; +} + + int MonitorManager::GetWidth(int id) const { if (auto monitor = GetMonitor(id)) @@ -169,6 +236,16 @@ int MonitorManager::GetHeight(int id) const } +int MonitorManager::GetRotation(int id) const +{ + if (auto monitor = GetMonitor(id)) + { + return monitor->GetRotation(); + } + return DXGI_MODE_ROTATION_UNSPECIFIED; +} + + bool MonitorManager::IsCursorVisible(int id) const { if (auto monitor = GetMonitor(id)) diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.h b/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.h index 2378dfa..f0769ce 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.h +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/MonitorManager.h @@ -36,10 +36,17 @@ public: // Getters from Unity public: int GetMonitorCount() const; + int GetTotalWidth() const; + int GetTotalHeight() const; void GetName(int id, char* buf, int len) const; bool IsPrimary(int id) const; + int GetLeft(int id) const; + int GetRight(int id) const; + int GetTop(int id) const; + int GetBottom(int id) const; int GetWidth(int id) const; int GetHeight(int id) const; + int GetRotation(int id) const; bool IsCursorVisible(int id) const; int GetCursorX(int id) const; int GetCursorY(int id) const; diff --git a/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp b/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp index 76afd1b..0201dc3 100644 --- a/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp +++ b/Plugins/uDesktopDuplication/uDesktopDuplication/main.cpp @@ -106,6 +106,18 @@ extern "C" return g_manager->GetMonitorCount(); } + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalWidth() + { + if (!g_manager) return 0; + return g_manager->GetTotalWidth(); + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalHeight() + { + if (!g_manager) return 0; + return g_manager->GetTotalHeight(); + } + UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTimeout(int timeout) { if (!g_manager) return; @@ -124,6 +136,30 @@ extern "C" return g_manager->IsPrimary(id); } + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetLeft(int id) + { + if (!g_manager) return -1; + return g_manager->GetLeft(id); + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetRight(int id) + { + if (!g_manager) return -1; + return g_manager->GetRight(id); + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTop(int id) + { + if (!g_manager) return -1; + return g_manager->GetTop(id); + } + + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetBottom(int id) + { + if (!g_manager) return -1; + return g_manager->GetBottom(id); + } + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetWidth(int id) { if (!g_manager) return -1; @@ -136,6 +172,12 @@ extern "C" return g_manager->GetHeight(id); } + UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetRotation(int id) + { + if (!g_manager) return -1; + return g_manager->GetRotation(id); + } + UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsCursorVisible(int id) { if (!g_manager) return false;