prevent screen lost after admin screen.

This commit is contained in:
hecomi
2016-11-04 19:11:17 +09:00
parent 2c61fcd470
commit 2e763d994d
9 changed files with 230 additions and 17 deletions
+16
View File
@@ -5,6 +5,12 @@ using System.Runtime.InteropServices;
namespace uDesktopDuplication
{
public enum Message
{
None = -1,
Reinitialized = 0,
}
public enum CursorShapeType
{
MonoChrome = 1,
@@ -14,6 +20,16 @@ public enum CursorShapeType
public static class Lib
{
public delegate void MessageHandler(Message message);
[DllImport("uDesktopDuplication")]
public static extern void Initialize();
[DllImport("uDesktopDuplication")]
public static extern void Finalize();
[DllImport("uDesktopDuplication")]
public static extern void Update();
[DllImport("uDesktopDuplication")]
public static extern Message PopMessage();
[DllImport("uDesktopDuplication")]
public static extern int GetMonitorCount();
[DllImport("uDesktopDuplication")]
+52 -4
View File
@@ -26,7 +26,7 @@ public class Manager : MonoBehaviour
static public int monitorCount
{
get { return instance.monitors_.Count; }
get { return Lib.GetMonitorCount(); }
}
static public Monitor primary
@@ -41,19 +41,25 @@ public class Manager : MonoBehaviour
int timeout = 0;
private Coroutine renderCoroutine_ = null;
Message message_ = Message.None;
void Awake()
{
Lib.Initialize();
if (instance_ != null) return;
instance_ = this;
for (int i = 0; i < Lib.GetMonitorCount(); ++i) {
monitors.Add(new Monitor(i));
}
CreateMonitors();
Lib.SetTimeout(timeout);
}
void OnApplicationQuit()
{
Lib.Finalize();
}
void OnEnable()
{
renderCoroutine_ = StartCoroutine(OnRender());
@@ -67,6 +73,26 @@ public class Manager : MonoBehaviour
}
}
void Update()
{
Lib.Update();
var message = Lib.PopMessage();
while (message != Message.None) {
switch (message) {
case Message.Reinitialized:
Debug.Log("Reinitialize");
Reinitialize();
break;
default:
break;
}
message = Lib.PopMessage();
}
message_ = Message.None;
}
IEnumerator OnRender()
{
for (;;) {
@@ -80,6 +106,28 @@ public class Manager : MonoBehaviour
}
}
}
void CreateMonitors()
{
for (int i = 0; i < monitorCount; ++i) {
monitors.Add(new Monitor(i));
}
}
void OnMessage(Message message)
{
message_ = message;
}
void Reinitialize()
{
for (int i = 0; i < monitorCount; ++i) {
if (i == monitors.Count) {
monitors.Add(new Monitor(i));
}
monitors[i].Reinitialize();
}
}
}
}
+32 -4
View File
@@ -16,6 +16,11 @@ public class Monitor
private set;
}
public bool exists
{
get { return id < Manager.monitorCount; }
}
public string name
{
get { return Lib.GetName(id); }
@@ -93,10 +98,7 @@ public class Monitor
get
{
if (texture_ == null) {
var w = isHorizontal ? width : height;
var h = isHorizontal ? height : width;
texture_ = new Texture2D(w, h, TextureFormat.BGRA32, false);
Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
CreateTexture();
}
return texture_;
}
@@ -104,6 +106,7 @@ public class Monitor
public void Render()
{
Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id);
}
@@ -111,6 +114,31 @@ public class Monitor
{
Lib.UpdateCursorTexture(id, ptr);
}
void CreateTexture()
{
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 (shouldCreate) {
texture_ = new Texture2D(w, h, TextureFormat.BGRA32, false);
}
}
public void Reinitialize()
{
CreateTexture();
}
}
}