-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2364 from MarchingCube/feature/skia-renderinterface
Allow for modifying Skia PlatformRenderInterface behavior.
- Loading branch information
Showing
8 changed files
with
171 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters