committed by
GitHub
8 changed files with 171 additions and 9 deletions
@ -0,0 +1,42 @@ |
|||||
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using Avalonia.Platform; |
||||
|
using Avalonia.Rendering; |
||||
|
|
||||
|
namespace Avalonia.Skia |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Adapts <see cref="ICustomSkiaRenderTarget"/> to be used within Skia rendering pipeline.
|
||||
|
/// </summary>
|
||||
|
internal class CustomRenderTarget : IRenderTarget |
||||
|
{ |
||||
|
private readonly ICustomSkiaRenderTarget _renderTarget; |
||||
|
|
||||
|
public CustomRenderTarget(ICustomSkiaRenderTarget renderTarget) |
||||
|
{ |
||||
|
_renderTarget = renderTarget; |
||||
|
} |
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
_renderTarget.Dispose(); |
||||
|
} |
||||
|
|
||||
|
public IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer) |
||||
|
{ |
||||
|
ICustomSkiaRenderSession session = _renderTarget.BeginRendering(); |
||||
|
|
||||
|
var nfo = new DrawingContextImpl.CreateInfo |
||||
|
{ |
||||
|
GrContext = session.GrContext, |
||||
|
Canvas = session.Canvas, |
||||
|
Dpi = SkiaPlatform.DefaultDpi * session.ScaleFactor, |
||||
|
VisualBrushRenderer = visualBrushRenderer, |
||||
|
DisableTextLcdRendering = true |
||||
|
}; |
||||
|
|
||||
|
return new DrawingContextImpl(nfo, session); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using SkiaSharp; |
||||
|
|
||||
|
namespace Avalonia.Skia |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Custom Skia gpu instance.
|
||||
|
/// </summary>
|
||||
|
public interface ICustomSkiaGpu |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Skia GrContext used.
|
||||
|
/// </summary>
|
||||
|
GRContext GrContext { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Attempts to create custom render target from given surfaces.
|
||||
|
/// </summary>
|
||||
|
/// <param name="surfaces">Surfaces.</param>
|
||||
|
/// <returns>Created render target or <see langword="null"/> if it fails.</returns>
|
||||
|
ICustomSkiaRenderTarget TryCreateRenderTarget(IEnumerable<object> surfaces); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System; |
||||
|
using SkiaSharp; |
||||
|
|
||||
|
namespace Avalonia.Skia |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Custom render session for Skia render target.
|
||||
|
/// </summary>
|
||||
|
public interface ICustomSkiaRenderSession : IDisposable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// GrContext used by this session.
|
||||
|
/// </summary>
|
||||
|
GRContext GrContext { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Canvas that will be used to render.
|
||||
|
/// </summary>
|
||||
|
SKCanvas Canvas { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Scaling factor.
|
||||
|
/// </summary>
|
||||
|
double ScaleFactor { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System; |
||||
|
|
||||
|
namespace Avalonia.Skia |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Custom Skia render target.
|
||||
|
/// </summary>
|
||||
|
public interface ICustomSkiaRenderTarget : IDisposable |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Start rendering to this render target.
|
||||
|
/// </summary>
|
||||
|
/// <returns></returns>
|
||||
|
ICustomSkiaRenderSession BeginRendering(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
||||
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
||||
|
|
||||
|
using System; |
||||
|
using Avalonia.Skia; |
||||
|
|
||||
|
namespace Avalonia |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Options for Skia rendering subsystem.
|
||||
|
/// </summary>
|
||||
|
public class SkiaOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Custom gpu factory to use. Can be used to customize behavior of Skia renderer.
|
||||
|
/// </summary>
|
||||
|
public Func<ICustomSkiaGpu> CustomGpuFactory { get; set; } |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue