public override bool BeginDraw()
        {
            if (GraphicsDevice != null && Window.Visible)
            {
                savedPresenter = GraphicsDevice.Presenter;
                savedViewport = GraphicsDevice.Viewport;

                CreateOrUpdatePresenter();

                if (isBackBufferToResize || windowUserResized)
                {
                    PixelFormat resizeFormat;
                    var size = GetRequestedSize(out resizeFormat);
                    Presenter.Resize(size.Width, size.Height, resizeFormat);

                    isBackBufferToResize = false;
                    windowUserResized = false;
                }

                GraphicsDevice.Presenter = Presenter;
                GraphicsDevice.SetViewport(Presenter.DefaultViewport);
                GraphicsDevice.SetRenderTargets(Presenter.DepthStencilBuffer, Presenter.BackBuffer);

                beginDrawOk = true;
                return true;
            }

            beginDrawOk = false;
            return false;
        }
        /// <summary>
        /// Prepares control surface for rendering.
        /// </summary>
        private void StartRendering()
        {
            Debug.Assert(_presenter == null);
            Debug.Assert(_graphicsDevice.Presenter == null);
            Debug.Assert(_graphicsDevice != null);

            Redraw();

            var parameters = new PresentationParameters((int)ActualWidth, (int)ActualHeight, swapChainPanel);

            _presenter = _disposeCollector.Collect(new SwapChainGraphicsPresenter(_graphicsDevice, parameters));
            _graphicsDevice.Presenter = _presenter;

            Debug.Assert(_bitmapTarget == null);

            CreateD2DRenderTarget();

            CompositionTarget.Rendering += HandleRendering;
        }
Exemple #3
0
        public void ResizePresenter()
        {
            int width = m_host.HostedWindowWidth;
            int height = m_host.HostedWindowHeight;

            if (width == 0 || height == 0)
            {
                RemoveAndDispose(ref m_presenter);
                return;
            }

            bool sizeChanged;

            if (m_presenter == null)
            {
                var presentParams = new PresentationParameters(width, height, m_host.Handle, m_pixelFormat)
                {
                    PresentationInterval = PresentInterval.Immediate,
                };

                m_presenter = ToDispose(new SwapChainGraphicsPresenter(m_device, presentParams));

                sizeChanged = true;
            }
            else
            {
                // Resize is a no-op if the size hasn't changed
                sizeChanged = m_presenter.Resize(width, height, m_pixelFormat);
            }

            if (sizeChanged)
            {
                if (this.SizeChanged != null)
                    this.SizeChanged(width, height);
            }
        }
        /// <summary>
        /// Unloads content and disposes all unmanaged resources.
        /// </summary>
        private void DisposeAndUnloadContent()
        {
            _disposeCollector.DisposeAndClear();

            _d2dDeviceContext = null;
            _d2dDevice = null;
            _dwFactory = null;
            _presenter = null;
            _graphicsDevice = null;
        }