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.14k stars 522 forks source link

[BUG] SKGLView on .NET MAUI is missing a handler (the return) #2838

Open softlion opened 1 month ago

softlion commented 1 month ago

Description

There is no more overload of UseSkiaSharp(true), and the handler for SKGLView is not registered anymore.

This is a regression, or is there a breaking change I missed ?

skiasharp maui 2.88.8
my maui ios+android app is net8

I verified the source code on github, and I do see the handler being registered.

But when I decompile UseSkiaSharp with rider on get to the ios source code, there is no such registration.

Bad release ?

Should be that code instead :(

https://github.com/mono/SkiaSharp/blob/main/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/AppHostBuilderExtensions.cs

Code

Decompiled 2.88.8, not same code as in https://github.com/mono/SkiaSharp/blob/main/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/AppHostBuilderExtensions.cs

// Decompiled with JetBrains decompiler
// Type: SkiaSharp.Views.Maui.Controls.Hosting.AppHostBuilderExtensions
// Assembly: SkiaSharp.Views.Maui.Controls, Version=2.88.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 746A20A3-036F-4E0B-9FD2-26297B262D4E
// Assembly location: C:\Users\benja_lfpsq1j\.nuget\packages\skiasharp.views.maui.controls\2.88.8\lib\net6.0-ios13.6\SkiaSharp.Views.Maui.Controls.dll
// XML documentation location: C:\Users\benja_lfpsq1j\.nuget\packages\skiasharp.views.maui.controls\2.88.8\lib\net6.0-ios13.6\SkiaSharp.Views.Maui.Controls.xml

using Microsoft.Maui.Hosting;
using SkiaSharp.Views.Maui.Handlers;
using System;

#nullable enable
namespace SkiaSharp.Views.Maui.Controls.Hosting
{
  public static class AppHostBuilderExtensions
  {
    public static 
    #nullable disable
    MauiAppBuilder UseSkiaSharp(this MauiAppBuilder builder)
    {
      return builder.ConfigureMauiHandlers((Action<IMauiHandlersCollection>) (handlers => handlers.AddHandler<SKCanvasView, SKCanvasViewHandler>())).ConfigureImageSources((Action<IImageSourceServiceCollection>) (sources =>
      {
        sources.AddService<ISKImageImageSource, SKImageSourceService>();
        sources.AddService<ISKBitmapImageSource, SKImageSourceService>();
        sources.AddService<ISKPixmapImageSource, SKImageSourceService>();
        sources.AddService<ISKPictureImageSource, SKImageSourceService>();
      }));
    }
  }
}

Expected Behavior

No response

Actual Behavior

No response

Version of SkiaSharp

Other (Please indicate in the description)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Other (Please indicate in the description)

Platform / Operating System

Windows

Platform / Operating System Version

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

softlion commented 1 month ago

it looks like it's back in the version 3.0.0-preview3.1

Did I dream that it was there before ? I don't think so.
My add did work on iOS before I upgraded.

It used to be there with the UseSkiSharp(true) overload.

btw 3.0.0-preview3.1 is crashing with that message:

The version of the native libSkiaSharp library (88.1) is incompatible with this version of SkiaSharp. Supported versions of the native libSkiaSharp library are in the range [115.0, 116.0).

at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Version minSupported, Version current, Boolean throwIfIncompatible)
   at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)
   at SkiaSharp.SKObject..cctor()

InnerException was TypeInitializationException: The type initializer for 'SkiaSharp.SKObject' threw an exception.
       at SkiaSharp.SKData..ctor(IntPtr x, Boolean owns)
   at SkiaSharp.SKData.SKDataStatic..ctor(IntPtr x)
   at SkiaSharp.SKData..cctor()
janne-hmp commented 1 month ago

.NET runtime in .NET 9.0 Preview 3 is broken since they removed some globalization code. For the time being, adding <InvariantGlobalization>true</InvariantGlobalization> to your project file should help.

softlion commented 1 month ago

.NET runtime in .NET 9.0 Preview 3 is broken since they removed some globalization code. For the time being, adding <InvariantGlobalization>true</InvariantGlobalization> to your project file should help.

I'm using the .NET 8 stable release, not .NET 9 previews. Does that still apply ?

janne-hmp commented 1 month ago

Then it may be something different. On that note, not sure if SkiaSharp 3.0 Preview 3.1 is fully compatible with .NET 8. It seems like it is being developed for .NET 9.

softlion commented 1 month ago

Then it may be something different. On that note, not sure if SkiaSharp 3.0 Preview 3.1 is fully compatible with .NET 8. It seems like it is being developed for .NET 9.

Well when you develop something specifically for .net9, your tfm won't be .net7. Not sure you are right on that one.

mattleibow commented 3 weeks ago

I think the issue about the missing API is that you need to use the compatibility nuget for 2.x: https://github.com/mono/SkiaSharp/blob/release/2.x/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls.Compatibility/AppHostBuilderExtensions.cs#L22

For 3.x, this API is no longer needed since the GL view is now part of the handlers: https://github.com/mono/SkiaSharp/blob/main/source/SkiaSharp.Views.Maui/SkiaSharp.Views.Maui.Controls/AppHostBuilderExtensions.cs#L16