Browse Source

Revert "Avoid "using system" because"

This reverts commit 34b4f970e9.
pull/7565/head
Dan Walmsley 4 years ago
parent
commit
3344e436b3
  1. 2
      src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs
  2. 17
      src/iOS/Avalonia.iOS/AvaloniaView.cs
  3. 9
      src/iOS/Avalonia.iOS/ClipboardImpl.cs
  4. 5
      src/iOS/Avalonia.iOS/DisplayLinkTimer.cs
  5. 11
      src/iOS/Avalonia.iOS/EaglDisplay.cs
  6. 10
      src/iOS/Avalonia.iOS/EaglLayerSurface.cs
  7. 1
      src/iOS/Avalonia.iOS/Extensions.cs
  8. 14
      src/iOS/Avalonia.iOS/LayerFbo.cs
  9. 6
      src/iOS/Avalonia.iOS/Platform.cs
  10. 9
      src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs
  11. 5
      src/iOS/Avalonia.iOS/Stubs.cs

2
src/iOS/Avalonia.iOS/AvaloniaAppDelegate.cs

@ -12,7 +12,7 @@ namespace Avalonia.iOS
[Export("window")] [Export("window")]
public UIWindow Window { get; set; } public UIWindow Window { get; set; }
[Export("application:didFinishLaunchingWithOptions:")] [Export("application:didFinishLaunchingWithOptions:")]
public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{ {

17
src/iOS/Avalonia.iOS/AvaloniaView.cs

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Embedding; using Avalonia.Controls.Embedding;
@ -93,14 +94,14 @@ namespace Avalonia.iOS
public Size? FrameSize => null; public Size? FrameSize => null;
public double RenderScaling => _view.ContentScaleFactor; public double RenderScaling => _view.ContentScaleFactor;
public IEnumerable<object> Surfaces { get; set; } public IEnumerable<object> Surfaces { get; set; }
public System.Action<RawInputEventArgs> Input { get; set; } public Action<RawInputEventArgs> Input { get; set; }
public System.Action<Rect> Paint { get; set; } public Action<Rect> Paint { get; set; }
public System.Action<Size, PlatformResizeReason> Resized { get; set; } public Action<Size, PlatformResizeReason> Resized { get; set; }
public System.Action<double> ScalingChanged { get; set; } public Action<double> ScalingChanged { get; set; }
public System.Action<WindowTransparencyLevel> TransparencyLevelChanged { get; set; } public Action<WindowTransparencyLevel> TransparencyLevelChanged { get; set; }
public System.Action Closed { get; set; } public Action Closed { get; set; }
public System.Action LostFocus { get; set; } public Action LostFocus { get; set; }
// legacy no-op // legacy no-op
public IMouseDevice MouseDevice { get; } = new MouseDevice(); public IMouseDevice MouseDevice { get; } = new MouseDevice();

9
src/iOS/Avalonia.iOS/ClipboardImpl.cs

@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Input.Platform; using Avalonia.Input.Platform;
@ -24,10 +25,10 @@ namespace Avalonia.iOS
return Task.FromResult(0); return Task.FromResult(0);
} }
public Task SetDataObjectAsync(IDataObject data) => throw new System.PlatformNotSupportedException(); public Task SetDataObjectAsync(IDataObject data) => throw new PlatformNotSupportedException();
public Task<string[]> GetFormatsAsync() => throw new System.PlatformNotSupportedException(); public Task<string[]> GetFormatsAsync() => throw new PlatformNotSupportedException();
public Task<object> GetDataAsync(string format) => throw new System.PlatformNotSupportedException(); public Task<object> GetDataAsync(string format) => throw new PlatformNotSupportedException();
} }
} }

5
src/iOS/Avalonia.iOS/DisplayLinkTimer.cs

@ -1,3 +1,4 @@
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,7 +11,7 @@ namespace Avalonia.iOS
{ {
class DisplayLinkTimer : IRenderTimer class DisplayLinkTimer : IRenderTimer
{ {
public event System.Action<System.TimeSpan> Tick; public event Action<TimeSpan> Tick;
private Stopwatch _st = Stopwatch.StartNew(); private Stopwatch _st = Stopwatch.StartNew();
public DisplayLinkTimer() public DisplayLinkTimer()
@ -33,4 +34,4 @@ namespace Avalonia.iOS
Tick?.Invoke(_st.Elapsed); Tick?.Invoke(_st.Elapsed);
} }
} }
} }

11
src/iOS/Avalonia.iOS/EaglDisplay.cs

