You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be possible and we are currently considering our options. The major blocker is that HTML5 doesn't have a proper 2D drawing API, so Skia needs to be compiled to wasm and somehow linked to resulting application. The problem with linking is that Mono doesn't currently provide P/Invoke support for wasm target. Another problem is that P/Invoke means indirect calls (i. e. calls via pointer), while WebAssembly doesn't support indirect calls between modules. That means that Skia needs to be linked statically, so we'll need a custom Mono build.
It would be easier with CoreRT, since it supports static linking out of the box, but they are still implementing MSIL instructions for wasm target, so it's not ready even for an experimental port.
Reacted by itsamelambda, Shimmy Weitzhandler, Alexey Debelov, Michal Turecki, Eduardo Larios, 久永, José Luis, Wiesław Šoltés, Ricardo and Cong Zhang
@pmoorelegistek We will be using WebGL at some point. The problem is that WebGL by itself doesn't support drawing 2D vector graphics. So we need Skia anyway.
Oh I see what you're saying. I didn't realize it lacked basic 2D drawing. I take it the plain HTML5 canvas doesn't have good enough performance either?
I've been watching this project for awhile and would love to help how I can. Getting this on the web would be the Holy Grail. (Befitting the name Avalon(ia))
Get Outlook for Android<https://aka.ms/ghei36>
From: Nikita Tsukanov
Sent: Friday, March 9, 12:30 AM
Subject: Re: [AvaloniaUI/Avalonia] Hosting Avalonia in WebAssembly (#1387)
To: AvaloniaUI/Avalonia
Cc: Peter N. Moore, Mention
@pmoorelegistek<https://github.com/pmoorelegistek> We will be using WebGL at some point. The problem is that WebGL by itself doesn't support drawing 2D vector graphics. So we need Skia anyway.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#1387 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AMw7S1GOycAJX3aLJnlzy5xM6yq_KrTiks5tciGKgaJpZM4SR4pe>.
Hmm. The problem with compiling Skia to WASM is you'll lose any benefits of hardware graphics acceleration on the device. Browser will be doing all the math, painting pixels, etc. I don't know that you'd ever get anything close to 60fps with a complex UI.
Have you tried just using the HTML5 Canvas or SVG?
Skia can use OpenGL ES profile for hardware-accelerated rendering. Which is basically what is provided by WebGL.
HTML5 Canvas and SVG are not sufficient to render Avalonia.
You're saying Skia / OpenGL will be able to access hardware acceleration (i.e. the GPU) after compiled to WASM? Are you certain about that? Everything I understand about WASM would lead me to think not.
I would think you'd be better off using three.js - or better yet porting it to C# - wrapped around WebGL.
I'd be happy to look into it some more and experiment. Do you have a working prototype using Mono-to-WASM at the moment with any rendering at all?
You're saying Skia / OpenGL will be able to access hardware acceleration (i.e. the GPU) after compiled to WASM
Emscripten toolchain has complete support for WebGL. It might be a bit difficult to make it work with Mono since it has it's own js glue code, but other than that I don't see any issues.
if I understand right, what @kekekeks is saying is that it's not feasible at the moment because Mono can't use P/invoke to call the Skia functions. So while they can compile Skia to WASM, there would be no way for the .NET code to access it.
What I don't understand fully, though, is why it has to be Skia. There are Javascript libraries that provide 2D drawing function wrappers over WebGL (e.g., https://threejs.org/). I'd think it at least worth an experiment to make a DrawingContext that wraps three.js and go from there. If that works, porting threejs to C# and simply including it in the Avalonia build would not be too bad of a project and would probably get you performance on par with Skia.
Reacted by Friedrich von Never, Shimmy Weitzhandler, Eduardo Larios, Oleksii Halahan and Tim Schneeberger
@pmoorelegistek The main problem is the complete lack of a proper text measurement API. We can't get our TextBox to work if we don't have an accurate position of each individual symbol. Even for our TextBlock we need to be able to measure and lay out text lines properly. There is no way we can do that with the APIs available to JavaScript.
Reacted by Shimmy Weitzhandler, itsamelambda, Eduardo Larios, Oleksii Halahan, Sergey Mikolaitis and Tim Schneeberger
Uno Platform (https://platform.uno/) is rendering the WPF from Microsoft to WebAssembly. There should not that difficult to port the code to render Avalonia too ...
On Windows 7, we still have the WebAssembly story, but we also announced a new Skia backend, that can be wrapped in a WPF shell so you can run "natively" and outside of a browser context.
When using Uno Platform to get your UWP/WinUI 3.0 and later apps on Windows 7 you now have THREE options for running your app on Windows 7: 1. Run your app as a PWA. Your Windows 7 will need Chrome installed on it. 2. Run your app on Chromium through Electron. 3. Use Uno Platform 3.0 supported Skia backend, that can be wrapped in a WPF shell so you can run natively on Windows 7 and outside of a browser context.
Just to be clear. Text rendering is no longer an issue. The "only" thing we need is a platform implementation for WASM that is setting up WebGL and exposes all input events. The threading implementation might also be tricky.
Activity
kekekeks commentedon Feb 24, 2018
It would be possible and we are currently considering our options. The major blocker is that HTML5 doesn't have a proper 2D drawing API, so Skia needs to be compiled to wasm and somehow linked to resulting application. The problem with linking is that Mono doesn't currently provide P/Invoke support for wasm target. Another problem is that P/Invoke means indirect calls (i. e. calls via pointer), while WebAssembly doesn't support indirect calls between modules. That means that Skia needs to be linked statically, so we'll need a custom Mono build.
It would be easier with CoreRT, since it supports static linking out of the box, but they are still implementing MSIL instructions for wasm target, so it's not ready even for an experimental port.
legistek commentedon Mar 7, 2018
Sorry if this is an obviously terrible idea, but why wouldn't you use WebGL?
danwalmsley commentedon Mar 8, 2018
Maybe this helps? https://github.com/aspnet/Blazor/blob/dev/README.md
kekekeks commentedon Mar 9, 2018
@pmoorelegistek We will be using WebGL at some point. The problem is that WebGL by itself doesn't support drawing 2D vector graphics. So we need Skia anyway.
legistek commentedon Mar 9, 2018
legistek commentedon Mar 9, 2018
Hmm. The problem with compiling Skia to WASM is you'll lose any benefits of hardware graphics acceleration on the device. Browser will be doing all the math, painting pixels, etc. I don't know that you'd ever get anything close to 60fps with a complex UI.
Have you tried just using the HTML5 Canvas or SVG?
kekekeks commentedon Mar 9, 2018
Skia can use OpenGL ES profile for hardware-accelerated rendering. Which is basically what is provided by WebGL.
HTML5 Canvas and SVG are not sufficient to render Avalonia.
legistek commentedon Mar 9, 2018
You're saying Skia / OpenGL will be able to access hardware acceleration (i.e. the GPU) after compiled to WASM? Are you certain about that? Everything I understand about WASM would lead me to think not.
I would think you'd be better off using three.js - or better yet porting it to C# - wrapped around WebGL.
I'd be happy to look into it some more and experiment. Do you have a working prototype using Mono-to-WASM at the moment with any rendering at all?
kekekeks commentedon Mar 10, 2018
Emscripten toolchain has complete support for WebGL. It might be a bit difficult to make it work with Mono since it has it's own js glue code, but other than that I don't see any issues.
danwalmsley commentedon Mar 15, 2018
https://github.com/praeclarum/Ooui/wiki/Xamarin.Forms-with-Web-Assembly
No need for Skia now,
kekekeks commentedon Mar 16, 2018
@danwalmsley it uses HTML. Avalonia can't be rendered with HTML.
adoris commentedon Mar 16, 2018
Is there are any try to use Skia/WebGL? Any branch for this experiment?
legistek commentedon Mar 16, 2018
if I understand right, what @kekekeks is saying is that it's not feasible at the moment because Mono can't use P/invoke to call the Skia functions. So while they can compile Skia to WASM, there would be no way for the .NET code to access it.
What I don't understand fully, though, is why it has to be Skia. There are Javascript libraries that provide 2D drawing function wrappers over WebGL (e.g., https://threejs.org/). I'd think it at least worth an experiment to make a DrawingContext that wraps three.js and go from there. If that works, porting threejs to C# and simply including it in the Avalonia build would not be too bad of a project and would probably get you performance on par with Skia.
kekekeks commentedon Mar 17, 2018
@pmoorelegistek The main problem is the complete lack of a proper text measurement API. We can't get our TextBox to work if we don't have an accurate position of each individual symbol. Even for our TextBlock we need to be able to measure and lay out text lines properly. There is no way we can do that with the APIs available to JavaScript.
56 remaining items
aboimpinto commentedon Sep 29, 2020
Uno Platform (https://platform.uno/) is rendering the WPF from Microsoft to WebAssembly. There should not that difficult to port the code to render Avalonia too ...
Maybe, there could be a way to join efforts ...
Gillibald commentedon Sep 29, 2020
Uno does not render anything as Avalonia does. They use HTML elements.
yowl commentedon Sep 29, 2020
They also have a Skia backend, not sure it's generally available for Wasm yet, but it is the plan.
birbilis commentedon Oct 12, 2020
related comment:
https://developercommunity.visualstudio.com/idea/378455/net-ui-standard.html
also:
https://platform.uno/windows7/
aboimpinto commentedon Oct 12, 2020
What about Ubuntu (Linux environment)?
birbilis commentedon Oct 13, 2020
regarding Uno and Linux see here: https://platform.uno/uno-platform-for-linux/
aboimpinto commentedon Oct 13, 2020
I was referring Avalonia in Linux environment compiling into WebAssembly
birbilis commentedon Oct 13, 2020
guess Avalonia could also get ideas from Uno, or maybe even use it as a backend or something?
Gillibald commentedon Oct 13, 2020
Just to be clear. Text rendering is no longer an issue. The "only" thing we need is a platform implementation for WASM that is setting up WebGL and exposes all input events. The threading implementation might also be tricky.
congzhangzh commentedon Jul 11, 2021
May be we can learn from google flutter, skia should not be a problem!
starikcetin commentedon Jul 28, 2021
I don't know if it is of any help, but there is this: lume/glas: WebGL in WebAssembly with AssemblyScript
mikernet commentedon Oct 18, 2021
Seems skia with p/invoke is possible now:
https://visualstudiomagazine.com/articles/2021/10/15/aspnet-update.aspx
artemiusgreat commentedon Oct 25, 2021
This, to be exact.
mono/SkiaSharp#1811
https://github.com/mattleibow/SkiaSharpBlazorWebAssembly