Browse Source

Fixed hit-testing for the first frame

pull/8105/head
Nikita Tsukanov 4 years ago
parent
commit
7e4fa1d84b
  1. 25
      src/Avalonia.Base/Rendering/Composition/Server/ReadbackIndices.cs
  2. 10
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs
  3. 3
      src/Avalonia.Base/Rendering/Composition/Server/ServerVisual.cs

25
src/Avalonia.Base/Rendering/Composition/Server/ReadbackIndices.cs

@ -4,29 +4,24 @@ namespace Avalonia.Rendering.Composition.Server
{ {
private readonly object _lock = new object(); private readonly object _lock = new object();
public int ReadIndex { get; private set; } = 0; 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 ReadRevision { get; private set; }
public ulong WriteRevision { get; private set; } public ulong LastWrittenRevision { get; private set; }
private ulong[] _revisions = new ulong[3];
public void NextRead() public void NextRead()
{ {
lock (_lock) lock (_lock)
{ {
for (var c = 0; c < 3; c++) if (ReadRevision < LastWrittenRevision)
{ {
if (c != WriteIndex && c != ReadIndex && _revisions[c] > ReadRevision) ReadIndex = WrittenIndex;
{ ReadRevision = LastWrittenRevision;
ReadIndex = c;
ReadRevision = _revisions[c];
return;
}
} }
} }
} }
public void NextWrite(ulong revision) public void CompleteWrite(ulong writtenRevision)
{ {
lock (_lock) lock (_lock)
{ {
@ -34,9 +29,9 @@ namespace Avalonia.Rendering.Composition.Server
{ {
if (c != WriteIndex && c != ReadIndex) if (c != WriteIndex && c != ReadIndex)
{ {
WrittenIndex = WriteIndex;
LastWrittenRevision = writtenRevision;
WriteIndex = c; WriteIndex = c;
WriteRevision = revision;
_revisions[c] = revision;
return; return;
} }
} }

10
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs

@ -15,7 +15,7 @@ namespace Avalonia.Rendering.Composition.Server
private readonly Func<IRenderTarget> _renderTargetFactory; private readonly Func<IRenderTarget> _renderTargetFactory;
private static long s_nextId = 1; private static long s_nextId = 1;
public long Id { get; } public long Id { get; }
private ulong _frame = 1; public ulong Revision { get; private set; }
private IRenderTarget? _renderTarget; private IRenderTarget? _renderTarget;
private FpsCounter _fpsCounter = new FpsCounter(Typeface.Default.GlyphTypeface); private FpsCounter _fpsCounter = new FpsCounter(Typeface.Default.GlyphTypeface);
private Rect _dirtyRect; private Rect _dirtyRect;
@ -58,9 +58,14 @@ namespace Avalonia.Rendering.Composition.Server
if(_dirtyRect.IsEmpty && !_redrawRequested) if(_dirtyRect.IsEmpty && !_redrawRequested)
return; return;
Revision++;
// Update happens in a separate phase to extend dirty rect if needed
Root.Update(this, Matrix4x4.Identity); Root.Update(this, Matrix4x4.Identity);
Readback.CompleteWrite(Revision);
_redrawRequested = false; _redrawRequested = false;
using (var targetContext = _renderTarget.CreateDrawingContext(null)) using (var targetContext = _renderTarget.CreateDrawingContext(null))
{ {
@ -102,9 +107,6 @@ namespace Avalonia.Rendering.Composition.Server
_dirtyRect = Rect.Empty; _dirtyRect = Rect.Empty;
} }
Readback.NextWrite(_frame);
_frame++;
} }
private static Rect SnapToDevicePixels(Rect rect, double scale) private static Rect SnapToDevicePixels(Rect rect, double scale)

3
src/Avalonia.Base/Rendering/Composition/Server/ServerVisual.cs

@ -63,7 +63,7 @@ namespace Avalonia.Rendering.Composition.Server
Scale, RotationAngle, Orientation, Offset); Scale, RotationAngle, Orientation, Offset);
var i = Root!.Readback; var i = Root!.Readback;
ref var readback = ref GetReadback(i.WriteIndex); ref var readback = ref GetReadback(i.WriteIndex);
readback.Revision = i.WriteRevision; readback.Revision = root.Revision;
readback.Matrix = res; readback.Matrix = res;
readback.TargetId = Root.Id; readback.TargetId = Root.Id;
//TODO: check effective opacity too //TODO: check effective opacity too
@ -85,7 +85,6 @@ namespace Avalonia.Rendering.Composition.Server
public struct ReadbackData public struct ReadbackData
{ {
public Matrix4x4 Matrix; public Matrix4x4 Matrix;
public bool Visible;
public ulong Revision; public ulong Revision;
public long TargetId; public long TargetId;
} }

Loading…
Cancel
Save