@ -1,3 +1,4 @@
using System;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using Avalonia.OpenGL; using Avalonia.OpenGL;
using OpenGLES; using OpenGLES;
@ -7,7 +8,7 @@ namespace Avalonia.iOS
class EaglFeature : IPlatformOpenGlInterface class EaglFeature : IPlatformOpenGlInterface
{ {
public IGlContext PrimaryContext => Context; public IGlContext PrimaryContext => Context;
public IGlContext CreateSharedContext() => throw new System.NotSupportedException(); public IGlContext CreateSharedContext() => throw new NotSupportedException();
public bool CanShareContexts => false; public bool CanShareContexts => false;
public bool CanCreateContexts => false; public bool CanCreateContexts => false;
public IGlContext CreateContext() => throw new System.NotSupportedException(); public IGlContext CreateContext() => throw new System.NotSupportedException();
@ -22,7 +23,7 @@ namespace Avalonia.iOS
{ {
const string path = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES"; const string path = "/System/Library/Frameworks/OpenGLES.framework/OpenGLES";
var libGl = ObjCRuntime.Dlfcn.dlopen(path, 1); var libGl = ObjCRuntime.Dlfcn.dlopen(path, 1);
if (libGl == System.IntPtr.Zero) if (libGl == IntPtr.Zero)
throw new OpenGlException("Unable to load " + path); throw new OpenGlException("Unable to load " + path);
GlInterface = new GlInterface(Version, proc => ObjCRuntime.Dlfcn.dlsym(libGl, proc)); GlInterface = new GlInterface(Version, proc => ObjCRuntime.Dlfcn.dlsym(libGl, proc));
Context = new EAGLContext(EAGLRenderingAPI.OpenGLES3); Context = new EAGLContext(EAGLRenderingAPI.OpenGLES3);
@ -34,7 +35,7 @@ namespace Avalonia.iOS
Context = null; Context = null;
} }
class ResetContext : System.IDisposable class ResetContext : IDisposable
{ {
private EAGLContext _old; private EAGLContext _old;
private bool _disposed; private bool _disposed;
@ -54,7 +55,7 @@ namespace Avalonia.iOS
} }
} }
public System.IDisposable MakeCurrent() public IDisposable MakeCurrent()
{ {
var old = EAGLContext.CurrentContext; var old = EAGLContext.CurrentContext;
if (!EAGLContext.SetCurrentContext(Context)) if (!EAGLContext.SetCurrentContext(Context))
@ -62,7 +63,7 @@ namespace Avalonia.iOS
return new ResetContext(old); return new ResetContext(old);
} }
public System.IDisposable EnsureCurrent() public IDisposable EnsureCurrent()
{ {
if(EAGLContext.CurrentContext == Context) if(EAGLContext.CurrentContext == Context)
return Disposable.Empty; return Disposable.Empty;

10
src/iOS/Avalonia.iOS/EaglLayerSurface.cs

@ -1,3 +1,5 @@
using System;
using System.Threading; using System.Threading;
using Avalonia.OpenGL; using Avalonia.OpenGL;
using Avalonia.OpenGL.Surfaces; using Avalonia.OpenGL.Surfaces;
@ -17,10 +19,10 @@ namespace Avalonia.iOS
class RenderSession : IGlPlatformSurfaceRenderingSession class RenderSession : IGlPlatformSurfaceRenderingSession
{ {
private readonly GlContext _ctx; private readonly GlContext _ctx;
private readonly System.IDisposable _restoreContext; private readonly IDisposable _restoreContext;
private readonly SizeSynchronizedLayerFbo _fbo; private readonly SizeSynchronizedLayerFbo _fbo;
public RenderSession(GlContext ctx, System.IDisposable restoreContext, SizeSynchronizedLayerFbo fbo) public RenderSession(GlContext ctx, IDisposable restoreContext, SizeSynchronizedLayerFbo fbo)
{ {
_ctx = ctx; _ctx = ctx;
_restoreContext = restoreContext; _restoreContext = restoreContext;
@ -73,7 +75,7 @@ namespace Avalonia.iOS
static void CheckThread() static void CheckThread()
{ {
if (Platform.Timer.TimerThread != Thread.CurrentThread) if (Platform.Timer.TimerThread != Thread.CurrentThread)
throw new System.InvalidOperationException("Invalid thread, go away"); throw new InvalidOperationException("Invalid thread, go away");
} }
public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget() public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget()
@ -84,7 +86,7 @@ namespace Avalonia.iOS
{ {
var fbo = new SizeSynchronizedLayerFbo(ctx.Context, ctx.GlInterface, _layer); var fbo = new SizeSynchronizedLayerFbo(ctx.Context, ctx.GlInterface, _layer);
if (!fbo.Sync()) if (!fbo.Sync())
throw new System.InvalidOperationException("Unable to create render target"); throw new InvalidOperationException("Unable to create render target");
return new RenderTarget(ctx, fbo); return new RenderTarget(ctx, fbo);
} }
} }

1
src/iOS/Avalonia.iOS/Extensions.cs

@ -1,3 +1,4 @@
using System;
using Avalonia.Media; using Avalonia.Media;
using CoreGraphics; using CoreGraphics;
using UIKit; using UIKit;

14
src/iOS/Avalonia.iOS/LayerFbo.cs

@ -1,12 +1,8 @@
using System;
using Avalonia.OpenGL; using Avalonia.OpenGL;
using CoreAnimation; using CoreAnimation;
using OpenGLES; using OpenGLES;
// We can't import System because System has a type called nint on iOS and Mac Catalyst.
// As such, throughout this file System is fully qualified.
// See https://github.com/xamarin/xamarin-macios/issues/10508
// And https://github.com/dotnet/Silk.NET/blob/main/src/Windowing/Silk.NET.Windowing.Sdl/SdlView.cs
namespace Avalonia.iOS namespace Avalonia.iOS
{ {
public class LayerFbo public class LayerFbo
@ -96,11 +92,11 @@ namespace Avalonia.iOS
_gl.DeleteRenderbuffers(1, _depthBuffer); _gl.DeleteRenderbuffers(1, _depthBuffer);
_gl.DeleteRenderbuffers(1, _renderbuffer); _gl.DeleteRenderbuffers(1, _renderbuffer);
if (_context != EAGLContext.CurrentContext) if (_context != EAGLContext.CurrentContext)
throw new System.InvalidOperationException("Associated EAGLContext is not current"); throw new InvalidOperationException("Associated EAGLContext is not current");
} }
} }
class SizeSynchronizedLayerFbo : System.IDisposable class SizeSynchronizedLayerFbo : IDisposable
{ {
private readonly EAGLContext _context; private readonly EAGLContext _context;
private readonly GlInterface _gl; private readonly GlInterface _gl;
@ -134,7 +130,7 @@ namespace Avalonia.iOS
public void Dispose() public void Dispose()
{ {
if (_context != EAGLContext.CurrentContext) if (_context != EAGLContext.CurrentContext)
throw new System.InvalidOperationException("Associated EAGLContext is not current"); throw new InvalidOperationException("Associated EAGLContext is not current");
_fbo?.Dispose(); _fbo?.Dispose();
_fbo = null; _fbo = null;
} }
@ -142,7 +138,7 @@ namespace Avalonia.iOS
public void Bind() public void Bind()
{ {
if(!Sync()) if(!Sync())
throw new System.InvalidOperationException("Unable to create a render target"); throw new InvalidOperationException("Unable to create a render target");
_fbo.Bind(); _fbo.Bind();
} }

6
src/iOS/Avalonia.iOS/Platform.cs

@ -1,3 +1,5 @@
using System;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Input.Platform; using Avalonia.Input.Platform;
@ -30,11 +32,11 @@ namespace Avalonia.iOS
public Size TouchDoubleClickSize => new Size(10, 10); public Size TouchDoubleClickSize => new Size(10, 10);
/// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/> /// <inheritdoc cref="IPlatformSettings.TouchDoubleClickTime"/>
public System.TimeSpan TouchDoubleClickTime => System.TimeSpan.FromMilliseconds(500); public TimeSpan TouchDoubleClickTime => TimeSpan.FromMilliseconds(500);
public Size DoubleClickSize => new Size(4, 4); public Size DoubleClickSize => new Size(4, 4);
public System.TimeSpan DoubleClickTime => TouchDoubleClickTime; public TimeSpan DoubleClickTime => TouchDoubleClickTime;
} }
public static void Register() public static void Register()

9
src/iOS/Avalonia.iOS/PlatformThreadingInterface.cs

@ -1,3 +1,4 @@
using System;
using System.Threading; using System.Threading;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Threading; using Avalonia.Threading;
@ -12,14 +13,14 @@ namespace Avalonia.iOS
public static PlatformThreadingInterface Instance { get; } = new PlatformThreadingInterface(); public static PlatformThreadingInterface Instance { get; } = new PlatformThreadingInterface();
public bool CurrentThreadIsLoopThread => NSThread.Current.IsMainThread; public bool CurrentThreadIsLoopThread => NSThread.Current.IsMainThread;
public event System.Action<DispatcherPriority?> Signaled; public event Action<DispatcherPriority?> Signaled;
public void RunLoop(CancellationToken cancellationToken) public void RunLoop(CancellationToken cancellationToken)
{ {
//Mobile platforms are using external main loop //Mobile platforms are using external main loop
throw new System.NotSupportedException(); throw new NotSupportedException();
} }
public System.IDisposable StartTimer(DispatcherPriority priority, System.TimeSpan interval, System.Action tick) public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick)
=> NSTimer.CreateRepeatingScheduledTimer(interval, _ => tick()); => NSTimer.CreateRepeatingScheduledTimer(interval, _ => tick());
public void Signal(DispatcherPriority prio) public void Signal(DispatcherPriority prio)
@ -39,4 +40,4 @@ namespace Avalonia.iOS
}); });
} }
} }
} }

5
src/iOS/Avalonia.iOS/Stubs.cs

@ -1,3 +1,4 @@
using System;
using System.IO; using System.IO;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Platform; using Avalonia.Platform;
@ -17,9 +18,9 @@ namespace Avalonia.iOS
class WindowingPlatformStub : IWindowingPlatform class WindowingPlatformStub : IWindowingPlatform
{ {
public IWindowImpl CreateWindow() => throw new System.NotSupportedException(); public IWindowImpl CreateWindow() => throw new NotSupportedException();
public IWindowImpl CreateEmbeddableWindow() => throw new System.NotSupportedException(); public IWindowImpl CreateEmbeddableWindow() => throw new NotSupportedException();
public ITrayIconImpl CreateTrayIcon() => null; public ITrayIconImpl CreateTrayIcon() => null;
} }

Loading…
Cancel
Save