diff --git a/Avalonia.sln b/Avalonia.sln
index 76d8a14524..f71a94888d 100644
--- a/Avalonia.sln
+++ b/Avalonia.sln
@@ -186,6 +186,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Designer.HostApp.N
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Skia.UnitTests", "tests\Avalonia.Skia.UnitTests\Avalonia.Skia.UnitTests.csproj", "{E1240B49-7B4B-4371-A00E-068778C5CF0B}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.OpenGL", "src\Avalonia.OpenGL\Avalonia.OpenGL.csproj", "{7CCAEFC4-135D-401D-BDDD-896B9B7D3569}"
+EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Shared\RenderHelpers\RenderHelpers.projitems*{3c4c0cb4-0c0f-4450-a37b-148c84ff905f}*SharedItemsImports = 13
@@ -1663,6 +1665,30 @@ Global
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|iPhone.Build.0 = Release|Any CPU
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{E1240B49-7B4B-4371-A00E-068778C5CF0B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|Any CPU.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhone.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhone.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhone.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhone.ActiveCfg = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhone.Build.0 = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
+ {7CCAEFC4-135D-401D-BDDD-896B9B7D3569}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/Avalonia.Base/Avalonia.Base.csproj b/src/Avalonia.Base/Avalonia.Base.csproj
index bc068857ff..3d13169aa8 100644
--- a/src/Avalonia.Base/Avalonia.Base.csproj
+++ b/src/Avalonia.Base/Avalonia.Base.csproj
@@ -3,6 +3,7 @@
netstandard2.0
Avalonia.Base
Avalonia
+ True
diff --git a/src/Avalonia.Base/Platform/Interop/IDynamicLibraryLoader.cs b/src/Avalonia.Base/Platform/Interop/IDynamicLibraryLoader.cs
new file mode 100644
index 0000000000..8124ce6bc4
--- /dev/null
+++ b/src/Avalonia.Base/Platform/Interop/IDynamicLibraryLoader.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace Avalonia.Platform.Interop
+{
+ public interface IDynamicLibraryLoader
+ {
+ IntPtr LoadLibrary(string dll);
+ IntPtr GetProcAddress(IntPtr dll, string proc, bool optional);
+ }
+
+ public class DynamicLibraryLoaderException : Exception
+ {
+ public DynamicLibraryLoaderException(string message) : base(message)
+ {
+
+ }
+ }
+}
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Utf8Buffer.cs b/src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs
similarity index 94%
rename from src/Gtk/Avalonia.Gtk3/Interop/Utf8Buffer.cs
rename to src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs
index c932aac950..dc7a3e5634 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/Utf8Buffer.cs
+++ b/src/Avalonia.Base/Platform/Interop/Utf8Buffer.cs
@@ -2,9 +2,9 @@
using System.Runtime.InteropServices;
using System.Text;
-namespace Avalonia.Gtk3.Interop
+namespace Avalonia.Platform.Interop
{
- class Utf8Buffer : SafeHandle
+ public class Utf8Buffer : SafeHandle
{
private GCHandle _gchandle;
private byte[] _data;
diff --git a/src/Gtk/Avalonia.Gtk3/ClipboardImpl.cs b/src/Gtk/Avalonia.Gtk3/ClipboardImpl.cs
index a3e7590cf5..a860673732 100644
--- a/src/Gtk/Avalonia.Gtk3/ClipboardImpl.cs
+++ b/src/Gtk/Avalonia.Gtk3/ClipboardImpl.cs
@@ -3,6 +3,7 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Avalonia.Gtk3.Interop;
using Avalonia.Input.Platform;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3
{
diff --git a/src/Gtk/Avalonia.Gtk3/CursorFactory.cs b/src/Gtk/Avalonia.Gtk3/CursorFactory.cs
index d6a3c1f260..a28b1cbb1a 100644
--- a/src/Gtk/Avalonia.Gtk3/CursorFactory.cs
+++ b/src/Gtk/Avalonia.Gtk3/CursorFactory.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Avalonia.Gtk3.Interop;
using Avalonia.Input;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
using CursorType = Avalonia.Gtk3.GdkCursorType;
namespace Avalonia.Gtk3
{
diff --git a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs
index bbb6a01c05..1ab0c7576c 100644
--- a/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs
+++ b/src/Gtk/Avalonia.Gtk3/Gtk3Platform.cs
@@ -8,6 +8,7 @@ using Avalonia.Gtk3.Interop;
using Avalonia.Input;
using Avalonia.Input.Platform;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
using Avalonia.Rendering;
using Avalonia.Threading;
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/GException.cs b/src/Gtk/Avalonia.Gtk3/Interop/GException.cs
index b0c171089e..5ff6cbe8ed 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/GException.cs
+++ b/src/Gtk/Avalonia.Gtk3/Interop/GException.cs
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3.Interop
{
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Native.cs b/src/Gtk/Avalonia.Gtk3/Interop/Native.cs
index 914d0feafc..98a73a98a9 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/Native.cs
+++ b/src/Gtk/Avalonia.Gtk3/Interop/Native.cs
@@ -2,6 +2,7 @@
using System;
using System.Runtime.InteropServices;
using Avalonia.Controls;
+using Avalonia.Platform.Interop;
using gdouble = System.Double;
using gint = System.Int32;
using gint16 = System.Int16;
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Pixbuf.cs b/src/Gtk/Avalonia.Gtk3/Interop/Pixbuf.cs
index 989a96a4f0..322b9bdfae 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/Pixbuf.cs
+++ b/src/Gtk/Avalonia.Gtk3/Interop/Pixbuf.cs
@@ -2,6 +2,7 @@
using System.IO;
using System.Runtime.InteropServices;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3.Interop
{
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Resolver.cs b/src/Gtk/Avalonia.Gtk3/Interop/Resolver.cs
index 57c8ac7c3a..c39cb9e394 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/Resolver.cs
+++ b/src/Gtk/Avalonia.Gtk3/Interop/Resolver.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3.Interop
{
@@ -82,7 +83,7 @@ namespace Avalonia.Gtk3.Interop
}
}
- static IntPtr LoadDll(IDynLoader loader, GtkDll dll)
+ static IntPtr LoadDll(IDynamicLibraryLoader loader, GtkDll dll)
{
var exceptions = new List();
@@ -118,7 +119,7 @@ namespace Avalonia.Gtk3.Interop
public static void Resolve(string basePath = null)
{
- var loader = Platform.Value == OperatingSystemType.WinNT ? (IDynLoader)new Win32Loader() : new UnixLoader();
+ var loader = AvaloniaLocator.Current.GetService();
var dlls = Enum.GetValues(typeof(GtkDll)).Cast().ToDictionary(x => x, x => LoadDll(loader, x));
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/Signal.cs b/src/Gtk/Avalonia.Gtk3/Interop/Signal.cs
index bc55558551..8eaca93152 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/Signal.cs
+++ b/src/Gtk/Avalonia.Gtk3/Interop/Signal.cs
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3.Interop
{
diff --git a/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs b/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs
index d4bd878d53..5e6615f92d 100644
--- a/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs
+++ b/src/Gtk/Avalonia.Gtk3/SystemDialogs.cs
@@ -7,6 +7,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Gtk3.Interop;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3
{
diff --git a/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs b/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs
index 67ddcf1e5f..8cc7974c3e 100644
--- a/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs
+++ b/src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs
@@ -8,6 +8,7 @@ using Avalonia.Gtk3.Interop;
using Avalonia.Input;
using Avalonia.Input.Raw;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
using Avalonia.Rendering;
using Avalonia.Threading;
diff --git a/src/Gtk/Avalonia.Gtk3/WindowImpl.cs b/src/Gtk/Avalonia.Gtk3/WindowImpl.cs
index a0b754c229..34950ca8b8 100644
--- a/src/Gtk/Avalonia.Gtk3/WindowImpl.cs
+++ b/src/Gtk/Avalonia.Gtk3/WindowImpl.cs
@@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Gtk3.Interop;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
namespace Avalonia.Gtk3
{
diff --git a/src/Gtk/Avalonia.Gtk3/Interop/DynLoader.cs b/src/Shared/PlatformSupport/DynLoader.cs
similarity index 73%
rename from src/Gtk/Avalonia.Gtk3/Interop/DynLoader.cs
rename to src/Shared/PlatformSupport/DynLoader.cs
index 112e00c879..5884558baa 100644
--- a/src/Gtk/Avalonia.Gtk3/Interop/DynLoader.cs
+++ b/src/Shared/PlatformSupport/DynLoader.cs
@@ -1,22 +1,12 @@
-using System;
+using System;
using System.Runtime.InteropServices;
+using Avalonia.Platform;
+using Avalonia.Platform.Interop;
-/*
- * Source code imported from https://github.com/kekekeks/evhttp-sharp
- * Source is provided under MIT license for Avalonia project and derived works
- */
-
-
-namespace Avalonia.Gtk3.Interop
+namespace Avalonia.Shared.PlatformSupport
{
- internal interface IDynLoader
- {
- IntPtr LoadLibrary(string dll);
- IntPtr GetProcAddress(IntPtr dll, string proc, bool optional);
-
- }
-
- class UnixLoader : IDynLoader
+#if !__IOS__
+ class UnixLoader : IDynamicLibraryLoader
{
// ReSharper disable InconsistentNaming
static class LinuxImports
@@ -37,6 +27,7 @@ namespace Avalonia.Gtk3.Interop
DlError = dlerror;
}
}
+
static class OsXImports
{
@@ -86,7 +77,7 @@ namespace Avalonia.Gtk3.Interop
{
var handle = DlOpen(dll, 1);
if (handle == IntPtr.Zero)
- throw new NativeException(DlErrorString());
+ throw new DynamicLibraryLoaderException(DlErrorString());
return handle;
}
@@ -94,12 +85,12 @@ namespace Avalonia.Gtk3.Interop
{
var ptr = DlSym(dll, proc);
if (ptr == IntPtr.Zero && !optional)
- throw new NativeException(DlErrorString());
+ throw new DynamicLibraryLoaderException(DlErrorString());
return ptr;
}
}
- internal class Win32Loader : IDynLoader
+ internal class Win32Loader : IDynamicLibraryLoader
{
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
@@ -107,22 +98,37 @@ namespace Avalonia.Gtk3.Interop
[DllImport("kernel32", EntryPoint = "LoadLibraryW", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string lpszLib);
- IntPtr IDynLoader.LoadLibrary(string dll)
+ IntPtr IDynamicLibraryLoader.LoadLibrary(string dll)
{
var handle = LoadLibrary(dll);
if (handle != IntPtr.Zero)
return handle;
var err = Marshal.GetLastWin32Error();
- throw new NativeException("Error loading " + dll + " error " + err);
+ throw new DynamicLibraryLoaderException("Error loading " + dll + " error " + err);
}
- IntPtr IDynLoader.GetProcAddress(IntPtr dll, string proc, bool optional)
+ IntPtr IDynamicLibraryLoader.GetProcAddress(IntPtr dll, string proc, bool optional)
{
var ptr = GetProcAddress(dll, proc);
if (ptr == IntPtr.Zero && !optional)
- throw new NativeException("Error " + Marshal.GetLastWin32Error());
+ throw new DynamicLibraryLoaderException("Error " + Marshal.GetLastWin32Error());
return ptr;
}
}
+
+#else
+ internal class IOSLoader : IDynamicLibraryLoader
+ {
+ IntPtr IDynamicLibraryLoader.LoadLibrary(string dll)
+ {
+ throw new PlatformNotSupportedException();
+ }
+
+ IntPtr IDynamicLibraryLoader.GetProcAddress(IntPtr dll, string proc, bool optional)
+ {
+ throw new PlatformNotSupportedException();
+ }
+ }
+#endif
}
diff --git a/src/Shared/PlatformSupport/PlatformSupport.projitems b/src/Shared/PlatformSupport/PlatformSupport.projitems
index a9b6a8fa2a..34515a0912 100644
--- a/src/Shared/PlatformSupport/PlatformSupport.projitems
+++ b/src/Shared/PlatformSupport/PlatformSupport.projitems
@@ -10,6 +10,7 @@
+
diff --git a/src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs b/src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs
index 9ccf097ffd..ad6535e91c 100644
--- a/src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs
+++ b/src/Shared/PlatformSupport/StandardRuntimePlatformServices.cs
@@ -1,5 +1,7 @@
using System.Reflection;
+using System.Runtime.InteropServices;
using Avalonia.Platform;
+using Avalonia.Platform.Interop;
namespace Avalonia.Shared.PlatformSupport
{
@@ -7,9 +9,19 @@ namespace Avalonia.Shared.PlatformSupport
{
public static void Register(Assembly assembly = null)
{
+ var standardPlatform = new StandardRuntimePlatform();
AvaloniaLocator.CurrentMutable
- .Bind().ToSingleton()
- .Bind().ToConstant(new AssetLoader(assembly));
+ .Bind().ToConstant(standardPlatform)
+ .Bind().ToConstant(new AssetLoader(assembly))
+ .Bind().ToConstant(
+#if __IOS__
+ new IOSLoader()
+#else
+ standardPlatform.GetRuntimeInfo().OperatingSystem == OperatingSystemType.WinNT
+ ? (IDynamicLibraryLoader)new Win32Loader()
+ : new UnixLoader()
+#endif
+ );
}
}
}