directly use the surface window handle cached in InvalidationAwareSurfaceView instead of requesting new handles (#20093)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user