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 { _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 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); } }