public bool Get(Texture2D Texture, DxMousePointer DxMousePointer, Point TargetPosition = default) { lock (_syncLock) { // Disposed if (_device == null) { return(false); } if (_bkpTexture == null) { var desc = Texture.Description; desc.Width = _width; desc.Height = _height; // _device is being used by Desktop Duplication _bkpTexture = new Texture2D(Texture.Device, desc); } var acquireResult = _frameGrabber.Grab(); if (acquireResult == null) { // _device is being used by Desktop Duplication Texture.Device.ImmediateContext.CopySubresourceRegion(_bkpTexture, 0, new ResourceRegion(0, 0, 0, _width, _height, 1), Texture, 0, TargetPosition.X, TargetPosition.Y); return(true); } if (acquireResult.Result.Failure) { throw new Exception($"Failed to acquire next frame: {acquireResult.Result.Code}"); } using (acquireResult.DesktopResource) using (var tempTexture = acquireResult.DesktopResource.QueryInterface <Texture2D>()) { DxMousePointer?.Update(tempTexture, acquireResult.FrameInfo, _deskDupl); Texture.Device.ImmediateContext.CopySubresourceRegion(tempTexture, 0, new ResourceRegion(0, 0, 0, _width, _height, 1), Texture, 0, TargetPosition.X, TargetPosition.Y); _device.ImmediateContext.CopyResource(tempTexture, _bkpTexture); } _frameGrabber.Release(); return(true); } }
public void Dispose() { try { _mousePointer?.Dispose(); } catch { } finally { _mousePointer = null; } try { _editorSession.Dispose(); } catch { } finally { _editorSession = null; } try { _duplCapture.Dispose(); } catch { } finally { _duplCapture = null; } try { _desktopImageTexture.Dispose(); } catch { } finally { _desktopImageTexture = null; } try { _stagingTexture.Dispose(); } catch { } finally { _stagingTexture = null; } try { _device.Dispose(); } catch { } finally { _device = null; } try { _deviceForDeskDupl.Dispose(); } catch { } finally { _deviceForDeskDupl = null; } }
public void Dispose() { try { _mousePointer?.Dispose(); } catch { // Ignored in dispose } _mousePointer = null; try { _editorSession.Dispose(); } catch { // Ignored in dispose } _editorSession = null; try { _desktopDuplicationCapture.Dispose(); } catch { // Ignored in dispose } _desktopDuplicationCapture = null; try { _desktopImageTexture.Dispose(); } catch { // Ignored in dispose } _desktopImageTexture = null; try { _stagingTexture.Dispose(); } catch { // Ignored in dispose } _stagingTexture = null; try { _device.Dispose(); } catch { // Ignored in dispose } _device = null; try { _deviceForDesktopDuplication.Dispose(); } catch { // Ignored in dispose } _deviceForDesktopDuplication = null; }
public DesktopDuplicator(bool includeCursor, Output1 output) { _device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_11_1); // Separate Device required otherwise AccessViolationException happens using (var adapter = output.GetParent <Adapter>()) _deviceForDesktopDuplication = new Device(adapter); _desktopDuplicationCapture = new DesktopDuplicationCapture(_deviceForDesktopDuplication, output); var bounds = output.Description.DesktopBounds; var width = bounds.Right - bounds.Left; var height = bounds.Bottom - bounds.Top; _stagingTexture = new Texture2D(_device, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }); _desktopImageTexture = new Texture2D(_device, new Texture2DDescription { CpuAccessFlags = CpuAccessFlags.None, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm, Width = width, Height = height, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Default }); _editorSession = new Direct2DEditorSession(_desktopImageTexture, _device, _stagingTexture); if (includeCursor) { _mousePointer = new DxMousePointer(_editorSession); } }
public void Dispose() { try { _mousePointer?.Dispose(); } catch { } finally { _mousePointer = null; } try { _duplCapture.Dispose(); } catch { } finally { _duplCapture = null; } try { _editorSession.Dispose(); } catch { } finally { _editorSession = null; } }
public DesktopDuplicator(bool IncludeCursor, Output1 Output, IPreviewWindow PreviewWindow) { _duplCapture = new DuplCapture(Output); var bounds = Output.Description.DesktopBounds; var width = bounds.Right - bounds.Left; var height = bounds.Bottom - bounds.Top; _editorSession = new Direct2DEditorSession(width, height, PreviewWindow); if (IncludeCursor) { _mousePointer = new DxMousePointer(_editorSession); } }
public void Dispose() { try { _duplCapture.Dispose(); } catch { } finally { _duplCapture = null; } // Mouse Pointer disposed later to prevent errors. try { _mousePointer?.Dispose(); } catch { } finally { _mousePointer = null; } try { _editorSession.Dispose(); } catch { } finally { _editorSession = null; } }
public bool Get(Texture2D texture, DxMousePointer dxMousePointer) { lock (_syncLock) { if (_acquireTask == null) { BeginAcquireFrame(); return(false); } var acquireResult = _acquireTask.Result; if (acquireResult.Result == ResultCode.WaitTimeout) { BeginAcquireFrame(); return(false); } if (acquireResult.Result.Failure) { throw new Exception($"Failed to acquire next frame: {acquireResult.Result.Code}"); } using (acquireResult.DesktopResource) using (var tempTexture = acquireResult.DesktopResource.QueryInterface <Texture2D>()) { dxMousePointer?.Update(tempTexture, acquireResult.FrameInfo, _outputDuplication); _device.ImmediateContext.CopyResource(tempTexture, texture); } _outputDuplication.ReleaseFrame(); BeginAcquireFrame(); return(true); } }
public bool Get(Texture2D Texture, DxMousePointer DxMousePointer) { lock (_syncLock) { if (_bkpTexture == null) { // _device is being used by Desktop Duplication _bkpTexture = new Texture2D(Texture.Device, Texture.Description); } var acquireResult = _frameGrabber.Grab(); if (acquireResult == null) { // _device is being used by Desktop Duplication Texture.Device.ImmediateContext.CopyResource(_bkpTexture, Texture); return(true); } if (acquireResult.Result.Failure) { throw new Exception($"Failed to acquire next frame: {acquireResult.Result.Code}"); } using (acquireResult.DesktopResource) using (var tempTexture = acquireResult.DesktopResource.QueryInterface <Texture2D>()) { DxMousePointer?.Update(tempTexture, acquireResult.FrameInfo, _deskDupl); _device.ImmediateContext.CopyResource(tempTexture, Texture); _device.ImmediateContext.CopyResource(tempTexture, _bkpTexture); } _frameGrabber.Release(); return(true); } }