Exemplo n.º 1
0
        public MaskedPointerShape(int Width, int Height, Direct2DEditorSession EditorSession)
        {
            this.Width     = Width;
            this.Height    = Height;
            _editorSession = EditorSession;

            var copyTexDesc = new Texture2DDescription
            {
                Width             = this.Width,
                Height            = this.Height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.B8G8R8A8_UNorm,
                SampleDescription =
                {
                    Count   = 1,
                    Quality = 0
                },
                Usage          = ResourceUsage.Staging,
                BindFlags      = 0,
                CpuAccessFlags = CpuAccessFlags.Read
            };

            _copyTex = new Texture2D(_editorSession.Device, copyTexDesc);

            ShapeBuffer   = new byte[Width * Height * 4];
            DesktopBuffer = new byte[Width * Height * 4];
        }
Exemplo n.º 2
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.º 3
0
        public FullScreenDesktopDuplicator(bool IncludeCursor,
                                           IPreviewWindow PreviewWindow,
                                           IPlatformServices PlatformServices)
        {
            using (var factory = new Factory1())
            {
                var outputs = factory
                              .Adapters1
                              .SelectMany(M => M.Outputs)
                              .ToArray();

                var bounds = PlatformServices.DesktopRectangle;

                Width  = bounds.Width;
                Height = bounds.Height;

                PointTransform = P => new Point(P.X - bounds.Left, P.Y - bounds.Top);

                _editorSession = new Direct2DEditorSession(Width, Height, PreviewWindow);

                _outputs.AddRange(outputs.Select(M =>
                {
                    var output1 = M.QueryInterface <Output1>();

                    var rect = M.Description.DesktopBounds;

                    return(new DeskDuplOutputEntry
                    {
                        DuplCapture = new DuplCapture(output1),
                        Location = new SharpDX.Point(rect.Left - bounds.Left, rect.Top - bounds.Top),
                        MousePointer = IncludeCursor ? new DxMousePointer(_editorSession) : null
                    });
                }));
            }
        }
Exemplo n.º 4
0
 public MaskedColorPointerShape(IntPtr ShapeBuffer,
                                OutputDuplicatePointerShapeInformation ShapeInfo,
                                Direct2DEditorSession EditorSession)
     : base(ShapeInfo.Width, ShapeInfo.Height, EditorSession)
 {
     _maskedShapeBuffer = new byte[Width * Height * 4];
     Marshal.Copy(ShapeBuffer, _maskedShapeBuffer, 0, _maskedShapeBuffer.Length);
 }
Exemplo n.º 5
0
        public Direct2DEditor(Direct2DEditorSession EditorSession)
        {
            _editorSession = EditorSession;

            Width  = EditorSession.StagingTexture.Description.Width;
            Height = EditorSession.StagingTexture.Description.Height;

            EditorSession.BeginDraw();
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        public Direct2DEditor(Direct2DEditorSession editorSession)
        {
            _editorSession = editorSession;

            var desc = editorSession.StagingTexture.Description;

            Width  = desc.Width;
            Height = desc.Height;

            editorSession.BeginDraw();
        }
Exemplo n.º 8
0
        public MonochromePointerShape(IntPtr ShapeBuffer,
                                      OutputDuplicatePointerShapeInformation ShapeInfo,
                                      Direct2DEditorSession EditorSession)
            : base(ShapeInfo.Width, ShapeInfo.Height / 2, EditorSession)
        {
            _andMaskBuffer = new byte[Width * Height / 8];
            Marshal.Copy(ShapeBuffer, _andMaskBuffer, 0, _andMaskBuffer.Length);

            _xorMaskBuffer = new byte[Width * Height / 8];
            Marshal.Copy(ShapeBuffer + _andMaskBuffer.Length, _xorMaskBuffer, 0, _xorMaskBuffer.Length);
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public void Dispose()
        {
            _bmp?.Dispose();
            _bmp = null;

            _copyTex?.Dispose();
            _copyTex = null;

            ShapeBuffer = DesktopBuffer = null;

            _editorSession = null;

            OnDispose();
        }
Exemplo n.º 11
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.º 12
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.º 13
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.º 14
0
        public void Dispose()
        {
            foreach (var entry in _outputs)
            {
                try { entry.MousePointer?.Dispose(); }
                catch { }
                finally { entry.MousePointer = null; }

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

            try { _editorSession.Dispose(); }
            catch { }
            finally { _editorSession = null; }
        }
Exemplo n.º 15
0
 public DxMousePointer(Direct2DEditorSession EditorSession)
 {
     _editorSession = EditorSession;
 }