Compare commits

...

6 Commits

Author SHA1 Message Date
hecomi
60889d53f4 modify layouter to fix height. 2016-11-19 13:49:38 +09:00
hecomi
f207e65952 do not stop initialization even when getting dpi has error. 2016-11-19 13:09:50 +09:00
hecomi
aea8d112c6 fix indent. 2016-11-18 02:33:24 +09:00
hecomi
9f6971dd45 register callbacks. 2016-11-18 02:28:27 +09:00
hecomi
1be698af63 keep local scale of monitors as 1. 2016-11-18 00:19:22 +09:00
hecomi
064db9f137 modify access rights of layouter. 2016-11-17 23:31:39 +09:00
10 changed files with 142 additions and 99 deletions

View File

@@ -125,8 +125,8 @@ public class MultipleMonitorCreator : MonoBehaviour
height = monitor.heightMeter;
break;
case ScaleMode.Fixed:
width = scale * (monitor.isHorizontal ? 1f : monitor.aspect);
height = scale * (monitor.isHorizontal ? 1f / monitor.aspect : 1f);
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);

View File

@@ -4,9 +4,9 @@
public class MultipleMonitorLayouter : MonoBehaviour
{
protected MultipleMonitorCreator creator_;
[SerializeField] bool updateEveryFrame = true;
[SerializeField] protected float margin = 0.1f;
[SerializeField][Range(0f, 10f)] protected float thickness = 1f;
public bool updateEveryFrame = true;
public float margin = 0.1f;
[Range(0f, 10f)] public float thickness = 1f;
void Start()
{
@@ -30,7 +30,7 @@ public class MultipleMonitorLayouter : MonoBehaviour
var totalWidth = 0f;
foreach (var info in monitors) {
var width = info.gameObject.transform.localEulerAngles.x * (info.mesh.bounds.extents.x * 2f);
var width = info.gameObject.transform.localScale.x * (info.mesh.bounds.extents.x * 2f);
totalWidth += width;
}
totalWidth += margin * (n - 1);
@@ -38,7 +38,7 @@ public class MultipleMonitorLayouter : MonoBehaviour
var x = -totalWidth / 2;
foreach (var info in monitors) {
var width = info.gameObject.transform.localEulerAngles.x;
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;

View File

@@ -17,6 +17,17 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
var monitors = creator_.monitors;
var n = monitors.Count;
// keep the local scale z of monitors as 1 to bend them correctly.
foreach (var info in monitors) {
var scale = info.gameObject.transform.localScale;
scale.z = 1f;
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);
@@ -24,9 +35,13 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
}
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) {
@@ -53,7 +68,12 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
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) {

View File

@@ -14,6 +14,7 @@ public enum Message
public enum CursorShapeType
{
Unspecified = 0,
MonoChrome = 1,
Color = 2,
MaskedColor = 4,

View File

@@ -73,8 +73,8 @@ public class Manager : MonoBehaviour
void Awake()
{
Lib.SetDebugMode(debugMode);
Lib.InitializeUDD();
Lib.SetTimeout(desktopDuplicationApiTimeout);
Lib.InitializeUDD();
if (instance_ != null) {
Destroy(gameObject);

View File

@@ -73,7 +73,7 @@ void Cursor::UpdateBuffer(const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
Debug::Error("Cursor::UpdateBuffer() => GetFramePointerShape() failed.");
apiBuffer_.reset();
apiBufferSize_ = 0;
return;
return;
}
shapeInfo_ = shapeInfo;
@@ -94,7 +94,7 @@ void Cursor::UpdateTexture()
const auto cursorImageHeight = GetHeight();
const auto cursorImagePitch = GetPitch();
// Captured area
// Captured area
auto capturedImageWidth = cursorImageWidth;
auto capturedImageHeight = cursorImageHeight;
@@ -105,24 +105,24 @@ void Cursor::UpdateTexture()
bgra32BufferSize_ = bgraBufferSize;
bgra32Buffer_ = std::make_unique<BYTE[]>(bgra32BufferSize_);
}
// Check buffers
if (!bgra32Buffer_ || !apiBuffer_)
{
return;
}
// Check buffers
if (!bgra32Buffer_ || !apiBuffer_)
{
return;
}
// If masked, copy the desktop image and merge it with masked image.
if (isMono || isColorMask)
{
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;
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_;
@@ -158,56 +158,56 @@ void Cursor::UpdateTexture()
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;
}
}
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 (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)
{
@@ -259,26 +259,26 @@ void Cursor::UpdateTexture()
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;
}
};
// 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_.get());

View File

@@ -50,7 +50,7 @@ void Monitor::Initialize(IDXGIOutput* output)
if (FAILED(GetDpiForMonitor(outputDesc_.Monitor, MDT_RAW_DPI, &dpiX_, &dpiY_)))
{
Debug::Error("Monitor::Initialize() => GetDpiForMonitor() failed.");
return;
// DPI is set as -1, so the application has to use the appropriate value.
}
auto output1 = reinterpret_cast<IDXGIOutput1*>(output);

View File

@@ -36,14 +36,30 @@ extern "C"
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API FinalizeUDD()
{
if (g_manager)
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)
{
g_manager.reset();
std::queue<Message> empty;
g_messages.swap(empty);
Debug::Finalize();
case kUnityGfxDeviceEventInitialize:
{
InitializeUDD();
break;
}
case kUnityGfxDeviceEventShutdown:
{
FinalizeUDD();
break;
}
}
}
@@ -51,10 +67,16 @@ extern "C"
{
g_unity = unityInterfaces;
InitializeUDD();
auto unityGraphics = g_unity->Get<IUnityGraphics>();
unityGraphics->RegisterDeviceEventCallback(OnGraphicsDeviceEvent);
}
UNITY_INTERFACE_EXPORT void UNITY_INTERFACE_API UnityPluginUnload()
{
auto unityGraphics = g_unity->Get<IUnityGraphics>();
unityGraphics->UnregisterDeviceEventCallback(OnGraphicsDeviceEvent);
FinalizeUDD();
g_unity = nullptr;
}