Compare commits

...

2 Commits

Author SHA1 Message Date
hecomi
49aef432e7 improve performance. 2016-11-20 15:59:06 +09:00
hecomi
fc81892917 cache cursor texture pointer to improve performance. 2016-11-20 15:41:47 +09:00
4 changed files with 42 additions and 17 deletions

View File

@@ -3,6 +3,8 @@ using MeshForwardDirection = uDesktopDuplication.Texture.MeshForwardDirection;
public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
{
[SerializeField] bool debugDraw = true;
public float radius = 10f;
public Vector3 offsetAngle = Vector3.zero;
@@ -80,7 +82,7 @@ public class MultipleMonitorRoundLayouter : MultipleMonitorLayouter
protected override void Update()
{
base.Update();
DebugDraw();
if (debugDraw) DebugDraw();
}
void DebugDraw()

View File

@@ -15,7 +15,18 @@ public class Cursor : MonoBehaviour
private Texture uddTexture_;
private Monitor monitor { get { return uddTexture_.monitor; } }
private Dictionary<int, Texture2D> textures_ = new Dictionary<int, Texture2D>();
struct TextureInfo
{
public Texture2D texture;
public System.IntPtr ptr;
public TextureInfo(Texture2D texture)
{
this.texture = texture;
this.ptr = texture.GetNativeTexturePtr();
}
}
private Dictionary<int, TextureInfo> textures_ = new Dictionary<int, TextureInfo>();
void Start()
{
@@ -50,13 +61,13 @@ public class Cursor : MonoBehaviour
if (!textures_.ContainsKey(key)) {
var texture = new Texture2D(w, h, TextureFormat.BGRA32, false);
texture.wrapMode = TextureWrapMode.Clamp;
textures_.Add(key, texture);
textures_.Add(key, new TextureInfo(texture));
}
var cursorTexture = textures_[key];
Assert.IsNotNull(cursorTexture);
monitor.GetCursorTexture(cursorTexture.GetNativeTexturePtr());
uddTexture_.material.SetTexture("_CursorTex", cursorTexture);
Assert.IsNotNull(cursorTexture.texture);
monitor.GetCursorTexture(cursorTexture.ptr);
uddTexture_.material.SetTexture("_CursorTex", cursorTexture.texture);
}
void UpdateMaterial()

View File

@@ -15,15 +15,17 @@ public class Manager : MonoBehaviour
public static Manager CreateInstance()
{
if (instance_) {
return instance_;
}
if (instance_ != null) return instance_;
var manager = FindObjectOfType<Manager>();
if (manager) return manager;
if (manager) {
instance_ = manager;
return manager;
}
var go = new GameObject("uDesktopDuplicationManager");
return go.AddComponent<Manager>();
instance_ = go.AddComponent<Manager>();
return instance_;
}
private List<Monitor> monitors_ = new List<Monitor>();
@@ -74,10 +76,16 @@ public class Manager : MonoBehaviour
void Awake()
{
// for simple singleton
if (instance_ != null) {
if (instance_ == this) {
return;
}
if (instance_ != null && instance_ != this) {
Destroy(gameObject);
return;
}
instance_ = this;
Lib.SetDebugMode(debugMode);
@@ -134,11 +142,12 @@ public class Manager : MonoBehaviour
for (int i = 0; i < monitors.Count; ++i) {
var monitor = monitors[i];
var state = monitor.state;
if (
monitor.state == MonitorState.NotSet ||
monitor.state == MonitorState.AccessLost ||
monitor.state == MonitorState.AccessDenied ||
monitor.state == MonitorState.SessionDisconnected
state == MonitorState.NotSet ||
state == MonitorState.AccessLost ||
state == MonitorState.AccessDenied ||
state == MonitorState.SessionDisconnected
) {
reinitializeNeeded = true;
break;

View File

@@ -240,6 +240,7 @@ public class Monitor
}
private Texture2D texture_;
private System.IntPtr texturePtr_;
public Texture2D texture
{
get
@@ -253,7 +254,7 @@ public class Monitor
public void Render()
{
if (texture_ && available) {
Lib.SetTexturePtr(id, texture_.GetNativeTexturePtr());
Lib.SetTexturePtr(id, texturePtr_);
GL.IssuePluginEvent(Lib.GetRenderEventFunc(), id);
}
}
@@ -290,6 +291,7 @@ public class Monitor
var w = isHorizontal ? width : height;
var h = isHorizontal ? height : width;
texture_ = new Texture2D(w, h, TextureFormat.BGRA32, false);
texturePtr_ = texture_.GetNativeTexturePtr();
}
public void DestroyTexture()
@@ -297,6 +299,7 @@ public class Monitor
if (texture_) {
Object.Destroy(texture_);
texture_ = null;
texturePtr_ = System.IntPtr.Zero;
}
}