From 7e4fa1d84b7a8eac22fa72fb2d0c9c612e743bf3 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 25 May 2022 21:46:52 +0300 Subject: [PATCH] Fixed hit-testing for the first frame --- .../Composition/Server/ReadbackIndices.cs | 25 ++++++++----------- .../Server/ServerCompositionTarget.cs | 10 +++++--- .../Composition/Server/ServerVisual.cs | 3 +-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ReadbackIndices.cs b/src/Avalonia.Base/Rendering/Composition/Server/ReadbackIndices.cs index 372fa4d9ce..1971451811 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ReadbackIndices.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ReadbackIndices.cs @@ -4,29 +4,24 @@ namespace Avalonia.Rendering.Composition.Server { private readonly object _lock = new object(); public int ReadIndex { get; private set; } = 0; - public int WriteIndex { get; private set; } = -1; + public int WriteIndex { get; private set; } = 1; + public int WrittenIndex { get; private set; } = 0; public ulong ReadRevision { get; private set; } - public ulong WriteRevision { get; private set; } - private ulong[] _revisions = new ulong[3]; - - + public ulong LastWrittenRevision { get; private set; } + public void NextRead() { lock (_lock) { - for (var c = 0; c < 3; c++) + if (ReadRevision < LastWrittenRevision) { - if (c != WriteIndex && c != ReadIndex && _revisions[c] > ReadRevision) - { - ReadIndex = c; - ReadRevision = _revisions[c]; - return; - } + ReadIndex = WrittenIndex; + ReadRevision = LastWrittenRevision; } } } - public void NextWrite(ulong revision) + public void CompleteWrite(ulong writtenRevision) { lock (_lock) { @@ -34,9 +29,9 @@ namespace Avalonia.Rendering.Composition.Server { if (c != WriteIndex && c != ReadIndex) { + WrittenIndex = WriteIndex; + LastWrittenRevision = writtenRevision; WriteIndex = c; - WriteRevision = revision; - _revisions[c] = revision; return; } } diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs b/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs index d8a5de4f54..a50562eabc 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs @@ -15,7 +15,7 @@ namespace Avalonia.Rendering.Composition.Server private readonly Func _renderTargetFactory; private static long s_nextId = 1; public long Id { get; } - private ulong _frame = 1; + public ulong Revision { get; private set; } private IRenderTarget? _renderTarget; private FpsCounter _fpsCounter = new FpsCounter(Typeface.Default.GlyphTypeface); private Rect _dirtyRect; @@ -58,9 +58,14 @@ namespace Avalonia.Rendering.Composition.Server if(_dirtyRect.IsEmpty && !_redrawRequested) return; + + Revision++; + // Update happens in a separate phase to extend dirty rect if needed Root.Update(this, Matrix4x4.Identity); + Readback.CompleteWrite(Revision); + _redrawRequested = false; using (var targetContext = _renderTarget.CreateDrawingContext(null)) { @@ -102,9 +107,6 @@ namespace Avalonia.Rendering.Composition.Server _dirtyRect = Rect.Empty; } - - Readback.NextWrite(_frame); - _frame++; } private static Rect SnapToDevicePixels(Rect rect, double scale) diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ServerVisual.cs b/src/Avalonia.Base/Rendering/Composition/Server/ServerVisual.cs index 05b63a7a73..4e320c34be 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ServerVisual.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ServerVisual.cs @@ -63,7 +63,7 @@ namespace Avalonia.Rendering.Composition.Server Scale, RotationAngle, Orientation, Offset); var i = Root!.Readback; ref var readback = ref GetReadback(i.WriteIndex); - readback.Revision = i.WriteRevision; + readback.Revision = root.Revision; readback.Matrix = res; readback.TargetId = Root.Id; //TODO: check effective opacity too @@ -85,7 +85,6 @@ namespace Avalonia.Rendering.Composition.Server public struct ReadbackData { public Matrix4x4 Matrix; - public bool Visible; public ulong Revision; public long TargetId; }