Exemplo n.º 1
0
        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; }
        }
Exemplo n.º 2
0
        public DesktopDuplicator(bool IncludeCursor, Output1 Output)
        {
            _device = new Device(DriverType.Hardware,
                                 DeviceCreationFlags.BgraSupport,
                                 FeatureLevel.Level_11_1);

            // HACK: Don't know why but creating a separate device solves AccessViolationExceptions happening otherwise
            using (var adapter = Output.GetParent <Adapter>())
                _deviceForDeskDupl = new Device(adapter);

            _duplCapture = new DuplCapture(_deviceForDeskDupl, 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);
            }
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            try { _mousePointer?.Dispose(); }
            catch { }
            finally { _mousePointer = null; }

            try { _duplCapture.Dispose(); }
            catch { }
            finally { _duplCapture = null; }

            try { _editorSession.Dispose(); }
            catch { }
            finally { _editorSession = null; }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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; }
        }
Exemplo n.º 6
0
        public DesktopDuplicator(Rectangle Rect, bool IncludeCursor, Adapter Adapter, Output1 Output)
        {
            _device = new Device(Adapter);

            _duplCapture   = new DuplCapture(_device, Output);
            _rect          = Rect;
            _includeCursor = IncludeCursor;

            var textureDesc = new Texture2DDescription
            {
                CpuAccessFlags    = CpuAccessFlags.Read,
                BindFlags         = BindFlags.None,
                Format            = Format.B8G8R8A8_UNorm,
                Width             = Rect.Width,
                Height            = Rect.Height,
                OptionFlags       = ResourceOptionFlags.None,
                MipLevels         = 1,
                ArraySize         = 1,
                SampleDescription = { Count = 1, Quality = 0 },
                Usage             = ResourceUsage.Staging
            };

            _desktopImageTexture = new Texture2D(_device, textureDesc);
        }