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