simplify GraphicsCaptureItem creation

This commit is contained in:
Lightczx 2023-10-12 13:12:29 +08:00
parent cfd03833ab
commit a2025264b4
3 changed files with 3 additions and 21 deletions

View File

@ -30,7 +30,6 @@ GetWindowTextLength
D3D11CreateDevice
ID3D11Device3
IDirect3DDxgiInterfaceAccess
IGraphicsCaptureItemInterop
// Constants
D3D11_SDK_VERSION

View File

@ -1,7 +1,6 @@
using System.Drawing;
using Vision.WindowCapture.GraphicsCapture.Helpers;
using Windows.Foundation.Metadata;
using Windows.Graphics;
using Windows.Graphics.Capture;
using Windows.Graphics.DirectX;
using Windows.Win32.Foundation;

View File

@ -24,39 +24,23 @@
using System.Diagnostics.CodeAnalysis;
using Windows.Graphics.Capture;
using Windows.Win32;
using Windows.UI;
using Windows.Win32.Foundation;
using Windows.Win32.System.WinRT.Graphics.Capture;
using WinRT;
using WinRT.Interop;
namespace Vision.WindowCapture.GraphicsCapture.Helpers;
public static class CaptureHelper
{
static readonly Guid IGraphicsCaptureItemGuid = Guid.Parse("79C3F95B-31F7-4EC2-A464-632EF5D30760");
public static void SetWindow(this GraphicsCapturePicker picker, IntPtr hwnd)
{
InitializeWithWindow.Initialize(picker, hwnd);
}
[return:MaybeNull]
public static GraphicsCaptureItem CreateItemForWindow(HWND hwnd)
public static unsafe GraphicsCaptureItem CreateItemForWindow(HWND hwnd)
{
GraphicsCaptureItem
.As<IGraphicsCaptureItemInterop>()
.CreateForWindow(hwnd, IGraphicsCaptureItemGuid, out var thisPtr);
try
{
return GraphicsCaptureItem.FromAbi(thisPtr);
}
finally
{
// TODO: not sure if release is needed
MarshalInspectable<GraphicsCaptureItem>.DisposeAbi(thisPtr);
}
return GraphicsCaptureItem.TryCreateFromWindowId(*(WindowId*)&hwnd);
}
//public static GraphicsCaptureItem CreateItemForMonitor(IntPtr hmon)