-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
@@ -78,11 +79,8 @@ public void ReleaseImagePixelsWasInvoked() | |||
using (var image = SKImage.FromPixels(pixmap, onRelease, "RELEASING!")) | |||
{ | |||
Assert.False(image.IsTextureBacked); | |||
using (var raster = image.ToRasterImage()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
GCHandleProxy
to debug buildsGCHandle
Alloc
andFree
calls to ensure that all allocations are freed.ISKReferenceCounted
andISKNonVirtualReferenceCounted
interfaces to represent the reference counting types used in the native librarySKAbstractManagedStream
,SKAbstractManagedWStream
andSKDrawable
have been re-written to use better delegatesMarshal.GetFunctionPointerForDelegate
, which should help out with WASM (see [FEATURE] Add a SkiaApi and SKAbstractManagedStream native abstraction #876)SKObject
andSKNativeObject
ISKReferenceCounted
orISKNonVirtualReferenceCounted
SKData
,SKFontManager
andSKTypeface
now correctly prevent disposal of the "static" instancesSKPaint
now references theShader
,MaskFilter
,ColorFilter
,ImageFilter
,Typeface
andPathEffect
propertiesSKPath
iterators (Iterator
andRawIterator
) and op builder (OpBuilder
) now correctly own and dispose their native objectsSKRegion
objects are now disposed on the native sideSKTypeface
construction from aSKManagedStream
(via bothSKTypeface
andSKFontManager
) now copy the contents of the .NETStream
into a native memoryXunit.AssemblyFixture
andXunit.SkippableFact
NuGets instead of using the code directlyXunit.Categories
NuGet 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
,SKAbstractManagedWStream
andSKDrawable
no longer prevent the GC from collecting them. This means that if code no longer references them, they will be disposed.SKTypeface
andSKDocument
do 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.SKDrawable
is never kept around and is entirely a user-controlled object. If it goes out of scope, skia doesn't have a reference anyway.The
SKFontManager
andSKTypeface
no longer use the managed streams (SKManagedStream
orStream
) directly - they make a copy.SKFileStream
orSKMemoryStream
are passed, then the streams are not copied.MemoryStream
orbyte[]
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