Jelajahi Sumber

Fixed hit-testing for the first frame

Nikita Tsukanov 3 tahun lalu
induk
melakukan
7e4fa1d84b

+ 10 - 15
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;
                     }
                 }

+ 6 - 4
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs

@@ -15,7 +15,7 @@ namespace Avalonia.Rendering.Composition.Server
         private readonly Func<IRenderTarget> _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)

+ 1 - 2
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;
         }