int CCaptureFrame::CaptureFrameDX8(IDirect3DDevice8* pDevice)
{
dbgprintf("fps=%d", frameRate.m_curFPS);
IDirect3DSurface8 *pBackBuffer = 0;
if (frameRate.CheckFrameRate()==0)
{
if (GetFrameInfoDX8(pDevice, &pBackBuffer)==0)
{
//need capture
switch (m_bbFormat)
{
case D3DFMT_R8G8B8:
case D3DFMT_A8R8G8B8:
case D3DFMT_X8R8G8B8:
case D3DFMT_R5G6B5:
case D3DFMT_X1R5G5B5:
break;
default:
dynlog.Log("CaptureFrameDX8 Error -1");
return -1;
}
HRESULT hRes;
// copy rect to a new surface and lock the rect there.
// NOTE: apparently, this works faster than locking a rect on the back buffer itself.
// LOOKS LIKE: reading from the backbuffer is faster via CopyRects, but writing
// is faster if done directly.
if (m_pSurfTemp==NULL || m_bFrameInfoChg)
{
m_bFrameInfoChg = FALSE;
if (m_pSurfTemp) m_pSurfTemp->Release();
hRes = pDevice->CreateImageSurface(m_bbSize.cx, m_bbSize.cy, m_bbFormat,
&m_pSurfTemp);
if (FAILED(hRes))
{
if(pBackBuffer) pBackBuffer->Release();
dynlog.Log("CaptureFrameDX8 Error -3 hres=%X", hRes);
return -3;
}
}
RECT Rect = {0, 0, m_bbSize.cx, m_bbSize.cy};
POINT points[] = {{0, 0}};
hRes = pDevice->CopyRects(pBackBuffer, &Rect, 1, m_pSurfTemp, points);
if (FAILED(hRes))
{
if(pBackBuffer) pBackBuffer->Release();
dynlog.Log("CaptureFrameDX8 Error -4 hres=%X", hRes);
return -4;
}
D3DLOCKED_RECT lockedSrcRect;
RECT newRect = {0, 0, m_bbSize.cx, m_bbSize.cy};
hRes = m_pSurfTemp->LockRect(&lockedSrcRect, &newRect, 0);
if (FAILED(hRes))
{
if(pBackBuffer) pBackBuffer->Release();
dynlog.Log("CaptureFrameDX8 Error -5");
return -5;
}
int size = m_bbSize.cx*m_bbSize.cy*3;
CVideoFrame * frame = m_aviFile.GetAvailFrame(size);
//m_aviFile.m_FrameList.InsertFreeFrame(frame);
hRes = GetFrameFullSizeDX8(lockedSrcRect, frame);
if (m_pSurfTemp)
{
m_pSurfTemp->UnlockRect();
}
if(pBackBuffer) pBackBuffer->Release();
return 0;
}
}
return 0;
}