From cb4c25d8725c61fd838302822b2d4d5b535b2986 Mon Sep 17 00:00:00 2001 From: Matthew Davey Date: Thu, 7 Oct 2021 09:15:03 -0400 Subject: [PATCH 1/6] Floor values to handle rounding present elsewhere doesn't dirty. --- .../Editor/Utils/VFXSystemBorder.cs | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs index a74d0f97ebe..063f0b15651 100644 --- a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs +++ b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs @@ -11,7 +11,7 @@ namespace UnityEditor.VFX.UI { class VFXSystemBorderFactory : UxmlFactory - { } + {} class VFXSystemBorder : GraphElement, IControlledElement, IDisposable @@ -130,6 +130,13 @@ void OnTitleMouseDown(MouseDownEvent e) void OnTitleRelayout(GeometryChangedEvent e) { + Rect oldRoundedRect = new Rect(Mathf.Floor(e.oldRect.x), Mathf.Floor(e.oldRect.y), Mathf.Floor(e.oldRect.width), Mathf.Floor(e.oldRect.height)); + Rect newRoundedRect = new Rect(Mathf.Floor(e.newRect.x), Mathf.Floor(e.newRect.y), Mathf.Floor(e.newRect.width), Mathf.Floor(e.newRect.height)); + if (oldRoundedRect == newRoundedRect) + { + return; + } + UpdateTitleFieldRect(); RecomputeBounds(); } @@ -137,7 +144,6 @@ void OnTitleRelayout(GeometryChangedEvent e) void UpdateTitleFieldRect() { Rect rect = m_Title.layout; - m_Title.parent.ChangeCoordinatesTo(m_TitleField.parent, rect); @@ -186,16 +192,18 @@ public override string title } public bool m_WaitingRecompute; + private Rect m_previousBounds; public void RecomputeBounds() { if (m_WaitingRecompute) return; + visible = true; //title width should be at least as wide as a context to be valid. float titleWidth = m_Title.layout.width; - bool invalidTitleWidth = float.IsNaN(titleWidth) || titleWidth < 50; - bool titleEmpty = string.IsNullOrEmpty(m_Title.text) || invalidTitleWidth; + bool shouldDeferRecompute = float.IsNaN(titleWidth) || titleWidth < 50; + bool titleEmpty = string.IsNullOrEmpty(m_Title.text) || shouldDeferRecompute; if (titleEmpty) { m_Title.AddToClassList("empty"); @@ -226,22 +234,24 @@ public void RecomputeBounds() } if (float.IsNaN(rect.xMin) || float.IsNaN(rect.yMin) || float.IsNaN(rect.width) || float.IsNaN(rect.height)) + { rect = Rect.zero; + shouldDeferRecompute = true; + } + rect = RectUtils.Inflate(rect, 20, titleEmpty ? 20 : m_Title.layout.height, 20, 20); - - if (invalidTitleWidth) + rect = new Rect(Mathf.Floor(rect.x), Mathf.Floor(rect.y), Mathf.Floor(rect.width), Mathf.Floor(rect.height)); + if (rect != m_previousBounds) { SetPosition(rect); - if (!m_WaitingRecompute) - { - m_WaitingRecompute = true; - schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed - } + m_previousBounds = rect; } - else + + if (shouldDeferRecompute && !m_WaitingRecompute) { - SetPosition(rect); + m_WaitingRecompute = true; + schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed } } From af387acffe74face25bfb93c3cac87a60927b49c Mon Sep 17 00:00:00 2001 From: Matthew Davey Date: Thu, 7 Oct 2021 10:35:44 -0400 Subject: [PATCH 2/6] Add changes from auto formatter, to test theory on regex. --- .../Editor/Utils/VFXSystemBorder.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs index 063f0b15651..790de46bc4d 100644 --- a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs +++ b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs @@ -11,7 +11,7 @@ namespace UnityEditor.VFX.UI { class VFXSystemBorderFactory : UxmlFactory - {} + { } class VFXSystemBorder : GraphElement, IControlledElement, IDisposable @@ -198,7 +198,7 @@ public void RecomputeBounds() { if (m_WaitingRecompute) return; - + visible = true; //title width should be at least as wide as a context to be valid. float titleWidth = m_Title.layout.width; @@ -239,7 +239,6 @@ public void RecomputeBounds() shouldDeferRecompute = true; } - rect = RectUtils.Inflate(rect, 20, titleEmpty ? 20 : m_Title.layout.height, 20, 20); rect = new Rect(Mathf.Floor(rect.x), Mathf.Floor(rect.y), Mathf.Floor(rect.width), Mathf.Floor(rect.height)); if (rect != m_previousBounds) @@ -251,7 +250,7 @@ public void RecomputeBounds() if (shouldDeferRecompute && !m_WaitingRecompute) { m_WaitingRecompute = true; - schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed + schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed } } From 393f38b7318bd32c2e6b30ae8d9eadf46a973c4f Mon Sep 17 00:00:00 2001 From: Matthew Davey Date: Thu, 7 Oct 2021 10:51:43 -0400 Subject: [PATCH 3/6] Remove extra tab --- com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs index 790de46bc4d..436cae97d8e 100644 --- a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs +++ b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs @@ -136,7 +136,7 @@ void OnTitleRelayout(GeometryChangedEvent e) { return; } - + UpdateTitleFieldRect(); RecomputeBounds(); } From 56586ebce915c1815bdfed062a75c6938c702895 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Fri, 8 Oct 2021 11:54:20 +0200 Subject: [PATCH 4/6] Prevent layout pass if difference is less that a pixel Depending on DPI setting the bounds rect could be instable and vary of less than a pixel (especially visible with DPI set at 125%) --- .../Editor/Utils/VFXSystemBorder.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs index 436cae97d8e..6517ee979e8 100644 --- a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs +++ b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs @@ -128,11 +128,17 @@ void OnTitleMouseDown(MouseDownEvent e) } } + bool IsDifferenceTooSmall(float x, float y) + { + return Mathf.Abs(x - y) < 1f; + } + void OnTitleRelayout(GeometryChangedEvent e) { - Rect oldRoundedRect = new Rect(Mathf.Floor(e.oldRect.x), Mathf.Floor(e.oldRect.y), Mathf.Floor(e.oldRect.width), Mathf.Floor(e.oldRect.height)); - Rect newRoundedRect = new Rect(Mathf.Floor(e.newRect.x), Mathf.Floor(e.newRect.y), Mathf.Floor(e.newRect.width), Mathf.Floor(e.newRect.height)); - if (oldRoundedRect == newRoundedRect) + if (IsDifferenceTooSmall(e.oldRect.x, e.newRect.x) && + IsDifferenceTooSmall(e.oldRect.y, e.newRect.y) && + IsDifferenceTooSmall(e.oldRect.width, e.newRect.height) && + IsDifferenceTooSmall(e.oldRect.height, e.newRect.height)) { return; } @@ -192,7 +198,6 @@ public override string title } public bool m_WaitingRecompute; - private Rect m_previousBounds; public void RecomputeBounds() { @@ -236,21 +241,21 @@ public void RecomputeBounds() if (float.IsNaN(rect.xMin) || float.IsNaN(rect.yMin) || float.IsNaN(rect.width) || float.IsNaN(rect.height)) { rect = Rect.zero; - shouldDeferRecompute = true; } rect = RectUtils.Inflate(rect, 20, titleEmpty ? 20 : m_Title.layout.height, 20, 20); - rect = new Rect(Mathf.Floor(rect.x), Mathf.Floor(rect.y), Mathf.Floor(rect.width), Mathf.Floor(rect.height)); - if (rect != m_previousBounds) + if (shouldDeferRecompute) { SetPosition(rect); - m_previousBounds = rect; + if (!m_WaitingRecompute) + { + m_WaitingRecompute = true; + schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed + } } - - if (shouldDeferRecompute && !m_WaitingRecompute) + else { - m_WaitingRecompute = true; - schedule.Execute(() => { m_WaitingRecompute = false; RecomputeBounds(); }).ExecuteLater(0); // title height might have changed if width have changed + SetPosition(rect); } } From 9ce4f05e3bc5296a391145787501e4999670349e Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 26 Oct 2021 15:18:04 +0200 Subject: [PATCH 5/6] Fixed typo --- com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs index 6517ee979e8..1f43e952135 100644 --- a/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs +++ b/com.unity.visualeffectgraph/Editor/Utils/VFXSystemBorder.cs @@ -137,7 +137,7 @@ void OnTitleRelayout(GeometryChangedEvent e) { if (IsDifferenceTooSmall(e.oldRect.x, e.newRect.x) && IsDifferenceTooSmall(e.oldRect.y, e.newRect.y) && - IsDifferenceTooSmall(e.oldRect.width, e.newRect.height) && + IsDifferenceTooSmall(e.oldRect.width, e.newRect.width) && IsDifferenceTooSmall(e.oldRect.height, e.newRect.height)) { return; From 2e866d1f73968d27622b867cf2ddea55973053b8 Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 26 Oct 2021 15:20:55 +0200 Subject: [PATCH 6/6] Updated changelog --- com.unity.visualeffectgraph/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index ae830cec92c..9ad132d2b9c 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -119,6 +119,7 @@ The version number for this package has increased due to a version update of a r - Fix undetermitism in space with LocalToWorld and WorldToLocal operators [Case 1355820](https://issuetracker.unity3d.com/product/unity/issues/guid/1355820/) - Added a missing paste option in the context menu for VFX contexts. Also the paste options is now disabled when uneffective - Rename "Material Offset" to "Sorting Priority" in output render state settings [Case 1365257](https://issuetracker.unity3d.com/product/unity/issues/guid/1365257/) +- No more performance drop when Windows screen DPI setting is set to custom values (like 125%) ## [11.0.0] - 2020-10-21 ### Added