コード例 #1
0
        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;
        }
コード例 #2
0
        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);
            }
        }