Browse Source

Use the factory associated with the Direct2D1 device.

pull/850/head
Jeremy Koritzinsky 9 years ago
parent
commit
bde461f400
  1. 21
      src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
  2. 2
      src/Windows/Avalonia.Direct2D1/HwndRenderTarget.cs
  3. 12
      src/Windows/Avalonia.Direct2D1/SwapChainRenderTarget.cs

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

@ -28,17 +28,13 @@ namespace Avalonia.Direct2D1
{ {
private static readonly Direct2D1Platform s_instance = new Direct2D1Platform(); private static readonly Direct2D1Platform s_instance = new Direct2D1Platform();
private static readonly SharpDX.Direct2D1.Factory s_d2D1Factory =
#if DEBUG
new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.MultiThreaded, SharpDX.Direct2D1.DebugLevel.Error);
#else
new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.MultiThreaded, SharpDX.Direct2D1.DebugLevel.None);
#endif
private static readonly SharpDX.DirectWrite.Factory s_dwfactory = new SharpDX.DirectWrite.Factory(); private static readonly SharpDX.DirectWrite.Factory s_dwfactory = new SharpDX.DirectWrite.Factory();
private static readonly SharpDX.WIC.ImagingFactory s_imagingFactory = new SharpDX.WIC.ImagingFactory(); private static readonly SharpDX.WIC.ImagingFactory s_imagingFactory = new SharpDX.WIC.ImagingFactory();
private static readonly SharpDX.DXGI.Device s_device; private static readonly SharpDX.DXGI.Device s_dxgiDevice;
private static readonly SharpDX.Direct2D1.Device s_d2d1Device;
static Direct2D1Platform() static Direct2D1Platform()
{ {
@ -60,17 +56,20 @@ namespace Avalonia.Direct2D1
SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport | SharpDX.Direct3D11.DeviceCreationFlags.VideoSupport,
featureLevels)) featureLevels))
{ {
s_device = d3dDevice.QueryInterface<SharpDX.DXGI.Device>(); s_dxgiDevice = d3dDevice.QueryInterface<SharpDX.DXGI.Device>();
} }
s_d2d1Device = new SharpDX.Direct2D1.Device(s_dxgiDevice);
} }
public static void Initialize() => AvaloniaLocator.CurrentMutable public static void Initialize() => AvaloniaLocator.CurrentMutable
.Bind<IPlatformRenderInterface>().ToConstant(s_instance) .Bind<IPlatformRenderInterface>().ToConstant(s_instance)
.Bind<IRendererFactory>().ToConstant(s_instance) .Bind<IRendererFactory>().ToConstant(s_instance)
.BindToSelf(s_d2D1Factory) .BindToSelf(s_d2d1Device.Factory)
.BindToSelf(s_dwfactory) .BindToSelf(s_dwfactory)
.BindToSelf(s_imagingFactory) .BindToSelf(s_imagingFactory)
.BindToSelf(s_device); .BindToSelf(s_dxgiDevice)
.BindToSelf(s_d2d1Device);
public IBitmapImpl CreateBitmap(int width, int height) public IBitmapImpl CreateBitmap(int width, int height)
{ {
@ -110,7 +109,7 @@ namespace Avalonia.Direct2D1
public IRenderTargetBitmapImpl CreateRenderTargetBitmap(int width, int height) public IRenderTargetBitmapImpl CreateRenderTargetBitmap(int width, int height)
{ {
return new RenderTargetBitmapImpl(s_imagingFactory, s_d2D1Factory, width, height); return new RenderTargetBitmapImpl(s_imagingFactory, s_d2d1Device.Factory, width, height);
} }
public IStreamGeometryImpl CreateStreamGeometry() public IStreamGeometryImpl CreateStreamGeometry()

2
src/Windows/Avalonia.Direct2D1/HwndRenderTarget.cs

@ -20,7 +20,7 @@ namespace Avalonia.Direct2D1
protected override SwapChain1 CreateSwapChain(Factory2 dxgiFactory, SwapChainDescription1 swapChainDesc) protected override SwapChain1 CreateSwapChain(Factory2 dxgiFactory, SwapChainDescription1 swapChainDesc)
{ {
return new SwapChain1(dxgiFactory, Device, _hwnd, ref swapChainDesc); return new SwapChain1(dxgiFactory, DxgiDevice, _hwnd, ref swapChainDesc);
} }
protected override Size2F GetWindowDpi() protected override Size2F GetWindowDpi()

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

@ -25,7 +25,8 @@ namespace Avalonia.Direct2D1
protected SwapChainRenderTarget() protected SwapChainRenderTarget()
{ {
Device = AvaloniaLocator.Current.GetService<SharpDX.DXGI.Device>(); DxgiDevice = AvaloniaLocator.Current.GetService<SharpDX.DXGI.Device>();
D2DDevice = AvaloniaLocator.Current.GetService<Device>();
Direct2DFactory = AvaloniaLocator.Current.GetService<Factory>(); Direct2DFactory = AvaloniaLocator.Current.GetService<Factory>();
DirectWriteFactory = AvaloniaLocator.Current.GetService<SharpDX.DirectWrite.Factory>(); DirectWriteFactory = AvaloniaLocator.Current.GetService<SharpDX.DirectWrite.Factory>();
} }
@ -47,7 +48,9 @@ namespace Avalonia.Direct2D1
get; get;
} }
protected SharpDX.DXGI.Device Device { get; } protected SharpDX.DXGI.Device DxgiDevice { get; }
public Device D2DDevice { get; }
/// <summary> /// <summary>
/// Creates a drawing context for a rendering session. /// Creates a drawing context for a rendering session.
@ -76,12 +79,11 @@ namespace Avalonia.Direct2D1
private void CreateSwapChain() private void CreateSwapChain()
{ {
using (var d2dDevice = new Device(Device)) using (var dxgiAdaptor = DxgiDevice.Adapter)
using (var dxgiAdaptor = Device.Adapter)
using (var dxgiFactory = dxgiAdaptor.GetParent<Factory2>()) using (var dxgiFactory = dxgiAdaptor.GetParent<Factory2>())
{ {
_deviceContext?.Dispose(); _deviceContext?.Dispose();
_deviceContext = new DeviceContext(d2dDevice, DeviceContextOptions.None) {DotsPerInch = _savedDpi}; _deviceContext = new DeviceContext(D2DDevice, DeviceContextOptions.None) {DotsPerInch = _savedDpi};
var swapChainDesc = new SwapChainDescription1 var swapChainDesc = new SwapChainDescription1

Loading…
Cancel
Save