Browse Source

Merge branch 'master' into port-bindingredirects

pull/967/head
Steven Kirk 9 years ago
committed by GitHub
parent
commit
6942695190
  1. 10
      src/Avalonia.Diagnostics/ViewModels/ControlDetailsViewModel.cs
  2. 49
      src/Avalonia.Diagnostics/ViewModels/TreeNode.cs
  3. 4
      src/Avalonia.Diagnostics/ViewModels/TreePageViewModel.cs
  4. 7
      src/Avalonia.Diagnostics/ViewModels/VisualTreeNode.cs
  5. 4
      src/Avalonia.Diagnostics/Views/TreePage.xaml.cs
  6. 2
      src/Windows/Avalonia.Direct2D1/Avalonia.Direct2D1.csproj
  7. 91
      src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
  8. 29
      src/Windows/Avalonia.Direct2D1/Direct2DChecker.cs
  9. 2
      src/Windows/Avalonia.Direct2D1/Properties/AssemblyInfo.cs
  10. 6
      src/Windows/Avalonia.Direct2D1/SwapChainRenderTarget.cs
  11. 15
      src/Windows/Avalonia.Direct2D1/WindowsVersionChecker.cs

10
src/Avalonia.Diagnostics/ViewModels/ControlDetailsViewModel.cs

