Browse Source

directly use the surface window handle cached in InvalidationAwareSurfaceView instead of requesting new handles (#20093)

pull/20113/head
Emmanuel Hansen 3 months ago
committed by GitHub
parent
commit
8b23a2e342
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      src/Android/Avalonia.Android/Platform/SkiaPlatform/AndroidFramebuffer.cs
  2. 2
      src/Android/Avalonia.Android/Platform/SkiaPlatform/FramebufferManager.cs
  3. 10
      src/Android/Avalonia.Android/Platform/SkiaPlatform/InvalidationAwareSurfaceView.cs

7
src/Android/Avalonia.Android/Platform/SkiaPlatform/AndroidFramebuffer.cs

@ -1,8 +1,6 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Android.Runtime;
using Android.Views;
using Avalonia.Platform;
namespace Avalonia.Android.Platform.SkiaPlatform
@ -11,11 +9,11 @@ namespace Avalonia.Android.Platform.SkiaPlatform
{
private IntPtr _window;
public AndroidFramebuffer(Surface surface, double scaling)
public AndroidFramebuffer(InvalidationAwareSurfaceView surface, double scaling)
{
if(surface == null)
throw new ArgumentNullException(nameof(surface));
_window = ANativeWindow_fromSurface(JNIEnv.Handle, surface.Handle);
_window = (surface as IPlatformHandle).Handle;
if (_window == IntPtr.Zero)
throw new Exception("Unable to obtain ANativeWindow");
ANativeWindow_Buffer buffer;
@ -39,7 +37,6 @@ namespace Avalonia.Android.Platform.SkiaPlatform
public void Dispose()
{
ANativeWindow_unlockAndPost(_window);
ANativeWindow_release(_window);
_window = IntPtr.Zero;
Address = IntPtr.Zero;
}

2
src/Android/Avalonia.Android/Platform/SkiaPlatform/FramebufferManager.cs

@ -14,7 +14,7 @@ namespace Avalonia.Android.Platform.SkiaPlatform
}
public ILockedFramebuffer Lock() => new AndroidFramebuffer(
_topLevel.InternalView.Holder?.Surface ?? throw new InvalidOperationException("TopLevel.InternalView.Holder.Surface was not expected to be null."),
_topLevel.InternalView ?? throw new InvalidOperationException("TopLevel.InternalView was not expected to be null."),
_topLevel.RenderScaling);
public IFramebufferRenderTarget CreateFramebufferRenderTarget() => new FuncFramebufferRenderTarget(Lock);

10
src/Android/Avalonia.Android/Platform/SkiaPlatform/InvalidationAwareSurfaceView.cs

@ -42,26 +42,26 @@ namespace Avalonia.Android
public virtual void SurfaceChanged(ISurfaceHolder holder, Format format, int width, int height)
{
CacheSurfaceProperties(holder);
Logger.TryGet(LogEventLevel.Verbose, LogArea.AndroidPlatform)?
.Log(this, "InvalidationAwareSurfaceView Changed");
.Log(this, $"InvalidationAwareSurfaceView Changed. Format:{format} Size:{width} x {height}");
CacheSurfaceProperties(holder);
}
public void SurfaceCreated(ISurfaceHolder holder)
{
CacheSurfaceProperties(holder);
Logger.TryGet(LogEventLevel.Verbose, LogArea.AndroidPlatform)?
.Log(this, "InvalidationAwareSurfaceView Created");
CacheSurfaceProperties(holder);
SurfaceWindowCreated?.Invoke(this, EventArgs.Empty);
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
Logger.TryGet(LogEventLevel.Verbose, LogArea.AndroidPlatform)?
.Log(this, "InvalidationAwareSurfaceView Destroyed");
ReleaseNativeWindowHandle();
_size = new PixelSize(1, 1);
_scaling = 1;
Logger.TryGet(LogEventLevel.Verbose, LogArea.AndroidPlatform)?
.Log(this, "InvalidationAwareSurfaceView Destroyed");
}
public virtual void SurfaceRedrawNeeded(ISurfaceHolder holder)

Loading…
Cancel
Save