private void ResetFramePool(SizeInt32 size, bool recreateDevice)
        {
            do
            {
                try
                {
                    if (recreateDevice)
                    {
                        _canvasDevice = new Microsoft.Graphics.Canvas.CanvasDevice();
                    }

                    _framePool.Recreate(
                        _canvasDevice,
                        DirectXPixelFormat.B8G8R8A8UIntNormalized,
                        2,
                        size);
                }
                // This is the device-lost convention for Win2D.
                catch (Exception e) when(_canvasDevice.IsDeviceLost(e.HResult))
                {
                    _canvasDevice  = null;
                    recreateDevice = true;
                }
            } while (_canvasDevice == null);
        }
Beispiel #2
0
        public Encoder(Microsoft.Graphics.Canvas.CanvasDevice canvasDevice, GraphicsCaptureItem item, Windows.UI.Composition.CompositionDrawingSurface surface)
        {
            //_device = device;
            _canvasDevice = canvasDevice;
            _captureItem  = item;
            _surface      = surface;

            _isRecording = false;


            CreateMediaObjects();
        }
        public MainPage()
        {
            InitializeComponent();

            ApplicationView.GetForCurrentView().SetPreferredMinSize(
                new Size(350, 200));

            if (!GraphicsCaptureSession.IsSupported())
            {
                IsEnabled = false;

                var dialog = new MessageDialog(
                    "Screen capture is not supported on this device for this release of Windows!",
                    "Screen capture unsupported");

                var ignored = dialog.ShowAsync();
                return;
            }

            _device = new Microsoft.Graphics.Canvas.CanvasDevice();
            //_device = Direct3D11Helpers.CreateDevice();

            var settings = GetCachedSettings();

            var names = new List <string>();

            names.Add(nameof(VideoEncodingQuality.HD1080p));
            names.Add(nameof(VideoEncodingQuality.HD720p));
            names.Add(nameof(VideoEncodingQuality.Uhd2160p));
            names.Add(nameof(VideoEncodingQuality.Uhd4320p));
            QualityComboBox.ItemsSource   = names;
            QualityComboBox.SelectedIndex = names.IndexOf(settings.Quality.ToString());

            var frameRates = new List <string> {
                "30fps", "60fps"
            };

            FrameRateComboBox.ItemsSource   = frameRates;
            FrameRateComboBox.SelectedIndex = frameRates.IndexOf($"{settings.FrameRate}fps");

            UseCaptureItemSizeCheckBox.IsChecked = settings.UseSourceSize;

            CanvasSetup();
        }
        public CaptureFrameWait(
            Microsoft.Graphics.Canvas.CanvasDevice canvasDevice,
            GraphicsCaptureItem item,
            Windows.UI.Composition.CompositionDrawingSurface surface,
            SizeInt32 size)
        {
            // _device = device;
            _canvasDevice = canvasDevice;
            _d3dDevice    = Direct3D11Helpers.CreateSharpDXDevice(_canvasDevice);
            _multithread  = _d3dDevice.QueryInterface <SharpDX.Direct3D11.Multithread>();
            _multithread.SetMultithreadProtected(true);
            _item        = item;
            _surface     = surface;
            _frameEvent  = new ManualResetEvent(false);
            _closedEvent = new ManualResetEvent(false);
            _events      = new[] { _closedEvent, _frameEvent };

            InitializeBlankTexture(size);
            InitializeCapture(size);

            _frameCounter = 0;
        }