为了支持播放多声乐和录音,我需要将ID2D1HwndRenderTarget设置为D2D1_RENDER_TARGET_TYPE_SOFTWARE类型(请参阅https://docs.microsoft.com/en-us/windows/desktop/Direct2D/resources-and-resource-domains#sharing_render_target_resources),但是找到了我的本地计算机(CPU i7-7710、16G内存,Geforce GTX1060 6GB)测试绘图(“ _pRenderTarget-> EndDraw()”)的性能瓶颈相对较高:
HRESULT CD2D1Context::Present()
{
if (!_pRenderTarget || !_pBackRenderTarget)
{
return E_FAIL;
}
CComPtr<ID2D1Bitmap> pBackBitmap;
HRESULT hr = _pBackRenderTarget->GetBitmap(&pBackBitmap);
if (FAILED(hr))
{
return hr;
}
_pRenderTarget->BeginDraw();
_pRenderTarget->Clear(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f));
D2D1_SIZE_F sizeF = pBackBitmap->GetSize();
_pRenderTarget->DrawBitmap(pBackBitmap, D2D1::RectF(0, 0, sizeF.width, sizeF.height));
hr = _pRenderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET)
{
hr = S_OK;
DiscardDeviceResources();
}
return hr;
}