Skip to content

Commit

Permalink
Merge pull request #2716 from AvaloniaUI/v0.8-pre
Browse files Browse the repository at this point in the history
V0.8 pre
  • Loading branch information
kekekeks authored Jul 6, 2019
2 parents b6ee0d0 + 94e2cbb commit 146d51c
Show file tree
Hide file tree
Showing 22 changed files with 273 additions and 55 deletions.
5 changes: 3 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- job: macOS
pool:
vmImage: 'xcode9-macos10.13'
vmImage: 'macOS-10.14'
steps:
- task: DotNetCoreInstaller@0
inputs:
Expand All @@ -49,7 +49,7 @@ jobs:
inputs:
actions: 'build'
scheme: ''
sdk: 'macosx10.13'
sdk: 'macosx10.14'
configuration: 'Release'
xcWorkspacePath: '**/*.xcodeproj/project.xcworkspace'
xcodeVersion: 'default' # Options: 8, 9, default, specifyPath
Expand Down Expand Up @@ -134,3 +134,4 @@ jobs:
pathToPublish: '$(Build.SourcesDirectory)/artifacts/zip'
artifactName: 'Samples'
condition: succeeded()

2 changes: 1 addition & 1 deletion build/SharedVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>Avalonia</Product>
<Version>0.8.0</Version>
<Version>0.8.1</Version>
<Copyright>Copyright 2018 &#169; The AvaloniaUI Project</Copyright>
<PackageLicenseUrl>https://github.com/AvaloniaUI/Avalonia/blob/master/licence.md</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/AvaloniaUI/Avalonia/</PackageProjectUrl>
Expand Down
8 changes: 8 additions & 0 deletions nukebuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ void RunCoreTest(string project)

foreach(var fw in frameworks)
{
if (fw.StartsWith("net4")
&& RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
&& Environment.GetEnvironmentVariable("FORCE_LINUX_TESTS") != "1")
{
Information($"Skipping {fw} tests on Linux - https://github.com/mono/mono/issues/13969");
continue;
}

Information("Running for " + fw);
DotNetTest(c =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ProjectReference Include="..\ControlCatalog\ControlCatalog.csproj" />
<ProjectReference Include="..\..\src\Avalonia.Desktop\Avalonia.Desktop.csproj" />
<ProjectReference Include="..\..\src\Avalonia.X11\Avalonia.X11.csproj" />
<PackageReference Include="Avalonia.Angle.Windows.Natives" Version="2.1.0.2019013001"/>
</ItemGroup>


Expand Down
5 changes: 4 additions & 1 deletion samples/ControlCatalog.NetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Threading;
using Avalonia;
using Avalonia.Skia;

namespace ControlCatalog.NetCore
{
Expand Down Expand Up @@ -45,6 +44,10 @@ static void AppMain(Application app, string[] args)
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.With(new Win32PlatformOptions
{
AllowEglInitialization = true
})
.UseSkia()
.UseReactiveUI()
.UseDataGrid();
Expand Down
2 changes: 0 additions & 2 deletions src/Avalonia.Native/Avalonia.Native.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<CastXmlPath Condition="Exists('/usr/bin/castxml')">/usr/bin/castxml</CastXmlPath>
<CastXmlPath Condition="Exists('/usr/local/bin/castxml')">/usr/local/bin/castxml</CastXmlPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- This is needed because Rider doesn't see generated files in obj for some reason -->
<SharpGenGeneratedCodeFolder>$(MSBuildThisFileDirectory)/Generated</SharpGenGeneratedCodeFolder>
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release' AND '$([MSBuild]::IsOSPlatform(OSX))' == 'true'">
Expand Down
18 changes: 18 additions & 0 deletions src/Avalonia.OpenGL/AngleOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;

namespace Avalonia.OpenGL
{
public class AngleOptions
{
public enum PlatformApi
{
DirectX9,
DirectX11
}

public List<PlatformApi> AllowedPlatformApis = new List<PlatformApi>
{
PlatformApi.DirectX9
};
}
}
71 changes: 50 additions & 21 deletions src/Avalonia.OpenGL/EglDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Avalonia.Platform.Interop;
using static Avalonia.OpenGL.EglConsts;
Expand All @@ -13,21 +14,42 @@ public class EglDisplay : IGlDisplay
private readonly int[] _contextAttributes;

public IntPtr Handle => _display;
private AngleOptions.PlatformApi? _angleApi;
public EglDisplay(EglInterface egl)
{
_egl = egl;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && _egl.GetPlatformDisplayEXT != null)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
foreach (var dapi in new[] {EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE})
if (_egl.GetPlatformDisplayEXT == null)
throw new OpenGlException("eglGetPlatformDisplayEXT is not supported by libegl.dll");

var allowedApis = AvaloniaLocator.Current.GetService<AngleOptions>()?.AllowedPlatformApis
?? new List<AngleOptions.PlatformApi> {AngleOptions.PlatformApi.DirectX9};

foreach (var platformApi in allowedApis)
{
int dapi;
if (platformApi == AngleOptions.PlatformApi.DirectX9)
dapi = EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE;
else if (platformApi == AngleOptions.PlatformApi.DirectX11)
dapi = EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
else
continue;

_display = _egl.GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, IntPtr.Zero, new[]
{
EGL_PLATFORM_ANGLE_TYPE_ANGLE, dapi, EGL_NONE
});
if(_display != IntPtr.Zero)
if (_display != IntPtr.Zero)
{
_angleApi = platformApi;
break;
}
}

if (_display == IntPtr.Zero)
throw new OpenGlException("Unable to create ANGLE display");
}

if (_display == IntPtr.Zero)
Expand Down Expand Up @@ -64,29 +86,35 @@ public EglDisplay(EglInterface egl)
if (!_egl.BindApi(cfg.Api))
continue;

var attribs = new[]
foreach(var stencilSize in new[]{8, 1, 0})
foreach (var depthSize in new []{8, 1, 0})
{
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, cfg.RenderableTypeBit,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_STENCIL_SIZE, 8,
EGL_DEPTH_SIZE, 8,
EGL_NONE
};
if (!_egl.ChooseConfig(_display, attribs, out _config, 1, out int numConfigs))
continue;
if (numConfigs == 0)
continue;
_contextAttributes = cfg.Attributes;
Type = cfg.Type;
var attribs = new[]
{
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,

EGL_RENDERABLE_TYPE, cfg.RenderableTypeBit,

EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_STENCIL_SIZE, stencilSize,
EGL_DEPTH_SIZE, depthSize,
EGL_NONE
};
if (!_egl.ChooseConfig(_display, attribs, out _config, 1, out int numConfigs))
continue;
if (numConfigs == 0)
continue;
_contextAttributes = cfg.Attributes;
Type = cfg.Type;
}
}

