Small refactorings

This commit is contained in:
Darth Affe 2022-05-01 14:34:12 +02:00
parent dee0c096a6
commit 19080e6ec7
10 changed files with 1031 additions and 1041 deletions

View File

@ -11,15 +11,15 @@ using Vortice.Mathematics;
using MapFlags = Vortice.Direct3D11.MapFlags;
using ResultCode = Vortice.DXGI.ResultCode;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents a ScreenCapture using DirectX 11 desktop duplicaton.
/// https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
/// </summary>
// ReSharper disable once InconsistentNaming
public sealed class DX11ScreenCapture : IScreenCapture
{
/// <summary>
/// Represents a ScreenCapture using DirectX 11 desktop duplicaton.
/// https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api
/// </summary>
// ReSharper disable once InconsistentNaming
public sealed class DX11ScreenCapture : IScreenCapture
{
#region Constants
private static readonly FeatureLevel[] FEATURE_LEVELS =
@ -353,12 +353,12 @@ namespace ScreenCapture.NET
List<CaptureZone> captureZones = _captureZones.Keys.ToList();
Dispose();
using IDXGIAdapter1 adapter = _factory.GetAdapter1(Display.GraphicsCard.Index);
using IDXGIAdapter1 adapter = _factory.GetAdapter1(Display.GraphicsCard.Index) ?? throw new ApplicationException("Couldn't create DirectX-Adapter.");
D3D11.D3D11CreateDevice(adapter, DriverType.Unknown, DeviceCreationFlags.None, FEATURE_LEVELS, out _device).CheckError();
_context = _device.ImmediateContext;
_context = _device!.ImmediateContext;
_output = adapter.GetOutput(Display.Index);
_output = adapter.GetOutput(Display.Index) ?? throw new ApplicationException("Couldn't get DirectX-Output.");
using IDXGIOutput5 output = _output.QueryInterface<IDXGIOutput5>();
Texture2DDescription captureTextureDesc = new()
@ -426,5 +426,4 @@ namespace ScreenCapture.NET
}
#endregion
}
}

View File

@ -2,13 +2,13 @@
using System.Collections.Generic;
using Vortice.DXGI;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents a <see cref="IScreenCaptureService"/> using the <see cref="DX11ScreenCapture"/>.
/// </summary>
public class DX11ScreenCaptureService : IScreenCaptureService
{
/// <summary>
///
/// </summary>
public class DX11ScreenCaptureService : IScreenCaptureService
{
#region Properties & Fields
private readonly IDXGIFactory1 _factory;
@ -20,11 +20,11 @@ namespace ScreenCapture.NET
#region Constructors
/// <summary>
///
/// Initializes a new instance of the <see cref="DX11ScreenCaptureService"/> class.
/// </summary>
public DX11ScreenCaptureService()
{
DXGI.CreateDXGIFactory1(out _factory).CheckError();
DXGI.CreateDXGIFactory1(out _factory!).CheckError();
}
#endregion
@ -80,5 +80,4 @@ namespace ScreenCapture.NET
}
#endregion
}
}

View File

@ -2,14 +2,14 @@
using System;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <inheritdoc />
/// <summary>
/// Represents the information supplied with an <see cref="E:ScreenCapture.IDX11ScreenCapture.Updated" />-event.
/// </summary>
public class ScreenCaptureUpdatedEventArgs : EventArgs
{
/// <inheritdoc />
/// <summary>
/// Represents the information supplied with an <see cref="E:ScreenCapture.IDX11ScreenCapture.Updated" />-event.
/// </summary>
public class ScreenCaptureUpdatedEventArgs : EventArgs
{
#region Properties & Fields
/// <summary>
@ -31,5 +31,4 @@ namespace ScreenCapture.NET
}
#endregion
}
}

View File

@ -3,13 +3,13 @@
using System.Runtime.InteropServices;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Helper-class for DPI-related WIN-API calls.
/// </summary>
public static class DPIAwareness
{
/// <summary>
/// Helper-class for DPI-related WIN-API calls.
/// </summary>
public static class DPIAwareness
{
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool SetProcessDpiAwarenessContext(int dpiFlag);
@ -38,5 +38,4 @@ namespace ScreenCapture.NET
/// Sets the DPI-Awareness-Context to V2. This is needed to prevent issues when using desktop duplication.
/// </summary>
public static void Initalize() => SetProcessDpiAwarenessContext((int)DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
}
}

View File

@ -1,12 +1,12 @@
using System;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents the duplication of a single display.
/// </summary>
public interface IScreenCapture : IDisposable
{
/// <summary>
/// Represents the duplication of a single display.
/// </summary>
public interface IScreenCapture : IDisposable
{
/// <summary>
/// Gets the <see cref="Display"/> this capture is duplicating.
/// </summary>
@ -59,5 +59,4 @@ namespace ScreenCapture.NET
/// Restarts the <see cref="IScreenCapture"/>.
/// </summary>
void Restart();
}
}

View File

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
///
/// </summary>
public interface IScreenCaptureService : IDisposable
{
/// <summary>
///
/// </summary>
public interface IScreenCaptureService : IDisposable
{
/// <summary>
/// Gets a enumerable of all available graphics-cards.
/// </summary>
@ -27,5 +27,4 @@ namespace ScreenCapture.NET
/// <param name="display">The display to duplicate.</param>
/// <returns>The <see cref="IScreenCapture"/> for the give display.</returns>
IScreenCapture GetScreenCapture(Display display);
}
}

View File

@ -2,13 +2,13 @@
using System;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents the configuration for the detection and removal of black bars around the screen image.
/// </summary>
public sealed class BlackBarDetection
{
/// <summary>
/// Represents the configuration for the detection and removal of black bars around the screen image.
/// </summary>
public sealed class BlackBarDetection
{
#region Properties & Fields
private readonly CaptureZone _captureZone;
@ -138,5 +138,4 @@ namespace ScreenCapture.NET
}
#endregion
}
}

View File

@ -2,13 +2,13 @@
using System;
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents a duplicated region on the screen.
/// </summary>
public sealed class CaptureZone
{
/// <summary>
/// Represents a duplicated region on the screen.
/// </summary>
public sealed class CaptureZone
{
#region Properties & Fields
/// <summary>
@ -158,5 +158,4 @@ namespace ScreenCapture.NET
public override int GetHashCode() => Id;
#endregion
}
}

View File

@ -1,12 +1,12 @@
// ReSharper disable MemberCanBePrivate.Global
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents a display connected to graphics-card.
/// </summary>
public readonly struct Display
{
/// <summary>
/// Represents a display connected to graphics-card.
/// </summary>
public readonly struct Display
{
#region Properties & Fields
/// <summary>
@ -89,5 +89,4 @@ namespace ScreenCapture.NET
public static bool operator !=(Display left, Display right) => !(left == right);
#endregion
}
}

View File

@ -1,12 +1,12 @@
// ReSharper disable MemberCanBePrivate.Global
namespace ScreenCapture.NET
namespace ScreenCapture.NET;
/// <summary>
/// Represents a graphics-card.
/// </summary>
public readonly struct GraphicsCard
{
/// <summary>
/// Represents a graphics-card.
/// </summary>
public readonly struct GraphicsCard
{
#region Properties & Fields
/// <summary>
@ -82,5 +82,4 @@ namespace ScreenCapture.NET
public static bool operator !=(GraphicsCard left, GraphicsCard right) => !(left == right);
#endregion
}
}