@@ -271,7 +271,7 @@ BOOL CProxyDirect3DDevice9::ShowCursor(BOOL bShow)
271271
272272HRESULT CProxyDirect3DDevice9::CreateAdditionalSwapChain (D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain)
273273{
274- return m_pDevice-> CreateAdditionalSwapChain ( pPresentationParameters, pSwapChain);
274+ return CDirect3DEvents9::CreateAdditionalSwapChainGuarded (m_pDevice, pPresentationParameters, pSwapChain);
275275}
276276
277277HRESULT CProxyDirect3DDevice9::GetSwapChain (UINT iSwapChain, IDirect3DSwapChain9** pSwapChain)
@@ -499,18 +499,32 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
499499
500500HRESULT CProxyDirect3DDevice9::Present (CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
501501{
502- CDirect3DEvents9::OnPresent (m_pDevice);
503-
504502 // Reset frame stat counters
505503 memset (&DeviceState.FrameStats , 0 , sizeof (DeviceState.FrameStats ));
506504
505+ bool bDeviceTemporarilyLost = false ;
506+ HRESULT hrCoopLevel = D3DERR_INVALIDCALL;
507+ if (!CDirect3DEvents9::IsDeviceOperational (m_pDevice, &bDeviceTemporarilyLost, &hrCoopLevel))
508+ {
509+ if (bDeviceTemporarilyLost)
510+ WriteDebugEvent (SString (" CProxyDirect3DDevice9::Present skipped due to device state: %08x" , hrCoopLevel));
511+ else if (hrCoopLevel != D3D_OK)
512+ WriteDebugEvent (SString (" CProxyDirect3DDevice9::Present unexpected cooperative level: %08x" , hrCoopLevel));
513+ else
514+ WriteDebugEvent (" CProxyDirect3DDevice9::Present invalid device state" );
515+
516+ return (hrCoopLevel != D3D_OK) ? hrCoopLevel : D3DERR_INVALIDCALL;
517+ }
518+
519+ CDirect3DEvents9::OnPresent (m_pDevice);
520+
507521 // A fog flicker fix for some ATI cards
508522 D3DMATRIX projMatrix;
509523 m_pData->GetTransform (D3DTS_PROJECTION, &projMatrix);
510524 m_pDevice->SetTransform (D3DTS_PROJECTION, &projMatrix);
511525
512526 TIMING_GRAPH (" Present" );
513- HRESULT hr = m_pDevice-> Present ( pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
527+ HRESULT hr = CDirect3DEvents9::PresentGuarded (m_pDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
514528 TIMING_GRAPH (" PostPresent" );
515529 return hr;
516530}
@@ -634,13 +648,13 @@ HRESULT CProxyDirect3DDevice9::CreateTexture(UINT Width, UINT Height, UINT Level
634648HRESULT CProxyDirect3DDevice9::CreateVolumeTexture (UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
635649 IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle)
636650{
637- return m_pDevice-> CreateVolumeTexture ( Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
651+ return CDirect3DEvents9::CreateVolumeTextureGuarded (m_pDevice, Width, Height, Depth, Levels, Usage, Format, Pool, ppVolumeTexture, pSharedHandle);
638652}
639653
640654HRESULT CProxyDirect3DDevice9::CreateCubeTexture (UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
641655 IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle)
642656{
643- return m_pDevice-> CreateCubeTexture ( EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
657+ return CDirect3DEvents9::CreateCubeTextureGuarded (m_pDevice, EdgeLength, Levels, Usage, Format, Pool, ppCubeTexture, pSharedHandle);
644658}
645659
646660HRESULT CProxyDirect3DDevice9::CreateVertexBuffer (UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer,
@@ -658,57 +672,56 @@ HRESULT CProxyDirect3DDevice9::CreateIndexBuffer(UINT Length, DWORD Usage, D3DFO
658672HRESULT CProxyDirect3DDevice9::CreateRenderTarget (UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
659673 BOOL Lockable, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle)
660674{
661- return m_pDevice-> CreateRenderTarget ( Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle);
675+ return CDirect3DEvents9::CreateRenderTargetGuarded (m_pDevice, Width, Height, Format, MultiSample, MultisampleQuality, Lockable, ppSurface, pSharedHandle);
662676}
663677
664678HRESULT CProxyDirect3DDevice9::CreateDepthStencilSurface (UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
665679 BOOL Discard, IDirect3DSurface9** ppSurface, HANDLE* pSharedHandle)
666680{
667- return m_pDevice-> CreateDepthStencilSurface ( Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle);
681+ return CDirect3DEvents9::CreateDepthStencilSurfaceGuarded (m_pDevice, Width, Height, Format, MultiSample, MultisampleQuality, Discard, ppSurface, pSharedHandle);
668682}
669683
670684HRESULT CProxyDirect3DDevice9::UpdateSurface (IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestinationSurface,
671685 CONST POINT* pDestPoint)
672686{
673- return m_pDevice-> UpdateSurface ( pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
687+ return CDirect3DEvents9::UpdateSurfaceGuarded (m_pDevice, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
674688}
675689
676690HRESULT CProxyDirect3DDevice9::UpdateTexture (IDirect3DBaseTexture9* pSourceTexture, IDirect3DBaseTexture9* pDestinationTexture)
677691{
678- return m_pDevice-> UpdateTexture ( pSourceTexture, pDestinationTexture);
692+ return CDirect3DEvents9::UpdateTextureGuarded (m_pDevice, pSourceTexture, pDestinationTexture);
679693}
680694
681695HRESULT CProxyDirect3DDevice9::GetRenderTargetData (IDirect3DSurface9* pRenderTarget, IDirect3DSurface9* pDestSurface)
682696{
683- return m_pDevice-> GetRenderTargetData ( pRenderTarget, pDestSurface);
697+ return CDirect3DEvents9::GetRenderTargetDataGuarded (m_pDevice, pRenderTarget, pDestSurface);
684698}
685699
686700HRESULT CProxyDirect3DDevice9::GetFrontBufferData (UINT iSwapChain, IDirect3DSurface9* pDestSurface)
687701{
688- return m_pDevice-> GetFrontBufferData ( iSwapChain, pDestSurface);
702+ return CDirect3DEvents9::GetFrontBufferDataGuarded (m_pDevice, iSwapChain, pDestSurface);
689703}
690704
691705HRESULT CProxyDirect3DDevice9::StretchRect (IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect,
692706 D3DTEXTUREFILTERTYPE Filter)
693707{
694- CGraphics::GetSingleton ().GetRenderItemManager ()->HandleStretchRect (pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
695- return D3D_OK;
708+ return CGraphics::GetSingleton ().GetRenderItemManager ()->HandleStretchRect (pSourceSurface, pSourceRect, pDestSurface, pDestRect, Filter);
696709}
697710
698711HRESULT CProxyDirect3DDevice9::ColorFill (IDirect3DSurface9* pSurface, CONST RECT* pRect, D3DCOLOR color)
699712{
700- return m_pDevice-> ColorFill ( pSurface, pRect, color);
713+ return CDirect3DEvents9::ColorFillGuarded (m_pDevice, pSurface, pRect, color);
701714}
702715
703716HRESULT CProxyDirect3DDevice9::CreateOffscreenPlainSurface (UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9** ppSurface,
704717 HANDLE* pSharedHandle)
705718{
706- return m_pDevice-> CreateOffscreenPlainSurface ( Width, Height, Format, Pool, ppSurface, pSharedHandle);
719+ return CDirect3DEvents9::CreateOffscreenPlainSurfaceGuarded (m_pDevice, Width, Height, Format, Pool, ppSurface, pSharedHandle);
707720}
708721
709722HRESULT CProxyDirect3DDevice9::SetRenderTarget (DWORD RenderTargetIndex, IDirect3DSurface9* pRenderTarget)
710723{
711- return m_pDevice-> SetRenderTarget ( RenderTargetIndex, pRenderTarget);
724+ return CDirect3DEvents9::SetRenderTargetGuarded (m_pDevice, RenderTargetIndex, pRenderTarget);
712725}
713726
714727HRESULT CProxyDirect3DDevice9::GetRenderTarget (DWORD RenderTargetIndex, IDirect3DSurface9** ppRenderTarget)
@@ -718,7 +731,7 @@ HRESULT CProxyDirect3DDevice9::GetRenderTarget(DWORD RenderTargetIndex, IDirect3
718731
719732HRESULT CProxyDirect3DDevice9::SetDepthStencilSurface (IDirect3DSurface9* pNewZStencil)
720733{
721- return m_pDevice-> SetDepthStencilSurface ( pNewZStencil);
734+ return CDirect3DEvents9::SetDepthStencilSurfaceGuarded (m_pDevice, pNewZStencil);
722735}
723736
724737HRESULT CProxyDirect3DDevice9::GetDepthStencilSurface (IDirect3DSurface9** ppZStencilSurface)
@@ -774,7 +787,7 @@ HRESULT CProxyDirect3DDevice9::Clear(DWORD Count, CONST D3DRECT* pRects, DWORD F
774787 if (Flags & D3DCLEAR_ZBUFFER)
775788 CGraphics::GetSingleton ().GetRenderItemManager ()->SaveReadableDepthBuffer ();
776789
777- return m_pDevice-> Clear ( Count, pRects, Flags, Color, Z, Stencil);
790+ return CDirect3DEvents9::ClearGuarded (m_pDevice, Count, pRects, Flags, Color, Z, Stencil);
778791}
779792
780793HRESULT CProxyDirect3DDevice9::SetTransform (D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix)
@@ -1008,21 +1021,21 @@ HRESULT CProxyDirect3DDevice9::DrawIndexedPrimitive(D3DPRIMITIVETYPE PrimitiveTy
10081021HRESULT CProxyDirect3DDevice9::DrawPrimitiveUP (D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void * pVertexStreamZeroData,
10091022 UINT VertexStreamZeroStride)
10101023{
1011- return m_pDevice-> DrawPrimitiveUP ( PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
1024+ return CDirect3DEvents9::DrawPrimitiveUPGuarded (m_pDevice, PrimitiveType, PrimitiveCount, pVertexStreamZeroData, VertexStreamZeroStride);
10121025}
10131026
10141027HRESULT CProxyDirect3DDevice9::DrawIndexedPrimitiveUP (D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertices, UINT PrimitiveCount,
10151028 CONST void * pIndexData, D3DFORMAT IndexDataFormat, CONST void * pVertexStreamZeroData,
10161029 UINT VertexStreamZeroStride)
10171030{
1018- return m_pDevice-> DrawIndexedPrimitiveUP ( PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData ,
1019- VertexStreamZeroStride);
1031+ return CDirect3DEvents9::DrawIndexedPrimitiveUPGuarded (m_pDevice, PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData,
1032+ IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
10201033}
10211034
10221035HRESULT CProxyDirect3DDevice9::ProcessVertices (UINT SrcStartIndex, UINT DestIndex, UINT VertexCount, IDirect3DVertexBuffer9* pDestBuffer,
10231036 IDirect3DVertexDeclaration9* pVertexDecl, DWORD Flags)
10241037{
1025- return m_pDevice-> ProcessVertices ( SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
1038+ return CDirect3DEvents9::ProcessVerticesGuarded (m_pDevice, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
10261039}
10271040
10281041HRESULT CProxyDirect3DDevice9::CreateVertexDeclaration (CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl)
@@ -1182,12 +1195,12 @@ HRESULT CProxyDirect3DDevice9::GetPixelShaderConstantB(UINT StartRegister, BOOL*
11821195
11831196HRESULT CProxyDirect3DDevice9::DrawRectPatch (UINT Handle, CONST float * pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo)
11841197{
1185- return m_pDevice-> DrawRectPatch ( Handle, pNumSegs, pRectPatchInfo);
1198+ return CDirect3DEvents9::DrawRectPatchGuarded (m_pDevice, Handle, pNumSegs, pRectPatchInfo);
11861199}
11871200
11881201HRESULT CProxyDirect3DDevice9::DrawTriPatch (UINT Handle, CONST float * pNumSegs, CONST D3DTRIPATCH_INFO* pTriPatchInfo)
11891202{
1190- return m_pDevice-> DrawTriPatch ( Handle, pNumSegs, pTriPatchInfo);
1203+ return CDirect3DEvents9::DrawTriPatchGuarded (m_pDevice, Handle, pNumSegs, pTriPatchInfo);
11911204}
11921205
11931206HRESULT CProxyDirect3DDevice9::DeletePatch (UINT Handle)
0 commit comments