Beispiel #1
0
        public DxCapture(int width, int height, int adapter, int monitor, FileLogger logger)
        {
            try
            {
                _logger = logger;
                _width  = width;
                _height = height;

                _factory = new Factory1();
                _adapter = _factory.GetAdapter1(adapter);
                _device  = new SharpDX.Direct3D11.Device(_adapter);

                _output           = _adapter.GetOutput(monitor);
                _output6          = _output.QueryInterface <Output6>();
                _duplicatedOutput = _output6.DuplicateOutput1(_device, 0, 1, new Format[] { Format.B8G8R8A8_UNorm });

                var textureDesc = 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
                };
                _screenTexture = new Texture2D(_device, textureDesc);
            }
            catch (Exception ex)
            {
                Task.Run(() => _logger?.WriteLog(ex.ToString()));
                throw;
            }
        }
Beispiel #2
0
        /// <summary>
        ///   Struct constructor
        /// </summary>
        /// <param name="adapter1">DXGI adapter device instance</param>
        /// <param name="output">DXGI output associated with this source</param>
        /// <param name="region">Region of the DXGI output device</param>
        internal DxgiCaptureSource(Adapter1 adapter1, Output output, Rectangle region)
        {
            Device   = null;
            Adapter1 = adapter1;
            Output   = output;
            Output1  = null;
            Output6  = null;
            Region   = region;

            if (region != output.Description.DesktopBounds)
            {
                Subregion = new ResourceRegion(region.Left - output.Description.DesktopBounds.Left,
                                               region.Top - output.Description.DesktopBounds.Top,
                                               0,
                                               region.Width + region.Left,
                                               region.Height + region.Top,
                                               1);
            }
            else
            {
                Subregion = null;
            }

            try {
                // create device
                Device = new Device(adapter1, DeviceCreationFlags.None, FeatureLevel.Level_11_0)
                {
#if DEBUG
                    DebugName = output.Description.DeviceName + " // " + adapter1.Description.Description
#endif
                };

                DxgiDevice = Device.QueryInterface <SharpDX.DXGI.Device>();

                // create texture
                Texture = new Texture2D(Device, new Texture2DDescription {
                    CpuAccessFlags    = CpuAccessFlags.Read,
                    BindFlags         = BindFlags.None,
                    Format            = Format.B8G8R8A8_UNorm,
                    Width             = region.Width,
                    Height            = region.Height,
                    OptionFlags       = ResourceOptionFlags.None,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    SampleDescription = { Count = 1, Quality = 0 },
                    Usage             = ResourceUsage.Staging
                });

                // duplicate desktop
                try {
                    Format[] formats = { Format.B8G8R8A8_UNorm };
                    Output6     = output.QueryInterface <Output6>();
                    Duplication = Output6.DuplicateOutput1(Device, 0, formats.Length, formats);
                } catch (Exception exception)
                    when(exception is NotSupportedException ||
                         exception.HResult == ResultCode.Unsupported.Result ||
                         exception.HResult == Result.NoInterface.Result)
                    {
                        Output1     = output.QueryInterface <Output1>();
                        Duplication = Output1.DuplicateOutput(Device);
                    }
            } catch (Exception exception)
                when(exception is NotSupportedException ||
                     exception is NotImplementedException ||
                     exception.HResult == ResultCode.Unsupported.Result ||
                     exception.HResult == Result.NotImplemented.Result ||
                     exception.HResult == Result.NoInterface.Result)
                {
                    throw new NotSupportedException("Platform not supported", exception);
                }

            Alive = true;
        }