Browse Source

Use ImmediateDrawingContext in the ICustomDrawOperation interface

pull/11189/head
Max Katz 3 years ago
parent
commit
bc79b388b5
  1. 4
      samples/RenderDemo/Pages/CustomSkiaPage.cs
  2. 16
      src/Avalonia.Base/Media/PlatformDrawingContext.cs
  3. 14
      src/Avalonia.Base/Rendering/SceneGraph/CustomDrawOperation.cs
  4. 2
      src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs

4
samples/RenderDemo/Pages/CustomSkiaPage.cs

@ -44,9 +44,9 @@ namespace RenderDemo.Pages
public bool HitTest(Point p) => false;
public bool Equals(ICustomDrawOperation other) => false;
static Stopwatch St = Stopwatch.StartNew();
public void Render(IDrawingContextImpl context)
public void Render(ImmediateDrawingContext context)
{
var leaseFeature = context.GetFeature<ISkiaSharpApiLeaseFeature>();
var leaseFeature = context.TryGetFeature<ISkiaSharpApiLeaseFeature>();
if (leaseFeature == null)
context.DrawGlyphRun(Brushes.Black, _noSkia.PlatformImpl);
else

16
src/Avalonia.Base/Media/PlatformDrawingContext.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Avalonia.Logging;
using Avalonia.Media.Imaging;
using Avalonia.Media.Immutable;
using Avalonia.Platform;
@ -41,8 +42,19 @@ internal sealed class PlatformDrawingContext : DrawingContext, IDrawingContextWi
BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default) =>
_impl.DrawBitmap(source, opacity, sourceRect, destRect, bitmapInterpolationMode);
public override void Custom(ICustomDrawOperation custom) =>
custom.Render(_impl);
public override void Custom(ICustomDrawOperation custom)
{
using var immediateDrawingContext = new ImmediateDrawingContext(_impl, false);
try
{
custom.Render(immediateDrawingContext);
}
catch (Exception e)
{
Logger.TryGet(LogEventLevel.Error, LogArea.Visual)
?.Log(custom, $"Exception in {custom.GetType().Name}.{nameof(ICustomDrawOperation.Render)} {{0}}", e);
}
}
public override void DrawGlyphRun(IBrush? foreground, GlyphRun glyphRun)
{

14
src/Avalonia.Base/Rendering/SceneGraph/CustomDrawOperation.cs

@ -1,4 +1,5 @@
using System;
using Avalonia.Logging;
using Avalonia.Media;
using Avalonia.Platform;
@ -17,7 +18,16 @@ namespace Avalonia.Rendering.SceneGraph
public override void Render(IDrawingContextImpl context)
{
Custom.Render(context);
using var immediateDrawingContext = new ImmediateDrawingContext(context, false);
try
{
Custom.Render(immediateDrawingContext);
}
catch (Exception e)
{
Logger.TryGet(LogEventLevel.Error, LogArea.Visual)
?.Log(Custom, $"Exception in {Custom.GetType().Name}.{nameof(ICustomDrawOperation.Render)} {{0}}", e);
}
}
public override void Dispose() => Custom.Dispose();
@ -48,6 +58,6 @@ namespace Avalonia.Rendering.SceneGraph
/// Renders the node to a drawing context.
/// </summary>
/// <param name="context">The drawing context.</param>
void Render(IDrawingContextImpl context);
void Render(ImmediateDrawingContext context);
}
}

2
src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs

@ -37,7 +37,7 @@ namespace Avalonia.Browser
return false;
}
public void Render(IDrawingContextImpl context)
public void Render(ImmediateDrawingContext context)
{
_hasRendered = true;
_onFirstRender();

Loading…
Cancel
Save