mirror of
https://github.com/DarthAffe/ScreenCapture.NET.git
synced 2025-12-13 05:48:39 +00:00
Small refactorings
This commit is contained in:
parent
dee0c096a6
commit
19080e6ec7
@ -11,15 +11,15 @@ using Vortice.Mathematics;
|
|||||||
using MapFlags = Vortice.Direct3D11.MapFlags;
|
using MapFlags = Vortice.Direct3D11.MapFlags;
|
||||||
using ResultCode = Vortice.DXGI.ResultCode;
|
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
|
#region Constants
|
||||||
|
|
||||||
private static readonly FeatureLevel[] FEATURE_LEVELS =
|
private static readonly FeatureLevel[] FEATURE_LEVELS =
|
||||||
@ -353,12 +353,12 @@ namespace ScreenCapture.NET
|
|||||||
List<CaptureZone> captureZones = _captureZones.Keys.ToList();
|
List<CaptureZone> captureZones = _captureZones.Keys.ToList();
|
||||||
Dispose();
|
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();
|
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>();
|
using IDXGIOutput5 output = _output.QueryInterface<IDXGIOutput5>();
|
||||||
|
|
||||||
Texture2DDescription captureTextureDesc = new()
|
Texture2DDescription captureTextureDesc = new()
|
||||||
@ -426,5 +426,4 @@ namespace ScreenCapture.NET
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -2,13 +2,13 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Vortice.DXGI;
|
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
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly IDXGIFactory1 _factory;
|
private readonly IDXGIFactory1 _factory;
|
||||||
@ -20,11 +20,11 @@ namespace ScreenCapture.NET
|
|||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Initializes a new instance of the <see cref="DX11ScreenCaptureService"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DX11ScreenCaptureService()
|
public DX11ScreenCaptureService()
|
||||||
{
|
{
|
||||||
DXGI.CreateDXGIFactory1(out _factory).CheckError();
|
DXGI.CreateDXGIFactory1(out _factory!).CheckError();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -80,5 +80,4 @@ namespace ScreenCapture.NET
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
using System;
|
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
|
#region Properties & Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,5 +31,4 @@ namespace ScreenCapture.NET
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
using System.Runtime.InteropServices;
|
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)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
internal static extern bool SetProcessDpiAwarenessContext(int dpiFlag);
|
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.
|
/// Sets the DPI-Awareness-Context to V2. This is needed to prevent issues when using desktop duplication.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Initalize() => SetProcessDpiAwarenessContext((int)DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
public static void Initalize() => SetProcessDpiAwarenessContext((int)DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
using System;
|
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>
|
/// <summary>
|
||||||
/// Gets the <see cref="Display"/> this capture is duplicating.
|
/// Gets the <see cref="Display"/> this capture is duplicating.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -59,5 +59,4 @@ namespace ScreenCapture.NET
|
|||||||
/// Restarts the <see cref="IScreenCapture"/>.
|
/// Restarts the <see cref="IScreenCapture"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Restart();
|
void Restart();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,13 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ScreenCapture.NET
|
namespace ScreenCapture.NET;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public interface IScreenCaptureService : IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public interface IScreenCaptureService : IDisposable
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a enumerable of all available graphics-cards.
|
/// Gets a enumerable of all available graphics-cards.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -27,5 +27,4 @@ namespace ScreenCapture.NET
|
|||||||
/// <param name="display">The display to duplicate.</param>
|
/// <param name="display">The display to duplicate.</param>
|
||||||
/// <returns>The <see cref="IScreenCapture"/> for the give display.</returns>
|
/// <returns>The <see cref="IScreenCapture"/> for the give display.</returns>
|
||||||
IScreenCapture GetScreenCapture(Display display);
|
IScreenCapture GetScreenCapture(Display display);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
using System;
|
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
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly CaptureZone _captureZone;
|
private readonly CaptureZone _captureZone;
|
||||||
@ -138,5 +138,4 @@ namespace ScreenCapture.NET
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
using System;
|
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
|
#region Properties & Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -158,5 +158,4 @@ namespace ScreenCapture.NET
|
|||||||
public override int GetHashCode() => Id;
|
public override int GetHashCode() => Id;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// 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
|
#region Properties & Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -89,5 +89,4 @@ namespace ScreenCapture.NET
|
|||||||
public static bool operator !=(Display left, Display right) => !(left == right);
|
public static bool operator !=(Display left, Display right) => !(left == right);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// 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
|
#region Properties & Fields
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -82,5 +82,4 @@ namespace ScreenCapture.NET
|
|||||||
public static bool operator !=(GraphicsCard left, GraphicsCard right) => !(left == right);
|
public static bool operator !=(GraphicsCard left, GraphicsCard right) => !(left == right);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user