Compare commits
93 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
306a656c4e | ||
|
|
faf65b4200 | ||
|
|
ab25af516e | ||
|
|
45b0ab2cd8 | ||
|
|
68227e9af6 | ||
|
|
be9871ba92 | ||
|
|
110d5d7bda | ||
|
|
533a4c9f28 | ||
|
|
88e8342d7a | ||
|
|
72376b9e91 | ||
|
|
a10d5aa5c1 | ||
|
|
306185a1e9 | ||
|
|
60889d53f4 | ||
|
|
f207e65952 | ||
|
|
aea8d112c6 | ||
|
|
9f6971dd45 | ||
|
|
1be698af63 | ||
|
|
064db9f137 | ||
|
|
166d172db2 | ||
|
|
95f8099392 | ||
|
|
9c62157c0c | ||
|
|
be79e52135 | ||
|
|
e9c8b4e571 | ||
|
|
77c95ab1bb | ||
|
|
7b3990107d | ||
|
|
5c21b65afe | ||
|
|
e83f43d7fd | ||
|
|
58e14d76d8 | ||
|
|
f8d8e64e46 | ||
|
|
0a39e37659 | ||
|
|
931ff6b2db | ||
|
|
75819f0a7d | ||
|
|
d6ce41f9b6 | ||
|
|
9f8a026c24 | ||
|
|
dc702c6e1d | ||
|
|
5a3af11d08 | ||
|
|
0646621f73 | ||
|
|
c9d6d3ad6a | ||
|
|
78ee75a875 | ||
|
|
c83ce50468 | ||
|
|
3567182a4d | ||
|
|
e466aa65db | ||
|
|
a0edc1a439 | ||
|
|
1eb821b34d | ||
|
|
212d8ccb9b | ||
|
|
fac8fe1ea7 | ||
|
|
f90178f1db | ||
|
|
74e25f2bd7 | ||
|
|
70c126be6c | ||
|
|
f74221bf75 | ||
|
|
3a705732d1 | ||
|
|
804bfb96bd | ||
|
|
63d8f6936d | ||
|
|
e4e4917bcb | ||
|
|
0e205ecef7 | ||
|
|
cda8024b17 | ||
|
|
05085f7d24 | ||
|
|
52eafbe919 | ||
|
|
be1e0c25bb | ||
|
|
372e44d8c1 | ||
|
|
d79eb91333 | ||
|
|
f654df7f5b | ||
|
|
620762dba7 | ||
|
|
43ba445623 | ||
|
|
c7c12de730 | ||
|
|
1086595d6b | ||
|
|
f69fb6a7bb | ||
|
|
b661b4a93f | ||
|
|
8d9ef71829 | ||
|
|
fb7bcbfa5b | ||
|
|
9ed8bb8d5b | ||
|
|
fab67bbc61 | ||
|
|
5fa9f03a0e | ||
|
|
941bb2da91 | ||
|
|
d423e0d1db | ||
|
|
33a55d95bd | ||
|
|
8e2d8d3218 | ||
|
|
6ac1a5ee60 | ||
|
|
15a98cd774 | ||
|
|
06bb971a42 | ||
|
|
217e63d40c | ||
|
|
9e42fb0abf | ||
|
|
9de5064fbe | ||
|
|
2b108bd4b1 | ||
|
|
f9f8b14f46 | ||
|
|
7774290e71 | ||
|
|
a3a7754fb0 | ||
|
|
0accebb657 | ||
|
|
0a38eda14f | ||
|
|
720f74e6f6 | ||
|
|
80fa39f4eb | ||
|
|
22b21ae3f4 | ||
|
|
43153266a0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,3 +27,4 @@ sysinfo.txt
|
||||
.DS_Store
|
||||
/Assets/AssetStoreTools*
|
||||
/Assets/Extensions*
|
||||
/uDesktopDuplication.log
|
||||
|
||||
9
Assets/uDesktopDuplication/Editor.meta
Normal file
9
Assets/uDesktopDuplication/Editor.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 022a80d652ef0304e84e9d6ac689e21f
|
||||
folderAsset: yes
|
||||
timeCreated: 1478353382
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/uDesktopDuplication/Editor/Resources.meta
Normal file
9
Assets/uDesktopDuplication/Editor/Resources.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e15bc51aada81042a909c808e25c176
|
||||
folderAsset: yes
|
||||
timeCreated: 1477555207
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
Before Width: | Height: | Size: 967 B After Width: | Height: | Size: 967 B |
Binary file not shown.
BIN
Assets/uDesktopDuplication/Examples/Prefabs/Monitor Plane.prefab
Normal file
BIN
Assets/uDesktopDuplication/Examples/Prefabs/Monitor Plane.prefab
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 033e0db89e0ca1d46a399c953629f67d
|
||||
timeCreated: 1477555367
|
||||
guid: 42d6b6dbae38a384e882c2c907915139
|
||||
timeCreated: 1478889784
|
||||
licenseType: Pro
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
BIN
Assets/uDesktopDuplication/Examples/Scenes/Meta Data.unity
Normal file
BIN
Assets/uDesktopDuplication/Examples/Scenes/Meta Data.unity
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aac40d1b58f3f8940be815779d89b5a4
|
||||
timeCreated: 1479544409
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bae91f55031b98488c9e668031f7387
|
||||
timeCreated: 1478610618
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
Binary file not shown.
BIN
Assets/uDesktopDuplication/Examples/Scenes/Switch Scenes.unity
Normal file
BIN
Assets/uDesktopDuplication/Examples/Scenes/Switch Scenes.unity
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ce9467b01f36d647ace156faef9cb9f
|
||||
timeCreated: 1478927635
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
BIN
Assets/uDesktopDuplication/Examples/Scenes/Zoom.unity
Normal file
BIN
Assets/uDesktopDuplication/Examples/Scenes/Zoom.unity
Normal file
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3d41026babadc241b9d0852b0831584
|
||||
timeCreated: 1478436298
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
181
Assets/uDesktopDuplication/Examples/Scripts/GazePointAnalyzer.cs
Normal file
181
Assets/uDesktopDuplication/Examples/Scripts/GazePointAnalyzer.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
using UnityEngine;
|
||||
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
|
||||
|
||||
[RequireComponent(typeof(uDesktopDuplication.Texture))]
|
||||
public class GazePointAnalyzer : MonoBehaviour
|
||||
{
|
||||
uDesktopDuplication.Texture uddTexture_;
|
||||
|
||||
[Tooltip("This needs a small calculation cost.")]
|
||||
public bool calcAveragePos = true;
|
||||
|
||||
private Vector2 averageCoord_ = Vector2.zero;
|
||||
private Vector2 averageCoordVelocity_ = Vector2.zero;
|
||||
public Vector3 averagePos
|
||||
{
|
||||
get { return GetWorldPositionFromCoord((int)averageCoord_.x, (int)averageCoord_.y); }
|
||||
}
|
||||
private Vector2 preCursorCoord_ = Vector2.zero;
|
||||
|
||||
[Header("Filters")]
|
||||
[Range(0f, 1f)] public float moveRectFilter = 0.05f;
|
||||
[Range(0f, 1f)] public float mouseFilter = 0.05f;
|
||||
[Range(0f, 1f)] public float dirtyRectFilter = 0.01f;
|
||||
[Range(0f, 1f)] public float noEventFilter = 0.01f;
|
||||
[Range(0f, 1f)] public float velocityFilter = 0.1f;
|
||||
|
||||
[Header("Debug")]
|
||||
public bool drawAveragePos;
|
||||
public bool drawMoveRects;
|
||||
public bool drawDirtyRects;
|
||||
|
||||
void Start()
|
||||
{
|
||||
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
|
||||
averageCoord_ = new Vector2(uddTexture_.monitor.width / 2, uddTexture_.monitor.height / 2);
|
||||
}
|
||||
|
||||
public Vector3 GetWorldPositionFromCoord(int u, int v)
|
||||
{
|
||||
var monitor = uddTexture_.monitor;
|
||||
|
||||
// Mesh & Scale information
|
||||
var mesh = GetComponent<MeshFilter>().sharedMesh;
|
||||
var width = transform.localScale.x * (mesh.bounds.extents.x * 2f);
|
||||
var height = transform.localScale.y * (mesh.bounds.extents.y * 2f);
|
||||
|
||||
// Local position (scale included).
|
||||
var x = (float)(u - monitor.width / 2) / monitor.width;
|
||||
var y = -(float)(v - monitor.height / 2) / monitor.height;
|
||||
var localPos = new Vector3(width * x, height * y, 0f);
|
||||
|
||||
// Bending
|
||||
if (uddTexture_.bend) {
|
||||
var radius = uddTexture_.radius;
|
||||
var angle = localPos.x / radius;
|
||||
if (uddTexture_.meshForwardDirection == MeshForwardDirection.Y) {
|
||||
localPos.y -= radius * (1f - Mathf.Cos(angle));
|
||||
} else {
|
||||
localPos.z -= radius * (1f - Mathf.Cos(angle));
|
||||
}
|
||||
localPos.x = radius * Mathf.Sin(angle);
|
||||
}
|
||||
|
||||
// To world position
|
||||
return transform.position + (transform.rotation * localPos);
|
||||
}
|
||||
|
||||
void CalcAveragePos()
|
||||
{
|
||||
if (!calcAveragePos) return;
|
||||
|
||||
var coord = Vector2.zero;
|
||||
var monitor = uddTexture_.monitor;
|
||||
var cursorCoord = new Vector2(monitor.cursorX, monitor.cursorY);
|
||||
var filter = 0f;
|
||||
|
||||
// move rect
|
||||
if (monitor.moveRectCount > 0) {
|
||||
foreach (var rects in monitor.moveRects) {
|
||||
var rect = rects.destination;
|
||||
var center = new Vector2(
|
||||
(rect.right + rect.left) / 2,
|
||||
(rect.bottom + rect.top) / 2);
|
||||
coord += center;
|
||||
}
|
||||
coord /= monitor.moveRectCount;
|
||||
filter = moveRectFilter;
|
||||
}
|
||||
// mouse
|
||||
else if (
|
||||
monitor.isCursorVisible &&
|
||||
cursorCoord != preCursorCoord_ &&
|
||||
(cursorCoord - preCursorCoord_).magnitude > 5 &&
|
||||
monitor.cursorX >= 0 &&
|
||||
monitor.cursorY >= 0)
|
||||
{
|
||||
coord = cursorCoord;
|
||||
filter = mouseFilter;
|
||||
}
|
||||
// dirty rect
|
||||
else if (monitor.dirtyRectCount > 0) {
|
||||
var totalWeights = 0f;
|
||||
foreach (var rect in monitor.dirtyRects) {
|
||||
var center = new Vector2(
|
||||
(rect.right + rect.left) / 2,
|
||||
(rect.bottom + rect.top) / 2);
|
||||
var weight = 1f / Mathf.Sqrt((rect.right - rect.left) * (rect.bottom - rect.top));
|
||||
coord += center * weight;
|
||||
totalWeights += weight;
|
||||
}
|
||||
coord /= totalWeights;
|
||||
filter = dirtyRectFilter;
|
||||
}
|
||||
// no event
|
||||
else {
|
||||
coord = new Vector2(monitor.width / 2, monitor.height / 2);
|
||||
filter = noEventFilter;
|
||||
}
|
||||
|
||||
var cf = (filter / ((1f / 60) / Time.deltaTime));
|
||||
var vf = (velocityFilter / ((1f / 60) / Time.deltaTime));
|
||||
var targetCoord = averageCoord_ + (coord - averageCoord_) * cf;
|
||||
var targetVelocity = targetCoord - averageCoord_;
|
||||
|
||||
if (float.IsNaN(targetCoord.x) || float.IsNaN(targetCoord.y)) return;
|
||||
if (float.IsNaN(targetVelocity.x) || float.IsNaN(targetVelocity.y)) return;
|
||||
|
||||
averageCoordVelocity_ += (targetVelocity - averageCoordVelocity_) * vf;
|
||||
averageCoord_ += averageCoordVelocity_;
|
||||
averageCoord_.x = Mathf.Clamp(averageCoord_.x, 0, monitor.width);
|
||||
averageCoord_.y = Mathf.Clamp(averageCoord_.y, 0, monitor.height);
|
||||
|
||||
preCursorCoord_ = cursorCoord;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
CalcAveragePos();
|
||||
DebugDraw();
|
||||
}
|
||||
|
||||
void DebugDraw()
|
||||
{
|
||||
if (drawAveragePos) DrawAveragePos();
|
||||
if (drawDirtyRects) DrawDirtyRects();
|
||||
if (drawMoveRects) DrawMoveRects();
|
||||
}
|
||||
|
||||
void DrawRect(uDesktopDuplication.RECT rect, Color color)
|
||||
{
|
||||
var p0 = GetWorldPositionFromCoord(rect.left, rect.top);
|
||||
var p1 = GetWorldPositionFromCoord(rect.right, rect.top);
|
||||
var p2 = GetWorldPositionFromCoord(rect.right, rect.bottom);
|
||||
var p3 = GetWorldPositionFromCoord(rect.left, rect.bottom);
|
||||
|
||||
Debug.DrawLine(p0, p1, color);
|
||||
Debug.DrawLine(p1, p2, color);
|
||||
Debug.DrawLine(p2, p3, color);
|
||||
Debug.DrawLine(p3, p0, color);
|
||||
}
|
||||
|
||||
void DrawAveragePos()
|
||||
{
|
||||
Debug.DrawLine(transform.position, averagePos, Color.yellow);
|
||||
}
|
||||
|
||||
void DrawMoveRects()
|
||||
{
|
||||
foreach (var rect in uddTexture_.monitor.moveRects) {
|
||||
DrawRect(rect.source, Color.blue);
|
||||
DrawRect(rect.destination, Color.green);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawDirtyRects()
|
||||
{
|
||||
foreach (var rect in uddTexture_.monitor.dirtyRects) {
|
||||
DrawRect(rect, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52d402bdca823cc42925c9d65993ee59
|
||||
timeCreated: 1479546123
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs
Normal file
53
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(uDesktopDuplication.Texture)),
|
||||
RequireComponent(typeof(uDesktopDuplication.Cursor))]
|
||||
public class Loupe : MonoBehaviour
|
||||
{
|
||||
private uDesktopDuplication.Texture uddTexture_;
|
||||
private uDesktopDuplication.Cursor uddCursor_;
|
||||
public float zoom = 3f;
|
||||
public float aspect = 1f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
uddTexture_ = GetComponent<uDesktopDuplication.Texture>();
|
||||
uddCursor_ = GetComponent<uDesktopDuplication.Cursor>();
|
||||
uddTexture_.useClip = true;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
CheckVariables();
|
||||
|
||||
if (uDesktopDuplication.Manager.cursorMonitorId < 0) return;
|
||||
uddTexture_.monitorId = uDesktopDuplication.Manager.cursorMonitorId;
|
||||
|
||||
// To get other monitor textures, set dirty flag.
|
||||
foreach (var target in uDesktopDuplication.Manager.monitors) {
|
||||
target.CreateTextureIfNeeded();
|
||||
target.shouldBeUpdated = true;
|
||||
}
|
||||
|
||||
var monitor = uddTexture_.monitor;
|
||||
var x = monitor.isCursorVisible ?
|
||||
uddCursor_.coord.x :
|
||||
(float)monitor.systemCursorX / monitor.width;
|
||||
var y = monitor.isCursorVisible ?
|
||||
uddCursor_.coord.y :
|
||||
(float)monitor.systemCursorY / monitor.height;
|
||||
var w = 1f / zoom;
|
||||
var h = w / aspect * monitor.aspect;
|
||||
x = Mathf.Clamp(x - w / 2, 0f, 1f - w);
|
||||
y = Mathf.Clamp(y - h / 2, 0f, 1f - h);
|
||||
uddTexture_.clipPos = new Vector2(x, y);
|
||||
uddTexture_.clipScale = new Vector2(w, h);
|
||||
}
|
||||
|
||||
void CheckVariables()
|
||||
{
|
||||
if (zoom < 1f) zoom = 1f;
|
||||
if (aspect < 0.01f) aspect = 0.01f;
|
||||
}
|
||||
}
|
||||
|
||||
12
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs.meta
Normal file
12
Assets/uDesktopDuplication/Examples/Scripts/Loupe.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efd9499cdb931b945947a2cd47909676
|
||||
timeCreated: 1478438457
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MultipleMonitorCreator))]
|
||||
public class MultipleMonitorAnalyzer : MonoBehaviour
|
||||
{
|
||||
MultipleMonitorCreator creator_;
|
||||
Vector3 gazePoint_ = Vector3.zero;
|
||||
public Vector3 gazePoint
|
||||
{
|
||||
get { return gazePoint_; }
|
||||
private set
|
||||
{
|
||||
gazePoint_ += (value - gazePoint) * (gazePointFilter / (1f / 60 / Time.deltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Filters")]
|
||||
[Range(0f, 1f)] public float gazePointFilter = 0.1f;
|
||||
[Range(0f, 1f)] public float moveRectFilter = 0.05f;
|
||||
[Range(0f, 1f)] public float mouseFilter = 0.05f;
|
||||
[Range(0f, 1f)] public float dirtyRectFilter = 0.01f;
|
||||
[Range(0f, 1f)] public float noEventFilter = 0.01f;
|
||||
[Range(0f, 1f)] public float velocityFilter = 0.1f;
|
||||
|
||||
[Header("Debug")]
|
||||
[SerializeField] bool drawGazePoint;
|
||||
[SerializeField] bool drawAveragePos;
|
||||
[SerializeField] bool drawMoveRects;
|
||||
[SerializeField] bool drawDirtyRects;
|
||||
|
||||
void Start()
|
||||
{
|
||||
creator_ = GetComponent<MultipleMonitorCreator>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var cursorMonitorId = uDesktopDuplication.Manager.cursorMonitorId;
|
||||
for (int i = 0; i < creator_.monitors.Count; ++i) {
|
||||
var info = creator_.monitors[i];
|
||||
var analyzer =
|
||||
info.gameObject.GetComponent<GazePointAnalyzer>() ??
|
||||
info.gameObject.AddComponent<GazePointAnalyzer>();
|
||||
UpdateAnalyzer(analyzer);
|
||||
if (info.uddTexture.monitorId == cursorMonitorId) {
|
||||
gazePoint = analyzer.averagePos;
|
||||
}
|
||||
}
|
||||
|
||||
if (drawGazePoint) DrawGazePoint();
|
||||
}
|
||||
|
||||
void DrawGazePoint()
|
||||
{
|
||||
Debug.DrawLine(transform.position, gazePoint, Color.magenta);
|
||||
}
|
||||
|
||||
void UpdateAnalyzer(GazePointAnalyzer analyzer)
|
||||
{
|
||||
analyzer.moveRectFilter = moveRectFilter;
|
||||
analyzer.mouseFilter = mouseFilter;
|
||||
analyzer.dirtyRectFilter = dirtyRectFilter;
|
||||
analyzer.noEventFilter = noEventFilter;
|
||||
analyzer.velocityFilter = velocityFilter;
|
||||
analyzer.drawAveragePos = drawAveragePos;
|
||||
analyzer.drawMoveRects = drawMoveRects;
|
||||
analyzer.drawDirtyRects = drawDirtyRects;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbdfccef47068644b81b671bb4e6e166
|
||||
timeCreated: 1479620455
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,57 +1,203 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using System.Collections.Generic;
|
||||
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
|
||||
using MonitorState = uDesktopDuplication.MonitorState;
|
||||
|
||||
public class MultipleMonitorCreator : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject monitorPrefab;
|
||||
[SerializeField] float width = 0.3f;
|
||||
[SerializeField] float margin = 1f;
|
||||
[Tooltip("Create monitors using this prefab.")]
|
||||
public GameObject monitorPrefab;
|
||||
|
||||
public enum ScaleMode
|
||||
{
|
||||
Real,
|
||||
Fixed,
|
||||
Pixel,
|
||||
}
|
||||
|
||||
[Tooltip("Real: DPI-based real scale \nFixed: Same width \nPixel: bigger if screen resolution is high.")]
|
||||
public ScaleMode scaleMode = ScaleMode.Fixed;
|
||||
|
||||
[Tooltip("Use this scale as width if scaleMode is Fixed.")]
|
||||
public float scale = 0.5f;
|
||||
|
||||
[Tooltip("Please specify the surface direction of the mesh (e.g. Plane => Y.)")]
|
||||
public MeshForwardDirection meshForwardDirection = MeshForwardDirection.Z;
|
||||
|
||||
[Tooltip("Remove unsupported monitors automatically after removeWaitDuration.")]
|
||||
public bool removeIfUnsupported = true;
|
||||
|
||||
[Tooltip("Remove unsupported monitors automatically after removeWaitDuration.")]
|
||||
public float removeWaitDuration = 5f;
|
||||
|
||||
[Tooltip("Remove all childrens (for debug).")]
|
||||
public bool removeChildrenWhenClear = true;
|
||||
|
||||
bool hasMonitorUnsupportStateChecked_ = false;
|
||||
float removeWaitTimer_ = 0f;
|
||||
|
||||
public class MonitorInfo
|
||||
{
|
||||
public GameObject gameObject { get; set; }
|
||||
public Quaternion originalRotation { get; set; }
|
||||
public Vector3 originalLocalScale { get; set; }
|
||||
public uDesktopDuplication.Texture uddTexture { get; set; }
|
||||
public Mesh mesh { get; set; }
|
||||
}
|
||||
|
||||
private List<MonitorInfo> monitors_ = new List<MonitorInfo>();
|
||||
public List<MonitorInfo> monitors { get { return monitors_; } }
|
||||
|
||||
public class SavedMonitorInfo
|
||||
{
|
||||
public float widthScale = 1f;
|
||||
public float heightScale = 1f;
|
||||
}
|
||||
|
||||
private List<SavedMonitorInfo> savedInfoList_ = new List<SavedMonitorInfo>();
|
||||
public List<SavedMonitorInfo> savedInfoList { get { return savedInfoList_; } }
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Sort monitors in coordinate order
|
||||
var monitors = uDesktopDuplication.Manager.monitors;
|
||||
monitors.Sort((a, b) => a.left - b.left);
|
||||
uDesktopDuplication.Manager.CreateInstance();
|
||||
Create();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (removeIfUnsupported) {
|
||||
RemoveUnsupportedDisplayAfterRemoveTimer();
|
||||
}
|
||||
|
||||
if (uDesktopDuplication.Manager.monitorCount != monitors.Count) {
|
||||
Recreate();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
uDesktopDuplication.Manager.onReinitialized += Recreate;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
uDesktopDuplication.Manager.onReinitialized -= Recreate;
|
||||
}
|
||||
|
||||
void RemoveUnsupportedDisplayAfterRemoveTimer()
|
||||
{
|
||||
if (!hasMonitorUnsupportStateChecked_) {
|
||||
removeWaitTimer_ += Time.deltaTime;
|
||||
if (removeWaitTimer_ > removeWaitDuration) {
|
||||
hasMonitorUnsupportStateChecked_ = true;
|
||||
foreach (var info in monitors) {
|
||||
if (info.uddTexture.monitor.state == MonitorState.Unsupported) {
|
||||
Destroy(info.gameObject);
|
||||
}
|
||||
}
|
||||
monitors.RemoveAll(info => info.uddTexture.monitor.state == MonitorState.Unsupported);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ResetRemoveTimer()
|
||||
{
|
||||
hasMonitorUnsupportStateChecked_ = false;
|
||||
removeWaitTimer_ = 0f;
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
ResetRemoveTimer();
|
||||
|
||||
// Create monitors
|
||||
var n = monitors.Count;
|
||||
var totalWidth = 0f;
|
||||
for (int i = 0 ; i < n; ++i) {
|
||||
var n = uDesktopDuplication.Manager.monitors.Count;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Create monitor obeject
|
||||
var go = Instantiate(monitorPrefab);
|
||||
go.name = "Monitor " + i;
|
||||
|
||||
// Saved infomation
|
||||
if (savedInfoList.Count == i) {
|
||||
savedInfoList.Add(new SavedMonitorInfo());
|
||||
Assert.AreEqual(i, savedInfoList.Count - 1);
|
||||
}
|
||||
var savedInfo = savedInfoList[i];
|
||||
|
||||
// Expand AABB
|
||||
var mesh = go.GetComponent<MeshFilter>().mesh; // clone
|
||||
var aabbScale = mesh.bounds.size;
|
||||
aabbScale.y = Mathf.Max(aabbScale.y, aabbScale.x);
|
||||
aabbScale.z = Mathf.Max(aabbScale.z, aabbScale.x);
|
||||
mesh.bounds = new Bounds(mesh.bounds.center, aabbScale);
|
||||
|
||||
// Assign monitor
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
texture.monitorId = i;
|
||||
var monitor = texture.monitor;
|
||||
|
||||
// Set width / height
|
||||
var isHorizontal = texture.monitor.isHorizontal;
|
||||
var w = isHorizontal ? width : (width * texture.monitor.aspect);
|
||||
var h = isHorizontal ? width / texture.monitor.aspect : width;
|
||||
go.transform.localScale = new Vector3(w, go.transform.localScale.y, h);
|
||||
float width = 1f, height = 1f;
|
||||
switch (scaleMode) {
|
||||
case ScaleMode.Real:
|
||||
width = monitor.widthMeter;
|
||||
height = monitor.heightMeter;
|
||||
break;
|
||||
case ScaleMode.Fixed:
|
||||
width = scale * (monitor.isHorizontal ? monitor.aspect : 1f);
|
||||
height = scale * (monitor.isHorizontal ? 1f : 1f / monitor.aspect);
|
||||
break;
|
||||
case ScaleMode.Pixel:
|
||||
width = scale * (monitor.isHorizontal ? 1f : monitor.aspect) * ((float)monitor.width / 1920);
|
||||
height = scale * (monitor.isHorizontal ? 1f / monitor.aspect : 1f) * ((float)monitor.width / 1920);
|
||||
break;
|
||||
}
|
||||
|
||||
width *= savedInfo.widthScale;
|
||||
height *= savedInfo.heightScale;
|
||||
|
||||
if (meshForwardDirection == MeshForwardDirection.Y) {
|
||||
go.transform.localScale = new Vector3(width, go.transform.localScale.y, height);
|
||||
} else {
|
||||
go.transform.localScale = new Vector3(width, height, go.transform.localScale.z);
|
||||
}
|
||||
|
||||
// Set parent as this object
|
||||
go.transform.SetParent(transform);
|
||||
|
||||
// Calc actual size considering mesh size
|
||||
var scaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x * 2f;
|
||||
totalWidth += w * scaleX;
|
||||
// Save
|
||||
var info = new MonitorInfo();
|
||||
info.gameObject = go;
|
||||
info.originalRotation = go.transform.rotation;
|
||||
info.originalLocalScale = go.transform.localScale;
|
||||
info.uddTexture = texture;
|
||||
info.mesh = mesh;
|
||||
monitors.Add(info);
|
||||
}
|
||||
|
||||
// Set positions with margin
|
||||
totalWidth += margin * (n - 1);
|
||||
var x = -totalWidth / 2;
|
||||
for (int i = 0 ; i < n; ++i) {
|
||||
//
|
||||
var go = transform.FindChild("Monitor " + i);
|
||||
var texture = go.GetComponent<uDesktopDuplication.Texture>();
|
||||
var halfScaleX = go.GetComponent<MeshFilter>().sharedMesh.bounds.extents.x;
|
||||
var w = texture.monitor.isHorizontal ? width : (width * texture.monitor.aspect);
|
||||
var halfWidth = w * halfScaleX;
|
||||
x += halfWidth;
|
||||
go.transform.localPosition = new Vector3(x, 0f, 0f);
|
||||
x += halfWidth + margin;
|
||||
// Sort monitors in coordinate order
|
||||
monitors.Sort((a, b) => a.uddTexture.monitor.left - b.uddTexture.monitor.left);
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
foreach (var info in monitors) {
|
||||
Destroy(info.gameObject);
|
||||
}
|
||||
if (removeChildrenWhenClear) {
|
||||
for (int i = 0; i < transform.childCount; ++i) {
|
||||
Destroy(transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
monitors.Clear();
|
||||
}
|
||||
|
||||
[ContextMenu("Recreate")]
|
||||
public void Recreate()
|
||||
{
|
||||
Clear();
|
||||
Create();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(MultipleMonitorCreator))]
|
||||
public class MultipleMonitorLayouter : MonoBehaviour
|
||||
{
|
||||
protected MultipleMonitorCreator creator_;
|
||||
public bool updateEveryFrame = true;
|
||||
public float margin = 0.1f;
|
||||
[Range(0f, 10f)] public float thickness = 1f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
creator_ = GetComponent<MultipleMonitorCreator>();
|
||||
Layout();
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
margin = Mathf.Max(margin, 0f);
|
||||
|
||||
if (updateEveryFrame) {
|
||||
Layout();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Layout()
|
||||
{
|
||||
var monitors = creator_.monitors;
|
||||
var n = monitors.Count;
|
||||
|
||||
var totalWidth = 0f;
|
||||
foreach (var info in monitors) {
|
||||
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
|
||||
totalWidth += width;
|
||||
}
|
||||
totalWidth += margin * (n - 1);
|
||||
|
||||
var x = -totalWidth / 2;
|
||||
|
||||
foreach (var info in monitors) {
|
||||
var width = info.gameObject.transform.localScale.x;
|
||||
x += (width * info.mesh.bounds.extents.x);
|
||||
info.gameObject.transform.localPosition = new Vector3(x, 0f, 0f);
|
||||
info.gameObject.transform.localRotation = info.originalRotation;
|
||||
x += (width * info.mesh.bounds.extents.x) + margin;
|
||||
}
|
||||
|
||||
foreach (var info in monitors) {
|
||||
info.uddTexture.thickness = thickness;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0db1dcac2dedc724194c423ee75b3bf4
|
||||
timeCreated: 1478608632
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,100 @@
|
||||
using UnityEngine;
|
||||
using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
|
||||
|
||||
public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
|
||||
{
|
||||
public float radius = 10f;
|
||||
public Vector3 offsetAngle = Vector3.zero;
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
foreach (var info in creator_.monitors) {
|
||||
info.uddTexture.bend = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Layout()
|
||||
{
|
||||
var monitors = creator_.monitors;
|
||||
var n = monitors.Count;
|
||||
|
||||
// Keep the local scale z of monitors as 1 to bend them correctly.
|
||||
// And save width / height to use same values after reinitialization.
|
||||
for (int i = 0; i < n; ++i) {
|
||||
var info = monitors[i];
|
||||
var savedInfo = creator_.savedInfoList[i];
|
||||
var scale = info.gameObject.transform.localScale;
|
||||
if (creator_.meshForwardDirection == MeshForwardDirection.Y) {
|
||||
scale.y = 1f;
|
||||
savedInfo.widthScale = scale.x / info.originalLocalScale.x;
|
||||
savedInfo.heightScale = scale.z / info.originalLocalScale.z;
|
||||
} else {
|
||||
scale.z = 1f;
|
||||
savedInfo.widthScale = scale.x / info.originalLocalScale.x;
|
||||
savedInfo.heightScale = scale.y / info.originalLocalScale.y;
|
||||
}
|
||||
info.gameObject.transform.localScale = scale;
|
||||
}
|
||||
|
||||
// keep thicness plus value.
|
||||
thickness = Mathf.Max(thickness, 0f);
|
||||
|
||||
// calculate total width
|
||||
var totalWidth = 0f;
|
||||
foreach (var info in monitors) {
|
||||
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
|
||||
totalWidth += width;
|
||||
}
|
||||
totalWidth += margin * (n - 1);
|
||||
|
||||
// expand radius if total width is larger than the circumference.
|
||||
radius = Mathf.Max(radius, (totalWidth + margin) / (2 * Mathf.PI));
|
||||
|
||||
// total angle of monitors
|
||||
var totalAngle = totalWidth / radius;
|
||||
|
||||
// layout
|
||||
float angle = -totalAngle / 2;
|
||||
var offsetRot = Quaternion.Euler(offsetAngle);
|
||||
foreach (var info in monitors) {
|
||||
var uddTex = info.uddTexture;
|
||||
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
|
||||
|
||||
angle += (width / radius) * 0.5f;
|
||||
var pos = radius * new Vector3(Mathf.Sin(angle), 0f, Mathf.Cos(angle) - 1f);
|
||||
pos += radius * Vector3.forward;
|
||||
pos = offsetRot * pos;
|
||||
pos -= radius * Vector3.forward;
|
||||
uddTex.transform.localPosition = pos;
|
||||
uddTex.transform.localRotation = offsetRot * Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.up) * info.originalRotation;
|
||||
angle += (width * 0.5f + margin) / radius;
|
||||
|
||||
uddTex.bend = true;
|
||||
uddTex.meshForwardDirection = creator_.meshForwardDirection;
|
||||
uddTex.radius = radius;
|
||||
uddTex.thickness = thickness;
|
||||
uddTex.width = uddTex.transform.localScale.x;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
DebugDraw();
|
||||
}
|
||||
|
||||
void DebugDraw()
|
||||
{
|
||||
// draw the circumference in the scene view.
|
||||
var scale = transform.localScale.x;
|
||||
var center = transform.position - Vector3.forward * radius * scale;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
var a0 = 2 * Mathf.PI * i / 100;
|
||||
var a1 = 2 * Mathf.PI * (i + 1) / 100;
|
||||
var p0 = center + radius * scale * new Vector3(Mathf.Cos(a0), 0f, Mathf.Sin(a0));
|
||||
var p1 = center + radius * scale * new Vector3(Mathf.Cos(a1), 0f, Mathf.Sin(a1));
|
||||
Debug.DrawLine(p0, p1, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a31b05fdfa301f14e88365e64622b43a
|
||||
timeCreated: 1478524060
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,10 +6,12 @@ public class ToggleMonitors : MonoBehaviour
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Tab)) {
|
||||
var texture = GetComponent<uDesktopDuplication.Texture>();
|
||||
var id = texture.monitorId;
|
||||
var n = uDesktopDuplication.Manager.monitorCount;
|
||||
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) {
|
||||
texture.monitorId--;
|
||||
texture.monitorId = (id - 1 < 0) ? 0 : (id - 1);
|
||||
} else {
|
||||
texture.monitorId++;
|
||||
texture.monitorId = (id + 1 >= n) ? (n - 1) : (id + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class UddSceneManager : MonoBehaviour
|
||||
{
|
||||
public static UddSceneManager instance { get; set; }
|
||||
[SerializeField] string[] scenes;
|
||||
[SerializeField] int sceneNo = 0;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (!instance) {
|
||||
instance = this;
|
||||
} else {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
Load();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.RightArrow)) {
|
||||
Next();
|
||||
} else if (Input.GetKeyDown(KeyCode.LeftArrow)) {
|
||||
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()
|
||||
{
|
||||
sceneNo = (sceneNo + 1) % scenes.Length;
|
||||
Load();
|
||||
}
|
||||
|
||||
void Prev()
|
||||
{
|
||||
sceneNo = (sceneNo - 1) % scenes.Length;
|
||||
Load();
|
||||
}
|
||||
|
||||
void Load()
|
||||
{
|
||||
SceneManager.LoadScene(scenes[Mathf.Clamp(sceneNo, 0, scenes.Length - 1)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 426ff762e9c02b0499e1453018ecdc94
|
||||
timeCreated: 1478927673
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
9
Assets/uDesktopDuplication/Models.meta
Normal file
9
Assets/uDesktopDuplication/Models.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75494e992a22ea44d9b614d7fd3dc235
|
||||
folderAsset: yes
|
||||
timeCreated: 1478887431
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/uDesktopDuplication/Models/uDD_Board.fbx
Normal file
BIN
Assets/uDesktopDuplication/Models/uDD_Board.fbx
Normal file
Binary file not shown.
78
Assets/uDesktopDuplication/Models/uDD_Board.fbx.meta
Normal file
78
Assets/uDesktopDuplication/Models/uDD_Board.fbx.meta
Normal file
@@ -0,0 +1,78 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6b30b913257fee4d8246bf7a2620fcd
|
||||
timeCreated: 1478887431
|
||||
licenseType: Pro
|
||||
ModelImporter:
|
||||
serializedVersion: 19
|
||||
fileIDToRecycleName:
|
||||
100000: //RootNode
|
||||
400000: //RootNode
|
||||
2300000: //RootNode
|
||||
3300000: //RootNode
|
||||
4300000: pCube1
|
||||
4300002: uDD_Board
|
||||
9500000: //RootNode
|
||||
materials:
|
||||
importMaterials: 0
|
||||
materialName: 0
|
||||
materialSearch: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 4
|
||||
bakeSimulation: 0
|
||||
resampleCurves: 1
|
||||
optimizeGameObjects: 0
|
||||
motionNodeName:
|
||||
animationImportErrors:
|
||||
animationImportWarnings:
|
||||
animationRetargetingWarnings:
|
||||
animationDoRetargetingWarnings: 0
|
||||
animationCompression: 1
|
||||
animationRotationError: 0.5
|
||||
animationPositionError: 0.5
|
||||
animationScaleError: 0.5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
clipAnimations: []
|
||||
isReadable: 0
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: 0.1
|
||||
meshCompression: 0
|
||||
addColliders: 0
|
||||
importBlendShapes: 1
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 0
|
||||
useFileUnits: 1
|
||||
optimizeMeshForGPU: 1
|
||||
keepQuads: 0
|
||||
weldVertices: 1
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVPackMargin: 4
|
||||
useFileScale: 1
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 2
|
||||
importAnimation: 0
|
||||
copyAvatar: 0
|
||||
humanDescription:
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: 0.5
|
||||
foreArmTwist: 0.5
|
||||
upperLegTwist: 0.5
|
||||
legTwist: 0.5
|
||||
armStretch: 0.05
|
||||
legStretch: 0.05
|
||||
feetSpacing: 0
|
||||
rootMotionBoneName:
|
||||
hasTranslationDoF: 0
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
animationType: 0
|
||||
humanoidOversampling: 1
|
||||
additionalBone: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
9
Assets/uDesktopDuplication/Plugins/x86_64.meta
Normal file
9
Assets/uDesktopDuplication/Plugins/x86_64.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99257566ccd0582439a44abad90e65d4
|
||||
folderAsset: yes
|
||||
timeCreated: 1478626361
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -1,8 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e15bc51aada81042a909c808e25c176
|
||||
guid: b281589e6b8e27b4fbf0509d620b7871
|
||||
folderAsset: yes
|
||||
timeCreated: 1477555207
|
||||
licenseType: Pro
|
||||
timeCreated: 1478354860
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48b92326b146fa848beec6f35365b1f4
|
||||
guid: e36cd526b654d024e875d5110a1b0442
|
||||
folderAsset: yes
|
||||
timeCreated: 1477555207
|
||||
licenseType: Pro
|
||||
timeCreated: 1478354877
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e2bcc27e10c0d141a0c11cd88cdcf98
|
||||
folderAsset: yes
|
||||
timeCreated: 1478353263
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
@@ -0,0 +1,59 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9855ecfc2b823c94d8a1354715d343a1
|
||||
timeCreated: 1478353264
|
||||
licenseType: Pro
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 7
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapMode: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 0
|
||||
spriteTessellationDetail: -1
|
||||
textureType: -1
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,21 +1,21 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace uDesktopDuplication
|
||||
{
|
||||
|
||||
[AddComponentMenu("uDesktopDuplication/Cursor"),
|
||||
RequireComponent(typeof(Texture))]
|
||||
[AddComponentMenu("uDesktopDuplication/Cursor"), RequireComponent(typeof(Texture))]
|
||||
public class Cursor : MonoBehaviour
|
||||
{
|
||||
Vector3 worldPosition { get; set; }
|
||||
[SerializeField] Vector2 modelScale = Vector2.one;
|
||||
|
||||
public Vector3 worldPosition { get; set; }
|
||||
public Vector2 coord { get; set; }
|
||||
|
||||
private Texture uddTexture_;
|
||||
private Monitor monitor { get { return uddTexture_.monitor; } }
|
||||
|
||||
private Texture2D currentTexture_;
|
||||
private Dictionary<Vector2, Texture2D> textures_ = new Dictionary<Vector2, Texture2D>();
|
||||
[SerializeField] Vector2 modelScale = Vector2.one;
|
||||
private Dictionary<int, Texture2D> textures_ = new Dictionary<int, Texture2D>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -27,14 +27,14 @@ public class Cursor : MonoBehaviour
|
||||
if (monitor.isCursorVisible) {
|
||||
UpdatePosition();
|
||||
UpdateTexture();
|
||||
UpdateMaterial();
|
||||
}
|
||||
UpdateMaterial();
|
||||
}
|
||||
|
||||
void UpdatePosition()
|
||||
{
|
||||
var x = (1f * monitor.pointerX / monitor.width - 0.5f) * modelScale.x;
|
||||
var y = (1f * monitor.pointerY / monitor.height - 0.5f) * modelScale.y;
|
||||
var x = (1f * monitor.cursorX / monitor.width - 0.5f) * modelScale.x;
|
||||
var y = (1f * monitor.cursorY / monitor.height - 0.5f) * modelScale.y;
|
||||
var iy = uddTexture_.invertY ? -1 : +1;
|
||||
var localPos = transform.right * x + iy * transform.up * y;
|
||||
worldPosition = transform.TransformPoint(localPos);
|
||||
@@ -42,29 +42,32 @@ public class Cursor : MonoBehaviour
|
||||
|
||||
void UpdateTexture()
|
||||
{
|
||||
var w = monitor.pointerShapeWidth;
|
||||
var h = monitor.pointerShapeHeight;
|
||||
var w = monitor.cursorShapeWidth;
|
||||
var h = monitor.cursorShapeHeight;
|
||||
if (w == 0 || h == 0) return;
|
||||
|
||||
var scale = new Vector2(w, h);
|
||||
if (!textures_.ContainsKey(scale)) {
|
||||
var key = w + h * 100;
|
||||
if (!textures_.ContainsKey(key)) {
|
||||
var texture = new Texture2D(w, h, TextureFormat.BGRA32, false);
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
textures_.Add(scale, texture);
|
||||
textures_.Add(key, texture);
|
||||
}
|
||||
|
||||
var pointerTexture = textures_[scale];
|
||||
monitor.UpdateCursorTexture(pointerTexture.GetNativeTexturePtr());
|
||||
uddTexture_.material.SetTexture("_CursorTex", pointerTexture);
|
||||
var cursorTexture = textures_[key];
|
||||
Assert.IsNotNull(cursorTexture);
|
||||
monitor.GetCursorTexture(cursorTexture.GetNativeTexturePtr());
|
||||
uddTexture_.material.SetTexture("_CursorTex", cursorTexture);
|
||||
}
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
var x = (float)monitor.pointerX / monitor.width;
|
||||
var y = (float)monitor.pointerY / monitor.height;
|
||||
var w = (float)monitor.pointerShapeWidth / monitor.width;
|
||||
var h = (float)monitor.pointerShapeHeight / monitor.height;
|
||||
var x = monitor.isCursorVisible ? (float)monitor.cursorX / monitor.width : -9999f;
|
||||
var y = monitor.isCursorVisible ? (float)monitor.cursorY / monitor.height : -9999f;
|
||||
var w = (float)monitor.cursorShapeWidth / monitor.width;
|
||||
var h = (float)monitor.cursorShapeHeight / monitor.height;
|
||||
uddTexture_.material.SetVector("_CursorPositionScale", new Vector4(x, y, w, h));
|
||||
|
||||
coord = new Vector2(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@ public enum Message
|
||||
{
|
||||
None = -1,
|
||||
Reinitialized = 0,
|
||||
TextureSizeChanged = 1,
|
||||
}
|
||||
|
||||
public enum CursorShapeType
|
||||
{
|
||||
Unspecified = 0,
|
||||
MonoChrome = 1,
|
||||
Color = 2,
|
||||
MaskedColor = 4,
|
||||
@@ -27,21 +29,80 @@ public enum MonitorRotation
|
||||
Rotate270 = 4
|
||||
}
|
||||
|
||||
public enum MonitorState
|
||||
{
|
||||
NotSet = -1,
|
||||
Available = 0,
|
||||
InvalidArg = 1,
|
||||
AccessDenied = 2,
|
||||
Unsupported = 3,
|
||||
CurrentlyNotAvailable = 4,
|
||||
SessionDisconnected = 5,
|
||||
AccessLost = 6,
|
||||
TextureSizeInconsistent = 7,
|
||||
Unknown = 999,
|
||||
}
|
||||
|
||||
public enum DebugMode
|
||||
{
|
||||
None = 0,
|
||||
File = 1,
|
||||
UnityLog = 2, /* currently has bug when app exits. */
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT
|
||||
{
|
||||
[MarshalAs(UnmanagedType.I4)]
|
||||
public int left;
|
||||
[MarshalAs(UnmanagedType.I4)]
|
||||
public int top;
|
||||
[MarshalAs(UnmanagedType.I4)]
|
||||
public int right;
|
||||
[MarshalAs(UnmanagedType.I4)]
|
||||
public int bottom;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DXGI_OUTDUPL_MOVE_RECT
|
||||
{
|
||||
public RECT source;
|
||||
public RECT destination;
|
||||
}
|
||||
|
||||
public static class Lib
|
||||
{
|
||||
public delegate void MessageHandler(Message message);
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void DebugLogDelegate(string str);
|
||||
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void InitializeUDD();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void FinalizeUDD();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void Reinitialize();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void Update();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern Message PopMessage();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void EnableDebug();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void DisableDebug();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetDebugMode(DebugMode mode);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetLogFunc(IntPtr func);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void SetErrorFunc(IntPtr func);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetMonitorCount();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern bool HasMonitorCountChanged();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetCursorMonitorId();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalWidth();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetTotalHeight();
|
||||
@@ -50,6 +111,10 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern IntPtr GetRenderEventFunc();
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetId(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern MonitorState GetState(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void GetName(int id, StringBuilder buf, int len);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetLeft(int id);
|
||||
@@ -64,6 +129,10 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetHeight(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetDpiX(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetDpiY(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern MonitorRotation GetRotation(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern bool IsPrimary(int id);
|
||||
@@ -82,9 +151,17 @@ public static class Lib
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern CursorShapeType GetCursorShapeType(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern void UpdateCursorTexture(int id, System.IntPtr ptr);
|
||||
public static extern void GetCursorTexture(int id, System.IntPtr ptr);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int SetTexturePtr(int id, IntPtr ptr);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetMoveRectCount(int id);
|
||||
[DllImport("uDesktopDuplication", EntryPoint = "GetMoveRects")]
|
||||
private static extern IntPtr GetMoveRects_Internal(int id);
|
||||
[DllImport("uDesktopDuplication")]
|
||||
public static extern int GetDirtyRectCount(int id);
|
||||
[DllImport("uDesktopDuplication", EntryPoint = "GetDirtyRects")]
|
||||
private static extern IntPtr GetDirtyRects_Internal(int id);
|
||||
|
||||
public static string GetName(int id)
|
||||
{
|
||||
@@ -92,6 +169,32 @@ public static class Lib
|
||||
GetName(id, buf, buf.Capacity);
|
||||
return buf.ToString();
|
||||
}
|
||||
|
||||
public static DXGI_OUTDUPL_MOVE_RECT[] GetMoveRects(int id)
|
||||
{
|
||||
var count = GetMoveRectCount(id);
|
||||
var rects = new DXGI_OUTDUPL_MOVE_RECT[count];
|
||||
var ptr = GetMoveRects_Internal(id);
|
||||
var size = Marshal.SizeOf(typeof(DXGI_OUTDUPL_MOVE_RECT));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
var data = new IntPtr(ptr.ToInt64() + size * i);
|
||||
rects[i] = (DXGI_OUTDUPL_MOVE_RECT)Marshal.PtrToStructure(data, typeof(DXGI_OUTDUPL_MOVE_RECT));
|
||||
}
|
||||
return rects;
|
||||
}
|
||||
|
||||
public static RECT[] GetDirtyRects(int id)
|
||||
{
|
||||
var count = GetDirtyRectCount(id);
|
||||
var rects = new RECT[count];
|
||||
var ptr = GetDirtyRects_Internal(id);
|
||||
var size = Marshal.SizeOf(typeof(RECT));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
var data = new IntPtr(ptr.ToInt64() + size * i);
|
||||
rects[i] = (RECT)Marshal.PtrToStructure(data, typeof(RECT));
|
||||
}
|
||||
return rects;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,20 @@ public class Manager : MonoBehaviour
|
||||
private static Manager instance_;
|
||||
public static Manager instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance_) return instance_;
|
||||
var go = new GameObject("uDesktopDuplicationManager");
|
||||
return go.AddComponent<Manager>();
|
||||
get { return CreateInstance(); }
|
||||
}
|
||||
|
||||
public static Manager CreateInstance()
|
||||
{
|
||||
if (instance_) {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
var manager = FindObjectOfType<Manager>();
|
||||
if (manager) return manager;
|
||||
|
||||
var go = new GameObject("uDesktopDuplicationManager");
|
||||
return go.AddComponent<Manager>();
|
||||
}
|
||||
|
||||
private List<Monitor> monitors_ = new List<Monitor>();
|
||||
@@ -29,6 +37,11 @@ public class Manager : MonoBehaviour
|
||||
get { return Lib.GetMonitorCount(); }
|
||||
}
|
||||
|
||||
static public int cursorMonitorId
|
||||
{
|
||||
get { return Lib.GetCursorMonitorId(); }
|
||||
}
|
||||
|
||||
static public Monitor primary
|
||||
{
|
||||
get
|
||||
@@ -37,31 +50,55 @@ public class Manager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField, Tooltip("Set Desktop Duplication API timeout (milliseconds).")]
|
||||
int timeout = 0;
|
||||
[SerializeField] DebugMode debugMode = DebugMode.File;
|
||||
[SerializeField] int desktopDuplicationApiTimeout = 0;
|
||||
[SerializeField] float retryReinitializationDuration = 1f;
|
||||
|
||||
private Coroutine renderCoroutine_ = null;
|
||||
private bool shouldReinitialize_ = false;
|
||||
private float reinitializationTimer_ = 0f;
|
||||
private bool isFirstFrame_ = true;
|
||||
|
||||
public delegate void ReinitializeHandler();
|
||||
public static event ReinitializeHandler onReinitialized;
|
||||
|
||||
public static Monitor GetMonitor(int id)
|
||||
{
|
||||
if (id < 0 || id >= Manager.monitors.Count) {
|
||||
Debug.LogErrorFormat("[uDD::Error] there is no monitor whose id is {0}.", id);
|
||||
return Manager.primary;
|
||||
}
|
||||
return monitors[Mathf.Clamp(id, 0, Manager.monitorCount - 1)];
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Lib.InitializeUDD();
|
||||
|
||||
if (instance_ != null) return;
|
||||
// for simple singleton
|
||||
if (instance_ != null) {
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
instance_ = this;
|
||||
|
||||
CreateMonitors();
|
||||
Lib.SetDebugMode(debugMode);
|
||||
Lib.SetTimeout(desktopDuplicationApiTimeout);
|
||||
Lib.InitializeUDD();
|
||||
|
||||
Lib.SetTimeout(timeout);
|
||||
CreateMonitors();
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
Lib.FinalizeUDD();
|
||||
DestroyMonitors();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
renderCoroutine_ = StartCoroutine(OnRender());
|
||||
if (!isFirstFrame_) {
|
||||
Reinitialize();
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
@@ -75,13 +112,68 @@ public class Manager : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
Lib.Update();
|
||||
ReinitializeIfNeeded();
|
||||
UpdateMessage();
|
||||
isFirstFrame_ = false;
|
||||
}
|
||||
|
||||
[ContextMenu("Reinitialize")]
|
||||
public void Reinitialize()
|
||||
{
|
||||
Debug.Log("[uDD] Reinitialize");
|
||||
Lib.Reinitialize();
|
||||
CreateMonitors();
|
||||
if (onReinitialized != null) {
|
||||
onReinitialized();
|
||||
}
|
||||
}
|
||||
|
||||
void ReinitializeIfNeeded()
|
||||
{
|
||||
bool reinitializeNeeded = false;
|
||||
|
||||
for (int i = 0; i < monitors.Count; ++i) {
|
||||
var monitor = monitors[i];
|
||||
if (
|
||||
monitor.state == MonitorState.NotSet ||
|
||||
monitor.state == MonitorState.AccessLost ||
|
||||
monitor.state == MonitorState.AccessDenied ||
|
||||
monitor.state == MonitorState.SessionDisconnected
|
||||
) {
|
||||
reinitializeNeeded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Lib.HasMonitorCountChanged()) {
|
||||
reinitializeNeeded = true;
|
||||
}
|
||||
|
||||
if (!shouldReinitialize_ && reinitializeNeeded) {
|
||||
shouldReinitialize_ = true;
|
||||
reinitializationTimer_ = 0f;
|
||||
}
|
||||
|
||||
if (shouldReinitialize_) {
|
||||
if (reinitializationTimer_ > retryReinitializationDuration) {
|
||||
Reinitialize();
|
||||
shouldReinitialize_ = false;
|
||||
}
|
||||
reinitializationTimer_ += Time.deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateMessage()
|
||||
{
|
||||
var message = Lib.PopMessage();
|
||||
while (message != Message.None) {
|
||||
Debug.Log("[uDD] " + message);
|
||||
switch (message) {
|
||||
case Message.Reinitialized:
|
||||
Debug.Log("Reinitialize");
|
||||
Reinitialize();
|
||||
ReinitializeMonitors();
|
||||
break;
|
||||
case Message.TextureSizeChanged:
|
||||
RecreateTextures();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -106,18 +198,35 @@ public class Manager : MonoBehaviour
|
||||
|
||||
void CreateMonitors()
|
||||
{
|
||||
DestroyMonitors();
|
||||
for (int i = 0; i < monitorCount; ++i) {
|
||||
monitors.Add(new Monitor(i));
|
||||
}
|
||||
}
|
||||
|
||||
void Reinitialize()
|
||||
void DestroyMonitors()
|
||||
{
|
||||
for (int i = 0; i < monitors.Count; ++i) {
|
||||
monitors[i].DestroyTexture();
|
||||
}
|
||||
monitors.Clear();
|
||||
}
|
||||
|
||||
void ReinitializeMonitors()
|
||||
{
|
||||
for (int i = 0; i < monitorCount; ++i) {
|
||||
if (i == monitors.Count) {
|
||||
monitors.Add(new Monitor(i));
|
||||
} else {
|
||||
monitors[i].Reinitialize();
|
||||
}
|
||||
monitors[i].Reinitialize();
|
||||
}
|
||||
}
|
||||
|
||||
void RecreateTextures()
|
||||
{
|
||||
for (int i = 0; i < monitorCount; ++i) {
|
||||
monitors[i].CreateTextureIfNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,39 @@ public class Monitor
|
||||
public Monitor(int id)
|
||||
{
|
||||
this.id = id;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case MonitorState.Available:
|
||||
break;
|
||||
case MonitorState.InvalidArg:
|
||||
Debug.LogErrorFormat("[uDD] {0}:{1} => Invalid.", id, name);
|
||||
break;
|
||||
case MonitorState.AccessDenied:
|
||||
Debug.LogWarningFormat("[uDD] {0}:{1} => Access Denied.", id, name);
|
||||
break;
|
||||
case MonitorState.Unsupported:
|
||||
Debug.LogWarningFormat("[uDD] {0}:{1} => Unsupported.", id, name);
|
||||
break;
|
||||
case MonitorState.SessionDisconnected:
|
||||
Debug.LogWarningFormat("[uDD] {0}:{1} => Disconnected.", id, name);
|
||||
break;
|
||||
case MonitorState.NotSet:
|
||||
Debug.LogErrorFormat("[uDD] {0}:{1} => Something wrong.", id, name);
|
||||
break;
|
||||
default:
|
||||
Debug.LogErrorFormat("[uDD] {0}:{1} => Unknown error.", id, name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (dpiX == 0 || dpiY == 0) {
|
||||
Debug.LogWarningFormat("[uDD] {0}:{1} => Could not get DPI", id, name);
|
||||
}
|
||||
}
|
||||
|
||||
~Monitor()
|
||||
{
|
||||
DestroyTexture();
|
||||
}
|
||||
|
||||
public int id
|
||||
@@ -21,6 +54,16 @@ public class Monitor
|
||||
get { return id < Manager.monitorCount; }
|
||||
}
|
||||
|
||||
public MonitorState state
|
||||
{
|
||||
get { return Lib.GetState(id); }
|
||||
}
|
||||
|
||||
public bool available
|
||||
{
|
||||
get { return state == MonitorState.Available; }
|
||||
}
|
||||
|
||||
public string name
|
||||
{
|
||||
get { return Lib.GetName(id); }
|
||||
@@ -61,6 +104,36 @@ public class Monitor
|
||||
get { return Lib.GetHeight(id); }
|
||||
}
|
||||
|
||||
public int dpiX
|
||||
{
|
||||
get
|
||||
{
|
||||
var dpi = Lib.GetDpiX(id);
|
||||
if (dpi == 0) dpi = 100; // when monitors are duplicated
|
||||
return dpi;
|
||||
}
|
||||
}
|
||||
|
||||
public int dpiY
|
||||
{
|
||||
get
|
||||
{
|
||||
var dpi = Lib.GetDpiY(id);
|
||||
if (dpi == 0) dpi = 100; // when monitors are duplicated
|
||||
return dpi;
|
||||
}
|
||||
}
|
||||
|
||||
public float widthMeter
|
||||
{
|
||||
get { return width / dpiX * 0.0254f; }
|
||||
}
|
||||
|
||||
public float heightMeter
|
||||
{
|
||||
get { return height / dpiY * 0.0254f; }
|
||||
}
|
||||
|
||||
public MonitorRotation rotation
|
||||
{
|
||||
get { return Lib.GetRotation(id); }
|
||||
@@ -86,83 +159,150 @@ public class Monitor
|
||||
get { return Lib.IsCursorVisible(id); }
|
||||
}
|
||||
|
||||
public int pointerX
|
||||
public int cursorX
|
||||
{
|
||||
get { return Lib.GetCursorX(id); }
|
||||
}
|
||||
|
||||
public int pointerY
|
||||
public int cursorY
|
||||
{
|
||||
get { return Lib.GetCursorY(id); }
|
||||
}
|
||||
|
||||
public int pointerShapeWidth
|
||||
public int systemCursorX
|
||||
{
|
||||
get
|
||||
{
|
||||
var p = Utility.GetCursorPos();
|
||||
return p.x - left;
|
||||
}
|
||||
}
|
||||
|
||||
public int systemCursorY
|
||||
{
|
||||
get
|
||||
{
|
||||
var p = Utility.GetCursorPos();
|
||||
return p.y - top;
|
||||
}
|
||||
}
|
||||
|
||||
public int cursorShapeWidth
|
||||
{
|
||||
get { return Lib.GetCursorShapeWidth(id); }
|
||||
}
|
||||
|
||||
public int pointerShapeHeight
|
||||
public int cursorShapeHeight
|
||||
{
|
||||
get { return Lib.GetCursorShapeHeight(id); }
|
||||
}
|
||||
|
||||
public CursorShapeType pointerShapeType
|
||||
public CursorShapeType cursorShapeType
|
||||
{
|
||||
get { return Lib.GetCursorShapeType(id); }
|
||||
}
|
||||
|
||||
public int moveRectCount
|
||||
{
|
||||
get { return Lib.GetMoveRectCount(id); }
|
||||
}
|
||||
|
||||
public DXGI_OUTDUPL_MOVE_RECT[] moveRects
|
||||
{
|
||||
get { return Lib.GetMoveRects(id); }
|
||||
}
|
||||
|
||||
public int dirtyRectCount
|
||||
{
|
||||
get { return Lib.GetDirtyRectCount(id); }
|
||||
}
|
||||
|
||||
public RECT[] dirtyRects
|
||||
{
|
||||
get { return Lib.GetDirtyRects(id); }
|
||||
}
|
||||
|
||||
public bool shouldBeUpdated
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private static Texture2D errorTexture_;
|
||||
private static readonly string errorTexturePath = "uDesktopDuplication/Textures/NotAvailable";
|
||||
private Texture2D errorTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
return errorTexture_ ??
|
||||
(errorTexture_ = Resources.Load<Texture2D>(errorTexturePath));
|
||||
}
|
||||
}
|
||||
|
||||
private Texture2D texture_;
|
||||
public Texture2D texture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (texture_ == null) {
|
||||
CreateTexture();
|
||||
}
|
||||
if (!available) return errorTexture;
|
||||
if (texture_ == null) CreateTextureIfNeeded();
|
||||
return texture_;
|
||||
}
|
||||
}
|
||||
|
||||
public void Render()
|
||||
{
|
||||
Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
|
||||
GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id);
|
||||
if (texture_ && available) {
|
||||
Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
|
||||
GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCursorTexture(System.IntPtr ptr)
|
||||
public void GetCursorTexture(System.IntPtr ptr)
|
||||
{
|
||||
Lib.UpdateCursorTexture(id, ptr);
|
||||
Lib.GetCursorTexture(id, ptr);
|
||||
}
|
||||
|
||||
void CreateTexture()
|
||||
public void CreateTextureIfNeeded()
|
||||
{
|
||||
if (!available) return;
|
||||
|
||||
var w = isHorizontal ? width : height;
|
||||
var h = isHorizontal ? height : width;
|
||||
bool shouldCreate = true;
|
||||
|
||||
if (texture_) {
|
||||
if (texture_.width != w || texture_.height != h) {
|
||||
if (texture_) Object.DestroyImmediate(texture_);
|
||||
shouldCreate = true;
|
||||
} else {
|
||||
shouldCreate = false;
|
||||
}
|
||||
if (texture_ && texture_.width == w && texture_.height == h) {
|
||||
shouldCreate = false;
|
||||
}
|
||||
|
||||
if (w <= 0 || h <= 0) {
|
||||
shouldCreate = false;
|
||||
}
|
||||
|
||||
if (shouldCreate) {
|
||||
texture_ = new Texture2D(w, h, TextureFormat.BGRA32, false);
|
||||
CreateTexture();
|
||||
}
|
||||
}
|
||||
|
||||
void CreateTexture()
|
||||
{
|
||||
DestroyTexture();
|
||||
var w = isHorizontal ? width : height;
|
||||
var h = isHorizontal ? height : width;
|
||||
texture_ = new Texture2D(w, h, TextureFormat.BGRA32, false);
|
||||
}
|
||||
|
||||
public void DestroyTexture()
|
||||
{
|
||||
if (texture_) {
|
||||
Object.Destroy(texture_);
|
||||
texture_ = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reinitialize()
|
||||
{
|
||||
CreateTexture();
|
||||
CreateTextureIfNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace uDesktopDuplication
|
||||
{
|
||||
|
||||
[AddComponentMenu("uDesktopDuplication/Texture")]
|
||||
[AddComponentMenu("uDesktopDuplication/Texture"), RequireComponent(typeof(Cursor))]
|
||||
public class Texture : MonoBehaviour
|
||||
{
|
||||
private Monitor monitor_;
|
||||
@@ -13,20 +13,95 @@ public class Texture : MonoBehaviour
|
||||
set
|
||||
{
|
||||
monitor_ = value;
|
||||
material = GetComponent<Renderer>().material;
|
||||
material.mainTexture = monitor_.texture;
|
||||
if (monitor_ != null) {
|
||||
material = GetComponent<Renderer>().material; // clone
|
||||
material.mainTexture = monitor_.texture;
|
||||
material.SetFloat("_Width", transform.localScale.x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int lastMonitorId_ = 0;
|
||||
public int monitorId
|
||||
{
|
||||
get { return monitor.id; }
|
||||
set { monitor = Manager.monitors[Mathf.Clamp(value, 0, Manager.monitorCount - 1)]; }
|
||||
set { monitor = Manager.GetMonitor(value); }
|
||||
}
|
||||
|
||||
[Header("Invert UVs")]
|
||||
public bool invertX = false;
|
||||
public bool invertY = false;
|
||||
|
||||
[Header("Clip")]
|
||||
public bool useClip = false;
|
||||
public Vector2 clipPos = Vector2.zero;
|
||||
public Vector2 clipScale = new Vector2(0.2f, 0.2f);
|
||||
|
||||
public enum MeshForwardDirection
|
||||
{
|
||||
Y = 0,
|
||||
Z = 1,
|
||||
}
|
||||
|
||||
public bool bend
|
||||
{
|
||||
get
|
||||
{
|
||||
return material.GetInt("_Bend") != 0;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value) {
|
||||
material.EnableKeyword("BEND_ON");
|
||||
material.SetInt("_Bend", 1);
|
||||
} else {
|
||||
material.DisableKeyword("BEND_ON");
|
||||
material.SetInt("_Bend", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MeshForwardDirection meshForwardDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
return (MeshForwardDirection)material.GetInt("_Forward");
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value) {
|
||||
case MeshForwardDirection.Y:
|
||||
material.SetInt("_Forward", 0);
|
||||
material.EnableKeyword("_FORWARD_Y");
|
||||
material.DisableKeyword("_FORWARD_Z");
|
||||
break;
|
||||
case MeshForwardDirection.Z:
|
||||
material.SetInt("_Forward", 1);
|
||||
material.DisableKeyword("_FORWARD_Y");
|
||||
material.EnableKeyword("_FORWARD_Z");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float radius
|
||||
{
|
||||
get { return material.GetFloat("_Radius"); }
|
||||
set { material.SetFloat("_Radius", value); }
|
||||
}
|
||||
|
||||
public float width
|
||||
{
|
||||
get { return material.GetFloat("_Width"); }
|
||||
set { material.SetFloat("_Width", value); }
|
||||
}
|
||||
|
||||
public float thickness
|
||||
{
|
||||
get { return material.GetFloat("_Thickness"); }
|
||||
set { material.SetFloat("_Thickness", value); }
|
||||
}
|
||||
|
||||
public Material material
|
||||
{
|
||||
get;
|
||||
@@ -35,10 +110,7 @@ public class Texture : MonoBehaviour
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (!GetComponent<Cursor>())
|
||||
{
|
||||
gameObject.AddComponent<Cursor>();
|
||||
}
|
||||
AddCursorIfNotAttached();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
@@ -46,15 +118,52 @@ public class Texture : MonoBehaviour
|
||||
if (monitor == null) {
|
||||
monitor = Manager.primary;
|
||||
}
|
||||
Manager.onReinitialized += Reinitialize;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
Manager.onReinitialized -= Reinitialize;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
KeepMonitor();
|
||||
monitor.shouldBeUpdated = true;
|
||||
UpdateMaterial();
|
||||
}
|
||||
|
||||
void KeepMonitor()
|
||||
{
|
||||
if (monitor == null) {
|
||||
Reinitialize();
|
||||
} else {
|
||||
lastMonitorId_ = monitorId;
|
||||
}
|
||||
}
|
||||
|
||||
void AddCursorIfNotAttached()
|
||||
{
|
||||
if (!GetComponent<Cursor>())
|
||||
{
|
||||
gameObject.AddComponent<Cursor>();
|
||||
}
|
||||
}
|
||||
|
||||
void Reinitialize()
|
||||
{
|
||||
// Monitor instance is released here when initialized.
|
||||
monitor = Manager.GetMonitor(lastMonitorId_);
|
||||
}
|
||||
|
||||
void UpdateMaterial()
|
||||
{
|
||||
Invert();
|
||||
Rotate();
|
||||
Clip();
|
||||
}
|
||||
|
||||
void Invert()
|
||||
{
|
||||
if (invertX) {
|
||||
material.EnableKeyword("INVERT_X");
|
||||
@@ -67,7 +176,10 @@ public class Texture : MonoBehaviour
|
||||
} else {
|
||||
material.DisableKeyword("INVERT_Y");
|
||||
}
|
||||
}
|
||||
|
||||
void Rotate()
|
||||
{
|
||||
switch (monitor.rotation)
|
||||
{
|
||||
case MonitorRotation.Identity:
|
||||
@@ -94,6 +206,16 @@ public class Texture : MonoBehaviour
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Clip()
|
||||
{
|
||||
if (useClip) {
|
||||
material.EnableKeyword("USE_CLIP");
|
||||
material.SetVector("_ClipPositionScale", new Vector4(clipPos.x, clipPos.y, clipScale.x, clipScale.y));
|
||||
} else {
|
||||
material.DisableKeyword("USE_CLIP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
42
Assets/uDesktopDuplication/Scripts/Utility.cs
Normal file
42
Assets/uDesktopDuplication/Scripts/Utility.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace uDesktopDuplication
|
||||
{
|
||||
|
||||
public struct MousePoint
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
}
|
||||
|
||||
public static class Utility
|
||||
{
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetCursorPos(out MousePoint point);
|
||||
|
||||
public static MousePoint GetCursorPos()
|
||||
{
|
||||
MousePoint p;
|
||||
if (!GetCursorPos(out p)) {
|
||||
p.x = -1;
|
||||
p.y = -1;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
Assets/uDesktopDuplication/Scripts/Utility.cs.meta
Normal file
12
Assets/uDesktopDuplication/Scripts/Utility.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c7e8da181b03ce4fb343ffa33cbb929
|
||||
timeCreated: 1479043365
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 89616e59e1cccb346bd4e959257990ca, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,6 +2,7 @@
|
||||
#define UDD_COMMON_CGINC
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -17,35 +18,42 @@ struct v2f
|
||||
|
||||
struct Input
|
||||
{
|
||||
float2 uv_MainTex;
|
||||
float2 uv_MainTex;
|
||||
};
|
||||
|
||||
float2 uddInvertUV(float2 uv)
|
||||
inline float2 uddInvertUV(float2 uv)
|
||||
{
|
||||
#ifdef INVERT_X
|
||||
uv.x = 1.0 - uv.x;
|
||||
uv.x = 1.0 - uv.x;
|
||||
#endif
|
||||
#ifdef INVERT_Y
|
||||
uv.y = 1.0 - uv.y;
|
||||
uv.y = 1.0 - uv.y;
|
||||
#endif
|
||||
return uv;
|
||||
return uv;
|
||||
}
|
||||
|
||||
float2 uddRotateUV(float2 uv)
|
||||
inline float2 uddRotateUV(float2 uv)
|
||||
{
|
||||
#ifdef ROTATE90
|
||||
float2 tmp = uv;
|
||||
uv.x = tmp.y;
|
||||
uv.y = 1.0 - tmp.x;
|
||||
#elif ROTATE180
|
||||
uv.x = 1.0 - uv.x;
|
||||
uv.y = 1.0 - uv.y;
|
||||
uv.x = 1.0 - uv.x;
|
||||
uv.y = 1.0 - uv.y;
|
||||
#elif ROTATE270
|
||||
float2 tmp = uv;
|
||||
uv.x = 1.0 - tmp.y;
|
||||
uv.y = tmp.x;
|
||||
#endif
|
||||
return uv;
|
||||
return uv;
|
||||
}
|
||||
|
||||
inline float2 uddClipUV(float2 uv)
|
||||
{
|
||||
uv.x = _ClipX + uv.x * _ClipWidth;
|
||||
uv.y = _ClipY + uv.y * _ClipHeight;
|
||||
return uv;
|
||||
}
|
||||
|
||||
inline void uddConvertToLinearIfNeeded(inout fixed3 rgb)
|
||||
@@ -55,30 +63,56 @@ inline void uddConvertToLinearIfNeeded(inout fixed3 rgb)
|
||||
}
|
||||
}
|
||||
|
||||
inline fixed4 uddGetScreenTexture(sampler2D tex, float2 uv)
|
||||
inline fixed4 uddGetScreenTexture(float2 uv)
|
||||
{
|
||||
fixed4 c = tex2D(tex, uv);
|
||||
fixed4 c = tex2D(_MainTex, uv);
|
||||
return c;
|
||||
}
|
||||
|
||||
inline fixed4 uddGetCursorTexture(sampler2D tex, float2 uv, fixed4 cursorPosScale)
|
||||
inline fixed4 uddGetCursorTexture(float2 uv)
|
||||
{
|
||||
uv.x = (uv.x - cursorPosScale.x) / cursorPosScale.z;
|
||||
uv.y = (uv.y - cursorPosScale.y) / cursorPosScale.w;
|
||||
fixed4 c = tex2D(tex, uv);
|
||||
fixed a = c.a * step(0, uv.x) * step(0, uv.y) * step(uv.x, 1) * step(uv.y, 1);
|
||||
c *= step(0.01, a);
|
||||
return c;
|
||||
uv.x = (uv.x - _CursorX) / _CursorWidth;
|
||||
uv.y = (uv.y - _CursorY) / _CursorHeight;
|
||||
fixed4 c = tex2D(_CursorTex, uv);
|
||||
fixed a = step(0, uv.x) * step(0, uv.y) * step(uv.x, 1) * step(uv.y, 1);
|
||||
c.a *= step(0.01, a);
|
||||
return c;
|
||||
}
|
||||
|
||||
inline fixed4 uddGetScreenTextureWithCursor(sampler2D screenTex, sampler2D cursorTex, float2 uv, fixed4 cursorPosScale)
|
||||
inline fixed4 uddGetScreenTextureWithCursor(float2 uv)
|
||||
{
|
||||
uv = uddInvertUV(uv);
|
||||
fixed4 screen = uddGetScreenTexture(screenTex, uddRotateUV(uv));
|
||||
fixed4 cursor = uddGetCursorTexture(cursorTex, uv, cursorPosScale);
|
||||
fixed4 color = lerp(screen, cursor, cursor.a);
|
||||
uddConvertToLinearIfNeeded(color.rgb);
|
||||
return color;
|
||||
uv = uddInvertUV(uv);
|
||||
#ifdef USE_CLIP
|
||||
uv = uddClipUV(uv);
|
||||
#endif
|
||||
fixed4 screen = uddGetScreenTexture(uddRotateUV(uv));
|
||||
fixed4 cursor = uddGetCursorTexture(uv);
|
||||
fixed4 color = lerp(screen, cursor, cursor.a);
|
||||
uddConvertToLinearIfNeeded(color.rgb);
|
||||
return color;
|
||||
}
|
||||
|
||||
inline void uddBendVertex(inout float4 v, half radius, half width, half thickness)
|
||||
{
|
||||
#ifdef BEND_ON
|
||||
half angle = width * v.x / radius;
|
||||
#ifdef _FORWARD_Z
|
||||
v.z *= thickness;
|
||||
radius += v.z;
|
||||
v.z -= radius * (1 - cos(angle));
|
||||
#elif _FORWARD_Y
|
||||
v.y *= thickness;
|
||||
radius += v.y;
|
||||
v.y += radius * (1 - cos(angle));
|
||||
#endif
|
||||
v.x = radius * sin(angle) / width;
|
||||
#else
|
||||
#ifdef _FORWARD_Z
|
||||
v.y *= thickness;
|
||||
#elif _FORWARD_Y
|
||||
v.z *= thickness;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -4,7 +4,18 @@
|
||||
sampler2D _MainTex;
|
||||
fixed4 _Color;
|
||||
sampler2D _CursorTex;
|
||||
|
||||
half4 _CursorPositionScale;
|
||||
#define _CursorX _CursorPositionScale.x
|
||||
#define _CursorY _CursorPositionScale.y
|
||||
#define _CursorWidth _CursorPositionScale.z
|
||||
#define _CursorHeight _CursorPositionScale.w
|
||||
|
||||
half4 _ClipPositionScale;
|
||||
#define _ClipX _ClipPositionScale.x
|
||||
#define _ClipY _ClipPositionScale.y
|
||||
#define _ClipWidth _ClipPositionScale.z
|
||||
#define _ClipHeight _ClipPositionScale.w
|
||||
|
||||
#ifndef SURFACE_SHADER
|
||||
float4 _MainTex_ST;
|
||||
|
||||
@@ -22,19 +22,19 @@ SubShader
|
||||
#pragma surface surf Standard fullforwardshadows
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_BEND
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
|
||||
#define SURFACE_SHADER
|
||||
#define SURFACE_SHADER
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
half _Glossiness;
|
||||
half _Metallic;
|
||||
half _Glossiness;
|
||||
half _Metallic;
|
||||
|
||||
void surf(Input IN, inout SurfaceOutputStandard o)
|
||||
{
|
||||
fixed4 c = uddGetScreenTextureWithCursor(_MainTex, _CursorTex, IN.uv_MainTex, _CursorPositionScale) * _Color;
|
||||
fixed4 c = uddGetScreenTextureWithCursor(IN.uv_MainTex) * _Color;
|
||||
o.Albedo = c.rgb;
|
||||
o.Metallic = _Metallic;
|
||||
o.Smoothness = _Glossiness;
|
||||
|
||||
@@ -5,8 +5,11 @@ Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
[Toggle(USE_BEND)] _UseBend("UseBend", Float) = 0
|
||||
[PowerSlider(10.0)]_Radius ("Radius", Range(3, 100)) = 10
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Y, Z)] _Forward("Mesh Forward Direction", Int) = 0
|
||||
[Toggle(BEND_ON)] _Bend("Use Bend", Int) = 0
|
||||
[PowerSlider(10.0)] _Radius("Bend Radius", Range(1, 100)) = 30
|
||||
[PowerSlider(10.0)] _Thickness("Thickness", Range(0.01, 10)) = 1
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -20,18 +23,15 @@ Cull [_Cull]
|
||||
CGINCLUDE
|
||||
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
fixed _Radius;
|
||||
half _Radius;
|
||||
half _Width;
|
||||
half _Thickness;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
#ifdef USE_BEND
|
||||
half a = v.vertex.x / _Radius;
|
||||
v.vertex.x = _Radius * sin(a);
|
||||
v.vertex.y += _Radius * (1 - cos(a));
|
||||
#endif
|
||||
uddBendVertex(v.vertex, _Radius, _Width, _Thickness);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
@@ -39,7 +39,7 @@ v2f vert(appdata v)
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
return uddGetScreenTextureWithCursor(_MainTex, _CursorTex, i.uv, _CursorPositionScale);
|
||||
return uddGetScreenTextureWithCursor(i.uv);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
@@ -51,9 +51,10 @@ Pass
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma shader_feature ___ USE_BEND
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
#pragma multi_compile ___ BEND_ON
|
||||
#pragma multi_compile _FORWARD_Y _FORWARD_Z
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,11 @@ Properties
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Mask ("Mask", Range(0, 1)) = 0.1
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Y, Z)] _Forward("Mesh Forward Direction", Int) = 0
|
||||
[Toggle(BEND_ON)] _Bend("Use Bend", Int) = 0
|
||||
[PowerSlider(10.0)] _Radius("Bend Radius", Range(1, 100)) = 30
|
||||
[PowerSlider(10.0)] _Thickness("Thickness", Range(0.01, 10)) = 1
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -21,13 +26,16 @@ Blend SrcAlpha OneMinusSrcAlpha
|
||||
CGINCLUDE
|
||||
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
fixed _Mask;
|
||||
half _Radius;
|
||||
half _Width;
|
||||
half _Thickness;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
uddBendVertex(v.vertex, _Radius, _Width, _Thickness);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
@@ -35,23 +43,25 @@ v2f vert(appdata v)
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
fixed4 tex = uddGetScreenTextureWithCursor(_MainTex, _CursorTex, i.uv, _CursorPositionScale);
|
||||
fixed alpha = pow((tex.r + tex.g + tex.b) / 3.0, _Mask);
|
||||
return fixed4(tex.rgb * _Color.rgb, alpha * _Color.a);
|
||||
fixed4 tex = uddGetScreenTextureWithCursor(i.uv);
|
||||
fixed alpha = pow((tex.r + tex.g + tex.b) / 3.0, _Mask);
|
||||
return fixed4(tex.rgb * _Color.rgb, alpha * _Color.a);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
ENDCG
|
||||
#pragma multi_compile ___ USE_BEND
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
#pragma multi_compile _BEND_OFF _BEND_Y _BEND_Z
|
||||
ENDCG
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,11 @@ Properties
|
||||
{
|
||||
_Color ("Color", Color) = (1, 1, 1, 1)
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_CursorTex ("Cursor Texture", 2D) = "white" {}
|
||||
[KeywordEnum(Y, Z)] _Forward("Mesh Forward Direction", Int) = 0
|
||||
[Toggle(BEND_ON)] _Bend("Use Bend", Int) = 0
|
||||
[PowerSlider(10.0)] _Radius("Bend Radius", Range(1, 100)) = 30
|
||||
[PowerSlider(10.0)] _Thickness("Thickness", Range(0.01, 10)) = 1
|
||||
[KeywordEnum(Off, Front, Back)] _Cull("Culling", Int) = 2
|
||||
}
|
||||
|
||||
@@ -20,11 +25,15 @@ Blend SrcAlpha OneMinusSrcAlpha
|
||||
CGINCLUDE
|
||||
|
||||
#include "./uDD_Common.cginc"
|
||||
#include "./uDD_Params.cginc"
|
||||
|
||||
half _Radius;
|
||||
half _Width;
|
||||
half _Thickness;
|
||||
|
||||
v2f vert(appdata v)
|
||||
{
|
||||
v2f o;
|
||||
uddBendVertex(v.vertex, _Radius, _Width, _Thickness);
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
@@ -32,7 +41,7 @@ v2f vert(appdata v)
|
||||
|
||||
fixed4 frag(v2f i) : SV_Target
|
||||
{
|
||||
return fixed4(uddGetScreenTextureWithCursor(_MainTex, _CursorTex, i.uv, _CursorPositionScale).rgb, 1.0) * _Color;
|
||||
return fixed4(uddGetScreenTextureWithCursor(i.uv).rgb, 1.0) * _Color;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
@@ -44,8 +53,10 @@ Pass
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile ___ INVERT_X
|
||||
#pragma multi_compile ___ INVERT_Y
|
||||
#pragma multi_compile ___ VERTICAL
|
||||
#pragma multi_compile ___ ROTATE90 ROTATE180 ROTATE270
|
||||
#pragma multi_compile ___ USE_BEND
|
||||
#pragma multi_compile ___ USE_CLIP
|
||||
#pragma multi_compile _BEND_OFF _BEND_Y _BEND_Z
|
||||
ENDCG
|
||||
}
|
||||
|
||||
|
||||
39
Plugins/uDesktopDuplication/uDesktopDuplication/Common.cpp
Normal file
39
Plugins/uDesktopDuplication/uDesktopDuplication/Common.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
#include <d3d11.h>
|
||||
|
||||
#include "IUnityInterface.h"
|
||||
#include "IUnityGraphicsD3D11.h"
|
||||
#include "Common.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
|
||||
extern IUnityInterfaces* g_unity;
|
||||
extern std::unique_ptr<MonitorManager> g_manager;
|
||||
extern std::queue<Message> g_messages;
|
||||
|
||||
|
||||
IUnityInterfaces* GetUnity()
|
||||
{
|
||||
return g_unity;
|
||||
}
|
||||
|
||||
|
||||
ComPtr<ID3D11Device> GetDevice()
|
||||
{
|
||||
return GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||
}
|
||||
|
||||
|
||||
const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
||||
{
|
||||
return g_manager;
|
||||
}
|
||||
|
||||
|
||||
void SendMessageToUnity(Message message)
|
||||
{
|
||||
g_messages.push(message);
|
||||
}
|
||||
@@ -1,15 +1,99 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "IUnityInterface.h"
|
||||
#include <wrl/client.h>
|
||||
|
||||
class MonitorManager;
|
||||
|
||||
// Unity interface and ID3D11Device getters
|
||||
struct IUnityInterfaces;
|
||||
IUnityInterfaces* GetUnity();
|
||||
ID3D11Device* GetDevice();
|
||||
|
||||
struct ID3D11Device;
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> GetDevice();
|
||||
|
||||
|
||||
// Manager getter
|
||||
class MonitorManager;
|
||||
const std::unique_ptr<MonitorManager>& GetMonitorManager();
|
||||
|
||||
|
||||
// Message is pooled and fetch from Unity.
|
||||
enum class Message
|
||||
{
|
||||
None = -1,
|
||||
Reinitialized = 0,
|
||||
None = -1,
|
||||
Reinitialized = 0,
|
||||
TextureSizeChanged = 1,
|
||||
};
|
||||
void SendMessageToUnity(Message message);
|
||||
|
||||
void SendMessageToUnity(Message message);
|
||||
|
||||
|
||||
// Buffer
|
||||
template <class T>
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer() {}
|
||||
~Buffer() {}
|
||||
|
||||
void ExpandIfNeeded(UINT size)
|
||||
{
|
||||
if (size > size_)
|
||||
{
|
||||
size_ = size;
|
||||
value_ = std::make_unique<T[]>(size);
|
||||
}
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
value_.reset();
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
UINT Size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
T* Get() const
|
||||
{
|
||||
return value_.get();
|
||||
}
|
||||
|
||||
T* Get(UINT offset) const
|
||||
{
|
||||
return (value_.get() + offset);
|
||||
}
|
||||
|
||||
template <class U>
|
||||
U* As() const
|
||||
{
|
||||
return reinterpret_cast<U*>(Get());
|
||||
}
|
||||
|
||||
template <class U>
|
||||
U* As(UINT offset) const
|
||||
{
|
||||
return reinterpret_cast<U*>(Get(offset));
|
||||
}
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return value_ != nullptr;
|
||||
}
|
||||
|
||||
T operator [](UINT index) const
|
||||
{
|
||||
if (index >= size_)
|
||||
{
|
||||
Debug::Error("Array index out of range: ", index, size_);
|
||||
return T(0);
|
||||
}
|
||||
return value_[index];
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<T[]> value_;
|
||||
UINT size_ = 0;
|
||||
};
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <d3d11.h>
|
||||
#include "Common.h"
|
||||
#include <wrl/client.h>
|
||||
#include "Debug.h"
|
||||
#include "MonitorManager.h"
|
||||
#include "Monitor.h"
|
||||
#include "Cursor.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
|
||||
Cursor::Cursor(Monitor* monitor)
|
||||
: monitor_(monitor)
|
||||
@@ -13,83 +16,196 @@ Cursor::Cursor(Monitor* monitor)
|
||||
|
||||
Cursor::~Cursor()
|
||||
{
|
||||
if (apiBuffer_ != nullptr)
|
||||
{
|
||||
delete[] apiBuffer_;
|
||||
apiBuffer_ = nullptr;
|
||||
}
|
||||
if (bgra32Buffer_ != nullptr)
|
||||
{
|
||||
delete[] bgra32Buffer_;
|
||||
bgra32Buffer_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Cursor::Update(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
void Cursor::UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
isVisible_ = frameInfo.PointerPosition.Visible != 0;
|
||||
x_ = frameInfo.PointerPosition.Position.x;
|
||||
y_ = frameInfo.PointerPosition.Position.y;
|
||||
if (frameInfo.LastMouseUpdateTime.QuadPart == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: see more information to check where the cursor is.
|
||||
if (isVisible_)
|
||||
isVisible_ = frameInfo.PointerPosition.Visible != 0;
|
||||
if (isVisible_)
|
||||
{
|
||||
GetMonitorManager()->SetCursorMonitorId(monitor_->GetId());
|
||||
}
|
||||
|
||||
if (GetMonitorManager()->GetCursorMonitorId() != monitor_->GetId()) {
|
||||
x_ = frameInfo.PointerPosition.Position.x;
|
||||
y_ = frameInfo.PointerPosition.Position.y;
|
||||
timestamp_ = frameInfo.LastMouseUpdateTime;
|
||||
|
||||
if (!IsCursorOnParentMonitor())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Increase the buffer size if needed
|
||||
if (frameInfo.PointerShapeBufferSize > apiBufferSize_)
|
||||
if (frameInfo.PointerShapeBufferSize == 0)
|
||||
{
|
||||
if (apiBuffer_) delete[] apiBuffer_;
|
||||
apiBuffer_ = new BYTE[frameInfo.PointerShapeBufferSize];
|
||||
apiBufferSize_ = frameInfo.PointerShapeBufferSize;
|
||||
}
|
||||
if (apiBuffer_ == nullptr) return;
|
||||
|
||||
// Get information about the mouse pointer if needed
|
||||
if (frameInfo.PointerShapeBufferSize != 0)
|
||||
{
|
||||
UINT bufferSize;
|
||||
monitor_->GetDeskDupl()->GetFramePointerShape(
|
||||
frameInfo.PointerShapeBufferSize,
|
||||
reinterpret_cast<void*>(apiBuffer_),
|
||||
&bufferSize,
|
||||
&shapeInfo_);
|
||||
return;
|
||||
}
|
||||
|
||||
// cursor type
|
||||
const auto cursorType = shapeInfo_.Type;
|
||||
const bool isMono = cursorType == DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME;
|
||||
const bool isColorMask = cursorType == DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR;
|
||||
apiBuffer_.ExpandIfNeeded(frameInfo.PointerShapeBufferSize);
|
||||
if (!apiBuffer_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Size
|
||||
const auto w = shapeInfo_.Width;
|
||||
const auto h = shapeInfo_.Height / (isMono ? 2 : 1);
|
||||
const auto p = shapeInfo_.Pitch;
|
||||
// Get mouse pointer information
|
||||
UINT bufferSize;
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo;
|
||||
const auto hr = monitor_->GetDeskDupl()->GetFramePointerShape(
|
||||
apiBuffer_.Size(),
|
||||
apiBuffer_.Get(),
|
||||
&bufferSize,
|
||||
&shapeInfo);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
Debug::Error("Cursor::UpdateBuffer() => GetFramePointerShape() failed.");
|
||||
apiBuffer_.Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
shapeInfo_ = shapeInfo;
|
||||
}
|
||||
|
||||
|
||||
void Cursor::UpdateTexture()
|
||||
{
|
||||
if (!IsCursorOnParentMonitor())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Cursor information
|
||||
const bool isMono = GetType() == DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME;
|
||||
const bool isColorMask = GetType() == DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR;
|
||||
const auto cursorImageWidth = GetWidth();
|
||||
const auto cursorImageHeight = GetHeight();
|
||||
const auto cursorImagePitch = GetPitch();
|
||||
|
||||
// Captured area
|
||||
auto capturedImageWidth = cursorImageWidth;
|
||||
auto capturedImageHeight = cursorImageHeight;
|
||||
|
||||
// Convert the buffer given by API into BGRA32
|
||||
const auto bgraBufferSize = w * h * 4;
|
||||
if (bgraBufferSize > bgra32BufferSize_)
|
||||
const UINT bgraBufferSize = cursorImageWidth * cursorImageHeight * 4;
|
||||
bgra32Buffer_.ExpandIfNeeded(bgraBufferSize);
|
||||
|
||||
// Check buffers
|
||||
if (!bgra32Buffer_ || !apiBuffer_)
|
||||
{
|
||||
if (bgra32Buffer_) delete[] bgra32Buffer_;
|
||||
bgra32Buffer_ = new BYTE[bgraBufferSize];
|
||||
bgra32BufferSize_ = bgraBufferSize;
|
||||
return;
|
||||
}
|
||||
if (bgra32Buffer_ == nullptr) return;
|
||||
|
||||
// If masked, copy the desktop image and merge it with masked image.
|
||||
if (isMono || isColorMask)
|
||||
{
|
||||
HRESULT hr;
|
||||
const auto monitorWidth = monitor_->GetWidth();
|
||||
const auto monitorHeight = monitor_->GetHeight();
|
||||
const auto monitorRot = static_cast<DXGI_MODE_ROTATION>(monitor_->GetRotation());
|
||||
const auto isVertical =
|
||||
monitorRot == DXGI_MODE_ROTATION_ROTATE90 ||
|
||||
monitorRot == DXGI_MODE_ROTATION_ROTATE270;
|
||||
const auto desktopImageWidth = !isVertical ? monitorWidth : monitorHeight;
|
||||
const auto desktopImageHeight = !isVertical ? monitorHeight : monitorWidth;
|
||||
|
||||
auto x = x_;
|
||||
auto y = y_;
|
||||
auto colMin = 0;
|
||||
auto colMax = cursorImageWidth;
|
||||
auto rowMin = 0;
|
||||
auto rowMax = cursorImageHeight;
|
||||
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
capturedImageWidth = cursorImageWidth + x_;
|
||||
colMin = cursorImageWidth - capturedImageWidth;
|
||||
}
|
||||
if (x + capturedImageWidth >= monitorWidth)
|
||||
{
|
||||
capturedImageWidth = monitorWidth - x_;
|
||||
colMax = capturedImageWidth;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
capturedImageHeight = cursorImageHeight + y_;
|
||||
rowMin = cursorImageHeight - capturedImageHeight;
|
||||
}
|
||||
if (y + capturedImageHeight >= monitorHeight)
|
||||
{
|
||||
capturedImageHeight = monitorHeight - y_;
|
||||
rowMax = capturedImageHeight;
|
||||
}
|
||||
|
||||
D3D11_BOX box;
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
|
||||
switch (monitorRot)
|
||||
{
|
||||
case DXGI_MODE_ROTATION_ROTATE90:
|
||||
{
|
||||
box.left = y;
|
||||
box.top = monitorWidth - x - capturedImageWidth;
|
||||
box.right = y + capturedImageWidth;
|
||||
box.bottom = monitorWidth - x;
|
||||
break;
|
||||
}
|
||||
case DXGI_MODE_ROTATION_ROTATE180:
|
||||
{
|
||||
box.left = monitorWidth - x - capturedImageWidth;
|
||||
box.top = monitorHeight - y - capturedImageHeight;
|
||||
box.right = monitorWidth - x;
|
||||
box.bottom = monitorHeight - y;
|
||||
break;
|
||||
}
|
||||
case DXGI_MODE_ROTATION_ROTATE270:
|
||||
{
|
||||
box.left = monitorHeight - y - capturedImageHeight;
|
||||
box.top = x;
|
||||
box.right = monitorHeight - y;
|
||||
box.bottom = x + capturedImageWidth;
|
||||
break;
|
||||
}
|
||||
case DXGI_MODE_ROTATION_IDENTITY:
|
||||
case DXGI_MODE_ROTATION_UNSPECIFIED:
|
||||
{
|
||||
box.left = x;
|
||||
box.top = y;
|
||||
box.right = x + capturedImageWidth;
|
||||
box.bottom = y + capturedImageHeight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (box.left < 0 ||
|
||||
box.top < 0 ||
|
||||
box.right > static_cast<UINT>(desktopImageWidth) ||
|
||||
box.bottom > static_cast<UINT>(desktopImageHeight))
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => box is out of area.");
|
||||
Debug::Error(
|
||||
" ",
|
||||
"(", box.left, ", ", box.top, ")",
|
||||
" ~ (", box.right, ", ", box.bottom, ") > ",
|
||||
"(", desktopImageWidth, ", ", desktopImageHeight, ")");
|
||||
return;
|
||||
}
|
||||
|
||||
if (monitor_->GetUnityTexture() == nullptr)
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => Monitor::GetUnityTexture() is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
desc.Width = w;
|
||||
desc.Height = h;
|
||||
desc.Width = capturedImageWidth;
|
||||
desc.Height = capturedImageHeight;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
@@ -100,39 +216,30 @@ void Cursor::Update(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
ID3D11Texture2D* texture = nullptr;
|
||||
hr = GetDevice()->CreateTexture2D(&desc, nullptr, &texture);
|
||||
if (FAILED(hr))
|
||||
ComPtr<ID3D11Texture2D> texture;
|
||||
if (FAILED(GetDevice()->CreateTexture2D(&desc, nullptr, &texture)))
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => GetDevice()->CreateTexture2D() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
D3D11_BOX box;
|
||||
box.front = 0;
|
||||
box.back = 1;
|
||||
box.left = x_;
|
||||
box.top = y_;
|
||||
box.right = x_ + w;
|
||||
box.bottom = y_ + h;
|
||||
|
||||
ID3D11DeviceContext* context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopySubresourceRegion(texture, 0, 0, 0, 0, monitor_->GetUnityTexture(), 0, &box);
|
||||
context->Release();
|
||||
|
||||
IDXGISurface* surface = nullptr;
|
||||
hr = texture->QueryInterface(__uuidof(IDXGISurface), (void**)&surface);
|
||||
texture->Release();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopySubresourceRegion(texture.Get(), 0, 0, 0, 0, monitor_->GetUnityTexture(), 0, &box);
|
||||
}
|
||||
|
||||
ComPtr<IDXGISurface> surface;
|
||||
if (FAILED(texture.As(&surface)))
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => texture->QueryInterface() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
DXGI_MAPPED_RECT mappedSurface;
|
||||
hr = surface->Map(&mappedSurface, DXGI_MAP_READ);
|
||||
if (FAILED(hr))
|
||||
if (FAILED(surface->Map(&mappedSurface, DXGI_MAP_READ)))
|
||||
{
|
||||
surface->Release();
|
||||
Debug::Error("Cursor::UpdateTexture() => surface->Map() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -140,41 +247,60 @@ void Cursor::Update(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
const auto desktop32 = reinterpret_cast<UINT*>(mappedSurface.pBits);
|
||||
const UINT desktopPitch = mappedSurface.Pitch / sizeof(UINT);
|
||||
|
||||
// Take the monitor orientation into consideration.
|
||||
const auto getDesktop32 = [&](int col, int row)
|
||||
{
|
||||
switch (monitorRot)
|
||||
{
|
||||
case DXGI_MODE_ROTATION_ROTATE90:
|
||||
return desktop32[(capturedImageWidth - 1 - col) * desktopPitch + row];
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE180:
|
||||
return desktop32[(capturedImageHeight - 1 - row) * desktopPitch + (capturedImageWidth - 1 - col)];
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE270:
|
||||
return desktop32[col * desktopPitch + (capturedImageHeight - 1 - row)];
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_IDENTITY:
|
||||
case DXGI_MODE_ROTATION_UNSPECIFIED:
|
||||
return desktop32[row * desktopPitch + col];
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// Access RGBA values at the same time
|
||||
auto output32 = reinterpret_cast<UINT*>(bgra32Buffer_);
|
||||
auto output32 = reinterpret_cast<UINT*>(bgra32Buffer_.Get());
|
||||
|
||||
if (isMono)
|
||||
{
|
||||
for (UINT row = 0; row < h; ++row)
|
||||
for (int row = rowMin, y = 0; row < rowMax; ++row, ++y)
|
||||
{
|
||||
BYTE mask = 0x80;
|
||||
for (UINT col = 0; col < w; ++col)
|
||||
for (int col = colMin, x = 0; col < colMax; ++col, ++x)
|
||||
{
|
||||
const int i = row * w + col;
|
||||
const BYTE andMask = apiBuffer_[col / 8 + row * p] & mask;
|
||||
const BYTE xorMask = apiBuffer_[col / 8 + (row + h) * p] & mask;
|
||||
const UINT andMask32 = andMask ? 0xFFFFFFFF : 0xFF000000;
|
||||
const UINT xorMask32 = xorMask ? 0x00FFFFFF : 0x00000000;
|
||||
output32[i] = (desktop32[row * desktopPitch + col] & andMask32) ^ xorMask32;
|
||||
mask = (mask == 0x01) ? 0x80 : (mask >> 1);
|
||||
BYTE mask = 0b10000000 >> (col % 8);
|
||||
const BYTE andMask = apiBuffer_[col / 8 + row * cursorImagePitch] & mask;
|
||||
const BYTE xorMask = apiBuffer_[col / 8 + (row + capturedImageHeight) * cursorImagePitch] & mask;
|
||||
const UINT andMask32 = andMask ? 0xFFFFFFFF : 0x00000000;
|
||||
const UINT xorMask32 = xorMask ? 0xFFFFFFFF : 0x00000000;
|
||||
output32[row * cursorImageWidth + col] = (getDesktop32(x, y) & andMask32) ^ xorMask32;
|
||||
}
|
||||
}
|
||||
}
|
||||
else // DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MASKED_COLOR
|
||||
{
|
||||
const auto buffer32 = reinterpret_cast<UINT*>(apiBuffer_);
|
||||
const auto buffer32 = reinterpret_cast<UINT*>(apiBuffer_.Get());
|
||||
|
||||
for (UINT row = 0; row < h; ++row)
|
||||
for (int row = rowMin, y = 0; row < rowMax; ++row, ++y)
|
||||
{
|
||||
for (UINT col = 0; col < w; ++col)
|
||||
for (int col = colMin, x = 0; col < colMax; ++col, ++x)
|
||||
{
|
||||
const int i = row * w + col;
|
||||
const int j = row * p / sizeof(UINT) + col;
|
||||
const int i = col + row * cursorImageWidth;
|
||||
const int j = col + row * cursorImagePitch / sizeof(UINT);
|
||||
|
||||
UINT mask = 0xFF000000 & buffer32[j];
|
||||
if (mask)
|
||||
{
|
||||
output32[i] = (desktop32[row * desktopPitch + col] ^ buffer32[j]) | 0xFF000000;
|
||||
output32[i] = (getDesktop32(x, y) ^ buffer32[j]) | 0xFF000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,34 +310,53 @@ void Cursor::Update(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
}
|
||||
}
|
||||
|
||||
hr = surface->Unmap();
|
||||
surface->Release();
|
||||
if (FAILED(hr))
|
||||
if (FAILED(surface->Unmap()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else // DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR
|
||||
{
|
||||
auto output32 = reinterpret_cast<UINT*>(bgra32Buffer_);
|
||||
const auto buffer32 = reinterpret_cast<UINT*>(apiBuffer_);
|
||||
for (UINT i = 0; i < w * h; ++i)
|
||||
auto output32 = reinterpret_cast<UINT*>(bgra32Buffer_.Get());
|
||||
const auto buffer32 = reinterpret_cast<UINT*>(apiBuffer_.Get());
|
||||
for (int i = 0; i < cursorImageWidth * cursorImageHeight; ++i)
|
||||
{
|
||||
output32[i] = buffer32[i];
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void Cursor::UpdateTexture(ID3D11Texture2D* texture)
|
||||
void Cursor::GetTexture(ID3D11Texture2D* texture)
|
||||
{
|
||||
if (bgra32Buffer_ == nullptr) return;
|
||||
ID3D11DeviceContext* context;
|
||||
if (!bgra32Buffer_)
|
||||
{
|
||||
Debug::Error("Cursor::GetTexture() => bgra32Buffer is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (texture == nullptr)
|
||||
{
|
||||
Debug::Error("Cursor::GetTexture() => The given texture is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
texture->GetDesc(&desc);
|
||||
if ((int)desc.Width < GetWidth() || (int)desc.Height < GetHeight())
|
||||
{
|
||||
char buf[256];
|
||||
sprintf_s(buf, 256,
|
||||
"Cursor::GetTexture() => The given texture has smaller width / height.\n"
|
||||
"Given => (%d, %d) Buffer => (%d, %d)",
|
||||
desc.Width, desc.Height, GetWidth(), GetHeight());
|
||||
Debug::Error(buf);
|
||||
return;
|
||||
}
|
||||
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->UpdateSubresource(texture, 0, nullptr, bgra32Buffer_, shapeInfo_.Width * 4, 0);
|
||||
context->Release();
|
||||
context->UpdateSubresource(texture, 0, nullptr, bgra32Buffer_.Get(), GetWidth() * 4, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -257,3 +402,9 @@ int Cursor::GetType() const
|
||||
{
|
||||
return shapeInfo_.Type;
|
||||
}
|
||||
|
||||
|
||||
bool Cursor::IsCursorOnParentMonitor() const
|
||||
{
|
||||
return GetMonitorManager()->GetCursorMonitorId() == monitor_->GetId();
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <memory>
|
||||
#include "Common.h"
|
||||
|
||||
class Monitor;
|
||||
|
||||
@@ -9,8 +12,9 @@ class Cursor
|
||||
public:
|
||||
explicit Cursor(Monitor* monitor);
|
||||
~Cursor();
|
||||
void Update(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void UpdateTexture(ID3D11Texture2D* texture);
|
||||
void UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void UpdateTexture();
|
||||
void GetTexture(ID3D11Texture2D* texture);
|
||||
|
||||
bool IsVisible() const;
|
||||
int GetX() const;
|
||||
@@ -21,13 +25,14 @@ public:
|
||||
int GetType() const;
|
||||
|
||||
private:
|
||||
bool IsCursorOnParentMonitor() const;
|
||||
|
||||
Monitor* monitor_;
|
||||
bool isVisible_ = false;
|
||||
int x_ = -1;
|
||||
int y_ = -1;
|
||||
BYTE* apiBuffer_ = nullptr;
|
||||
UINT apiBufferSize_ = 0;
|
||||
BYTE* bgra32Buffer_ = nullptr;
|
||||
UINT bgra32BufferSize_ = 0;
|
||||
Buffer<BYTE> apiBuffer_;
|
||||
Buffer<BYTE> bgra32Buffer_;
|
||||
DXGI_OUTDUPL_POINTER_SHAPE_INFO shapeInfo_;
|
||||
LARGE_INTEGER timestamp_;
|
||||
};
|
||||
33
Plugins/uDesktopDuplication/uDesktopDuplication/Debug.cpp
Normal file
33
Plugins/uDesktopDuplication/uDesktopDuplication/Debug.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include "Debug.h"
|
||||
|
||||
|
||||
decltype(Debug::mode_) Debug::mode_ = Debug::Mode::File;
|
||||
decltype(Debug::logFunc_) Debug::logFunc_ = nullptr;
|
||||
decltype(Debug::errFunc_) Debug::errFunc_ = nullptr;
|
||||
decltype(Debug::fs_) Debug::fs_;
|
||||
decltype(Debug::ss_) Debug::ss_;
|
||||
|
||||
|
||||
void Debug::Initialize()
|
||||
{
|
||||
if (mode_ == Mode::File)
|
||||
{
|
||||
fs_.open("uDesktopDuplication.log");
|
||||
Debug::Log("Start");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Debug::Finalize()
|
||||
{
|
||||
if (mode_ == Mode::File)
|
||||
{
|
||||
Debug::Log("Stop");
|
||||
fs_.close();
|
||||
}
|
||||
Debug::SetLogFunc(nullptr);
|
||||
Debug::SetErrorFunc(nullptr);
|
||||
}
|
||||
127
Plugins/uDesktopDuplication/uDesktopDuplication/Debug.h
Normal file
127
Plugins/uDesktopDuplication/uDesktopDuplication/Debug.h
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
#include <time.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "IUnityInterface.h"
|
||||
|
||||
// Logging
|
||||
class Debug
|
||||
{
|
||||
public:
|
||||
enum class Mode
|
||||
{
|
||||
None = 0,
|
||||
File = 1,
|
||||
UnityLog = 2,
|
||||
};
|
||||
|
||||
using DebugLogFuncPtr = void(UNITY_INTERFACE_API *)(const char*);
|
||||
|
||||
static void SetMode(Mode mode) { mode_ = mode; }
|
||||
static void Initialize();
|
||||
static void Finalize();
|
||||
static void SetLogFunc(DebugLogFuncPtr func) { logFunc_ = func; }
|
||||
static void SetErrorFunc(DebugLogFuncPtr func) { errFunc_ = func; }
|
||||
|
||||
private:
|
||||
enum class Level
|
||||
{
|
||||
Log,
|
||||
Error
|
||||
};
|
||||
|
||||
template <class T>
|
||||
static void Output(T&& arg)
|
||||
{
|
||||
if (mode_ == Mode::None) return;
|
||||
if (ss_.good())
|
||||
{
|
||||
ss_ << std::forward<T>(arg);
|
||||
}
|
||||
}
|
||||
|
||||
static void Flush(Level level)
|
||||
{
|
||||
switch (mode_)
|
||||
{
|
||||
case Mode::None:
|
||||
{
|
||||
return;
|
||||
}
|
||||
case Mode::File:
|
||||
{
|
||||
if (fs_.good() && ss_.good())
|
||||
{
|
||||
const auto str = ss_.str();
|
||||
fs_ << str << std::endl;
|
||||
fs_.flush();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Mode::UnityLog:
|
||||
{
|
||||
if (ss_.good())
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case Level::Log : logFunc_(ss_.str().c_str()); break;
|
||||
case Level::Error : errFunc_(ss_.str().c_str()); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ss_.str("");
|
||||
ss_.clear(std::stringstream::goodbit);
|
||||
}
|
||||
|
||||
template <class Arg, class... RestArgs>
|
||||
static void _Log(Level level, Arg&& arg, RestArgs&&... restArgs)
|
||||
{
|
||||
Output(std::forward<Arg>(arg));
|
||||
_Log(level, std::forward<RestArgs>(restArgs)...);
|
||||
}
|
||||
|
||||
static void _Log(Level 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:
|
||||
template <class Arg, class... RestArgs>
|
||||
static void Log(Arg&& arg, RestArgs&&... restArgs)
|
||||
{
|
||||
Output("[uDD::Log]");
|
||||
OutputTime();
|
||||
Output(" ");
|
||||
_Log(Level::Log, std::forward<Arg>(arg), std::forward<RestArgs>(restArgs)...);
|
||||
}
|
||||
|
||||
template <class Arg, class... RestArgs>
|
||||
static void Error(Arg&& arg, RestArgs&&... restArgs)
|
||||
{
|
||||
Output("[uDD::Err]");
|
||||
OutputTime();
|
||||
Output(" ");
|
||||
_Log(Level::Error, std::forward<Arg>(arg), std::forward<RestArgs>(restArgs)...);
|
||||
}
|
||||
|
||||
private:
|
||||
static Mode mode_;
|
||||
static std::ofstream fs_;
|
||||
static std::ostringstream ss_;
|
||||
static DebugLogFuncPtr logFunc_;
|
||||
static DebugLogFuncPtr errFunc_;
|
||||
};
|
||||
@@ -1,95 +1,303 @@
|
||||
#include <d3d11.h>
|
||||
#include "Common.h"
|
||||
#include <ShellScalingAPI.h>
|
||||
#include "Debug.h"
|
||||
#include "Cursor.h"
|
||||
#include "MonitorManager.h"
|
||||
#include "Monitor.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
Monitor::Monitor(int id, IDXGIOutput* output)
|
||||
|
||||
Monitor::Monitor(int id)
|
||||
: id_(id)
|
||||
, cursor_(std::make_unique<Cursor>(this))
|
||||
{
|
||||
output->GetDesc(&outputDesc_);
|
||||
monitorInfo_.cbSize = sizeof(MONITORINFOEX);
|
||||
GetMonitorInfo(outputDesc_.Monitor, &monitorInfo_);
|
||||
|
||||
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);
|
||||
const auto hr = output1->DuplicateOutput(GetDevice(), &deskDupl_);
|
||||
|
||||
auto error = 0;
|
||||
|
||||
// TODO: error check
|
||||
switch (hr)
|
||||
{
|
||||
case S_OK:
|
||||
break;
|
||||
case E_INVALIDARG:
|
||||
error = 1;
|
||||
break;
|
||||
case E_ACCESSDENIED:
|
||||
error = 2;
|
||||
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
||||
// switches to admin screen, this error occurs.
|
||||
break;
|
||||
case DXGI_ERROR_UNSUPPORTED:
|
||||
error = 3;
|
||||
break;
|
||||
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
||||
error = 4;
|
||||
// Other application use Desktop Duplication API...
|
||||
break;
|
||||
case DXGI_ERROR_SESSION_DISCONNECTED:
|
||||
error = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
cursor_ = std::make_unique<Cursor>(this);
|
||||
|
||||
// MEMO: 'output' will be released automatically after this ctor.
|
||||
}
|
||||
|
||||
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
if (deskDupl_ != nullptr)
|
||||
{
|
||||
deskDupl_->Release();
|
||||
}
|
||||
if (deskDupl_)
|
||||
{
|
||||
deskDupl_->Release();
|
||||
deskDupl_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HRESULT Monitor::Render(UINT timeout)
|
||||
void Monitor::Initialize(IDXGIOutput* output)
|
||||
{
|
||||
if (deskDupl_ == nullptr)
|
||||
{
|
||||
GetMonitorManager()->RequireReinitilization();
|
||||
return 0;
|
||||
}
|
||||
if (FAILED(output->GetDesc(&outputDesc_)))
|
||||
{
|
||||
Debug::Error("Monitor::Initialize() => IDXGIOutput::GetDesc() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (unityTexture_ == nullptr) return 0;
|
||||
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;
|
||||
}
|
||||
|
||||
IDXGIResource* resource = nullptr;
|
||||
if (FAILED(GetDpiForMonitor(outputDesc_.Monitor, MDT_RAW_DPI, &dpiX_, &dpiY_)))
|
||||
{
|
||||
Debug::Error("Monitor::Initialize() => GetDpiForMonitor() failed.");
|
||||
// DPI is set as -1, so the application has to use the appropriate value.
|
||||
}
|
||||
|
||||
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);
|
||||
switch (output1->DuplicateOutput(GetDevice().Get(), &deskDupl_))
|
||||
{
|
||||
case S_OK:
|
||||
{
|
||||
state_ = State::Available;
|
||||
Debug::Log("Monitor::Initialize() => OK.");
|
||||
Debug::Log(" ID : ", GetId());
|
||||
Debug::Log(" Size : (", GetWidth(), ", ", GetHeight(), ")");
|
||||
Debug::Log(" DPI : (", GetDpiX(), ", ", GetDpiY(), ")");
|
||||
break;
|
||||
}
|
||||
case E_INVALIDARG:
|
||||
{
|
||||
state_ = State::InvalidArg;
|
||||
Debug::Error("Monitor::Initialize() => Invalid arguments.");
|
||||
break;
|
||||
}
|
||||
case E_ACCESSDENIED:
|
||||
{
|
||||
// For example, when the user presses Ctrl + Alt + Delete and the screen
|
||||
// switches to admin screen, this error occurs.
|
||||
state_ = State::AccessDenied;
|
||||
Debug::Error("Monitor::Initialize() => Access denied.");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_UNSUPPORTED:
|
||||
{
|
||||
// If the display adapter on the computer is running under the Microsoft Hybrid system,
|
||||
// this error occurs.
|
||||
state_ = State::Unsupported;
|
||||
Debug::Error("Monitor::Initialize() => Unsupported display.");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE:
|
||||
{
|
||||
// When other application use Desktop Duplication API, this error occurs.
|
||||
state_ = State::CurrentlyNotAvailable;
|
||||
Debug::Error("Monitor::Initialize() => Currently not available.");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_SESSION_DISCONNECTED:
|
||||
{
|
||||
state_ = State::SessionDisconnected;
|
||||
Debug::Error("Monitor::Initialize() => Session disconnected.");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
state_ = State::Unknown;
|
||||
Debug::Error("Monitor::Render() => Unknown Error.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Monitor::Render(UINT timeout)
|
||||
{
|
||||
if (!deskDupl_) return;
|
||||
|
||||
ComPtr<IDXGIResource> resource;
|
||||
DXGI_OUTDUPL_FRAME_INFO frameInfo;
|
||||
|
||||
const auto hr = deskDupl_->AcquireNextFrame(timeout, &frameInfo, &resource);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return hr;
|
||||
switch (hr)
|
||||
{
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
{
|
||||
// If any monitor setting has changed (e.g. monitor size has changed),
|
||||
// it is necessary to re-initialize monitors.
|
||||
Debug::Log("Monitor::Render() => DXGI_ERROR_ACCESS_LOST.");
|
||||
state_ = State::AccessLost;
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_WAIT_TIMEOUT:
|
||||
{
|
||||
// This often occurs when timeout value is small and it is not problem.
|
||||
// Debug::Log("Monitor::Render() => DXGI_ERROR_WAIT_TIMEOUT.");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_INVALID_CALL:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => DXGI_ERROR_INVALID_CALL.");
|
||||
break;
|
||||
}
|
||||
case E_INVALIDARG:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => E_INVALIDARG.");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
state_ = State::Unknown;
|
||||
Debug::Error("Monitor::Render() => Unknown Error.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ID3D11Texture2D* texture;
|
||||
resource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture));
|
||||
// Get texture
|
||||
if (unityTexture_)
|
||||
{
|
||||
ID3D11Texture2D* texture;
|
||||
if (FAILED(resource.CopyTo(&texture)))
|
||||
{
|
||||
Debug::Error("Monitor::Render() => resource.As() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
ID3D11DeviceContext* context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopyResource(unityTexture_, texture);
|
||||
context->Release();
|
||||
D3D11_TEXTURE2D_DESC srcDesc, dstDesc;
|
||||
texture->GetDesc(&srcDesc);
|
||||
unityTexture_->GetDesc(&dstDesc);
|
||||
if (srcDesc.Width != dstDesc.Width ||
|
||||
srcDesc.Height != dstDesc.Height)
|
||||
{
|
||||
Debug::Error("Monitor::Render() => Texture sizes are defferent.");
|
||||
Debug::Error(" Source : (", srcDesc.Width, ", ", srcDesc.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
|
||||
{
|
||||
ComPtr<ID3D11DeviceContext> context;
|
||||
GetDevice()->GetImmediateContext(&context);
|
||||
context->CopyResource(unityTexture_, texture);
|
||||
}
|
||||
}
|
||||
|
||||
cursor_->Update(frameInfo);
|
||||
UpdateMetadata(frameInfo);
|
||||
UpdateCursor(frameInfo);
|
||||
|
||||
resource->Release();
|
||||
deskDupl_->ReleaseFrame();
|
||||
if (FAILED(deskDupl_->ReleaseFrame()))
|
||||
{
|
||||
Debug::Error("Monitor::Render() => ReleaseFrame() failed.");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
void Monitor::UpdateCursor(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
cursor_->UpdateBuffer(frameInfo);
|
||||
cursor_->UpdateTexture();
|
||||
}
|
||||
|
||||
|
||||
void Monitor::UpdateMetadata(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
metaData_.ExpandIfNeeded(frameInfo.TotalMetadataBufferSize);
|
||||
UpdateMoveRects(frameInfo);
|
||||
UpdateDirtyRects(frameInfo);
|
||||
}
|
||||
|
||||
|
||||
void Monitor::UpdateMoveRects(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
moveRectSize_ = metaData_.Size();
|
||||
|
||||
const auto hr = deskDupl_->GetFrameMoveRects(
|
||||
moveRectSize_,
|
||||
metaData_.As<DXGI_OUTDUPL_MOVE_RECT>(),
|
||||
&moveRectSize_);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
switch (hr)
|
||||
{
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
{
|
||||
Debug::Log("Monitor::Render() => DXGI_ERROR_ACCESS_LOST (GetFrameMoveRects()).");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_MORE_DATA:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => DXGI_ERROR_MORE_DATA (GetFrameMoveRects()).");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_INVALID_CALL:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => DXGI_ERROR_INVALID_CALL (GetFrameMoveRects()).");
|
||||
break;
|
||||
}
|
||||
case E_INVALIDARG:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => E_INVALIDARG (GetFrameMoveRects()).");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => Unknown Error (GetFrameMoveRects()).");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Monitor::UpdateDirtyRects(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
dirtyRectSize_ = metaData_.Size() - moveRectSize_;
|
||||
|
||||
const auto hr = deskDupl_->GetFrameDirtyRects(
|
||||
dirtyRectSize_,
|
||||
metaData_.As<RECT>(moveRectSize_ /* offset */),
|
||||
&dirtyRectSize_);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
switch (hr)
|
||||
{
|
||||
case DXGI_ERROR_ACCESS_LOST:
|
||||
{
|
||||
Debug::Log("Monitor::Render() => DXGI_ERROR_ACCESS_LOST (GetFrameDirtyRects()).");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_MORE_DATA:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => DXGI_ERROR_MORE_DATA (GetFrameDirtyRects()).");
|
||||
break;
|
||||
}
|
||||
case DXGI_ERROR_INVALID_CALL:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => DXGI_ERROR_INVALID_CALL (GetFrameDirtyRects()).");
|
||||
break;
|
||||
}
|
||||
case E_INVALIDARG:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => E_INVALIDARG (GetFrameDirtyRects()).");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug::Error("Monitor::Render() => Unknown Error (GetFrameDirtyRects()).");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +307,12 @@ int Monitor::GetId() const
|
||||
}
|
||||
|
||||
|
||||
MonitorState Monitor::GetState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
|
||||
|
||||
void Monitor::SetUnityTexture(ID3D11Texture2D* texture)
|
||||
{
|
||||
unityTexture_ = texture;
|
||||
@@ -123,9 +337,9 @@ const std::unique_ptr<Cursor>& Monitor::GetCursor()
|
||||
}
|
||||
|
||||
|
||||
void Monitor::UpdateCursorTexture(ID3D11Texture2D* texture)
|
||||
void Monitor::GetCursorTexture(ID3D11Texture2D* texture)
|
||||
{
|
||||
cursor_->UpdateTexture(texture);
|
||||
cursor_->GetTexture(texture);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,43 +357,77 @@ bool Monitor::IsPrimary() const
|
||||
|
||||
int Monitor::GetLeft() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.left;
|
||||
return static_cast<int>(outputDesc_.DesktopCoordinates.left);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetRight() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.right;
|
||||
return static_cast<int>(outputDesc_.DesktopCoordinates.right);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetTop() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.top;
|
||||
return static_cast<int>(outputDesc_.DesktopCoordinates.top);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetBottom() const
|
||||
{
|
||||
return outputDesc_.DesktopCoordinates.bottom;
|
||||
return static_cast<int>(outputDesc_.DesktopCoordinates.bottom);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetRotation() const
|
||||
{
|
||||
return static_cast<int>(outputDesc_.Rotation);
|
||||
return static_cast<int>(outputDesc_.Rotation);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetDpiX() const
|
||||
{
|
||||
return static_cast<int>(dpiX_);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetDpiY() const
|
||||
{
|
||||
return static_cast<int>(dpiY_);
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetWidth() const
|
||||
{
|
||||
const auto rect = monitorInfo_.rcMonitor;
|
||||
return rect.right - rect.left;
|
||||
return width_;
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetHeight() const
|
||||
{
|
||||
const auto rect = monitorInfo_.rcMonitor;
|
||||
return rect.bottom - rect.top;
|
||||
return height_;
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetMoveRectCount() const
|
||||
{
|
||||
return moveRectSize_ / sizeof(DXGI_OUTDUPL_MOVE_RECT);
|
||||
}
|
||||
|
||||
|
||||
DXGI_OUTDUPL_MOVE_RECT* Monitor::GetMoveRects() const
|
||||
{
|
||||
return metaData_.As<DXGI_OUTDUPL_MOVE_RECT>();
|
||||
}
|
||||
|
||||
|
||||
int Monitor::GetDirtyRectCount() const
|
||||
{
|
||||
return dirtyRectSize_ / sizeof(RECT);
|
||||
}
|
||||
|
||||
|
||||
RECT* Monitor::GetDirtyRects() const
|
||||
{
|
||||
return metaData_.As<RECT>(moveRectSize_);
|
||||
}
|
||||
@@ -1,38 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <wrl/client.h>
|
||||
#include <memory>
|
||||
#include "Common.h"
|
||||
|
||||
class Cursor;
|
||||
|
||||
enum class MonitorState
|
||||
{
|
||||
NotSet = -1,
|
||||
Available = 0,
|
||||
InvalidArg = 1,
|
||||
AccessDenied = 2,
|
||||
Unsupported = 3,
|
||||
CurrentlyNotAvailable = 4,
|
||||
SessionDisconnected = 5,
|
||||
AccessLost = 6,
|
||||
TextureSizeInconsistent = 7,
|
||||
Unknown = 999,
|
||||
};
|
||||
|
||||
class Monitor
|
||||
{
|
||||
public:
|
||||
Monitor(int id, IDXGIOutput* output);
|
||||
using State = MonitorState;
|
||||
|
||||
explicit Monitor(int id);
|
||||
~Monitor();
|
||||
HRESULT Render(UINT timeout = 0);
|
||||
void UpdateCursorTexture(ID3D11Texture2D* texture);
|
||||
void Initialize(IDXGIOutput* output);
|
||||
void Render(UINT timeout = 0);
|
||||
void GetCursorTexture(ID3D11Texture2D* texture);
|
||||
|
||||
public:
|
||||
int GetId() const;
|
||||
State GetState() const;
|
||||
void SetUnityTexture(ID3D11Texture2D* texture);
|
||||
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 GetLeft() const;
|
||||
int GetRight() const;
|
||||
int GetTop() const;
|
||||
int GetBottom() const;
|
||||
int GetWidth() const;
|
||||
int GetHeight() const;
|
||||
int GetRotation() const;
|
||||
int GetRotation() const;
|
||||
int GetDpiX() const;
|
||||
int GetDpiY() const;
|
||||
IDXGIOutputDuplication* GetDeskDupl();
|
||||
const std::unique_ptr<Cursor>& GetCursor();
|
||||
int GetMoveRectCount() const;
|
||||
DXGI_OUTDUPL_MOVE_RECT* GetMoveRects() const;
|
||||
int GetDirtyRectCount() const;
|
||||
RECT* GetDirtyRects() const;
|
||||
|
||||
private:
|
||||
void UpdateCursor(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void UpdateMetadata(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void UpdateMoveRects(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
void UpdateDirtyRects(const DXGI_OUTDUPL_FRAME_INFO& frameInfo);
|
||||
|
||||
int id_ = -1;
|
||||
UINT dpiX_ = -1, dpiY_ = -1;
|
||||
int width_ = -1, height_ = -1;
|
||||
State state_ = State::NotSet;
|
||||
std::unique_ptr<Cursor> cursor_;
|
||||
IDXGIOutputDuplication* deskDupl_ = nullptr;
|
||||
ID3D11Texture2D* unityTexture_ = nullptr;
|
||||
DXGI_OUTPUT_DESC outputDesc_;
|
||||
MONITORINFOEX monitorInfo_;
|
||||
Buffer<BYTE> metaData_;
|
||||
UINT moveRectSize_ = 0;
|
||||
UINT dirtyRectSize_ = 0;;
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <d3d11.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <wrl/client.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
@@ -8,10 +9,13 @@
|
||||
#include "IUnityGraphicsD3D11.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "Debug.h"
|
||||
#include "Monitor.h"
|
||||
#include "Cursor.h"
|
||||
#include "MonitorManager.h"
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
|
||||
|
||||
MonitorManager::MonitorManager()
|
||||
{
|
||||
@@ -30,25 +34,27 @@ void MonitorManager::Initialize()
|
||||
Finalize();
|
||||
|
||||
// Get factory
|
||||
IDXGIFactory1* factory;
|
||||
CreateDXGIFactory1(__uuidof(IDXGIFactory1), reinterpret_cast<void**>(&factory));
|
||||
ComPtr<IDXGIFactory1> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||
{
|
||||
Debug::Error("MonitorManager::Initialize() => CreateDXGIFactory1() failed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check all display adapters
|
||||
int id = 0;
|
||||
IDXGIAdapter1* adapter;
|
||||
ComPtr<IDXGIAdapter1> adapter;
|
||||
for (int i = 0; (factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND); ++i)
|
||||
{
|
||||
// Search the main monitor from all outputs
|
||||
IDXGIOutput* output;
|
||||
ComPtr<IDXGIOutput> output;
|
||||
for (int j = 0; (adapter->EnumOutputs(j, &output) != DXGI_ERROR_NOT_FOUND); ++j)
|
||||
{
|
||||
auto monitor = std::make_shared<Monitor>(id++, output);
|
||||
auto monitor = std::make_shared<Monitor>(id++);
|
||||
monitor->Initialize(output.Get());
|
||||
monitors_.push_back(monitor);
|
||||
output->Release();
|
||||
}
|
||||
adapter->Release();
|
||||
}
|
||||
factory->Release();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +64,41 @@ void MonitorManager::Finalize()
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::RequireReinitilization()
|
||||
{
|
||||
isReinitializationRequired_ = true;
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::Reinitialize()
|
||||
{
|
||||
Initialize();
|
||||
SendMessageToUnity(Message::Reinitialized);
|
||||
Debug::Log("MonitorManager::Reinitialize()");
|
||||
Initialize();
|
||||
SendMessageToUnity(Message::Reinitialized);
|
||||
}
|
||||
|
||||
|
||||
bool MonitorManager::HasMonitorCountChanged() const
|
||||
{
|
||||
ComPtr<IDXGIFactory1> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||
{
|
||||
Debug::Error("MonitorManager::CheckMonitorConnection() => CreateDXGIFactory1() failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = 0;
|
||||
ComPtr<IDXGIAdapter1> adapter;
|
||||
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)
|
||||
{
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
||||
return monitors_.size() != id;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,34 +114,10 @@ std::shared_ptr<Monitor> MonitorManager::GetMonitor(int id) const
|
||||
|
||||
void MonitorManager::Update()
|
||||
{
|
||||
if (isReinitializationRequired_)
|
||||
{
|
||||
Reinitialize();
|
||||
isReinitializationRequired_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::OnRender(int id)
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
if (isReinitializationRequired_)
|
||||
{
|
||||
// If any monitor setting has changed (e.g. monitor size has changed),
|
||||
// it is necessary to re-initialize monitors.
|
||||
const auto hr = monitor->Render(timeout_);
|
||||
if (hr == DXGI_ERROR_ACCESS_LOST)
|
||||
{
|
||||
isReinitializationRequired_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::UpdateCursorTexture(int id, ID3D11Texture2D* texture)
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
monitor->UpdateCursorTexture(texture);
|
||||
Reinitialize();
|
||||
isReinitializationRequired_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,13 +128,9 @@ void MonitorManager::SetTimeout(int timeout)
|
||||
}
|
||||
|
||||
|
||||
void MonitorManager::SetTexturePtr(int id, void* texture)
|
||||
int MonitorManager::GetTimeout() const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
auto d3d11Texture = reinterpret_cast<ID3D11Texture2D*>(texture);
|
||||
monitor->SetUnityTexture(d3d11Texture);
|
||||
}
|
||||
return timeout_;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,187 +139,30 @@ int MonitorManager::GetMonitorCount() const
|
||||
return static_cast<int>(monitors_.size());
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetTotalWidth() const
|
||||
{
|
||||
std::vector<int> 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;
|
||||
std::vector<int> 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<int> 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
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
std::vector<int> tops, bottoms;
|
||||
for (const auto& monitor : monitors_)
|
||||
{
|
||||
monitor->GetName(buf, len);
|
||||
tops.push_back(monitor->GetTop());
|
||||
bottoms.push_back(monitor->GetBottom());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool MonitorManager::IsPrimary(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->IsPrimary();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
return monitor->GetWidth();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetHeight(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetHeight();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
return monitor->GetCursor()->IsVisible();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetCursorX(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetX();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetCursorY(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetY();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetCursorShapeWidth(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetWidth();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetCursorShapeHeight(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetHeight();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetCursorShapePitch(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetPitch();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int MonitorManager::GetCursorShapeType(int id) const
|
||||
{
|
||||
if (auto monitor = GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetType();
|
||||
}
|
||||
return -1;
|
||||
const auto minTop = *std::min_element(tops.begin(), tops.end());
|
||||
const auto maxBottom = *std::max_element(bottoms.begin(), bottoms.end());
|
||||
return maxBottom - minTop;
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi1_2.h>
|
||||
#include <vector>
|
||||
@@ -13,9 +15,9 @@ class MonitorManager
|
||||
public:
|
||||
explicit MonitorManager();
|
||||
~MonitorManager();
|
||||
|
||||
void RequireReinitilization() { isReinitializationRequired_ = true; }
|
||||
|
||||
void Reinitialize();
|
||||
bool HasMonitorCountChanged() const;
|
||||
void RequireReinitilization();
|
||||
void SetCursorMonitorId(int id) { cursorMonitorId_ = id; }
|
||||
int GetCursorMonitorId() const { return cursorMonitorId_; }
|
||||
std::shared_ptr<Monitor> GetMonitor(int id) const;
|
||||
@@ -23,42 +25,23 @@ public:
|
||||
private:
|
||||
void Initialize();
|
||||
void Finalize();
|
||||
void Reinitialize();
|
||||
|
||||
// Setters from Unity
|
||||
public:
|
||||
void OnRender(int id);
|
||||
void Update();
|
||||
void UpdateCursorTexture(int id, ID3D11Texture2D* ptr);
|
||||
void Update();
|
||||
void SetTimeout(int timeout);
|
||||
void SetTexturePtr(int id, void* texture);
|
||||
int GetTimeout() const;
|
||||
|
||||
// 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;
|
||||
int GetCursorShapeWidth(int id) const;
|
||||
int GetCursorShapeHeight(int id) const;
|
||||
int GetCursorShapePitch(int id) const;
|
||||
int GetCursorShapeType(int id) const;
|
||||
|
||||
private:
|
||||
int timeout_ = 10;
|
||||
std::vector<std::shared_ptr<Monitor>> monitors_;
|
||||
std::shared_ptr<Cursor> cursor_;
|
||||
int cursorMonitorId_ = -1;
|
||||
bool isReinitializationRequired_ = false;
|
||||
bool isReinitializationRequired_ = false;
|
||||
};
|
||||
@@ -7,77 +7,87 @@
|
||||
|
||||
#include "IUnityInterface.h"
|
||||
#include "IUnityGraphics.h"
|
||||
#include "IUnityGraphicsD3D11.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "Debug.h"
|
||||
#include "Monitor.h"
|
||||
#include "Cursor.h"
|
||||
#include "MonitorManager.h"
|
||||
|
||||
#pragma comment(lib, "dxgi.lib")
|
||||
#pragma comment(lib, "Shcore.lib")
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
IUnityInterfaces* g_unity = nullptr;
|
||||
std::unique_ptr<MonitorManager> g_manager;
|
||||
std::queue<Message> g_messages;
|
||||
}
|
||||
|
||||
|
||||
IUnityInterfaces* GetUnity()
|
||||
{
|
||||
return g_unity;
|
||||
}
|
||||
|
||||
|
||||
ID3D11Device* GetDevice()
|
||||
{
|
||||
return GetUnity()->Get<IUnityGraphicsD3D11>()->GetDevice();
|
||||
}
|
||||
|
||||
|
||||
const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
||||
{
|
||||
return g_manager;
|
||||
}
|
||||
|
||||
|
||||
void SendMessageToUnity(Message message)
|
||||
{
|
||||
g_messages.push(message);
|
||||
}
|
||||
IUnityInterfaces* g_unity = nullptr;
|
||||
std::unique_ptr<MonitorManager> g_manager;
|
||||
std::queue<Message> g_messages;
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API InitializeUDD()
|
||||
{
|
||||
if (g_unity && !g_manager)
|
||||
{
|
||||
g_manager = std::make_unique<MonitorManager>();
|
||||
}
|
||||
if (g_unity && !g_manager)
|
||||
{
|
||||
Debug::Initialize();
|
||||
g_manager = std::make_unique<MonitorManager>();
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
|
||||
{
|
||||
g_manager.reset();
|
||||
if (!g_manager) return;
|
||||
|
||||
g_manager.reset();
|
||||
|
||||
std::queue<Message> empty;
|
||||
g_messages.swap(empty);
|
||||
|
||||
Debug::Finalize();
|
||||
}
|
||||
|
||||
void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType event)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case kUnityGfxDeviceEventInitialize:
|
||||
{
|
||||
InitializeUDD();
|
||||
break;
|
||||
}
|
||||
case kUnityGfxDeviceEventShutdown:
|
||||
{
|
||||
FinalizeUDD();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginLoad(IUnityInterfaces* unityInterfaces)
|
||||
{
|
||||
g_unity = unityInterfaces;
|
||||
InitializeUDD();
|
||||
InitializeUDD();
|
||||
|
||||
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
||||
unityGraphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
|
||||
{
|
||||
g_unity = nullptr;
|
||||
FinalizeUDD();
|
||||
auto unityGraphics = g_unity->Get<IUnityGraphics>();
|
||||
unityGraphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
|
||||
|
||||
FinalizeUDD();
|
||||
g_unity = nullptr;
|
||||
}
|
||||
|
||||
void UNITY_INTERFACE_API OnRenderEvent(int id)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->OnRender(id);
|
||||
if (!g_manager) return;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
monitor->Render(g_manager->GetTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT UnityRenderingEvent UNITY_INTERFACE_API GetRenderEventFunc()
|
||||
@@ -85,150 +95,328 @@ extern "C"
|
||||
return OnRenderEvent;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Update()
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Reinitialize()
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->Update();
|
||||
if (!g_manager) return;
|
||||
return g_manager->Reinitialize();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT Message PopMessage()
|
||||
{
|
||||
if (g_messages.empty()) return Message::None;
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API Update()
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->Update();
|
||||
}
|
||||
|
||||
const auto message = g_messages.front();
|
||||
g_messages.pop();
|
||||
return message;
|
||||
}
|
||||
UNITY_INTERFACE_EXPORT Message UNITY_INTERFACE_API PopMessage()
|
||||
{
|
||||
if (g_messages.empty()) return Message::None;
|
||||
|
||||
const auto message = g_messages.front();
|
||||
g_messages.pop();
|
||||
return message;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetDebugMode(Debug::Mode mode)
|
||||
{
|
||||
Debug::SetMode(mode);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetLogFunc(Debug::DebugLogFuncPtr func)
|
||||
{
|
||||
Debug::SetLogFunc(func);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetErrorFunc(Debug::DebugLogFuncPtr func)
|
||||
{
|
||||
Debug::SetErrorFunc(func);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT size_t UNITY_INTERFACE_API GetMonitorCount()
|
||||
{
|
||||
if (!g_manager) return 0;
|
||||
if (!g_manager) return 0;
|
||||
return g_manager->GetMonitorCount();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API HasMonitorCountChanged()
|
||||
{
|
||||
if (!g_manager) return false;
|
||||
return g_manager->HasMonitorCountChanged();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorMonitorId()
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorMonitorId();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalWidth()
|
||||
{
|
||||
if (!g_manager) return 0;
|
||||
if (!g_manager) return 0;
|
||||
return g_manager->GetTotalWidth();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTotalHeight()
|
||||
{
|
||||
if (!g_manager) return 0;
|
||||
if (!g_manager) return 0;
|
||||
return g_manager->GetTotalHeight();
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTimeout(int timeout)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
if (!g_manager) return;
|
||||
g_manager->SetTimeout(timeout);
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API GetId(int id)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
monitor->GetId();
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT MonitorState UNITY_INTERFACE_API GetState(int id)
|
||||
{
|
||||
if (!g_manager) return MonitorState::NotSet;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetState();
|
||||
}
|
||||
return MonitorState::NotSet;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API GetName(int id, char* buf, int len)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->GetName(id, buf, len);
|
||||
if (!g_manager) return;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
monitor->GetName(buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsPrimary(int id)
|
||||
{
|
||||
if (!g_manager) return false;
|
||||
return g_manager->IsPrimary(id);
|
||||
if (!g_manager) return false;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->IsPrimary();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetLeft(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetLeft(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetLeft();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetRight(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetRight(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetRight();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetTop(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetTop(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetTop();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetBottom(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetBottom(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetBottom();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetWidth(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetWidth(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetWidth();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetHeight(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetHeight(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetHeight();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetRotation(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetRotation(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetRotation();
|
||||
}
|
||||
return DXGI_MODE_ROTATION_UNSPECIFIED;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetDpiX(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetDpiX();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetDpiY(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetDpiY();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT bool UNITY_INTERFACE_API IsCursorVisible(int id)
|
||||
{
|
||||
if (!g_manager) return false;
|
||||
return g_manager->IsCursorVisible(id);
|
||||
if (!g_manager) return false;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->IsVisible();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorX(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorX(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetX();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorY(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorY(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetY();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorShapeWidth(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorShapeWidth(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetWidth();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorShapeHeight(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorShapeHeight(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetHeight();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorShapePitch(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorShapePitch(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetPitch();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetCursorShapeType(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
return g_manager->GetCursorShapeType(id);
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetCursor()->GetType();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UpdateCursorTexture(int id, ID3D11Texture2D* ptr)
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API GetCursorTexture(int id, ID3D11Texture2D* texture)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->UpdateCursorTexture(id, ptr);
|
||||
if (!g_manager) return;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
monitor->GetCursorTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API SetTexturePtr(int id, void* texture)
|
||||
{
|
||||
if (!g_manager) return;
|
||||
g_manager->SetTexturePtr(id, texture);
|
||||
if (!g_manager) return;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
auto d3d11Texture = reinterpret_cast<ID3D11Texture2D*>(texture);
|
||||
monitor->SetUnityTexture(d3d11Texture);
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetMoveRectCount(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetMoveRectCount();
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void* UNITY_INTERFACE_API GetMoveRects(int id)
|
||||
{
|
||||
if (!g_manager) return nullptr;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetMoveRects();
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT int UNITY_INTERFACE_API GetDirtyRectCount(int id)
|
||||
{
|
||||
if (!g_manager) return -1;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetDirtyRectCount();
|
||||
}
|
||||
}
|
||||
|
||||
UNITY_INTERFACE_EXPORT void* UNITY_INTERFACE_API GetDirtyRects(int id)
|
||||
{
|
||||
if (!g_manager) return nullptr;
|
||||
if (auto monitor = g_manager->GetMonitor(id))
|
||||
{
|
||||
return monitor->GetDirtyRects();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<PostBuildEvent>
|
||||
<Command>copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetFileName)" "$(SolutionDir)..\..\Assets\$(ProjectName)\Plugins"</Command>
|
||||
<Command>copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetFileName)" "$(SolutionDir)..\..\Assets\$(ProjectName)\Plugins\x86_64"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@@ -122,10 +122,12 @@
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetFileName)" "$(SolutionDir)..\..\Assets\$(ProjectName)\Plugins"</Command>
|
||||
<Command>copy /Y "$(SolutionDir)$(Platform)\$(Configuration)\$(TargetFileName)" "$(SolutionDir)..\..\Assets\$(ProjectName)\Plugins\x86_64"</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Common.cpp" />
|
||||
<ClCompile Include="Debug.cpp" />
|
||||
<ClCompile Include="MonitorManager.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="Monitor.cpp" />
|
||||
@@ -133,6 +135,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Common.h" />
|
||||
<ClInclude Include="Debug.h" />
|
||||
<ClInclude Include="MonitorManager.h" />
|
||||
<ClInclude Include="include\IUnityGraphics.h" />
|
||||
<ClInclude Include="include\IUnityGraphicsD3D11.h" />
|
||||
|
||||
@@ -19,11 +19,14 @@
|
||||
<ClInclude Include="Cursor.h" />
|
||||
<ClInclude Include="Common.h" />
|
||||
<ClInclude Include="MonitorManager.h" />
|
||||
<ClInclude Include="Debug.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Monitor.cpp" />
|
||||
<ClCompile Include="Cursor.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="MonitorManager.cpp" />
|
||||
<ClCompile Include="Common.cpp" />
|
||||
<ClCompile Include="Debug.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Binary file not shown.
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
|
||||
|
||||
13
README.md
13
README.md
@@ -1,6 +1,9 @@
|
||||
uDesktopDuplication
|
||||
===================
|
||||
|
||||

|
||||

|
||||
|
||||
**uDesktopDuplication** is an Unity asset to use the realtime screen capture as `Texture2D` using Desktop Duplication API.
|
||||
|
||||
|
||||
@@ -25,16 +28,6 @@ Usage
|
||||
Attach `uDesktopDuplication/Texture` component to the target object, then its main texture will be replaced with the captured screen. Please see example scenes for more details.
|
||||
|
||||
|
||||
Version
|
||||
-------
|
||||
| Data | Version | Description |
|
||||
| ---------- | ------- | --------------------------------- |
|
||||
| 2016/10/28 | 1.0.0 | Support multiple screens. |
|
||||
| 2016/10/27 | 0.0.3 | Support lienar color. |
|
||||
| 2016/10/27 | 0.0.2 | Add mouse cursor / shaders. |
|
||||
| 2016/10/27 | 0.0.1 | Initial commit. |
|
||||
|
||||
|
||||
Lisence
|
||||
-------
|
||||
The MIT License (MIT)
|
||||
|
||||
Reference in New Issue
Block a user