OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/gamepad/data_fetcher_win.h" | 5 #include "content/browser/gamepad/platform_data_fetcher_win.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "content/common/gamepad_messages.h" | 8 #include "content/common/gamepad_messages.h" |
9 #include "content/common/gamepad_hardware_buffer.h" | 9 #include "content/common/gamepad_hardware_buffer.h" |
10 | 10 |
11 #include <delayimp.h> | 11 #include <delayimp.h> |
12 | 12 |
13 #pragma comment(lib, "delayimp.lib") | 13 #pragma comment(lib, "delayimp.lib") |
14 #pragma comment(lib, "xinput.lib") | 14 #pragma comment(lib, "xinput.lib") |
15 | 15 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 __try { | 71 __try { |
72 ;//XInputEnable(true); | 72 ;//XInputEnable(true); |
73 } __except(DelayLoadDllExceptionFilter(GetExceptionInformation())) { | 73 } __except(DelayLoadDllExceptionFilter(GetExceptionInformation())) { |
74 return false; | 74 return false; |
75 } | 75 } |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 } | 79 } |
80 | 80 |
81 GamepadDataFetcherWindows::GamepadDataFetcherWindows() | 81 GamepadPlatformDataFetcherWin::GamepadPlatformDataFetcherWin() |
82 : xinput_available_(EnableXInput()) { | 82 : xinput_available_(EnableXInput()) { |
83 } | 83 } |
84 | 84 |
85 void GamepadDataFetcherWindows::GetGamepadData(WebGamepads* pads, | 85 void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, |
86 bool devices_changed_hint) { | 86 bool devices_changed_hint) { |
87 TRACE_EVENT0("GAMEPAD", "GetGamepadData"); | 87 TRACE_EVENT0("GAMEPAD", "GetGamepadData"); |
88 | 88 |
89 // If there's no XInput DLL on the system, early out so that we don't | 89 // If there's no XInput DLL on the system, early out so that we don't |
90 // call any other XInput functions. | 90 // call any other XInput functions. |
91 if (!xinput_available_) { | 91 if (!xinput_available_) { |
92 pads->length = 0; | 92 pads->length = 0; |
93 return; | 93 return; |
94 } | 94 } |
95 | 95 |
(...skipping 10 matching lines...) Expand all Loading... |
106 WebGamepad& pad = pads->items[i]; | 106 WebGamepad& pad = pads->items[i]; |
107 TRACE_EVENT1("GAMEPAD", "GetCapabilities", "id", i); | 107 TRACE_EVENT1("GAMEPAD", "GetCapabilities", "id", i); |
108 XINPUT_CAPABILITIES caps; | 108 XINPUT_CAPABILITIES caps; |
109 DWORD res = XInputGetCapabilities(i, XINPUT_FLAG_GAMEPAD, &caps); | 109 DWORD res = XInputGetCapabilities(i, XINPUT_FLAG_GAMEPAD, &caps); |
110 if (res == ERROR_DEVICE_NOT_CONNECTED) { | 110 if (res == ERROR_DEVICE_NOT_CONNECTED) { |
111 pad.connected = false; | 111 pad.connected = false; |
112 } else { | 112 } else { |
113 pad.connected = true; | 113 pad.connected = true; |
114 base::swprintf(pad.id, | 114 base::swprintf(pad.id, |
115 WebGamepad::idLengthCap, | 115 WebGamepad::idLengthCap, |
116 L"Xbox 360 Controller (XInput %ls)", | 116 L"Xbox 360 Controller (XInput STANDARD %ls)", |
117 GamepadSubTypeName(caps.SubType)); | 117 GamepadSubTypeName(caps.SubType)); |
118 } | 118 } |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 // We've updated the connection state if necessary, now update the actual | 122 // We've updated the connection state if necessary, now update the actual |
123 // data for the devices that are connected. | 123 // data for the devices that are connected. |
124 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 124 for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
125 WebGamepad& pad = pads->items[i]; | 125 WebGamepad& pad = pads->items[i]; |
126 | 126 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 pad.axes[pad.axesLength++] = -state.Gamepad.sThumbLY / 32767.0; | 164 pad.axes[pad.axesLength++] = -state.Gamepad.sThumbLY / 32767.0; |
165 pad.axes[pad.axesLength++] = state.Gamepad.sThumbRX / 32767.0; | 165 pad.axes[pad.axesLength++] = state.Gamepad.sThumbRX / 32767.0; |
166 pad.axes[pad.axesLength++] = -state.Gamepad.sThumbRY / 32767.0; | 166 pad.axes[pad.axesLength++] = -state.Gamepad.sThumbRY / 32767.0; |
167 } else { | 167 } else { |
168 pad.connected = false; | 168 pad.connected = false; |
169 } | 169 } |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 } // namespace content | 173 } // namespace content |
OLD | NEW |