How to switch Dx11 flip model to BitBlt model on same HWND

勇强 韩 136 Reputation points
2021-04-24T03:28:17.417+00:00

I used flip model to display video (Dx11) on an hWnd. Now I want to use BitBlt model of Direct3D9 to display video on the same hWnd. How can I turn off flip model of Dx11?
For special reasons, I need to turn off Dx11 after using Dx11 display, and then use DX9 to display video.
The actual test result is: even after I release both swapchain and d3ddevice, I still can't use the BitBlt model of Direct3D9 to display video. Is there something wrong with the release code?

reference MSDN:
Use flip model in an HWND that is not also targeted by other APIs, including DXGI bitblt presentation model, other versions of Direct3D, or GDI. Because bitblt model maintains an additional copy of the surface, you can add GDI and other Direct3D contents to the same HWND through piecemeal updates from Direct3D and GDI. When you use the flip model, only Direct3D content in flip model swap chains that the runtime passes to DWM are visible. The runtime ignores all other bitblt model Direct3D or GDI content updates.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,427 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Fei Xue - MSFT 1,111 Reputation points
    2021-06-02T01:58:45.033+00:00

    @勇强 韩 , After investigate the code further, there are two problems in the code.

    1.There is a problem with the way about using smart pointers. The original code in RenderFrameRGB is:

    else {  
    …  
            hres = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&m_pDXGIBackBuffer.p);  
            if (FAILED(hres)) {  
                return false;  
            }  
            m_pD3D11Ctx->UpdateSubresource(m_pDXGIBackBuffer, 0, NULL, m_pOneFrame, m_iWidth * 4, 0);  
        }  
    

    &m_pDXGIBackBuffer.p is wrong. This will overwrite the previous pointer value stored in m_pDXGIBackBuffer, causing the object to leak. The correct code is:

            CComQIPtr<ID3D11Texture2D> pDXGIBackBuffer;  
    
            hres = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pDXGIBackBuffer);  
    
            if (FAILED(hres)) {  
                return false;  
            }  
            m_pD3D11Ctx->UpdateSubresource(pDXGIBackBuffer, 0, NULL, m_pOneFrame, m_iWidth * 4, 0);  
    

    There are other places do the same thing. Though they are not leaking any objects, I suggest fix all of them.

    The following is fine, though, because the function takes an array of pointers and it does not modify the array:

    (ID3D11RenderTargetView * const *ppRenderTargetViews):  
        m_pD3D11Ctx->OMSetRenderTargets(1, &m_pRenderView.p, NULL);  
    

    2 . DWM appears to be still in the flip mode for the window.

    If you restart DWM.exe, Dx9 Blt (or Dx11 Blt or GDI) starts working. Since the DWM issue is complex and requires more time to investigate, please create a support case so that our engineers can work with you closely and help fix the issue as soon as possible. Please refer to the link below and click the Contact US to open a support case:

    https://developer.microsoft.com/en-us/windows/support/

    0 comments No comments