Commit 94e1934d by apatrick@chromium.org

Fixed crash on context lost.

This fixes the crash on lost context for vista and windows 7 if suitable drivers are available. It now uses D3D9Ex when available and this only reports lost contexts for hardware failures and suchlike. Testing procedure was: - run simple_vertex_shader without this change. - ctrl+alt+del to lock machine. - return to desktop. - observe that simple_vertex_shader crashes. - repeat with this change and check that simple_vertex_shader is still animating. - simulate the code path that an XP machine would take using the debugger and check that old behavior is preserved. I decided to load D3D9.DLL at runtime for a couple of reasons. First, I didn't want to assume that older implementations of D3D9 would have the Direct3DCreate9Ex entry point. Second, it might be advantageous for some applications to not have a load time dependency on D3D9. I didn't address this for D3DX9 because it's a little harder - there's no clear way to determine which D3DX9_x.DLL library to open. At least D3DX9_x.DLL does not seem to import D3D9.DLL and D3DX is separately redistributable so there is still some advantage to be had. Review URL: http://codereview.appspot.com/1951044 git-svn-id: https://angleproject.googlecode.com/svn/trunk@384 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent b3999348
...@@ -231,7 +231,10 @@ ...@@ -231,7 +231,10 @@
], ],
'msvs_settings': { 'msvs_settings': {
'VCLinkerTool': { 'VCLinkerTool': {
'AdditionalDependencies': ['d3d9.lib'], 'AdditionalLibraryDirectories': ['$(DXSDK_DIR)/lib/x86'],
'AdditionalDependencies': [
'dxguid.lib',
],
} }
}, },
}, },
......
...@@ -23,7 +23,10 @@ namespace egl ...@@ -23,7 +23,10 @@ namespace egl
{ {
Display::Display(HDC deviceContext) : mDc(deviceContext) Display::Display(HDC deviceContext) : mDc(deviceContext)
{ {
mD3d9Module = NULL;
mD3d9 = NULL; mD3d9 = NULL;
mD3d9ex = NULL;
mDevice = NULL; mDevice = NULL;
mDeviceWindow = NULL; mDeviceWindow = NULL;
...@@ -52,7 +55,38 @@ bool Display::initialize() ...@@ -52,7 +55,38 @@ bool Display::initialize()
return true; return true;
} }
mD3d9 = Direct3DCreate9(D3D_SDK_VERSION); mD3d9Module = LoadLibrary(TEXT("d3d9.dll"));
if (mD3d9Module == NULL)
{
terminate();
return false;
}
typedef IDirect3D9* (WINAPI *Direct3DCreate9Func)(UINT);
Direct3DCreate9Func Direct3DCreate9Ptr = reinterpret_cast<Direct3DCreate9Func>(GetProcAddress(mD3d9Module, "Direct3DCreate9"));
if (Direct3DCreate9Ptr == NULL)
{
terminate();
return false;
}
typedef HRESULT (WINAPI *Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex**);
Direct3DCreate9ExFunc Direct3DCreate9ExPtr = reinterpret_cast<Direct3DCreate9ExFunc>(GetProcAddress(mD3d9Module, "Direct3DCreate9Ex"));
// Use Direct3D9Ex if available. Among other things, this version is less
// inclined to report a lost context, for example when the user switches
// desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available.
if (Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9ex)))
{
ASSERT(mD3d9ex);
mD3d9ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9));
ASSERT(mD3d9);
}
else
{
mD3d9 = Direct3DCreate9Ptr(D3D_SDK_VERSION);
}
if (mD3d9) if (mD3d9)
{ {
...@@ -197,6 +231,18 @@ void Display::terminate() ...@@ -197,6 +231,18 @@ void Display::terminate()
DestroyWindow(mDeviceWindow); DestroyWindow(mDeviceWindow);
mDeviceWindow = NULL; mDeviceWindow = NULL;
} }
if (mD3d9ex)
{
mD3d9ex->Release();
mD3d9ex = NULL;
}
if (mD3d9Module)
{
FreeLibrary(mD3d9Module);
mD3d9Module = NULL;
}
} }
void Display::startScene() void Display::startScene()
......
...@@ -65,9 +65,12 @@ class Display ...@@ -65,9 +65,12 @@ class Display
DISALLOW_COPY_AND_ASSIGN(Display); DISALLOW_COPY_AND_ASSIGN(Display);
const HDC mDc; const HDC mDc;
HMODULE mD3d9Module;
UINT mAdapter; UINT mAdapter;
D3DDEVTYPE mDeviceType; D3DDEVTYPE mDeviceType;
IDirect3D9 *mD3d9; IDirect3D9 *mD3d9; // Always valid after successful initialization.
IDirect3D9Ex *mD3d9ex; // Might be null if D3D9Ex is not supported.
IDirect3DDevice9 *mDevice; IDirect3DDevice9 *mDevice;
D3DCAPS9 mDeviceCaps; D3DCAPS9 mDeviceCaps;
HWND mDeviceWindow; HWND mDeviceWindow;
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="d3d9.lib" AdditionalDependencies="dxguid.lib"
LinkIncremental="2" LinkIncremental="2"
ModuleDefinitionFile="libEGL.def" ModuleDefinitionFile="libEGL.def"
GenerateDebugInformation="true" GenerateDebugInformation="true"
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="d3d9.lib" AdditionalDependencies="dxguid.lib"
LinkIncremental="1" LinkIncremental="1"
ModuleDefinitionFile="libEGL.def" ModuleDefinitionFile="libEGL.def"
GenerateDebugInformation="true" GenerateDebugInformation="true"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment