perf(ui-visuals): keep seeking and panning free of redundant work
The filmstrip moves one cached current-frame marker instead of building a geometry per seek; panning the preview no longer re-applies the wipe clip or re-sets an unchanged zoom. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
3 files changed
+19
-6
No files matched your search
@@ -39,6 +39,9 @@ public sealed class Filmstrip : DrawingElement
|
|||||||
|
|
||||||
private static readonly MarkerKind[] Kinds = Enum.GetValues<MarkerKind>();
|
private static readonly MarkerKind[] Kinds = Enum.GetValues<MarkerKind>();
|
||||||
|
|
||||||
|
/// <summary>The current-frame ▼ at x = 0; moved by <see cref="_markerShift"/> so seeking allocates no geometry.</summary>
|
||||||
|
private static readonly Geometry CurrentMarker = CreateCurrentMarker();
|
||||||
|
|
||||||
private LruCache<int, CachedFrame> _cache = new(256);
|
private LruCache<int, CachedFrame> _cache = new(256);
|
||||||
private readonly HashSet<int> _pending = [];
|
private readonly HashSet<int> _pending = [];
|
||||||
private CancellationTokenSource _loads = new();
|
private CancellationTokenSource _loads = new();
|
||||||
@@ -46,6 +49,7 @@ public sealed class Filmstrip : DrawingElement
|
|||||||
private Rect _cells;
|
private Rect _cells;
|
||||||
private bool _dragging;
|
private bool _dragging;
|
||||||
private int _wheelDelta;
|
private int _wheelDelta;
|
||||||
|
private readonly TranslateTransform _markerShift = new();
|
||||||
|
|
||||||
static Filmstrip()
|
static Filmstrip()
|
||||||
{
|
{
|
||||||
@@ -120,10 +124,10 @@ public sealed class Filmstrip : DrawingElement
|
|||||||
var outline = new Rect(left + 1, _cells.Top + 1, Math.Max(0, right - left - 2), Math.Max(0, _cells.Height - 2));
|
var outline = new Rect(left + 1, _cells.Top + 1, Math.Max(0, right - left - 2), Math.Max(0, _cells.Height - 2));
|
||||||
dc.DrawRectangle(null, GetPen("Brush.Accent", 2), outline);
|
dc.DrawRectangle(null, GetPen("Brush.Accent", 2), outline);
|
||||||
|
|
||||||
var marker = new StreamGeometry();
|
_markerShift.X = _strip.XForFrame(frame);
|
||||||
using (var ctx = marker.Open()) AddTriangleDown(ctx, _strip.XForFrame(frame), 1, 9);
|
dc.PushTransform(_markerShift);
|
||||||
marker.Freeze();
|
dc.DrawGeometry(GetBrush("Brush.Accent"), null, CurrentMarker);
|
||||||
dc.DrawGeometry(GetBrush("Brush.Accent"), null, marker);
|
dc.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||||
@@ -219,6 +223,14 @@ public sealed class Filmstrip : DrawingElement
|
|||||||
private static void OnCacheCapacityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
private static void OnCacheCapacityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) =>
|
||||||
((Filmstrip)d)._cache.Capacity = (int)e.NewValue;
|
((Filmstrip)d)._cache.Capacity = (int)e.NewValue;
|
||||||
|
|
||||||
|
private static StreamGeometry CreateCurrentMarker()
|
||||||
|
{
|
||||||
|
var geometry = new StreamGeometry();
|
||||||
|
using (var ctx = geometry.Open()) AddTriangleDown(ctx, 0, 1, 9);
|
||||||
|
geometry.Freeze();
|
||||||
|
return geometry;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Draws <paramref name="image"/> scaled to cover <paramref name="cell"/>, centred and cropped.</summary>
|
/// <summary>Draws <paramref name="image"/> scaled to cover <paramref name="cell"/>, centred and cropped.</summary>
|
||||||
private static void DrawCover(DrawingContext dc, ImageSource image, Rect cell)
|
private static void DrawCover(DrawingContext dc, ImageSource image, Rect cell)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,6 @@ public sealed class PreviewSurface : DrawingElement
|
|||||||
RenderOptions.SetBitmapScalingMode(_original, mode);
|
RenderOptions.SetBitmapScalingMode(_original, mode);
|
||||||
}
|
}
|
||||||
if (view.Scale != _overlayScale) RefreshOverlay();
|
if (view.Scale != _overlayScale) RefreshOverlay();
|
||||||
UpdateWipeClip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Rebuilds the overlays (crop mask, region boundary, motion vectors) in image coordinates.</summary>
|
/// <summary>Rebuilds the overlays (crop mask, region boundary, motion vectors) in image coordinates.</summary>
|
||||||
|
|||||||
@@ -363,10 +363,12 @@ public class PreviewViewport : Control
|
|||||||
if (ZoomMode == PreviewZoomMode.Actual) view = ViewportMath.SnapOffset(view, dpi);
|
if (ZoomMode == PreviewZoomMode.Actual) view = ViewportMath.SnapOffset(view, dpi);
|
||||||
_view = view;
|
_view = view;
|
||||||
_surface?.SetView(view, view.Scale * dpi);
|
_surface?.SetView(view, view.Scale * dpi);
|
||||||
|
var zoom = view.Scale * dpi;
|
||||||
|
if (zoom == Zoom) return;
|
||||||
_syncingZoom = true;
|
_syncingZoom = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetCurrentValue(ZoomProperty, view.Scale * dpi);
|
SetCurrentValue(ZoomProperty, zoom);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user