if (_contextAttributes == null)
throw new OpenGlException("No suitable EGL config was found");

GlInterface = GlInterface.FromNativeUtf8GetProcAddress(b => _egl.GetProcAddress(b));
}

Expand All @@ -97,6 +125,7 @@ public EglDisplay() : this(new EglInterface())

public GlDisplayType Type { get; }
public GlInterface GlInterface { get; }
public EglInterface EglInterface => _egl;
public IGlContext CreateContext(IGlContext share)
{
var shareCtx = (EglContext)share;
Expand Down
33 changes: 27 additions & 6 deletions src/Avalonia.OpenGL/EglGlPlatformSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,44 @@ public EglGlPlatformSurface(EglDisplay display, EglContext context, IEglWindowGl
public IGlPlatformSurfaceRenderTarget CreateGlRenderTarget()
{
var glSurface = _display.CreateWindowSurface(_info.Handle);
return new RenderTarget(_context, glSurface, _info);
return new RenderTarget(_display, _context, glSurface, _info);
}

class RenderTarget : IGlPlatformSurfaceRenderTarget
class RenderTarget : IGlPlatformSurfaceRenderTargetWithCorruptionInfo
{
private readonly EglDisplay _display;
private readonly EglContext _context;
private readonly EglSurface _glSurface;
private readonly IEglWindowGlPlatformSurfaceInfo _info;
private PixelSize _initialSize;

public RenderTarget(EglContext context, EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info)
public RenderTarget(EglDisplay display, EglContext context,
EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info)
{
_display = display;
_context = context;
_glSurface = glSurface;
_info = info;
_initialSize = info.Size;
}

public void Dispose() => _glSurface.Dispose();

public bool IsCorrupted => _initialSize != _info.Size;

public IGlPlatformSurfaceRenderingSession BeginDraw()
{
var l = _context.Lock();
try
{
if (IsCorrupted)
throw new RenderTargetCorruptedException();
_context.MakeCurrent(_glSurface);
return new Session(_context, _glSurface, _info, l);
_display.EglInterface.WaitClient();
_display.EglInterface.WaitGL();
_display.EglInterface.WaitNative();

return new Session(_display, _context, _glSurface, _info, l);
}
catch
{
Expand All @@ -61,15 +74,19 @@ public IGlPlatformSurfaceRenderingSession BeginDraw()

class Session : IGlPlatformSurfaceRenderingSession
{
private readonly IGlContext _context;
private readonly EglContext _context;
private readonly EglSurface _glSurface;
private readonly IEglWindowGlPlatformSurfaceInfo _info;
private readonly EglDisplay _display;
private IDisposable _lock;


public Session(IGlContext context, EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info,
public Session(EglDisplay display, EglContext context,
EglSurface glSurface, IEglWindowGlPlatformSurfaceInfo info,
IDisposable @lock)
{
_context = context;
_display = display;
_glSurface = glSurface;
_info = info;
_lock = @lock;
Expand All @@ -78,7 +95,11 @@ public Session(IGlContext context, EglSurface glSurface, IEglWindowGlPlatformSur
public void Dispose()
{
_context.Display.GlInterface.Flush();
_display.EglInterface.WaitGL();
_glSurface.SwapBuffers();
_display.EglInterface.WaitClient();
_display.EglInterface.WaitGL();
_display.EglInterface.WaitNative();
_context.Display.ClearContext();
_lock.Dispose();
}
Expand Down
26 changes: 26 additions & 0 deletions src/Avalonia.OpenGL/EglInterface.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using Avalonia.Platform;
using Avalonia.Platform.Interop;

Expand Down Expand Up @@ -91,6 +92,31 @@ public delegate IntPtr
[GlEntryPoint("eglGetConfigAttrib")]
public EglGetConfigAttrib GetConfigAttrib { get; }

public delegate bool EglWaitGL();
[GlEntryPoint("eglWaitGL")]
public EglWaitGL WaitGL { get; }

public delegate bool EglWaitClient();
[GlEntryPoint("eglWaitClient")]
public EglWaitGL WaitClient { get; }

public delegate bool EglWaitNative();
[GlEntryPoint("eglWaitNative")]
public EglWaitGL WaitNative { get; }

public delegate IntPtr EglQueryString(IntPtr display, int i);

[GlEntryPoint("eglQueryString")]
public EglQueryString QueryStringNative { get; }

public string QueryString(IntPtr display, int i)
{
var rv = QueryStringNative(display, i);
if (rv == IntPtr.Zero)
return null;
return Marshal.PtrToStringAnsi(rv);
}

// ReSharper restore UnassignedGetOnlyAutoProperty
}
}
18 changes: 14 additions & 4 deletions src/Avalonia.OpenGL/GlInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ namespace Avalonia.OpenGL
public class GlInterface : GlInterfaceBase
{
public string Version { get; }
public string Vendor { get; }
public string Renderer { get; }

public GlInterface(Func<string, bool, IntPtr> getProcAddress) : base(getProcAddress)
{
var versionPtr = GetString(GlConsts.GL_VERSION);
if (versionPtr != IntPtr.Zero)
Version = Marshal.PtrToStringAnsi(versionPtr);
Version = GetString(GlConsts.GL_VERSION);
Renderer = GetString(GlConsts.GL_RENDERER);
Vendor = GetString(GlConsts.GL_VENDOR);
}

public GlInterface(Func<Utf8Buffer, IntPtr> n) : this(ConvertNative(n))
Expand Down Expand Up @@ -54,7 +56,15 @@ public static GlInterface FromNativeUtf8GetProcAddress(Func<Utf8Buffer, IntPtr>

public delegate IntPtr GlGetString(int v);
[GlEntryPoint("glGetString")]
public GlGetString GetString { get; }
public GlGetString GetStringNative { get; }

public string GetString(int v)
{
var ptr = GetStringNative(v);
if (ptr != IntPtr.Zero)
return Marshal.PtrToStringAnsi(ptr);
return null;
}

public delegate void GlGetIntegerv(int name, out int rv);
[GlEntryPoint("glGetIntegerv")]
Expand Down
7 changes: 6 additions & 1 deletion src/Avalonia.OpenGL/IGlPlatformSurfaceRenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ public interface IGlPlatformSurfaceRenderTarget : IDisposable
{
IGlPlatformSurfaceRenderingSession BeginDraw();
}
}

public interface IGlPlatformSurfaceRenderTargetWithCorruptionInfo : IGlPlatformSurfaceRenderTarget
{
bool IsCorrupted { get; }
}
}
5 changes: 5 additions & 0 deletions src/Avalonia.Visuals/Platform/IRenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ public interface IRenderTarget : IDisposable
/// </param>
IDrawingContextImpl CreateDrawingContext(IVisualBrushRenderer visualBrushRenderer);
}

public interface IRenderTargetWithCorruptionInfo : IRenderTarget
{
bool IsCorrupted { get; }
}
}
Loading

0 comments on commit 146d51c

Please sign in to comment.