Skip to content

Add clone support#454

Merged
wieslawsoltes merged 3 commits into
masterfrom
DeepClone
Jan 3, 2026
Merged

Add clone support#454
wieslawsoltes merged 3 commits into
masterfrom
DeepClone

Conversation

@wieslawsoltes
Copy link
Copy Markdown
Owner

@wieslawsoltes wieslawsoltes commented Jan 3, 2026

Svg.Skia deep cloning and clone coverage enhancements

Overview

This branch standardizes deep cloning across ShimSkiaSharp and Svg.Model, preserves shared-reference semantics where appropriate, and adds comprehensive clone coverage tests. It introduces a formal clone contract via interfaces, extends drawable cloning across the Svg.Model object graph, and adds unit test projects and coverage checks to validate behavior.

Key changes

  • Standardized deep cloning across ShimSkiaSharp with IDeepCloneable<T> and DeepClone() implementations for records and classes, including SKDrawable support.
  • Added a clone context with reference-equality tracking and cycle detection, preserving shared-instance identity within a clone graph and rejecting self-referential record graphs.
  • Updated ShimSkiaSharp clone paths for canvases, commands, paths, paints, shaders, filters, pictures, images, text blobs, typefaces, clip paths, and recorders to use shared-context cloning.
  • Implemented deep-clone support for Svg.Model drawables, including base state copying, container/marker reparenting, and type-specific field cloning.
  • Added a new Svg.Model unit test project with clone tests for drawables and coverage checks for clone support.
  • Expanded ShimSkiaSharp unit tests to cover shared-reference preservation and cycle-detection behavior.

Behavior changes

  • DeepClone now preserves shared object identity within the same clone context rather than duplicating shared references.
  • Self-referential record graphs throw NotSupportedException during cloning to avoid infinite recursion.
  • Svg.Model drawables now provide consistent deep cloning with preserved parent relationships for cloned child graphs.

Tests

  • dotnet test tests/ShimSkiaSharp.UnitTests/ShimSkiaSharp.UnitTests.csproj -c Release
    • Note: existing nullable warnings in tests/ShimSkiaSharp.UnitTests/SKPathTests.cs.
  • dotnet test tests/Svg.Model.UnitTests/Svg.Model.UnitTests.csproj -c Release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant