Visual.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Numerics;
  3. using Avalonia.Media;
  4. using Avalonia.VisualTree;
  5. // Special license applies <see href="https://raw.githubusercontent.com/AvaloniaUI/Avalonia/master/src/Avalonia.Base/Rendering/Composition/License.md">License.md</see>
  6. namespace Avalonia.Rendering.Composition
  7. {
  8. /// <summary>
  9. /// The base visual object in the composition visual hierarchy.
  10. /// </summary>
  11. public abstract partial class CompositionVisual
  12. {
  13. private IBrush? _opacityMask;
  14. private protected virtual void OnRootChangedCore()
  15. {
  16. }
  17. partial void OnRootChanged() => OnRootChangedCore();
  18. partial void OnParentChanged() => Root = Parent?.Root;
  19. public IBrush? OpacityMask
  20. {
  21. get => _opacityMask;
  22. set
  23. {
  24. if (_opacityMask == value)
  25. return;
  26. OpacityMaskBrush = (_opacityMask = value)?.ToImmutable();
  27. }
  28. }
  29. internal Matrix4x4? TryGetServerGlobalTransform()
  30. {
  31. if (Root == null)
  32. return null;
  33. var i = Root.Server.Readback;
  34. ref var readback = ref Server.GetReadback(i.ReadIndex);
  35. // CompositionVisual wasn't visible or wasn't even attached to the composition target during the lat frame
  36. if (!readback.Visible || readback.Revision < i.ReadRevision)
  37. return null;
  38. // CompositionVisual was reparented (potential race here)
  39. if (readback.TargetId != Root.Server.Id)
  40. return null;
  41. return readback.Matrix;
  42. }
  43. internal object? Tag { get; set; }
  44. internal virtual bool HitTest(Point point) => true;
  45. }
  46. }