Skip to content

Commit

Permalink
chore: remove repetitively creating new SessionFactory boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed May 8, 2024
1 parent 27fa0b0 commit 9fa2333
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Uno.UI.Composition/Composition/Visual.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.UI.Composition;

public partial class Visual : global::Microsoft.UI.Composition.CompositionObject
{
private static readonly IPrivateSessionFactory _factory = new PaintingSession.SessionFactory();

private CompositionClip? _clip;
private RectangleClip? _cornerRadiusClip;
private Vector2 _anchorPoint = Vector2.Zero; // Backing for scroll offsets
Expand Down Expand Up @@ -157,10 +159,9 @@ internal void RenderRootVisual(SKSurface surface, Vector2? offsetOverride = null
initialTransform = translation * initialTransform;
}

using (var wrapper =
((IPrivateSessionFactory)new PaintingSession.SessionFactory()).CreateInstance(this, surface, canvas, DrawingFilters.Default, initialTransform))
using (var session = _factory.CreateInstance(this, surface, canvas, DrawingFilters.Default, initialTransform))
{
Render(wrapper.Session);
Render(session);
}

if (offsetOverride is { })
Expand All @@ -187,9 +188,8 @@ private void Render(in PaintingSession parentSession)
return;
}

using (var wrapper = CreateLocalSession(in parentSession))
using (var session = CreateLocalSession(in parentSession))
{
var session = wrapper.Session;
Paint(session);

// The CornerRadiusClip doesn't affect the visual itself, only its children
Expand Down Expand Up @@ -234,7 +234,7 @@ private protected virtual void ApplyClipping(in SKCanvas canvas)
/// Creates a new <see cref="PaintingSession"/> set up with the local coordinates,
/// clipping and opacity.
/// </summary>
private PaintingSessionWrapper CreateLocalSession(in PaintingSession parentSession)
private PaintingSession CreateLocalSession(in PaintingSession parentSession)
{
var surface = parentSession.Surface;
var canvas = parentSession.Canvas;
Expand All @@ -244,7 +244,7 @@ private PaintingSessionWrapper CreateLocalSession(in PaintingSession parentSessi
? parentSession.Filters
: parentSession.Filters with { Opacity = parentSession.Filters.Opacity * Opacity };

var session = ((IPrivateSessionFactory)new PaintingSession.SessionFactory()).CreateInstance(this, surface, canvas, filters, rootTransform);
var session = _factory.CreateInstance(this, surface, canvas, filters, rootTransform);

if (rootTransform.IsIdentity)
{
Expand Down

0 comments on commit 9fa2333

Please sign in to comment.