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 9c5aab1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class Visual
{
private interface IPrivateSessionFactory
{
PaintingSession CreateInstance(Visual visual, SKSurface surface, SKCanvas canvas, in DrawingFilters filters, in Matrix4x4 rootTransform);
PaintingSession CreateInstance(in Visual visual, in SKSurface surface, in SKCanvas canvas, in DrawingFilters filters, in Matrix4x4 rootTransform);
}

/// <summary>
Expand All @@ -23,7 +23,7 @@ private interface IPrivateSessionFactory
// This dance is done to make it so that only Visual can create a PaintingSession
public readonly struct SessionFactory : IPrivateSessionFactory
{
PaintingSession IPrivateSessionFactory.CreateInstance(Visual visual, SKSurface surface, SKCanvas canvas, in DrawingFilters filters, in Matrix4x4 rootTransform)
PaintingSession IPrivateSessionFactory.CreateInstance(in Visual visual, in SKSurface surface, in SKCanvas canvas, in DrawingFilters filters, in Matrix4x4 rootTransform)
{
return new PaintingSession(visual, surface, canvas, filters, rootTransform);
}
Expand Down
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 9c5aab1

Please sign in to comment.