Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,27 @@ public override void LogOnCanvas(string log)

internal override void OnBeginDraw()
{
if (Background == SKColor.Empty) return;
// For fully opaque backgrounds, Clear is safe and efficient.
if (Background.Alpha == 255)
{
Canvas.Clear(Background);
return;
}

// For transparent or translucent backgrounds, draw a filled rect with SrcOver
// to avoid clearing through to the underlying OS surface while still clearing
// the motion canvas to prevent ghosting/trails from previous frames.
var clearColor = Background == SKColor.Empty ? SKColors.Transparent : Background;

using var backgroundPaint = new SKPaint
{
Color = clearColor,
Style = SKPaintStyle.Fill,
BlendMode = SKBlendMode.SrcATop
};

_ = Canvas.SaveLayer();
Canvas.Clear(Background);
Canvas.Restore();
var bounds = Canvas.DeviceClipBounds;
Canvas.DrawRect(bounds, backgroundPaint);
}

internal override void OnEndDraw()
Expand Down
Loading