Browse Source

[ANDROID] Skip glWaitClient/glWaitGL/glWaitNative (#18974)

pull/18997/head
Nikita Tsukanov 1 year ago
committed by GitHub
parent
commit
72fa47157c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
  2. 10
      src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs
  3. 32
      src/Avalonia.OpenGL/Egl/EglGlPlatformSurfaceBase.cs

3
src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

@ -30,7 +30,7 @@ using ClipboardManager = Android.Content.ClipboardManager;
namespace Avalonia.Android.Platform.SkiaPlatform namespace Avalonia.Android.Platform.SkiaPlatform
{ {
class TopLevelImpl : IAndroidView, ITopLevelImpl, EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo class TopLevelImpl : IAndroidView, ITopLevelImpl, EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfoWithWaitPolicy
{ {
private readonly IGlPlatformSurface _gl; private readonly IGlPlatformSurface _gl;
private readonly IFramebufferPlatformSurface _framebuffer; private readonly IFramebufferPlatformSurface _framebuffer;
@ -302,6 +302,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
public AcrylicPlatformCompensationLevels AcrylicCompensationLevels => new AcrylicPlatformCompensationLevels(1, 1, 1); public AcrylicPlatformCompensationLevels AcrylicCompensationLevels => new AcrylicPlatformCompensationLevels(1, 1, 1);
IntPtr EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo.Handle => ((IPlatformHandle)_view).Handle; IntPtr EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfo.Handle => ((IPlatformHandle)_view).Handle;
bool EglGlPlatformSurface.IEglWindowGlPlatformSurfaceInfoWithWaitPolicy.SkipWaits => true;
public PixelSize Size => _view.Size; public PixelSize Size => _view.Size;

10
src/Avalonia.OpenGL/Egl/EglGlPlatformSurface.cs

@ -1,4 +1,5 @@
using System; using System;
using Avalonia.Metadata;
using Avalonia.OpenGL.Surfaces; using Avalonia.OpenGL.Surfaces;
namespace Avalonia.OpenGL.Egl namespace Avalonia.OpenGL.Egl
@ -12,6 +13,12 @@ namespace Avalonia.OpenGL.Egl
double Scaling { get; } double Scaling { get; }
} }
[PrivateApi]
public interface IEglWindowGlPlatformSurfaceInfoWithWaitPolicy : IEglWindowGlPlatformSurfaceInfo
{
public bool SkipWaits { get; }
}
private readonly IEglWindowGlPlatformSurfaceInfo _info; private readonly IEglWindowGlPlatformSurfaceInfo _info;
public EglGlPlatformSurface(IEglWindowGlPlatformSurfaceInfo info) public EglGlPlatformSurface(IEglWindowGlPlatformSurfaceInfo info)
@ -40,8 +47,11 @@ namespace Avalonia.OpenGL.Egl
_info = info; _info = info;
_currentSize = info.Size; _currentSize = info.Size;
_handle = _info.Handle; _handle = _info.Handle;
SkipWaits = info is IEglWindowGlPlatformSurfaceInfoWithWaitPolicy { SkipWaits: true };
} }
private protected override bool SkipWaits { get; }
public override void Dispose() => _glSurface?.Dispose(); public override void Dispose() => _glSurface?.Dispose();
public override IGlPlatformSurfaceRenderingSession BeginDrawCore() public override IGlPlatformSurfaceRenderingSession BeginDrawCore()

32
src/Avalonia.OpenGL/Egl/EglGlPlatformSurfaceBase.cs

@ -30,6 +30,8 @@ namespace Avalonia.OpenGL.Egl
return BeginDrawCore(); return BeginDrawCore();
} }
private protected virtual bool SkipWaits => false;
public abstract IGlPlatformSurfaceRenderingSession BeginDrawCore(); public abstract IGlPlatformSurfaceRenderingSession BeginDrawCore();
protected IGlPlatformSurfaceRenderingSession BeginDraw(EglSurface surface, protected IGlPlatformSurfaceRenderingSession BeginDraw(EglSurface surface,
@ -41,14 +43,17 @@ namespace Avalonia.OpenGL.Egl
try try
{ {
var egli = Context.Display.EglInterface; var egli = Context.Display.EglInterface;
egli.WaitClient(); if (!SkipWaits)
egli.WaitGL(); {
egli.WaitNative(EglConsts.EGL_CORE_NATIVE_ENGINE); egli.WaitClient();
egli.WaitGL();
egli.WaitNative(EglConsts.EGL_CORE_NATIVE_ENGINE);
}
Context.GlInterface.BindFramebuffer(GlConsts.GL_FRAMEBUFFER, 0); Context.GlInterface.BindFramebuffer(GlConsts.GL_FRAMEBUFFER, 0);
success = true; success = true;
return new Session(Context.Display, Context, surface, size, scaling, restoreContext, onFinish, isYFlipped); return new Session(Context.Display, Context, surface, size, scaling, restoreContext, onFinish, isYFlipped, SkipWaits);
} }
finally finally
{ {
@ -64,10 +69,11 @@ namespace Avalonia.OpenGL.Egl
private readonly EglDisplay _display; private readonly EglDisplay _display;
private readonly IDisposable _restoreContext; private readonly IDisposable _restoreContext;
private readonly Action? _onFinish; private readonly Action? _onFinish;
private readonly bool _skipWaits;
public Session(EglDisplay display, EglContext context, public Session(EglDisplay display, EglContext context,
EglSurface glSurface, PixelSize size, double scaling, EglSurface glSurface, PixelSize size, double scaling,
IDisposable restoreContext, Action? onFinish, bool isYFlipped) IDisposable restoreContext, Action? onFinish, bool isYFlipped, bool skipWaits)
{ {
Size = size; Size = size;
Scaling = scaling; Scaling = scaling;
@ -77,16 +83,22 @@ namespace Avalonia.OpenGL.Egl
_glSurface = glSurface; _glSurface = glSurface;
_restoreContext = restoreContext; _restoreContext = restoreContext;
_onFinish = onFinish; _onFinish = onFinish;
_skipWaits = skipWaits;
} }
public void Dispose() public void Dispose()
{ {
_context.GlInterface.Flush(); _context.GlInterface.Flush();
_display.EglInterface.WaitGL(); if (!_skipWaits)
_display.EglInterface.WaitGL();
_glSurface.SwapBuffers(); _glSurface.SwapBuffers();
_display.EglInterface.WaitClient(); if (!_skipWaits)
_display.EglInterface.WaitGL(); {
_display.EglInterface.WaitNative(EglConsts.EGL_CORE_NATIVE_ENGINE); _display.EglInterface.WaitClient();
_display.EglInterface.WaitGL();
_display.EglInterface.WaitNative(EglConsts.EGL_CORE_NATIVE_ENGINE);
}
_restoreContext.Dispose(); _restoreContext.Dispose();
_onFinish?.Invoke(); _onFinish?.Invoke();
} }

Loading…
Cancel
Save