-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
122 additions
and
64 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,74 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using Android.OS; | ||
using Android.Views; | ||
|
||
using Avalonia.Rendering; | ||
|
||
using Java.Lang; | ||
|
||
namespace Avalonia.Android | ||
{ | ||
internal sealed class ChoreographerTimer : Java.Lang.Object, IRenderTimer, Choreographer.IFrameCallback | ||
{ | ||
private readonly object _lock = new object(); | ||
|
||
private readonly Thread _thread; | ||
private readonly TaskCompletionSource<Choreographer> _choreographer = new TaskCompletionSource<Choreographer>(); | ||
|
||
private Action<TimeSpan> _tick; | ||
private int _count; | ||
|
||
public ChoreographerTimer() | ||
{ | ||
_thread = new Thread(Loop); | ||
_thread.Start(); | ||
} | ||
|
||
public event Action<TimeSpan> Tick | ||
{ | ||
add | ||
{ | ||
lock (_lock) | ||
{ | ||
_tick += value; | ||
_count++; | ||
|
||
if (_count == 1) | ||
{ | ||
_choreographer.Task.Result.PostFrameCallback(this); | ||
} | ||
} | ||
} | ||
remove | ||
{ | ||
lock (_lock) | ||
{ | ||
_tick -= value; | ||
_count--; | ||
} | ||
} | ||
} | ||
|
||
private void Loop() | ||
{ | ||
Looper.Prepare(); | ||
_choreographer.SetResult(Choreographer.Instance); | ||
Looper.Loop(); | ||
} | ||
|
||
public void DoFrame(long frameTimeNanos) | ||
{ | ||
_tick?.Invoke(TimeSpan.FromTicks(frameTimeNanos / 100)); | ||
|
||
lock (_lock) | ||
{ | ||
if (_count > 0) | ||
{ | ||
Choreographer.Instance.PostFrameCallback(this); | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,30 @@ | ||
using Avalonia.OpenGL.Egl; | ||
using System; | ||
|
||
using Avalonia.OpenGL.Egl; | ||
using Avalonia.OpenGL.Surfaces; | ||
|
||
namespace Avalonia.Android.OpenGL | ||
{ | ||
internal sealed class GlRenderTarget : EglPlatformSurfaceRenderTargetBase | ||
internal sealed class GlRenderTarget : EglPlatformSurfaceRenderTargetBase, IGlPlatformSurfaceRenderTargetWithCorruptionInfo | ||
{ | ||
private readonly EglGlPlatformSurfaceBase.IEglWindowGlPlatformSurfaceInfo _info; | ||
private readonly EglSurface _surface; | ||
private readonly IntPtr _handle; | ||
|
||
public GlRenderTarget( | ||
EglPlatformOpenGlInterface egl, | ||
EglGlPlatformSurfaceBase.IEglWindowGlPlatformSurfaceInfo info, | ||
EglSurface surface) | ||
EglSurface surface, | ||
IntPtr handle) | ||
: base(egl) | ||
{ | ||
_info = info; | ||
_surface = surface; | ||
_handle = handle; | ||
} | ||
|
||
public bool IsCorrupted => _handle != _info.Handle; | ||
|
||
public override IGlPlatformSurfaceRenderingSession BeginDraw() => BeginDraw(_surface, _info); | ||
} | ||
} |
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