change class names. / add multiple screen example. / performance tuning.
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 678e1de5e6de7914baed516a78940503
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1477643728
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: de6f36e446e5e8a48bf61fe198985bb4
|
||||||
|
timeCreated: 1477643732
|
||||||
|
licenseType: Pro
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0a3456d4b2f59e84f969e31deca4016d
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1477643596
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
BIN
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 445860b05342be845967392bfd70224e
|
||||||
|
timeCreated: 1477643648
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
@@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 71921882396f0f345aa8a66e2fcb0b6c
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1477643608
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class MultipleMonitorCreator : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] GameObject monitorPrefab;
|
||||||
|
[SerializeField] Vector3 margin = new Vector3(20f, 0f, 0f);
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
var monitors = uDesktopDuplication.Manager.monitors;
|
||||||
|
var n = monitors.Count;
|
||||||
|
for (int i = 0 ; i < n; ++i) {
|
||||||
|
var go = Instantiate(monitorPrefab);
|
||||||
|
go.transform.position = transform.position + margin * (i - n / 2f + 0.5f);
|
||||||
|
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||||
|
texture.monitorId = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fb22986017201f74aa864dcbf0cab751
|
||||||
|
timeCreated: 1477643778
|
||||||
|
licenseType: Pro
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
+5
-4
@@ -3,8 +3,9 @@
|
|||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
|
|
||||||
[RequireComponent(typeof(uDD_Texture))]
|
[AddComponentMenu("uDesktopDuplication/Cursor"),
|
||||||
public class uDD_Cursor : MonoBehaviour
|
RequireComponent(typeof(Texture))]
|
||||||
|
public class Cursor : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Transform cursor;
|
Transform cursor;
|
||||||
@@ -13,11 +14,11 @@ public class uDD_Cursor : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
Vector2 offset = new Vector2(0.5f, 0.5f);
|
Vector2 offset = new Vector2(0.5f, 0.5f);
|
||||||
|
|
||||||
private uDD_Texture texture_;
|
private Texture texture_;
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
texture_ = GetComponent<uDD_Texture>();
|
texture_ = GetComponent<Texture>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
+3
-1
@@ -5,11 +5,13 @@ using System.Runtime.InteropServices;
|
|||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class uDD_Lib
|
public static class Lib
|
||||||
{
|
{
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern int GetMonitorCount();
|
public static extern int GetMonitorCount();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
|
public static extern void SetTimeout(int timeout);
|
||||||
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern IntPtr GetRenderEventFunc();
|
public static extern IntPtr GetRenderEventFunc();
|
||||||
[DllImport("uDesktopDuplication")]
|
[DllImport("uDesktopDuplication")]
|
||||||
public static extern void GetName(int id, StringBuilder buf, int len);
|
public static extern void GetName(int id, StringBuilder buf, int len);
|
||||||
+21
-10
@@ -5,26 +5,31 @@ using System.Collections.Generic;
|
|||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
|
|
||||||
public class uDD_Manager : MonoBehaviour
|
public class Manager : MonoBehaviour
|
||||||
{
|
{
|
||||||
private static uDD_Manager instance_;
|
private static Manager instance_;
|
||||||
public static uDD_Manager instance
|
public static Manager instance
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (instance_) return instance_;
|
if (instance_) return instance_;
|
||||||
var go = new GameObject("uDesktopDuplicationManager");
|
var go = new GameObject("uDesktopDuplicationManager");
|
||||||
return go.AddComponent<uDD_Manager>();
|
return go.AddComponent<Manager>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<uDD_Monitor> monitors_ = new List<uDD_Monitor>();
|
private List<Monitor> monitors_ = new List<Monitor>();
|
||||||
static public List<uDD_Monitor> monitors
|
static public List<Monitor> monitors
|
||||||
{
|
{
|
||||||
get { return instance.monitors_; }
|
get { return instance.monitors_; }
|
||||||
}
|
}
|
||||||
|
|
||||||
static public uDD_Monitor primary
|
static public int monitorCount
|
||||||
|
{
|
||||||
|
get { return instance.monitors_.Count; }
|
||||||
|
}
|
||||||
|
|
||||||
|
static public Monitor primary
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -32,6 +37,9 @@ public class uDD_Manager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SerializeField, Tooltip("Set Desktop Duplication API timeout (milliseconds).")]
|
||||||
|
int timeout = 0;
|
||||||
|
|
||||||
private Coroutine renderCoroutine_ = null;
|
private Coroutine renderCoroutine_ = null;
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
@@ -39,9 +47,11 @@ public class uDD_Manager : MonoBehaviour
|
|||||||
if (instance_ != null) return;
|
if (instance_ != null) return;
|
||||||
instance_ = this;
|
instance_ = this;
|
||||||
|
|
||||||
for (int i = 0; i < uDD_Monitor.count; ++i) {
|
for (int i = 0; i < Lib.GetMonitorCount(); ++i) {
|
||||||
monitors.Add(new uDD_Monitor(i));
|
monitors.Add(new Monitor(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Lib.SetTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
@@ -61,7 +71,8 @@ public class uDD_Manager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
yield return new WaitForEndOfFrame();
|
yield return new WaitForEndOfFrame();
|
||||||
foreach (var monitor in monitors) {
|
for (int i = 0; i < monitors.Count; ++i) {
|
||||||
|
var monitor = monitors[i];
|
||||||
if (monitor.shouldBeUpdated) {
|
if (monitor.shouldBeUpdated) {
|
||||||
monitor.Render();
|
monitor.Render();
|
||||||
}
|
}
|
||||||
+11
-16
@@ -3,18 +3,13 @@
|
|||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
|
|
||||||
public class uDD_Monitor
|
public class Monitor
|
||||||
{
|
{
|
||||||
public uDD_Monitor(int id)
|
public Monitor(int id)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int count
|
|
||||||
{
|
|
||||||
get { return uDD_Lib.GetMonitorCount(); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public int id
|
public int id
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
@@ -23,37 +18,37 @@ public class uDD_Monitor
|
|||||||
|
|
||||||
public string name
|
public string name
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.GetName(id); }
|
get { return Lib.GetName(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isPrimary
|
public bool isPrimary
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.IsPrimary(id); }
|
get { return Lib.IsPrimary(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int width
|
public int width
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.GetWidth(id); }
|
get { return Lib.GetWidth(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int height
|
public int height
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.GetHeight(id); }
|
get { return Lib.GetHeight(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isPointerVisible
|
public bool isPointerVisible
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.IsPointerVisible(id); }
|
get { return Lib.IsPointerVisible(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int pointerX
|
public int pointerX
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.GetPointerX(id); }
|
get { return Lib.GetPointerX(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int pointerY
|
public int pointerY
|
||||||
{
|
{
|
||||||
get { return uDD_Lib.GetPointerY(id); }
|
get { return Lib.GetPointerY(id); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool shouldBeUpdated
|
public bool shouldBeUpdated
|
||||||
@@ -69,7 +64,7 @@ public class uDD_Monitor
|
|||||||
{
|
{
|
||||||
if (texture_ == null) {
|
if (texture_ == null) {
|
||||||
texture_ = new Texture2D(width, height, TextureFormat.BGRA32, false);
|
texture_ = new Texture2D(width, height, TextureFormat.BGRA32, false);
|
||||||
uDD_Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
|
Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
|
||||||
}
|
}
|
||||||
return texture_;
|
return texture_;
|
||||||
}
|
}
|
||||||
@@ -77,7 +72,7 @@ public class uDD_Monitor
|
|||||||
|
|
||||||
public void Render()
|
public void Render()
|
||||||
{
|
{
|
||||||
GL.IssuePluginEvent(uDD_Lib.GetRenderEventFunc(), id);
|
GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+20
-5
@@ -3,9 +3,26 @@
|
|||||||
namespace uDesktopDuplication
|
namespace uDesktopDuplication
|
||||||
{
|
{
|
||||||
|
|
||||||
public class uDD_Texture : MonoBehaviour
|
[AddComponentMenu("uDesktopDuplication/Texture")]
|
||||||
|
public class Texture : MonoBehaviour
|
||||||
{
|
{
|
||||||
public uDD_Monitor monitor { get; set; }
|
private Monitor monitor_;
|
||||||
|
public Monitor monitor
|
||||||
|
{
|
||||||
|
get { return monitor_; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
monitor_ = value;
|
||||||
|
material_ = GetComponent<Renderer>().material;
|
||||||
|
material_.mainTexture = monitor_.texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monitorId
|
||||||
|
{
|
||||||
|
get { return monitor.id; }
|
||||||
|
set { monitor = Manager.monitors[Mathf.Clamp(value, 0, Manager.monitorCount - 1)]; }
|
||||||
|
}
|
||||||
|
|
||||||
public bool invertX = false;
|
public bool invertX = false;
|
||||||
public bool invertY = false;
|
public bool invertY = false;
|
||||||
@@ -15,10 +32,8 @@ public class uDD_Texture : MonoBehaviour
|
|||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
monitor = uDD_Manager.primary;
|
monitor = Manager.primary;
|
||||||
}
|
}
|
||||||
material_ = GetComponent<Renderer>().material;
|
|
||||||
material_.mainTexture = monitor.texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
@@ -26,6 +26,7 @@ namespace
|
|||||||
};
|
};
|
||||||
|
|
||||||
IUnityInterfaces* g_unity = nullptr;
|
IUnityInterfaces* g_unity = nullptr;
|
||||||
|
int g_timeout = 10;
|
||||||
std::vector<Monitor> g_monitors;
|
std::vector<Monitor> g_monitors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,8 +114,7 @@ extern "C"
|
|||||||
IDXGIResource* resource = nullptr;
|
IDXGIResource* resource = nullptr;
|
||||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||||
|
|
||||||
const UINT timeout = 100; // ms
|
hr = monitor.output->AcquireNextFrame(g_timeout, &frameInfo, &resource);
|
||||||
hr = monitor.output->AcquireNextFrame(timeout, &frameInfo, &resource);
|
|
||||||
switch (hr)
|
switch (hr)
|
||||||
{
|
{
|
||||||
case S_OK:
|
case S_OK:
|
||||||
@@ -123,7 +123,7 @@ extern "C"
|
|||||||
}
|
}
|
||||||
case DXGI_ERROR_ACCESS_LOST:
|
case DXGI_ERROR_ACCESS_LOST:
|
||||||
{
|
{
|
||||||
FinalizeDuplication();
|
resource->Release();
|
||||||
InitializeDuplication();
|
InitializeDuplication();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -142,16 +142,17 @@ extern "C"
|
|||||||
if (hr != S_OK)
|
if (hr != S_OK)
|
||||||
{
|
{
|
||||||
resource->Release();
|
resource->Release();
|
||||||
|
monitor.output->ReleaseFrame();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
resource->Release();
|
|
||||||
|
|
||||||
ID3D11DeviceContext* context;
|
ID3D11DeviceContext* context;
|
||||||
auto device = g_unity->Get<IUnityGraphicsD3D11>()->GetDevice();
|
auto device = g_unity->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||||
device->GetImmediateContext(&context);
|
device->GetImmediateContext(&context);
|
||||||
context->CopyResource(monitor.texture, texture);
|
context->CopyResource(monitor.texture, texture);
|
||||||
|
|
||||||
|
resource->Release();
|
||||||
|
texture->Release();
|
||||||
monitor.output->ReleaseFrame();
|
monitor.output->ReleaseFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,6 +166,11 @@ extern "C"
|
|||||||
return g_monitors.size();
|
return g_monitors.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTimeout(int timeout)
|
||||||
|
{
|
||||||
|
g_timeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API GetName(int id, char* buf, int len)
|
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API GetName(int id, char* buf, int len)
|
||||||
{
|
{
|
||||||
if (!DoesMonitorExist(id)) return;
|
if (!DoesMonitorExist(id)) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user