diff --git a/api/Avalonia.Skia.nupkg.xml b/api/Avalonia.Skia.nupkg.xml index eda59fc334..8e9d60f7d4 100644 --- a/api/Avalonia.Skia.nupkg.xml +++ b/api/Avalonia.Skia.nupkg.xml @@ -1,6 +1,78 @@ + + CP0001 + T:Avalonia.Skia.ISkiaGpuRenderTarget2 + baseline/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + + + CP0001 + T:Avalonia.Skia.ISkiaGpuWithPlatformGraphicsContext + baseline/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + + + CP0001 + T:Avalonia.Skia.ISkiaGpuRenderTarget2 + baseline/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + + + CP0001 + T:Avalonia.Skia.ISkiaGpuWithPlatformGraphicsContext + baseline/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + + + CP0002 + M:Avalonia.Skia.ISkiaGpuRenderTarget.BeginRenderingSession + baseline/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + + + CP0002 + M:Avalonia.Skia.ISkiaGpuRenderTarget.BeginRenderingSession + baseline/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + + + CP0006 + M:Avalonia.Skia.ISkiaGpu.TryGetGrContext + baseline/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + + + CP0006 + M:Avalonia.Skia.ISkiaGpuRenderTarget.BeginRenderingSession(System.Nullable{Avalonia.PixelSize}) + baseline/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + + + CP0006 + P:Avalonia.Skia.ISkiaGpu.PlatformGraphicsContext + baseline/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net10.0/Avalonia.Skia.dll + + + CP0006 + M:Avalonia.Skia.ISkiaGpu.TryGetGrContext + baseline/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + + + CP0006 + M:Avalonia.Skia.ISkiaGpuRenderTarget.BeginRenderingSession(System.Nullable{Avalonia.PixelSize}) + baseline/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + + + CP0006 + P:Avalonia.Skia.ISkiaGpu.PlatformGraphicsContext + baseline/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + current/Avalonia.Skia/lib/net8.0/Avalonia.Skia.dll + CP0008 T:Avalonia.Skia.ISkiaGpu diff --git a/api/Avalonia.nupkg.xml b/api/Avalonia.nupkg.xml index 1c9ac0d5e9..38f5a7e8e1 100644 --- a/api/Avalonia.nupkg.xml +++ b/api/Avalonia.nupkg.xml @@ -79,6 +79,18 @@ baseline/Avalonia/lib/net10.0/Avalonia.Base.dll current/Avalonia/lib/net10.0/Avalonia.Base.dll + + CP0001 + T:Avalonia.Platform.IRenderTarget2 + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0001 + T:Avalonia.Platform.IRenderTargetWithProperties + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + CP0001 T:Avalonia.Platform.OptionalFeatureProviderExtensions @@ -199,6 +211,18 @@ baseline/Avalonia/lib/net10.0/Avalonia.Markup.Xaml.dll current/Avalonia/lib/net10.0/Avalonia.Markup.Xaml.dll + + CP0001 + T:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget2 + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + + + CP0001 + T:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTargetWithCorruptionInfo + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + CP0001 T:Avalonia.Media.Fonts.FontFamilyLoader @@ -283,6 +307,18 @@ baseline/Avalonia/lib/net8.0/Avalonia.Base.dll current/Avalonia/lib/net8.0/Avalonia.Base.dll + + CP0001 + T:Avalonia.Platform.IRenderTarget2 + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + + + CP0001 + T:Avalonia.Platform.IRenderTargetWithProperties + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + CP0001 T:Avalonia.Platform.OptionalFeatureProviderExtensions @@ -403,6 +439,18 @@ baseline/Avalonia/lib/net8.0/Avalonia.Markup.Xaml.dll current/Avalonia/lib/net8.0/Avalonia.Markup.Xaml.dll + + CP0001 + T:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget2 + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + + + CP0001 + T:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTargetWithCorruptionInfo + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + CP0001 T:Avalonia.Media.Fonts.FontFamilyLoader @@ -1261,6 +1309,24 @@ baseline/Avalonia/lib/net10.0/Avalonia.Markup.Xaml.dll current/Avalonia/lib/net10.0/Avalonia.Markup.Xaml.dll + + CP0002 + M:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase.BeginDraw + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + + + CP0002 + M:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase.BeginDrawCore + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + + + CP0002 + M:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget.BeginDraw + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + CP0002 F:Avalonia.Media.Fonts.FontCollectionBase._glyphTypefaceCache @@ -2149,6 +2215,24 @@ baseline/Avalonia/lib/net8.0/Avalonia.Markup.Xaml.dll current/Avalonia/lib/net8.0/Avalonia.Markup.Xaml.dll + + CP0002 + M:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase.BeginDraw + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + + + CP0002 + M:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase.BeginDrawCore + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + + + CP0002 + M:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget.BeginDraw + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + CP0002 F:Avalonia.Media.Fonts.FontCollectionBase._glyphTypefaceCache @@ -2191,6 +2275,18 @@ baseline/netstandard2.0/Avalonia.Base.dll target/netstandard2.0/Avalonia.Base.dll + + CP0005 + M:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase.BeginDrawCore(System.Nullable{Avalonia.PixelSize}) + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + + + CP0005 + M:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase.BeginDrawCore(System.Nullable{Avalonia.PixelSize}) + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + CP0006 M:Avalonia.Input.IKeyboardNavigationHandler.Move(Avalonia.Input.IInputElement,Avalonia.Input.NavigationDirection,Avalonia.Input.KeyModifiers,System.Nullable{Avalonia.Input.KeyDeviceType}) @@ -2251,6 +2347,12 @@ baseline/Avalonia/lib/net10.0/Avalonia.Base.dll current/Avalonia/lib/net10.0/Avalonia.Base.dll + + CP0006 + M:Avalonia.Platform.IRenderTarget.CreateDrawingContext(Avalonia.PixelSize,Avalonia.Platform.RenderTargetDrawingContextProperties@) + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + CP0006 P:Avalonia.Platform.ILockedFramebuffer.AlphaFormat @@ -2269,6 +2371,24 @@ baseline/Avalonia/lib/net10.0/Avalonia.Base.dll current/Avalonia/lib/net10.0/Avalonia.Base.dll + + CP0006 + P:Avalonia.Platform.IRenderTarget.Properties + baseline/Avalonia/lib/net10.0/Avalonia.Base.dll + current/Avalonia/lib/net10.0/Avalonia.Base.dll + + + CP0006 + M:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget.BeginDraw(System.Nullable{Avalonia.PixelSize}) + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + + + CP0006 + P:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget.IsCorrupted + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + CP0006 M:Avalonia.Input.Platform.IClipboard.SetDataAsync(Avalonia.Input.IAsyncDataTransfer) @@ -2419,6 +2539,12 @@ baseline/Avalonia/lib/net8.0/Avalonia.Base.dll current/Avalonia/lib/net8.0/Avalonia.Base.dll + + CP0006 + M:Avalonia.Platform.IRenderTarget.CreateDrawingContext(Avalonia.PixelSize,Avalonia.Platform.RenderTargetDrawingContextProperties@) + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + CP0006 M:Avalonia.Platform.Storage.IStorageProvider.SaveFilePickerWithResultAsync(Avalonia.Platform.Storage.FilePickerSaveOptions) @@ -2443,6 +2569,12 @@ baseline/Avalonia/lib/net8.0/Avalonia.Base.dll current/Avalonia/lib/net8.0/Avalonia.Base.dll + + CP0006 + P:Avalonia.Platform.IRenderTarget.Properties + baseline/Avalonia/lib/net8.0/Avalonia.Base.dll + current/Avalonia/lib/net8.0/Avalonia.Base.dll + CP0006 M:Avalonia.OpenGL.IGlExternalSemaphore.SignalTimelineSemaphore(Avalonia.OpenGL.IGlExternalImageTexture,System.UInt64) @@ -2455,12 +2587,24 @@ baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + + CP0006 + M:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget.BeginDraw(System.Nullable{Avalonia.PixelSize}) + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + CP0006 P:Avalonia.OpenGL.IGlExternalImageTexture.TextureType baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + + CP0006 + P:Avalonia.OpenGL.Surfaces.IGlPlatformSurfaceRenderTarget.IsCorrupted + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + CP0006 M:Avalonia.Input.Platform.IClipboard.SetDataAsync(Avalonia.Input.IAsyncDataTransfer) @@ -2629,6 +2773,12 @@ baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + + CP0008 + T:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase + baseline/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net10.0/Avalonia.OpenGL.dll + CP0008 T:Avalonia.OpenGL.IGlContext @@ -2743,6 +2893,12 @@ baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + + CP0008 + T:Avalonia.OpenGL.Egl.EglPlatformSurfaceRenderTargetBase + baseline/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + current/Avalonia/lib/net8.0/Avalonia.OpenGL.dll + CP0008 T:Avalonia.OpenGL.IGlContext diff --git a/src/Avalonia.Base/Platform/IRenderTarget.cs b/src/Avalonia.Base/Platform/IRenderTarget.cs index 1a46b376ac..a31e7e550a 100644 --- a/src/Avalonia.Base/Platform/IRenderTarget.cs +++ b/src/Avalonia.Base/Platform/IRenderTarget.cs @@ -1,6 +1,5 @@ using System; using Avalonia.Metadata; -using Avalonia.Rendering; namespace Avalonia.Platform { @@ -13,51 +12,29 @@ namespace Avalonia.Platform [PrivateApi] public interface IRenderTarget : IDisposable { - /// - /// Creates an for a rendering session. - /// - /// Apply DPI reported by the render target as a hidden transform matrix - IDrawingContextImpl CreateDrawingContext(bool useScaledDrawing); - /// /// Indicates if the render target is no longer usable and needs to be recreated /// - public bool IsCorrupted { get; } - } + bool IsCorrupted { get; } - [PrivateApi, Obsolete("Use IRenderTarget2", true)] - // TODO12: Remove - public interface IRenderTargetWithProperties : IRenderTarget - { - RenderTargetProperties Properties { get; } - } - - [PrivateApi] - // TODO12: Merge into IRenderTarget - public interface IRenderTarget2 : IRenderTarget - { + /// + /// Gets the properties of the render target. + /// RenderTargetProperties Properties { get; } + /// + /// Creates an for a rendering session. + /// + /// Apply DPI reported by the render target as a hidden transform matrix + IDrawingContextImpl CreateDrawingContext(bool useScaledDrawing); + /// /// Creates an for a rendering session. /// /// The pixel size of the surface /// Returns various properties about the returned drawing context - IDrawingContextImpl CreateDrawingContext(PixelSize expectedPixelSize, - out RenderTargetDrawingContextProperties properties); - } - - internal static class RenderTargetExtensions - { - public static IDrawingContextImpl CreateDrawingContextWithProperties( - this IRenderTarget renderTarget, + IDrawingContextImpl CreateDrawingContext( PixelSize expectedPixelSize, - out RenderTargetDrawingContextProperties properties) - { - if (renderTarget is IRenderTarget2 target) - return target.CreateDrawingContext(expectedPixelSize, out properties); - properties = default; - return renderTarget.CreateDrawingContext(false); - } + out RenderTargetDrawingContextProperties properties); } } diff --git a/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs b/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs index 19a5f0e881..b7a1993510 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs @@ -160,16 +160,13 @@ namespace Avalonia.Rendering.Composition.Server if (!_redrawRequested) return; - - var renderTargetWithProperties = _renderTarget as IRenderTarget2; - var needLayer = _overlays.RequireLayer // Check if we don't need overlays // Check if render target can be rendered to directly and preserves the previous frame - || !(renderTargetWithProperties?.Properties.RetainsPreviousFrameContents == true - && renderTargetWithProperties?.Properties.IsSuitableForDirectRendering == true); + || !(_renderTarget.Properties.RetainsPreviousFrameContents + && _renderTarget.Properties.IsSuitableForDirectRendering); - using (var renderTargetContext = _renderTarget.CreateDrawingContextWithProperties( + using (var renderTargetContext = _renderTarget.CreateDrawingContext( this.PixelSize, out var properties)) using (var renderTiming = Diagnostic.BeginCompositorRenderPass()) { diff --git a/src/Avalonia.Native/AvaloniaNativeGlPlatformGraphics.cs b/src/Avalonia.Native/AvaloniaNativeGlPlatformGraphics.cs index 2a6a1f16c7..fdf80bdc18 100644 --- a/src/Avalonia.Native/AvaloniaNativeGlPlatformGraphics.cs +++ b/src/Avalonia.Native/AvaloniaNativeGlPlatformGraphics.cs @@ -173,8 +173,11 @@ namespace Avalonia.Native _context = context; } - public IGlPlatformSurfaceRenderingSession BeginDraw() + public bool IsCorrupted => false; + + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize ObjectDisposedException.ThrowIf(_target is null, this); return new GlPlatformSurfaceRenderingSession(_context, _target.BeginDrawing()); } diff --git a/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs b/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs index d8d48d0944..0565dfee88 100644 --- a/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs +++ b/src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs @@ -54,8 +54,9 @@ namespace Avalonia.OpenGL.Egl public override void Dispose() => _glSurface?.Dispose(); - public override IGlPlatformSurfaceRenderingSession BeginDrawCore() + public override IGlPlatformSurfaceRenderingSession BeginDrawCore(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize if (_info.Size != _currentSize || _handle != _info.Handle || _glSurface == null) diff --git a/src/Avalonia.OpenGL/Egl/EglGlPlatformSurfaceBase.cs b/src/Avalonia.OpenGL/Egl/EglGlPlatformSurfaceBase.cs index 6df293e033..f7cfeecdc2 100644 --- a/src/Avalonia.OpenGL/Egl/EglGlPlatformSurfaceBase.cs +++ b/src/Avalonia.OpenGL/Egl/EglGlPlatformSurfaceBase.cs @@ -8,7 +8,7 @@ namespace Avalonia.OpenGL.Egl public abstract IGlPlatformSurfaceRenderTarget CreateGlRenderTarget(IGlContext context); } - public abstract class EglPlatformSurfaceRenderTargetBase : IGlPlatformSurfaceRenderTargetWithCorruptionInfo + public abstract class EglPlatformSurfaceRenderTargetBase : IGlPlatformSurfaceRenderTarget { protected EglContext Context { get; } @@ -22,17 +22,17 @@ namespace Avalonia.OpenGL.Egl } - public IGlPlatformSurfaceRenderingSession BeginDraw() + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize) { if (Context.IsLost) throw new RenderTargetCorruptedException(); - return BeginDrawCore(); + return BeginDrawCore(expectedPixelSize); } private protected virtual bool SkipWaits => false; - public abstract IGlPlatformSurfaceRenderingSession BeginDrawCore(); + public abstract IGlPlatformSurfaceRenderingSession BeginDrawCore(PixelSize? expectedPixelSize); protected IGlPlatformSurfaceRenderingSession BeginDraw(EglSurface surface, PixelSize size, double scaling, Action? onFinish = null, bool isYFlipped = false) diff --git a/src/Avalonia.OpenGL/Surfaces/IGlPlatformSurfaceRenderTarget.cs b/src/Avalonia.OpenGL/Surfaces/IGlPlatformSurfaceRenderTarget.cs index 13e89e9550..436cb4ce03 100644 --- a/src/Avalonia.OpenGL/Surfaces/IGlPlatformSurfaceRenderTarget.cs +++ b/src/Avalonia.OpenGL/Surfaces/IGlPlatformSurfaceRenderTarget.cs @@ -1,22 +1,11 @@ using System; -using Avalonia.Metadata; namespace Avalonia.OpenGL.Surfaces { public interface IGlPlatformSurfaceRenderTarget : IDisposable - { - IGlPlatformSurfaceRenderingSession BeginDraw(); - } - - public interface IGlPlatformSurfaceRenderTargetWithCorruptionInfo : IGlPlatformSurfaceRenderTarget { bool IsCorrupted { get; } - } - [PrivateApi] - public interface IGlPlatformSurfaceRenderTarget2 : IGlPlatformSurfaceRenderTargetWithCorruptionInfo - { - IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize expectedPixelSize); + IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize); } - } diff --git a/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs b/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs index a4d6e27451..e1cd12bece 100644 --- a/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs +++ b/src/Avalonia.X11/Glx/GlxGlPlatformSurface.cs @@ -21,7 +21,7 @@ namespace Avalonia.X11.Glx return new RenderTarget((GlxContext)context, _info); } - private class RenderTarget : IGlPlatformSurfaceRenderTarget2 + private class RenderTarget : IGlPlatformSurfaceRenderTarget { private readonly GlxContext _context; private readonly EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo _info; @@ -39,9 +39,8 @@ namespace Avalonia.X11.Glx } public bool IsCorrupted => false; - public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize size) => BeginDrawCore(size); - public IGlPlatformSurfaceRenderingSession BeginDraw() => BeginDrawCore(null); - public IGlPlatformSurfaceRenderingSession BeginDrawCore(PixelSize? expectedSize) + + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedSize) { var size = expectedSize ?? _info.Size; if (expectedSize.HasValue) diff --git a/src/Browser/Avalonia.Browser/Rendering/BrowserWebGlRenderTarget.cs b/src/Browser/Avalonia.Browser/Rendering/BrowserWebGlRenderTarget.cs index db66c9a0ee..4417dd2301 100644 --- a/src/Browser/Avalonia.Browser/Rendering/BrowserWebGlRenderTarget.cs +++ b/src/Browser/Avalonia.Browser/Rendering/BrowserWebGlRenderTarget.cs @@ -65,14 +65,17 @@ partial class BrowserWebGlRenderTarget : BrowserRenderTarget, IGlPlatformSurface { _target = target; } - + + public bool IsCorrupted => false; + public void Dispose() { // No-op } - public IGlPlatformSurfaceRenderingSession BeginDraw() + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize var s = _target._sizeGetter(); _target.UpdateSize(s.Size); var restoreContext = _target.GlContext.EnsureCurrent(); diff --git a/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index 2759db05c2..c2f024cf37 100644 --- a/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -400,11 +400,20 @@ namespace Avalonia.Headless } - public IDrawingContextImpl CreateDrawingContext(bool _) + public IDrawingContextImpl CreateDrawingContext(bool useScaledDrawing) { return new HeadlessDrawingContextStub(); } + public IDrawingContextImpl CreateDrawingContext(PixelSize expectedPixelSize, + out RenderTargetDrawingContextProperties properties) + { + properties = default; + return new HeadlessDrawingContextStub(); + } + + public RenderTargetProperties Properties => default; + public bool IsCorrupted => false; public void Blit(IDrawingContextImpl context) @@ -582,13 +591,22 @@ namespace Avalonia.Headless private class HeadlessRenderTarget : IRenderTarget { + public RenderTargetProperties Properties => default; + public void Dispose() { } - public IDrawingContextImpl CreateDrawingContext(bool _) + public IDrawingContextImpl CreateDrawingContext(bool useScaledDrawing) + { + return new HeadlessDrawingContextStub(); + } + + public IDrawingContextImpl CreateDrawingContext(PixelSize expectedPixelSize, + out RenderTargetDrawingContextProperties properties) { + properties = default; return new HeadlessDrawingContextStub(); } diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs index ddd3b6e49f..59de00f4b3 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs @@ -377,7 +377,7 @@ namespace Avalonia.LinuxFramebuffer.Output { //Go through two cycles of buffer swapping (there are render artifacts otherwise) for (var c = 0; c < 2; c++) - using (CreateGlRenderTarget().BeginDraw()) + using (CreateGlRenderTarget().BeginDraw(PixelSize)) { _deferredContext.GlInterface.ClearColor(initialBufferSwappingColorR, initialBufferSwappingColorG, initialBufferSwappingColorB, initialBufferSwappingColorA); @@ -406,6 +406,9 @@ namespace Avalonia.LinuxFramebuffer.Output { _parent = parent; } + + public bool IsCorrupted => false; + public void Dispose() { // We are wrapping GBM buffer chain associated with CRTC, and don't free it on a whim @@ -508,7 +511,7 @@ namespace Avalonia.LinuxFramebuffer.Output public bool IsYFlipped => false; } - public IGlPlatformSurfaceRenderingSession BeginDraw() + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize) { var clearContext = _parent._deferredContext.MakeCurrent(_parent._eglSurface); var gl = _parent._deferredContext.GlInterface; diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index 42448ed631..8051dd7993 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -170,8 +170,7 @@ namespace Avalonia.Skia public ISkiaSharpPlatformGraphicsApiLease? TryLeasePlatformGraphicsApi() { CheckLease(); - if (_context._gpu is ISkiaGpuWithPlatformGraphicsContext gpu && - gpu.PlatformGraphicsContext is { } context) + if (_context._gpu?.PlatformGraphicsContext is { } context) return new PlatformApiLease(this, context); return null; } diff --git a/src/Skia/Avalonia.Skia/FramebufferRenderTarget.cs b/src/Skia/Avalonia.Skia/FramebufferRenderTarget.cs index 7473563d13..0eb11ff404 100644 --- a/src/Skia/Avalonia.Skia/FramebufferRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/FramebufferRenderTarget.cs @@ -10,7 +10,7 @@ namespace Avalonia.Skia /// /// Skia render target that renders to a framebuffer surface. No gpu acceleration available. /// - internal class FramebufferRenderTarget : IRenderTarget2 + internal class FramebufferRenderTarget : IRenderTarget { private SKImageInfo _currentImageInfo; private IntPtr _currentFramebufferAddress; diff --git a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs index a4d8bafa56..93edea7169 100644 --- a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpu.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Avalonia.Metadata; using Avalonia.Platform; using SkiaSharp; @@ -13,6 +12,11 @@ namespace Avalonia.Skia /// public interface ISkiaGpu : IPlatformGraphicsContext { + /// + /// Gets the platform graphics context. + /// + IPlatformGraphicsContext? PlatformGraphicsContext { get; } + /// /// Attempts to create custom render target from given surfaces. /// @@ -26,13 +30,11 @@ namespace Avalonia.Skia /// size in pixels. /// An optional custom render session. ISkiaSurface? TryCreateSurface(PixelSize size, ISkiaGpuRenderSession? session); - } - //TODO12: Merge into ISkiaGpu - [Unstable] - public interface ISkiaGpuWithPlatformGraphicsContext : ISkiaGpu - { - IPlatformGraphicsContext? PlatformGraphicsContext { get; } + /// + /// Tries to get a . + /// + /// A . IScopedResource? TryGetGrContext(); } diff --git a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderTarget.cs index f8be7dc66f..eb7399f6a6 100644 --- a/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/ISkiaGpuRenderTarget.cs @@ -1,6 +1,4 @@ using System; -using Avalonia.Metadata; -using SkiaSharp; namespace Avalonia.Skia { @@ -12,16 +10,10 @@ namespace Avalonia.Skia /// /// Start rendering to this render target. /// - /// - ISkiaGpuRenderSession BeginRenderingSession(); + /// The expected size. + /// A render session instance. + ISkiaGpuRenderSession BeginRenderingSession(PixelSize? expectedPixelSize); bool IsCorrupted { get; } } - - [PrivateApi] - //TODO12: Merge with ISkiaGpuRenderTarget - public interface ISkiaGpuRenderTarget2 : ISkiaGpuRenderTarget - { - ISkiaGpuRenderSession BeginRenderingSession(PixelSize pixelSize); - } } diff --git a/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalGpu.cs b/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalGpu.cs index ad5f624a03..460a994839 100644 --- a/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/Metal/SkiaMetalGpu.cs @@ -6,7 +6,7 @@ using SkiaSharp; namespace Avalonia.Skia.Metal; -internal class SkiaMetalGpu : ISkiaGpu, ISkiaGpuWithPlatformGraphicsContext +internal class SkiaMetalGpu : ISkiaGpu { private GRContext? _context; private readonly IMetalDevice _device; @@ -80,8 +80,9 @@ internal class SkiaMetalGpu : ISkiaGpu, ISkiaGpuWithPlatformGraphicsContext _target = null; } - public ISkiaGpuRenderSession BeginRenderingSession() + public ISkiaGpuRenderSession BeginRenderingSession(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize var session = (_target ?? throw new ObjectDisposedException(nameof(SkiaMetalRenderTarget))).BeginRendering(); var backendTarget = new GRBackendRenderTarget(session.Size.Width, session.Size.Height, new GRMtlTextureInfo(session.Texture)); diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs index 56ce4a7194..bb43e13b55 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlRenderTarget.cs @@ -1,15 +1,12 @@ using System; -using Avalonia.Reactive; using Avalonia.OpenGL; using Avalonia.OpenGL.Surfaces; -using Avalonia.Platform; -using Avalonia.Rendering; using SkiaSharp; using static Avalonia.OpenGL.GlConsts; namespace Avalonia.Skia { - internal class GlRenderTarget : ISkiaGpuRenderTarget2 + internal class GlRenderTarget : ISkiaGpuRenderTarget { private readonly GRContext _grContext; private IGlPlatformSurfaceRenderTarget _surface; @@ -23,7 +20,7 @@ namespace Avalonia.Skia public void Dispose() => _surface.Dispose(); - public bool IsCorrupted => (_surface as IGlPlatformSurfaceRenderTargetWithCorruptionInfo)?.IsCorrupted == true; + public bool IsCorrupted => _surface.IsCorrupted; class GlGpuSession : ISkiaGpuRenderSession { @@ -58,16 +55,10 @@ namespace Avalonia.Skia public SKSurface SkSurface => _surface; public double ScaleFactor => _glSession.Scaling; } - - public ISkiaGpuRenderSession BeginRenderingSession(PixelSize size) => BeginRenderingSessionCore(size); - public ISkiaGpuRenderSession BeginRenderingSession() => BeginRenderingSessionCore(null); - ISkiaGpuRenderSession BeginRenderingSessionCore(PixelSize? expectedSize) + public ISkiaGpuRenderSession BeginRenderingSession(PixelSize? expectedPixelSize) { - var glSession = - expectedSize != null && _surface is IGlPlatformSurfaceRenderTarget2 surface2 - ? surface2.BeginDraw(expectedSize.Value) - : _surface.BeginDraw(); + var glSession = _surface.BeginDraw(expectedPixelSize); bool success = false; try diff --git a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs index 7336e7672b..a20ceb0fd0 100644 --- a/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/OpenGl/GlSkiaGpu.cs @@ -10,8 +10,7 @@ using static Avalonia.OpenGL.GlConsts; namespace Avalonia.Skia { - internal class GlSkiaGpu : ISkiaGpu, IOpenGlTextureSharingRenderInterfaceContextFeature, - ISkiaGpuWithPlatformGraphicsContext + internal class GlSkiaGpu : ISkiaGpu, IOpenGlTextureSharingRenderInterfaceContextFeature { private readonly GRContext _grContext; private readonly IGlContext _glContext; diff --git a/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs index 8d231a5784..488888f50a 100644 --- a/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/SkiaGpuRenderTarget.cs @@ -5,7 +5,7 @@ namespace Avalonia.Skia /// /// Adapts to be used within our rendering pipeline. /// - internal class SkiaGpuRenderTarget : IRenderTarget2 + internal class SkiaGpuRenderTarget : IRenderTarget { private readonly ISkiaGpu _skiaGpu; private readonly ISkiaGpuRenderTarget _renderTarget; @@ -34,10 +34,7 @@ namespace Avalonia.Skia out RenderTargetDrawingContextProperties properties) { properties = default; - var session = - expectedPixelSize.HasValue && _renderTarget is ISkiaGpuRenderTarget2 target2 - ? target2.BeginRenderingSession(expectedPixelSize.Value) - : _renderTarget.BeginRenderingSession(); + var session = _renderTarget.BeginRenderingSession(expectedPixelSize); var nfo = new DrawingContextImpl.CreateInfo { diff --git a/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaGpu.cs b/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaGpu.cs index a862424e51..9d3ca6789b 100644 --- a/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaGpu.cs +++ b/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaGpu.cs @@ -2,12 +2,11 @@ using System; using System.Collections.Generic; using Avalonia.Vulkan; using Avalonia.Platform; -using Avalonia.Rendering; using SkiaSharp; namespace Avalonia.Skia.Vulkan; -internal class VulkanSkiaGpu : ISkiaGpuWithPlatformGraphicsContext +internal class VulkanSkiaGpu : ISkiaGpu { private readonly VulkanSkiaExternalObjectsFeature? _externalObjects; public IVulkanPlatformGraphicsContext Vulkan { get; private set; } diff --git a/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaRenderTarget.cs b/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaRenderTarget.cs index c86a1204f3..3ab1714f6c 100644 --- a/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/Gpu/Vulkan/VulkanSkiaRenderTarget.cs @@ -21,8 +21,9 @@ class VulkanSkiaRenderTarget : ISkiaGpuRenderTarget _target.Dispose(); } - public ISkiaGpuRenderSession BeginRenderingSession() + public ISkiaGpuRenderSession BeginRenderingSession(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize var session = _target.BeginDraw(); bool success = false; try diff --git a/src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs b/src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs index 32b7340993..2e63f8bfd3 100644 --- a/src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs +++ b/src/Skia/Avalonia.Skia/RenderTargetBitmapImpl.cs @@ -1,6 +1,4 @@ -using System.IO; using Avalonia.Controls.Platform.Surfaces; -using Avalonia.Media.Imaging; using Avalonia.Platform; using SkiaSharp; @@ -19,9 +17,18 @@ internal class RenderTargetBitmapImpl : WriteableBitmapImpl, _renderTarget = new FramebufferRenderTarget(this); } + public RenderTargetProperties Properties => default; + IDrawingContextImpl IRenderTarget.CreateDrawingContext(bool useScaledDrawing) => _renderTarget.CreateDrawingContext(useScaledDrawing); + IDrawingContextImpl IRenderTarget.CreateDrawingContext(PixelSize expectedPixelSize, + out RenderTargetDrawingContextProperties properties) + { + properties = default; + return _renderTarget.CreateDrawingContext(false); + } + public bool IsCorrupted => false; public override void Dispose() @@ -31,4 +38,4 @@ internal class RenderTargetBitmapImpl : WriteableBitmapImpl, } public IFramebufferRenderTarget CreateFramebufferRenderTarget() => new FuncFramebufferRenderTarget(Lock); -} \ No newline at end of file +} diff --git a/src/Skia/Avalonia.Skia/SkiaBackendContext.cs b/src/Skia/Avalonia.Skia/SkiaBackendContext.cs index ee952457dc..dcaf6b542e 100644 --- a/src/Skia/Avalonia.Skia/SkiaBackendContext.cs +++ b/src/Skia/Avalonia.Skia/SkiaBackendContext.cs @@ -5,7 +5,6 @@ using System.Linq; using Avalonia.Controls.Platform.Surfaces; using Avalonia.OpenGL; using Avalonia.Platform; -using SkiaSharp; namespace Avalonia.Skia; @@ -29,7 +28,7 @@ internal class SkiaContext : IPlatformRenderInterfaceContext // TODO12: extend ISkiaGpu with PublicFeatures instead TryFeature(); TryFeature(); - using (var gr = (_gpu as ISkiaGpuWithPlatformGraphicsContext)?.TryGetGrContext()) + using (var gr = gpu.TryGetGrContext()) { var renderTargetSize = gr?.Value.MaxRenderTargetSize; if (renderTargetSize.HasValue) @@ -74,7 +73,7 @@ internal class SkiaContext : IPlatformRenderInterfaceContext public IDrawingContextLayerImpl CreateOffscreenRenderTarget(PixelSize pixelSize, Vector scaling, bool enableTextAntialiasing) { - using (var gr = (_gpu as ISkiaGpuWithPlatformGraphicsContext)?.TryGetGrContext()) + using (var gr = _gpu?.TryGetGrContext()) { var createInfo = new SurfaceRenderTarget.CreateInfo { diff --git a/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs b/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs index 87aebc2df1..82d0760207 100644 --- a/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs +++ b/src/Skia/Avalonia.Skia/SurfaceRenderTarget.cs @@ -72,6 +72,8 @@ namespace Avalonia.Skia _canvas = canvas; } + public RenderTargetProperties Properties => default; + /// /// Create backing Skia surface. /// @@ -114,6 +116,13 @@ namespace Avalonia.Skia return new DrawingContextImpl(createInfo, Disposable.Create(() => Version++)); } + public IDrawingContextImpl CreateDrawingContext(PixelSize expectedPixelSize, + out RenderTargetDrawingContextProperties properties) + { + properties = default; + return CreateDrawingContext(false); + } + public bool IsCorrupted => _gpu?.IsLost == true; /// diff --git a/src/Windows/Avalonia.Win32/DirectX/DxgiRenderTarget.cs b/src/Windows/Avalonia.Win32/DirectX/DxgiRenderTarget.cs index 6470aa48b8..698e47d27e 100644 --- a/src/Windows/Avalonia.Win32/DirectX/DxgiRenderTarget.cs +++ b/src/Windows/Avalonia.Win32/DirectX/DxgiRenderTarget.cs @@ -76,8 +76,9 @@ namespace Avalonia.Win32.DirectX } /// - public override IGlPlatformSurfaceRenderingSession BeginDrawCore() + public override IGlPlatformSurfaceRenderingSession BeginDrawCore(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize if (_swapChain is null) { throw new InvalidOperationException("No chain to draw on"); diff --git a/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleD3DTextureFeature.cs b/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleD3DTextureFeature.cs index ffdd4fdfd6..e4c63bbeba 100644 --- a/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleD3DTextureFeature.cs +++ b/src/Windows/Avalonia.Win32/OpenGl/Angle/AngleD3DTextureFeature.cs @@ -27,8 +27,9 @@ internal class AngleD3DTextureFeature : IGlPlatformSurfaceRenderTargetFactory _target = target; } - public override IGlPlatformSurfaceRenderingSession BeginDrawCore() + public override IGlPlatformSurfaceRenderingSession BeginDrawCore(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize var success = false; var contextLock = Context.EnsureCurrent(); IDirect3D11TextureRenderTargetRenderSession? session = null; diff --git a/src/Windows/Avalonia.Win32/OpenGl/WglGlPlatformSurface.cs b/src/Windows/Avalonia.Win32/OpenGl/WglGlPlatformSurface.cs index 6d3d2d28c4..40619660eb 100644 --- a/src/Windows/Avalonia.Win32/OpenGl/WglGlPlatformSurface.cs +++ b/src/Windows/Avalonia.Win32/OpenGl/WglGlPlatformSurface.cs @@ -28,6 +28,7 @@ namespace Avalonia.Win32.OpenGl private readonly WglContext _context; private readonly EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo _info; private IntPtr _hdc; + public RenderTarget(WglContext context, EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo info) { _context = context; @@ -35,13 +36,16 @@ namespace Avalonia.Win32.OpenGl _hdc = context.CreateConfiguredDeviceContext(info.Handle); } + public bool IsCorrupted => false; + public void Dispose() { WglGdiResourceManager.ReleaseDC(_info.Handle, _hdc); } - public IGlPlatformSurfaceRenderingSession BeginDraw() + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize var oldContext = _context.MakeCurrent(_hdc); // Reset to default FBO first diff --git a/src/iOS/Avalonia.iOS/Eagl/EaglLayerSurface.cs b/src/iOS/Avalonia.iOS/Eagl/EaglLayerSurface.cs index cc3ae528a2..fb0015476a 100644 --- a/src/iOS/Avalonia.iOS/Eagl/EaglLayerSurface.cs +++ b/src/iOS/Avalonia.iOS/Eagl/EaglLayerSurface.cs @@ -61,6 +61,8 @@ namespace Avalonia.iOS.Eagl _fbo = fbo; } + public bool IsCorrupted => false; + public void Dispose() { CheckThread(); @@ -68,8 +70,9 @@ namespace Avalonia.iOS.Eagl _fbo.Dispose(); } - public IGlPlatformSurfaceRenderingSession BeginDraw() + public IGlPlatformSurfaceRenderingSession BeginDraw(PixelSize? expectedPixelSize) { + // TODO: use expectedPixelSize CheckThread(); var restoreContext = _ctx.MakeCurrent(); _fbo.Bind();