From a7cc9121c07f497a1a59c4cddb84e710d8299e9b 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 49457b212546d5320c10f32632f7b412d7f4871a 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 866d4f8f265644a23b0bec93b1eb20038674312e 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 0e920c70fb41bba3539d949ec22787ff8dad0ff8 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 8c90acb6ab13d199a8658691b121d0973a52024f Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 26 Oct 2021 15:53:48 +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 d75e3310252cb97cb83a7576c92012ae94c74fec Mon Sep 17 00:00:00 2001 From: Julien Amsellem Date: Tue, 26 Oct 2021 16:30:34 +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 9feb9eaa6e7..679facfb31b 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -68,6 +68,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fix potential infinite compilation when using subgraphs [Case 1346576](https://issuetracker.unity3d.com/product/unity/issues/guid/1346576/) - Prevent out of sync serialization of VFX assets that could cause the asset to be dirtied without reason - Fix undetermitism in space with LocalToWorld and WorldToLocal operators [Case 1355820](https://issuetracker.unity3d.com/product/unity/issues/guid/1355820/) +- No more performance drop when Windows screen DPI setting is set to custom values (like 125%) ## [10.2.0] - 2020-10-19 ### Added