Jumar Macato 4 lat temu
rodzic
commit
1ab777c961

+ 5 - 1
samples/RenderDemo/Pages/PathMeasurementPage.cs

@@ -15,13 +15,17 @@ namespace RenderDemo.Pages
 {
     public class PathMeasurementPage : Control
     {
+        static PathMeasurementPage()
+        {
+            AffectsRender<PathMeasurementPage>(BoundsProperty);
+        }
+
         private RenderTargetBitmap _bitmap;
 
         protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
         {
             _bitmap = new RenderTargetBitmap(new PixelSize(500, 500), new Vector(96, 96));
             base.OnAttachedToLogicalTree(e);
-            AffectsRender<PathMeasurementPage>(BoundsProperty);
         }
 
         protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)

+ 1 - 1
src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs

@@ -178,7 +178,7 @@ namespace Avalonia.Rendering.SceneGraph
                 ++_drawOperationindex;
             }
         }
-        
+
         public void Custom(ICustomDrawOperation custom)
         {
             var next = NextDrawAs<CustomDrawOperation>();

+ 18 - 25
src/Skia/Avalonia.Skia/GeometryImpl.cs

@@ -11,7 +11,20 @@ namespace Avalonia.Skia
     internal abstract class GeometryImpl : IGeometryImpl
     {
         private PathCache _pathCache;
-        private SKPathMeasure _pathMeasureCache;
+        private SKPathMeasure _pathMeasureCachex;
+
+        private SKPathMeasure CachedPathMeasure
+        {
+            get
+            {
+                if (_pathMeasureCachex is null)
+                {
+                    _pathMeasureCachex = new SKPathMeasure(EffectivePath);
+                }
+
+                return _pathMeasureCachex;
+            }
+        }
 
         /// <inheritdoc />
         public abstract Rect Bounds { get; }
@@ -24,12 +37,7 @@ namespace Avalonia.Skia
                 if (EffectivePath is null)
                     return 0;
 
-                if (_pathMeasureCache is null)
-                {
-                    _pathMeasureCache = new SKPathMeasure(EffectivePath);
-                }
-
-                return (double)_pathMeasureCache?.Length;
+                return (double)CachedPathMeasure?.Length;
             }
         }
 
@@ -132,12 +140,7 @@ namespace Avalonia.Skia
                 return false;
             }
 
-            if (_pathMeasureCache is null)
-            {
-                _pathMeasureCache = new SKPathMeasure(EffectivePath);
-            }
-
-            var res = _pathMeasureCache.GetPosition((float)distance, out var skPoint);
+            var res = CachedPathMeasure.GetPosition((float)distance, out var skPoint);
             point = new Point(skPoint.X, skPoint.Y);
             return res;
         }
@@ -152,12 +155,7 @@ namespace Avalonia.Skia
                 return false;
             }
 
-            if (_pathMeasureCache is null)
-            {
-                _pathMeasureCache = new SKPathMeasure(EffectivePath);
-            }
-
-            var res = _pathMeasureCache.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent);
+            var res = CachedPathMeasure.GetPositionAndTangent((float)distance, out var skPoint, out var skTangent);
             point = new Point(skPoint.X, skPoint.Y);
             tangent = new Point(skTangent.X, skTangent.Y);
             return res;
@@ -172,16 +170,11 @@ namespace Avalonia.Skia
                 return false;
             }
 
-            if (_pathMeasureCache is null)
-            {
-                _pathMeasureCache = new SKPathMeasure(EffectivePath);
-            }
-            
             segmentGeometry = null;
 
             var _skPathSegment = new SKPath();
 
-            var res = _pathMeasureCache.GetSegment((float)startDistance, (float)stopDistance, _skPathSegment, startOnBeginFigure);
+            var res = CachedPathMeasure.GetSegment((float)startDistance, (float)stopDistance, _skPathSegment, startOnBeginFigure);
 
             if (res)
             {