locked
DPI change and window size change code in Direct3Dtutorial

    Question

  • I'm learning Direct3D tutorial code sample, lession 5. In file DirectXBase.cpp, the code handles DPI change and window size change is written as

    // Helps track the DPI in the helper class.
    // This is called in the dpiChanged event handler in the view class.
    void DirectXBase::SetDpi(float dpi)
    {
        if (dpi != m_dpi)
        {
            // Save the DPI of this display in our class.
            m_dpi = dpi;
    
            // Update Direct2D's stored DPI.
            m_d2dContext->SetDpi(m_dpi, m_dpi);
    
            // Often a DPI change implies a window size change. In some cases Windows will issue
            // both a size changed event and a DPI changed event. In this case, the resulting bounds
            // will not change, and the window resize code will only be executed once.
            UpdateForWindowSizeChange();
        }
    }
    
    // This routine is called in the event handler for the view SizeChanged event.
    void DirectXBase::UpdateForWindowSizeChange()
    {
        // Only handle window size changed if there is no pending DPI change.
        if (m_dpi != DisplayProperties::LogicalDpi)
        {
            return;
        }
    
        if (m_window->Bounds.Width  != m_windowBounds.Width ||
            m_window->Bounds.Height != m_windowBounds.Height)
        {
            m_d2dContext->SetTarget(nullptr);
            m_d2dTargetBitmap = nullptr;
            m_renderTargetView = nullptr;
            m_depthStencilView = nullptr;
            CreateWindowSizeDependentResources();
        }
    }

    The code looks elusive at first. Afer some analysis, I thought the code makes sense. The window resize code is guaruanteed to run only once.

            m_d2dContext->SetTarget(nullptr);
            m_d2dTargetBitmap = nullptr;
            m_renderTargetView = nullptr;
            m_depthStencilView = nullptr;
            CreateWindowSizeDependentResources();
    
    But I still don't understand the sentense "In this case, the resulting bounds will not change". I guess the resulting bounds refers to the CoreWindow::Bounds property and will always change if DPI is changed.
    Thursday, July 12, 2012 2:54 PM

Answers

  • I think it is saying that the result of  (m_window->Bounds.Width  != m_windowBounds.Width || m_window->Bounds.Height != m_windowBounds.Height)  is  FALSE when DPI changed.



    C++ DX11

    Monday, July 16, 2012 3:56 PM