MCPcopy Create free account
hub / github.com/Aleksoid1978/VideoRenderer / GetDisplayedImage

Method GetDisplayedImage

Source/DX11VideoProcessor.cpp:3610–3684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3608}
3609
3610HRESULT CDX11VideoProcessor::GetDisplayedImage(BYTE **ppDib, unsigned* pSize)
3611{
3612 if (!m_pDXGISwapChain1 || !m_pDevice || !m_pDeviceContext) {
3613 return E_ABORT;
3614 }
3615
3616 CComPtr<ID3D11Texture2D> pBackBuffer;
3617 HRESULT hr = m_pDXGISwapChain1->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
3618 if (FAILED(hr)) {
3619 DLog(L"CDX11VideoProcessor::GetDisplayedImage() failed with error {}", HR2Str(hr));
3620 return hr;
3621 }
3622
3623 D3D11_TEXTURE2D_DESC desc;
3624 pBackBuffer->GetDesc(&desc);
3625
3626 if (desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM && desc.Format != DXGI_FORMAT_R10G10B10A2_UNORM) {
3627 DLog(L"CDX11VideoProcessor::GetDisplayedImage() backbuffer format not supported");
3628 return E_FAIL;
3629 }
3630
3631 D3D11_TEXTURE2D_DESC desc2 = CreateTex2DDesc(desc.Format, desc.Width, desc.Height, Tex2D_StagingRead);
3632 CComPtr<ID3D11Texture2D> pTexture2DShared;
3633 hr = m_pDevice->CreateTexture2D(&desc2, nullptr, &pTexture2DShared);
3634 if (FAILED(hr)) {
3635 DLog(L"CDX11VideoProcessor::GetDisplayedImage() failed with error {}", HR2Str(hr));
3636 return hr;
3637 }
3638
3639 m_pDeviceContext->CopyResource(pTexture2DShared, pBackBuffer);
3640
3641 UINT dib_bitdepth;
3642 CopyFrameDataFn pConvertToDibFunc;
3643 if (desc2.Format == DXGI_FORMAT_R10G10B10A2_UNORM) {
3644 if (m_bAllowDeepColorBitmaps) {
3645 dib_bitdepth = 48;
3646 pConvertToDibFunc = ConvertR10G10B10A2toBGR48;
3647 } else {
3648 dib_bitdepth = 32;
3649 pConvertToDibFunc = ConvertR10G10B10A2toBGR32;
3650 }
3651 } else {
3652 dib_bitdepth = 32;
3653 pConvertToDibFunc = CopyPlaneAsIs;
3654 }
3655 const UINT dib_pitch = CalcDibRowPitch(desc.Width, dib_bitdepth);
3656 const UINT dib_size = dib_pitch * desc.Height;
3657
3658 *pSize = sizeof(BITMAPINFOHEADER) + dib_size;
3659 BYTE* p = (BYTE*)LocalAlloc(LMEM_FIXED, *pSize); // only this allocator can be used
3660 if (!p) {
3661 return E_OUTOFMEMORY;
3662 }
3663
3664 BITMAPINFOHEADER* pBIH = (BITMAPINFOHEADER*)p;
3665 ZeroMemory(pBIH, sizeof(BITMAPINFOHEADER));
3666 pBIH->biSize = sizeof(BITMAPINFOHEADER);
3667 pBIH->biWidth = desc.Width;

Callers

nothing calls this directly

Calls 6

DLogFunction · 0.85
HR2StrFunction · 0.85
CreateTex2DDescFunction · 0.85
CalcDibRowPitchFunction · 0.85
GetBufferMethod · 0.80
GetDescMethod · 0.45

Tested by

no test coverage detected