Index: content/browser/gamepad/platform_data_fetcher_win.cc |
diff --git a/content/browser/gamepad/platform_data_fetcher_win.cc b/content/browser/gamepad/platform_data_fetcher_win.cc |
index 752328ae3e8d8141fcd1a349de1f1782a670f02f..8a50a38694e3ba7409644ed04ec67f2b270dec9c 100644 |
--- a/content/browser/gamepad/platform_data_fetcher_win.cc |
+++ b/content/browser/gamepad/platform_data_fetcher_win.cc |
@@ -8,15 +8,6 @@ |
#include "content/common/gamepad_messages.h" |
#include "content/common/gamepad_hardware_buffer.h" |
-#if defined(_WIN32_WINNT_WIN8) |
-// The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h. |
-#undef FACILITY_VISUALCPP |
-#endif |
-#include <delayimp.h> |
- |
-#pragma comment(lib, "delayimp.lib") |
-#pragma comment(lib, "xinput.lib") |
- |
namespace content { |
using namespace WebKit; |
@@ -57,37 +48,14 @@ const WebUChar* const GamepadSubTypeName(BYTE sub_type) { |
} |
} |
-// Trap only the exceptions that DELAYLOAD can throw, otherwise rethrow. |
-// See http://msdn.microsoft.com/en-us/library/1c9e046h(v=VS.90).aspx. |
-LONG WINAPI DelayLoadDllExceptionFilter(PEXCEPTION_POINTERS pExcPointers) { |
- LONG disposition = EXCEPTION_EXECUTE_HANDLER; |
- switch (pExcPointers->ExceptionRecord->ExceptionCode) { |
- case VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND): |
- case VcppException(ERROR_SEVERITY_ERROR, ERROR_PROC_NOT_FOUND): |
- break; |
- default: |
- // Exception is not related to delay loading. |
- disposition = EXCEPTION_CONTINUE_SEARCH; |
- break; |
- } |
- return disposition; |
-} |
- |
-bool EnableXInput() { |
- // We have specified DELAYLOAD for xinput1_3.dll. If the DLL is not |
- // installed (XP w/o DirectX redist installed), we disable functionality. |
- __try { |
- XInputEnable(true); |
- } __except(DelayLoadDllExceptionFilter(GetExceptionInformation())) { |
- return false; |
- } |
- return true; |
-} |
- |
} // namespace |
GamepadPlatformDataFetcherWin::GamepadPlatformDataFetcherWin() |
- : xinput_available_(EnableXInput()) { |
+ : xinput_dll_(FilePath(FILE_PATH_LITERAL("xinput1_3.dll"))), |
+ xinput_available_(GetXinputDllFunctions()) { |
+} |
+ |
+GamepadPlatformDataFetcherWin::~GamepadPlatformDataFetcherWin() { |
} |
void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, |
@@ -114,7 +82,7 @@ void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, |
WebGamepad& pad = pads->items[i]; |
TRACE_EVENT1("GAMEPAD", "GetCapabilities", "id", i); |
XINPUT_CAPABILITIES caps; |
- DWORD res = XInputGetCapabilities(i, XINPUT_FLAG_GAMEPAD, &caps); |
+ DWORD res = xinput_get_capabilities_(i, XINPUT_FLAG_GAMEPAD, &caps); |
if (res == ERROR_DEVICE_NOT_CONNECTED) { |
pad.connected = false; |
} else { |
@@ -141,7 +109,7 @@ void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, |
XINPUT_STATE state; |
memset(&state, 0, sizeof(XINPUT_STATE)); |
TRACE_EVENT_BEGIN1("GAMEPAD", "XInputGetState", "id", i); |
- DWORD dwResult = XInputGetState(i, &state); |
+ DWORD dwResult = xinput_get_state_(i, &state); |
TRACE_EVENT_END1("GAMEPAD", "XInputGetState", "id", i); |
if (dwResult == ERROR_SUCCESS) { |
@@ -178,4 +146,21 @@ void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, |
} |
} |
+bool GamepadPlatformDataFetcherWin::GetXinputDllFunctions() { |
+ xinput_enable_ = static_cast<XInputEnableFunc>( |
+ xinput_dll_.GetFunctionPointer("XInputEnable")); |
+ if (!xinput_enable_) |
+ return false; |
+ xinput_get_capabilities_ = static_cast<XInputGetCapabilitiesFunc>( |
+ xinput_dll_.GetFunctionPointer("XInputGetCapabilities")); |
+ if (!xinput_get_capabilities_) |
+ return false; |
+ xinput_get_state_ = static_cast<XInputGetStateFunc>( |
+ xinput_dll_.GetFunctionPointer("XInputGetState")); |
+ if (!xinput_get_state_) |
+ return false; |
+ xinput_enable_(true); |
+ return true; |
+} |
+ |
} // namespace content |