mono / SkiaSharp

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.
MIT License
4.47k stars 538 forks source link

[FEATURE] Expose SkiaApi class #1205

Open kekekeks opened 4 years ago

kekekeks commented 4 years ago

SkObject initialization and housekeeping is quite costly in both CPU and allocations. On hot code paths it's desirable to just deal with raw IntPtr's and Skia C API and manage those manually.

Performance benefits far outweigh the loss of object-oriented API and backwards compatibility with previous SkiaSharp versions.

Since SkObject already exposes Handle property the only change that is needed is to make SkiaApi class to be public rather than internal.

daltonks commented 3 years ago

I'd like this as well, especially for path iterators. This seems really expensive when it's applied to every path verb:

      public unsafe SKPathVerb Next(Span<SKPoint> points)
      {
        if (points == (Span<SKPoint>) (SKPoint[]) null)
          throw new ArgumentNullException(nameof (points));
        if (points.Length != 4)
          throw new ArgumentException("Must be an array of four elements.", nameof (points));
        fixed (SKPoint* points1 = &points.GetPinnableReference())
          return SkiaApi.sk_path_rawiter_next(this.Handle, points1);
      }