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.45k stars 539 forks source link

Add a WPF renderer for Xamarin.Forms #486

Closed mattleibow closed 5 years ago

mattleibow commented 6 years ago

VS bug #727963

mterwoord commented 6 years ago

Not trying to push you or rush you, but any eta on this, or semi-working preview nuget packages?

mattleibow commented 6 years ago

This is going to be a bit harder to do since I will have to update to Xamarin.Forms v3.0. This is mostly fine, but the packaging is going to be tougher. If I update to v3.0, then so does everyone else who uses SkiaSharp with Xamarin.Forms.

I might create a new set of preview packages that target v3.0, and then when we get further on in life, I will update the existing package. But this makes life harder for everyone.

Also, I just added Tizen support, which appears to only support v2.5.0.

But, after all this, I can start a new branch and just upgrade to v3.0 for the world and hope something happens which will make life easier - maybe Tizen updates, maybe everyone does :)

mterwoord commented 6 years ago

You updating to XF3 is per project right?

For the world to update to xamarin forms 3, well, isn't that how things just work? if people want to stay on entity framework core, you have to be careful as well...

mterwoord commented 6 years ago

I mean, do you have things working for XF3? If so, what's the way to get things usable with XF3?

mterwoord commented 6 years ago

In the meantime, maybe could you make ISKCanvasViewController public? That way I can implement it myself..

DuncWatts commented 6 years ago

I see there's some WPF work included in the dev/forms-v3 branch, do you happen to know the status of this with WPF? I'm currently trying to investigate the feasibility of adding a WPF client so happy to work with an unfinished build for now if it can get me started with the basics.

mterwoord commented 6 years ago

@DuncWatts To me it seems, that if the ISKCanvasViewController interface was public, the actual work needed for xamarin forms support is minimal (matter of 2-3 event handlers that need hooking up)

@mattleibow Maybe you can shed a light here? I'm not even interested in using the wpf client as a real target, just as a development aid..

mattleibow commented 6 years ago

I created a PR that makes those types public so additional platforms can be added: https://github.com/mono/SkiaSharp/pull/522

This should be in the v1.60.1 release.

mattleibow commented 6 years ago

The dev/forms-v3 branch is a total hack that I will soon delete. I am probably going to move to Forms v3.0 after the v1.60.1 release. I hope to support one last v2.5.x version of Forms and then migrate.

I had a chat to the Tizen guys, and I didn't realize that Forms 3.0 has the Tizen types built in, so that makes life much easier.

mterwoord commented 6 years ago

Awesome!

Regarding v3 etc. It seems that the v2 packages work fine there, just not for WPF (obviously)...

I could hack it together with reflection, but that's not worth it for me, so I'll wait for the v1.60.1 release then. Thanks for the info!

mattleibow commented 6 years ago

The backwards compat info is good news.

mattleibow commented 6 years ago

I merged #522 so adding additional renderers should be much easier - until I manage to add them to the official repo.

If you do get a nice version, a PR is always welcome ;)

mattleibow commented 6 years ago

No WPF renderer just yet, but you should be able to quickly whip up your own now that the interfaces are all public: https://github.com/mono/SkiaSharp/releases/tag/v1.60.1

I created a test renderer for GTK#, and all I had to do was copy this code into my project and add a #if for GTK#: https://github.com/mono/SkiaSharp/blob/v1.60.1/source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.Native.Shared/SKCanvasViewRendererBase.cs

Then I added this for GTK#: https://github.com/mono/SkiaSharp/blob/v1.60.1/source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.UWP/SKCanvasViewRenderer.cs

mattleibow commented 6 years ago

@mterwoord, I hope this helps.

mterwoord commented 6 years ago

Works! Only thing I have to figure out for WPF is DPI translation. For me, images get shown now.

mattleibow commented 6 years ago

Nice, with some of these things, I just have a look at how Xamarin.Forms does it. For example, I am going to look at how they do touch and do something similar.

mattleibow commented 6 years ago

Moving this to v1.60.3 so we can get out a version that fixes a UWP bug (#536)

brettclutch commented 6 years ago

@mterwoord , any pointers or chance to share code you have to get WPF renderer working? I've hit road block, I created SKCanvasViewRenderer, SKCanvasViewRendererBase (Which btw there is an issue: SKTouchHandler is not accessible), and SKXamlCanvas. Its all getting called correctly but it won't attach itself to the WPF visual tree and hence has 0 actualwidth, 0 actualheigth and hence doens't render.

https://gist.github.com/brettclutch/ec2ef9a08e2c73f7af38069106adff25

mterwoord commented 6 years ago

Finally found time to respond. Like I said before, I'm not using it to target WPF for production. Therefore, not everything is working. (For example touch..).

See attached zip file for my renderer.

Renderers.zip

brettclutch commented 6 years ago

Thanks, your code is almost the same as what I had tried. Still not working for me but I think its a bug in Xamarin.WPF and my solution layout/setup which I've kinda stopped working on it since then since same exact code works in a Xamarin.UWP project but not a Xamarin.WPF project . Its still beta so just need to wait I feel.

amoscatelli commented 6 years ago

Thanks mterwoord, your renderers worked for my WPF project, maybe a PR could be accepted.

mattleibow commented 6 years ago

I will be upgrading to Xamarin.Forms 3.0 in the next major release. Work is currently being done in the development branch. The currently open PRs for this update are #570 and #588 .

Once those are merged into development, I will start accepting PRs for the forms 3.0 platforms (gtk/wpf)

roustan2 commented 6 years ago

Hello, touch dont'work in xamarin wpf projects. any ideas ? thanks

vividos commented 5 years ago

I'm trying to port an Xamarin.Forms Android app to WPF, and I'm using SkiaSharp there. Has anyone managed to get the renderer to work? I had some issues compiling the code in the examples above.

mattleibow commented 5 years ago

This is something that we will be looking at in the future.

memsom commented 5 years ago

I've hit a roadblock because the Mapsui.Forms uses SkiaSharp and seems to be using the SKGLViewRenderer for map rendering. Is there a solution in the works for WPF? I can't use UWP as need to support legacy systems. Going to look at their codebase too to see if I can switch the rendering to something else for WPF. I also can happily hack together something with the SkiaSharp.Views.Desktop.SKGLControl is that would work, just not 100% sure that road is the correct one.

Happy to help, but obviously, no expert in this side of things (just using someone else's library...)

kinosang commented 5 years ago

Nothing shown on WPF with Xamarin.Forms and SKGLViewRenderer, Got Unable to cast object of type 'SkiaSharp.Views.Forms.SKGLViewRenderer' to type 'Xamarin.Forms.IRegisterable' when resize the window.

mattleibow commented 5 years ago

Good news folks! Adding WPF as we speak (or as close as we can get) https://github.com/mono/SkiaSharp/pull/917

mattleibow commented 5 years ago

Just merged the bits. As soon as the build finishes, I'll push the the preview feed: https://nugetized.blob.core.windows.net/skiasharp-eap/index.json