|
|
@@ -37,6 +37,7 @@ namespace Avalonia.Web.Blazor
|
|
|
private const SKColorType ColorType = SKColorType.Rgba8888;
|
|
|
|
|
|
private bool _initialised;
|
|
|
+ private bool _useGL;
|
|
|
|
|
|
[Inject] private IJSRuntime Js { get; set; } = null!;
|
|
|
|
|
|
@@ -261,25 +262,44 @@ namespace Avalonia.Web.Blazor
|
|
|
_interop = await SKHtmlCanvasInterop.ImportAsync(Js, _htmlCanvas, OnRenderFrame);
|
|
|
|
|
|
Console.WriteLine("Interop created");
|
|
|
- _jsGlInfo = _interop.InitGL();
|
|
|
-
|
|
|
- Console.WriteLine("jsglinfo created - init gl");
|
|
|
+
|
|
|
+ var skiaOptions = AvaloniaLocator.Current.GetService<SkiaOptions>();
|
|
|
+ _useGL = skiaOptions?.CustomGpuFactory != null;
|
|
|
|
|
|
- // create the SkiaSharp context
|
|
|
- if (_context == null)
|
|
|
+ if (_useGL)
|
|
|
+ {
|
|
|
+ _jsGlInfo = _interop.InitGL();
|
|
|
+ Console.WriteLine("jsglinfo created - init gl");
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- Console.WriteLine("create glcontext");
|
|
|
- _glInterface = GRGlInterface.Create();
|
|
|
- _context = GRContext.CreateGl(_glInterface);
|
|
|
-
|
|
|
- var options = AvaloniaLocator.Current.GetService<SkiaOptions>();
|
|
|
- // bump the default resource cache limit
|
|
|
- _context.SetResourceCacheLimit(options?.MaxGpuResourceSizeBytes ?? 32 * 1024 * 1024);
|
|
|
- Console.WriteLine("glcontext created and resource limit set");
|
|
|
+ var rasterInitialized = _interop.InitRaster();
|
|
|
+ Console.WriteLine("raster initialized: {0}", rasterInitialized);
|
|
|
}
|
|
|
|
|
|
- _topLevelImpl.SetSurface(_context, _jsGlInfo, ColorType,
|
|
|
- new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi);
|
|
|
+ if (_useGL)
|
|
|
+ {
|
|
|
+ // create the SkiaSharp context
|
|
|
+ if (_context == null)
|
|
|
+ {
|
|
|
+ Console.WriteLine("create glcontext");
|
|
|
+ _glInterface = GRGlInterface.Create();
|
|
|
+ _context = GRContext.CreateGl(_glInterface);
|
|
|
+
|
|
|
+
|
|
|
+ // bump the default resource cache limit
|
|
|
+ _context.SetResourceCacheLimit(skiaOptions?.MaxGpuResourceSizeBytes ?? 32 * 1024 * 1024);
|
|
|
+ Console.WriteLine("glcontext created and resource limit set");
|
|
|
+ }
|
|
|
+
|
|
|
+ _topLevelImpl.SetSurface(_context, _jsGlInfo!, ColorType,
|
|
|
+ new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _topLevelImpl.SetSurface(ColorType,
|
|
|
+ new PixelSize((int)_canvasSize.Width, (int)_canvasSize.Height), _dpi, _interop.PutImageData);
|
|
|
+ }
|
|
|
|
|
|
_interop.SetCanvasSize((int)(_canvasSize.Width * _dpi), (int)(_canvasSize.Height * _dpi));
|
|
|
|
|
|
@@ -301,7 +321,12 @@ namespace Avalonia.Web.Blazor
|
|
|
|
|
|
private void OnRenderFrame()
|
|
|
{
|
|
|
- if (_canvasSize.Width <= 0 || _canvasSize.Height <= 0 || _dpi <= 0 || _jsGlInfo == null)
|
|
|
+ if (_useGL && (_jsGlInfo == null))
|
|
|
+ {
|
|
|
+ Console.WriteLine("nothing to render");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (_canvasSize.Width <= 0 || _canvasSize.Height <= 0 || _dpi <= 0)
|
|
|
{
|
|
|
Console.WriteLine("nothing to render");
|
|
|
return;
|