Re-work the managed-native types#900
Conversation
- pass a context around - clean up the API - don't use dictionaries - don't use GetFunctionPointerForDelegate
- added several debug-only hooks to track objects and exceptions
- added a field to keep the document stream alive
- drawable picture is not referenced as it is a plain pointer
- creating typefaces always copies the managed stream as multiple reads are needed
- automatically dispose objects that already exist in the instances dictionary when the same handle is loaded
- the object may already be deleted on the native side
- a native crash will happen if the object is unref-ed later
| using (var image = SKImage.FromPixels(pixmap, onRelease, "RELEASING!")) | ||
| { | ||
| Assert.False(image.IsTextureBacked); | ||
| using (var raster = image.ToRasterImage()) |
There was a problem hiding this comment.
This is no longer supported as it is not valid C#/.NET code. You have to actually dispose of the same SKImage instance twice (or more depending).If the instance is the same, you cannot dispose it more time.
| public const float DefaultRasterDpi = 72.0f; | ||
|
|
||
| // keep the stream alive for as long as the document exists | ||
| private SKWStream underlyingStream; |
There was a problem hiding this comment.
The streams were in danger of being disposed while the document was in progress. To fix this, we keep a reference to it to make sure the GC doesn't pick it up early. This is different to the internal stream ownership where the internal streams are DISPOSED after usage. This will allow the stream to stay open and alive.
This reverts commit 4d8836a.
|
This PR has a big set of changes that may be breaking due to bug fixes: The
The
|
Description of Change
GCHandleProxyto debug buildsGCHandleAllocandFreecalls to ensure that all allocations are freed.ISKReferenceCountedandISKNonVirtualReferenceCountedinterfaces to represent the reference counting types used in the native librarySKAbstractManagedStream,SKAbstractManagedWStreamandSKDrawablehave been re-written to use better delegatesMarshal.GetFunctionPointerForDelegate, which should help out with WASM (see [FEATURE] Add a SkiaApi and SKAbstractManagedStream native abstraction #876)SKObjectandSKNativeObjectISKReferenceCountedorISKNonVirtualReferenceCountedSKData,SKFontManagerandSKTypefacenow correctly prevent disposal of the "static" instancesSKPaintnow references theShader,MaskFilter,ColorFilter,ImageFilter,TypefaceandPathEffectpropertiesSKPathiterators (IteratorandRawIterator) and op builder (OpBuilder) now correctly own and dispose their native objectsSKRegionobjects are now disposed on the native sideSKTypefaceconstruction from aSKManagedStream(via bothSKTypefaceandSKFontManager) now copy the contents of the .NETStreaminto a native memoryXunit.AssemblyFixtureandXunit.SkippableFactNuGets instead of using the code directlyXunit.CategoriesNuGet as it was preventing tests from runningBugs Fixed
Provide links to issues here. Ensure that a GitHub issue was created for your feature or bug fix before sending PR.
API Changes
None visible.
Behavioral Changes
This PR has a big set of changes that may be breaking due to bug fixes:
The
SKAbstractManagedStream,SKAbstractManagedWStreamandSKDrawableno longer prevent the GC from collecting them. This means that if code no longer references them, they will be disposed.SKTypefaceandSKDocumentdo keep it around for a bit, but then they also take ownership of the stream and keep a hard reference to the streams themselves. They will dispose the streams when they are disposed.SKDrawableis never kept around and is entirely a user-controlled object. If it goes out of scope, skia doesn't have a reference anyway.The
SKFontManagerandSKTypefaceno longer use the managed streams (SKManagedStreamorStream) directly - they make a copy.SKFileStreamorSKMemoryStreamare passed, then the streams are not copied.MemoryStreamorbyte[]to not actually copy but use GC pinning to get a handle to the managed data and work with pointers. But this can be done later so that this PR can be merged and tested.PR Checklist