Skip to content
SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
C# C PowerShell Makefile Shell C++
Branch: master
Clone or download
mattleibow Re-work the managed-native types (#900)
Changes:
 - Added `GCHandleProxy` to debug builds
    - this is used to track all `GCHandle` `Alloc` and `Free` calls to ensure that all allocations are freed.
    - added some unit tests to make sure this is actually enforced
    - as a result, several object are now freed correctly
 - Added `ISKReferenceCounted` and `ISKNonVirtualReferenceCounted` interfaces to represent the reference counting types used in the native library
    - this helps with automatically de-referencing objects
 - `SKAbstractManagedStream`, `SKAbstractManagedWStream` and `SKDrawable` have been re-written to use better delegates
   - instead of passing each of the delegates as parameters, they are now a struct that is passed as a single object
   - better for extensions (which there shouldn't be) and only a single static field on the type
   - removed the usage of `Marshal.GetFunctionPointerForDelegate`, which should help out with WASM (see #876)
   - the objects now only keep weak references, meaning that they can now be garbage collected
   - instead of trying to resolve the instances with a dictionary, a delegate is used and passed as "user context"
 - Moved some of the repetitive logic from the types into the base `SKObject` and `SKNativeObject`
    - some logic is automatically executed if the concrete type is `ISKReferenceCounted` or `ISKNonVirtualReferenceCounted`
    - with the more centralized logic and stricter patterns, better tests can be written to make sure all memory is freed correctly and timely
 - `SKData`, `SKFontManager` and `SKTypeface` now correctly prevent disposal of the "static" instances
 - `SKPaint` now references the `Shader`, `MaskFilter`, `ColorFilter`, `ImageFilter`, `Typeface` and `PathEffect` properties
    - this prevents accidental collection, or non-collection when the object goes out of scope
 - the `SKPath` iterators (`Iterator` and `RawIterator`) and op builder (`OpBuilder`) now correctly own and dispose their native objects
 - `SKRegion` objects are now disposed on the native side
 - `SKTypeface` construction from a `SKManagedStream` (via both `SKTypeface` and `SKFontManager`) now copy the contents of the .NET `Stream` into a native memory
    - typeface construction requires multiple seeks (previously, the stream was copied only if it was non-seekable)
    - it also requires "duplicating" the stream, which is not supported on .NET streams
       - duplicates or forks of a stream means that each of the streams need to be read concurrently from different locations
       - .NET streams can only have a single position
 - Updated the NuGets used for the tests
     - using the `Xunit.AssemblyFixture` and `Xunit.SkippableFact` NuGets instead of using the code directly
    - removed the `Xunit.Categories` NuGet as it was preventing tests from running

This PR has a big set of changes that may be breaking due to bug fixes:
 - The `SKAbstractManagedStream`, `SKAbstractManagedWStream` and `SKDrawable` no longer prevent the GC from collecting them. This means that if code no longer references them, they will be disposed. 
    - As far as I can tell, this should not be a problem for the streams as they are never kept around - they are just used for reading and writing and typically only need to live for as long as a single method, and then need to be disposed by the caller. The `SKTypeface` and `SKDocument` 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` and `SKTypeface` no longer use the managed streams (`SKManagedStream` or `Stream`) directly 
- they make a copy.
    - This is simply because skia streams can do things that are not possible for .NET - they can be read concurrently from different positions. If a `SKFileStream` or `SKMemoryStream` are passed, then the streams are not copied.
    - Further optimizations can be made in the case of a `MemoryStream` or `byte[]` 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.
Latest commit d5aa34a Jul 30, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Rename .github/PULL_REQUEST_TEMPLATE/pull_request_template.md to .git… Jun 25, 2019
binding Re-work the managed-native types (#900) Jul 30, 2019
cake Re-work the managed-native types (#900) Jul 30, 2019
changelogs Split the desktop projects and packages (#899) Jul 23, 2019
docs @ 31ef21f Split the desktop projects and packages (#899) Jul 23, 2019
externals Re-work the managed-native types (#900) Jul 30, 2019
images Added an icon to the OS X sample Jul 29, 2016
native-builds Update HarfBuzz to v2.5.3 (#904) Jul 13, 2019
nuget Add the WPF backend for Xamarin.Forms (#917) Jul 26, 2019
samples Add the WPF backend for Xamarin.Forms (#917) Jul 26, 2019
scripts Re-work the managed-native types (#900) Jul 30, 2019
source Re-work the managed-native types (#900) Jul 30, 2019
tests Re-work the managed-native types (#900) Jul 30, 2019
tools Few changes for release (#850) May 24, 2019
workbooks Set the version to v1.60.2 for the upcoming release May 29, 2018
.editorconfig Use Span<T> for data, bitmap data and text blobs (#865) Jun 26, 2019
.gitattributes Add a .gitattributes for the bash scripts Jul 19, 2018
.gitignore Add the WPF backend for Xamarin.Forms (#917) Jul 26, 2019
.gitmodules Update HarfBuzz to v2.5.3 (#904) Jul 13, 2019
External-Dependency-Info.txt Added the licensing information to the nugets Feb 23, 2018
LICENSE.md updated the license Feb 23, 2018
LICENSE.txt Moving more work into MSBuild Mar 20, 2018
README.md A few tweaks to harfbuzz (#915) Jul 21, 2019
VERSIONS.txt Add the WPF backend for Xamarin.Forms (#917) Jul 26, 2019
bootstrapper.ps1 Few changes for release (#850) May 24, 2019
bootstrapper.sh Few changes for release (#850) May 24, 2019
build.cake Re-work the managed-native types (#900) Jul 30, 2019
global.json The new 2.x MSBuild.Sdk.Extras do not work without the custom SDK Jan 16, 2019
mono.pub Updated the project files to the new skia location and split the cake… Sep 15, 2016
mono.snk Updated the project files to the new skia location and split the cake… Sep 15, 2016

README.md

SkiaSharp

SkiaSharp SkiaSharp.Views SkiaSharp.Views.Forms HarfBuzzSharp
chat SkiaSharp API Docs HarfBuzzSharp API Docs SkiaSharp Guides
Build Status Build Status

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library (skia.org). It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.

SkiaSharp provides cross-platform bindings for:

  • .NET Standard 1.3
  • .NET Core
  • Tizen
  • Xamarin.Android
  • Xamarin.iOS
  • Xamarin.tvOS
  • Xamarin.watchOS
  • Xamarin.Mac
  • Windows Classic Desktop (Windows.Forms / WPF)
  • Windows UWP (Desktop / Mobile / Xbox / HoloLens)

The API Documentation is available on the web to browse.

Using SkiaSharp

SkiaSharp is available as a convenient NuGet package, to use install the package like this:

nuget install SkiaSharp

Because there are multiple distros of Linux, and we cannot possibly support them all, we have a separate NuGet package that will contain the supported binaries for a few distros: SkiaSharp.NativeAssets.Linux. (distros) (more info)

There is also a early access feed that you can use to get the latest and greatest, before it goes out to the public:

https://nugetized.blob.core.windows.net/skiasharp-eap/index.json

Building SkiaSharp

Before building SkiaSharp:

  • Python 2.7 is available in the PATH environment variable on Windows
  • Android NDK r15 is available in the ANDROID_NDK_HOME environment variable on macOS
  • .NET Core is installed on all platforms
  • C/C++ Compiler (MSVC / "Desktop development" package on Windows)

First, clone the repository:

$ git clone https://github.com/mono/SkiaSharp.git

Next, set up the submodules:

$ cd SkiaSharp
$ git submodule update --init --recursive

Finally, build everything:

Mac/Linux:

$ ./bootstrapper.sh -t everything

Windows:

> .\bootstrapper.ps1 -t everything

Compare Code

Here are some links to show the differences in our code as compared to Google's code.

What version are we on? m68
Are we up-to-date with Google? Compare
What have we added? Compare

You can’t perform that action at this time.