@ -3,19 +3,19 @@
using System.Collections.Generic;
using System.Linq;
using Avalonia.Controls;
using Avalonia.VisualTree;
using ReactiveUI;
namespace Avalonia.Diagnostics.ViewModels
{
internal class ControlDetailsViewModel : ReactiveObject
{
public ControlDetailsViewModel(Control control)
public ControlDetailsViewModel(IVisual control)
{
if (control != null)
if (control is AvaloniaObject avaloniaObject)
{
Properties = AvaloniaPropertyRegistry.Instance.GetRegistered(control)
.Select(x => new PropertyDetails(control, x))
Properties = AvaloniaPropertyRegistry.Instance.GetRegistered(avaloniaObject)
.Select(x => new PropertyDetails(avaloniaObject, x))
.OrderBy(x => x.IsAttached)
.ThenBy(x => x.Name);
}

49
src/Avalonia.Diagnostics/ViewModels/TreeNode.cs

@ -5,8 +5,8 @@ using System;
using System.Collections.Specialized;
using System.Reactive;
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Styling;
using Avalonia.VisualTree;
using ReactiveUI;
namespace Avalonia.Diagnostics.ViewModels
@ -16,32 +16,35 @@ namespace Avalonia.Diagnostics.ViewModels
private string _classes;
private bool _isExpanded;
public TreeNode(Control control, TreeNode parent)
public TreeNode(IVisual visual, TreeNode parent)
{
Control = control;
Parent = parent;
Type = control.GetType().Name;
Type = visual.GetType().Name;
Visual = visual;
var classesChanged = Observable.FromEventPattern<
NotifyCollectionChangedEventHandler,
NotifyCollectionChangedEventArgs>(
x => control.Classes.CollectionChanged += x,
x => control.Classes.CollectionChanged -= x)
.TakeUntil(((IStyleable)control).StyleDetach);
if (visual is IStyleable styleable)
{
var classesChanged = Observable.FromEventPattern<
NotifyCollectionChangedEventHandler,
NotifyCollectionChangedEventArgs>(
x => styleable.Classes.CollectionChanged += x,
x => styleable.Classes.CollectionChanged -= x)
.TakeUntil(((IStyleable)styleable).StyleDetach);
classesChanged.Select(_ => Unit.Default)
.StartWith(Unit.Default)
.Subscribe(_ =>
{
if (control.Classes.Count > 0)
classesChanged.Select(_ => Unit.Default)
.StartWith(Unit.Default)
.Subscribe(_ =>
{
Classes = "(" + string.Join(" ", control.Classes) + ")";
}
else
{
Classes = string.Empty;
}
});
if (styleable.Classes.Count > 0)
{
Classes = "(" + string.Join(" ", styleable.Classes) + ")";
}
else
{
Classes = string.Empty;
}
});
}
}
public IReadOnlyReactiveList<TreeNode> Children
@ -56,7 +59,7 @@ namespace Avalonia.Diagnostics.ViewModels
private set { this.RaiseAndSetIfChanged(ref _classes, value); }
}
public Control Control
public IVisual Visual
{
get;
}

4
src/Avalonia.Diagnostics/ViewModels/TreePageViewModel.cs

@ -18,7 +18,7 @@ namespace Avalonia.Diagnostics.ViewModels
{
Nodes = nodes;
_details = this.WhenAnyValue(x => x.SelectedNode)
.Select(x => x != null ? new ControlDetailsViewModel(x.Control) : null)
.Select(x => x != null ? new ControlDetailsViewModel(x.Visual) : null)
.ToProperty(this, x => x.Details);
}
@ -79,7 +79,7 @@ namespace Avalonia.Diagnostics.ViewModels
private TreeNode FindNode(TreeNode node, IControl control)
{
if (node.Control == control)
if (node.Visual == control)
{
return node;
}

7
src/Avalonia.Diagnostics/ViewModels/VisualTreeNode.cs

@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Controls;
using Avalonia.Styling;
using Avalonia.VisualTree;
using ReactiveUI;
@ -10,7 +11,7 @@ namespace Avalonia.Diagnostics.ViewModels
internal class VisualTreeNode : TreeNode
{
public VisualTreeNode(IVisual visual, TreeNode parent)
: base((Control)visual, parent)
: base(visual, parent)
{
var host = visual as IVisualTreeHost;
@ -23,9 +24,9 @@ namespace Avalonia.Diagnostics.ViewModels
Children = new ReactiveList<VisualTreeNode>(new[] { new VisualTreeNode(host.Root, this) });
}
if (Control != null)
if ((Visual is IStyleable styleable))
{
IsInTemplate = Control.TemplatedParent != null;
IsInTemplate = styleable.TemplatedParent != null;
}
}

4
src/Avalonia.Diagnostics/Views/TreePage.xaml.cs

@ -23,14 +23,14 @@ namespace Avalonia.Diagnostics.Views
protected void AddAdorner(object sender, PointerEventArgs e)
{
var node = (TreeNode)((Control)sender).DataContext;
var layer = AdornerLayer.GetAdornerLayer(node.Control);
var layer = AdornerLayer.GetAdornerLayer(node.Visual);
if (layer != null)
{
_adorner = new Rectangle
{
Fill = new SolidColorBrush(0x80a0c5e8),
[AdornerLayer.AdornedElementProperty] = node.Control,
[AdornerLayer.AdornedElementProperty] = node.Visual,
};
layer.Children.Add(_adorner);

2
src/Windows/Avalonia.Direct2D1/Avalonia.Direct2D1.csproj

@ -73,7 +73,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RenderTarget.cs" />
<Compile Include="SwapChainRenderTarget.cs" />
<Compile Include="WindowsVersionChecker.cs" />
<Compile Include="Direct2DChecker.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

91
src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

@ -31,49 +31,76 @@ namespace Avalonia.Direct2D1
{
private static readonly Direct2D1Platform s_instance = new Direct2D1Platform();
private static readonly SharpDX.Direct2D1.Factory s_d2D1Factory =
#if DEBUG
new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.MultiThreaded, SharpDX.Direct2D1.DebugLevel.Error);
#else
new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.MultiThreaded, SharpDX.Direct2D1.DebugLevel.None);
#endif
private static readonly SharpDX.DirectWrite.Factory s_dwfactory = new SharpDX.DirectWrite.Factory();
private static SharpDX.Direct2D1.Factory s_d2D1Factory;
private static readonly SharpDX.WIC.ImagingFactory s_imagingFactory = new SharpDX.WIC.ImagingFactory();
private static SharpDX.DirectWrite.Factory s_dwfactory;
private static readonly SharpDX.DXGI.Device s_dxgiDevice;
private static SharpDX.WIC.ImagingFactory s_imagingFactory;
private static readonly SharpDX.Direct2D1.Device s_d2D1Device;
private static SharpDX.DXGI.Device s_dxgiDevice;
static Direct2D1Platform()
{
var featureLevels = new[]
{
SharpDX.Direct3D.FeatureLevel.Level_11_1,
SharpDX.Direct3D.FeatureLevel.Level_11_0,
SharpDX.Direct3D.FeatureLevel.Level_10_1,
SharpDX.Direct3D.FeatureLevel.Level_10_0,
SharpDX.Direct3D.FeatureLevel.Level_9_3,
SharpDX.Direct3D.FeatureLevel.Level_9_2,
SharpDX.Direct3D.FeatureLevel.Level_9_1,
};
using (var d3dDevice = new SharpDX.Direct3D11.Device(
SharpDX.Direct3D.DriverType.Hardware,
SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport,
featureLevels))
{
s_dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>();
}
private static SharpDX.Direct2D1.Device s_d2D1Device;
private static readonly object s_initLock = new object();
private static bool s_initialized = false;
using (var factory1 = s_d2D1Factory.QueryInterface<SharpDX.Direct2D1.Factory1>())
internal static void InitializeDirect2D()
{
lock (s_initLock)
{
s_d2D1Device = new SharpDX.Direct2D1.Device(factory1, s_dxgiDevice);
if (s_initialized)
return;
#if DEBUG
try
{
s_d2D1Factory =
new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.MultiThreaded,
SharpDX.Direct2D1.DebugLevel.Error);
}
catch
{
//
}
#endif
s_dwfactory = new SharpDX.DirectWrite.Factory();
s_imagingFactory = new SharpDX.WIC.ImagingFactory();
if (s_d2D1Factory == null)
s_d2D1Factory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.MultiThreaded,
SharpDX.Direct2D1.DebugLevel.None);
var featureLevels = new[]
{
SharpDX.Direct3D.FeatureLevel.Level_11_1,
SharpDX.Direct3D.FeatureLevel.Level_11_0,
SharpDX.Direct3D.FeatureLevel.Level_10_1,
SharpDX.Direct3D.FeatureLevel.Level_10_0,
SharpDX.Direct3D.FeatureLevel.Level_9_3,
SharpDX.Direct3D.FeatureLevel.Level_9_2,
SharpDX.Direct3D.FeatureLevel.Level_9_1,
};
using (var d3dDevice = new SharpDX.Direct3D11.Device(
SharpDX.Direct3D.DriverType.Hardware,
SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport |
SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport,
featureLevels))
{
s_dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>();
}
using (var factory1 = s_d2D1Factory.QueryInterface<SharpDX.Direct2D1.Factory1>())
{
s_d2D1Device = new SharpDX.Direct2D1.Device(factory1, s_dxgiDevice);
}
s_initialized = true;
}
}
public static void Initialize()
{
InitializeDirect2D();
AvaloniaLocator.CurrentMutable
.Bind<IPlatformRenderInterface>().ToConstant(s_instance)
.BindToSelf(s_d2D1Factory)

29
src/Windows/Avalonia.Direct2D1/Direct2DChecker.cs

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Platform;
namespace Avalonia.Direct2D1
{
class Direct2DChecker : IModuleEnvironmentChecker
{
//Direct2D backend doesn't work on some machines anymore
public bool IsCompatible
{
get
{
try
{
Direct2D1Platform.InitializeDirect2D();
return true;
}
catch
{
return false;
}
}
}
}
}

2
src/Windows/Avalonia.Direct2D1/Properties/AssemblyInfo.cs

@ -7,5 +7,5 @@ using Avalonia.Direct2D1;
[assembly: AssemblyTitle("Avalonia.Direct2D1")]
[assembly: ExportRenderingSubsystem(OperatingSystemType.WinNT, 1, "Direct2D1", typeof(Direct2D1Platform), nameof(Direct2D1Platform.Initialize),
typeof(WindowsVersionChecker))]
typeof(Direct2DChecker))]

6
src/Windows/Avalonia.Direct2D1/SwapChainRenderTarget.cs

@ -99,9 +99,9 @@ namespace Avalonia.Direct2D1
Quality = 0,
},
Usage = Usage.RenderTargetOutput,
BufferCount = 2,
Scaling = Scaling.None,
SwapEffect = SwapEffect.FlipSequential,
BufferCount = 1,
Scaling = Scaling.Stretch,
SwapEffect = SwapEffect.Discard,
Flags = 0,
};

15
src/Windows/Avalonia.Direct2D1/WindowsVersionChecker.cs

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Platform;
namespace Avalonia.Direct2D1
{
class WindowsVersionChecker : IModuleEnvironmentChecker
{
//Direct2D backend doesn't work with Win7 anymore
public bool IsCompatible => Environment.OSVersion.Version >= new Version(6, 2);
}
}
Loading…
Cancel
Save