| OLD | NEW |
| 1 // Copyright (c) 2012 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/gamepad_platform_data_fetcher_win.h" | 5 #include "content/browser/gamepad/gamepad_platform_data_fetcher_win.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "content/common/gamepad_hardware_buffer.h" | 10 #include "content/common/gamepad_hardware_buffer.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 WebGamepad& pad = pads->items[pad_index]; | 131 WebGamepad& pad = pads->items[pad_index]; |
| 132 pad.connected = true; | 132 pad.connected = true; |
| 133 PadState& state = pad_state_[pad_index]; | 133 PadState& state = pad_state_[pad_index]; |
| 134 state.status = RAWINPUT_CONNECTED; | 134 state.status = RAWINPUT_CONNECTED; |
| 135 state.raw_input_handle = gamepad->handle; | 135 state.raw_input_handle = gamepad->handle; |
| 136 | 136 |
| 137 std::string vendor = base::StringPrintf("%04x", gamepad->vendor_id); | 137 std::string vendor = base::StringPrintf("%04x", gamepad->vendor_id); |
| 138 std::string product = base::StringPrintf("%04x", gamepad->product_id); | 138 std::string product = base::StringPrintf("%04x", gamepad->product_id); |
| 139 state.mapper = GetGamepadStandardMappingFunction(vendor, product); | 139 state.mapper = GetGamepadStandardMappingFunction(vendor, product); |
| 140 | 140 |
| 141 #ifdef ENABLE_NEW_GAMEPAD_API |
| 142 swprintf(pad.id, WebGamepad::idLengthCap, |
| 143 L"%ls (Vendor: %04x Product: %04x)", |
| 144 gamepad->id, gamepad->vendor_id, gamepad->product_id); |
| 145 |
| 146 if (state.mapper) |
| 147 swprintf(pad.mapping, WebGamepad::mappingLengthCap, L"standard"); |
| 148 else |
| 149 pad.mapping[0] = 0; |
| 150 #else |
| 141 swprintf(pad.id, WebGamepad::idLengthCap, | 151 swprintf(pad.id, WebGamepad::idLengthCap, |
| 142 L"%ls (%lsVendor: %04x Product: %04x)", | 152 L"%ls (%lsVendor: %04x Product: %04x)", |
| 143 gamepad->id, state.mapper ? L"STANDARD GAMEPAD " : L"", | 153 gamepad->id, state.mapper ? L"STANDARD GAMEPAD " : L"", |
| 144 gamepad->vendor_id, gamepad->product_id); | 154 gamepad->vendor_id, gamepad->product_id); |
| 155 #endif |
| 156 |
| 145 pads->length++; | 157 pads->length++; |
| 146 } | 158 } |
| 147 } | 159 } |
| 148 } | 160 } |
| 149 | 161 |
| 150 | 162 |
| 151 void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, | 163 void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads, |
| 152 bool devices_changed_hint) { | 164 bool devices_changed_hint) { |
| 153 TRACE_EVENT0("GAMEPAD", "GetGamepadData"); | 165 TRACE_EVENT0("GAMEPAD", "GetGamepadData"); |
| 154 | 166 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 WebGamepad* pad) const { | 206 WebGamepad* pad) const { |
| 195 DCHECK(pad); | 207 DCHECK(pad); |
| 196 TRACE_EVENT1("GAMEPAD", "GetXInputPadConnectivity", "id", i); | 208 TRACE_EVENT1("GAMEPAD", "GetXInputPadConnectivity", "id", i); |
| 197 XINPUT_CAPABILITIES caps; | 209 XINPUT_CAPABILITIES caps; |
| 198 DWORD res = xinput_get_capabilities_(i, XINPUT_FLAG_GAMEPAD, &caps); | 210 DWORD res = xinput_get_capabilities_(i, XINPUT_FLAG_GAMEPAD, &caps); |
| 199 if (res == ERROR_DEVICE_NOT_CONNECTED) { | 211 if (res == ERROR_DEVICE_NOT_CONNECTED) { |
| 200 pad->connected = false; | 212 pad->connected = false; |
| 201 return false; | 213 return false; |
| 202 } else { | 214 } else { |
| 203 pad->connected = true; | 215 pad->connected = true; |
| 216 #ifdef ENABLE_NEW_GAMEPAD_API |
| 217 swprintf(pad->id, WebGamepad::idLengthCap, L"Xbox 360 Controller (XInput)"); |
| 218 swprintf(pad->mapping, WebGamepad::mappingLengthCap, L"standard"); |
| 219 #else |
| 204 swprintf(pad->id, | 220 swprintf(pad->id, |
| 205 WebGamepad::idLengthCap, | 221 WebGamepad::idLengthCap, |
| 206 L"Xbox 360 Controller (XInput STANDARD %ls)", | 222 L"Xbox 360 Controller (XInput STANDARD %ls)", |
| 207 GamepadSubTypeName(caps.SubType)); | 223 GamepadSubTypeName(caps.SubType)); |
| 224 #endif |
| 208 return true; | 225 return true; |
| 209 } | 226 } |
| 210 } | 227 } |
| 211 | 228 |
| 212 void GamepadPlatformDataFetcherWin::GetXInputPadData( | 229 void GamepadPlatformDataFetcherWin::GetXInputPadData( |
| 213 int i, | 230 int i, |
| 214 WebGamepad* pad) { | 231 WebGamepad* pad) { |
| 215 XINPUT_STATE state; | 232 XINPUT_STATE state; |
| 216 memset(&state, 0, sizeof(XINPUT_STATE)); | 233 memset(&state, 0, sizeof(XINPUT_STATE)); |
| 217 TRACE_EVENT_BEGIN1("GAMEPAD", "XInputGetState", "id", i); | 234 TRACE_EVENT_BEGIN1("GAMEPAD", "XInputGetState", "id", i); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 return false; | 311 return false; |
| 295 xinput_get_state_ = reinterpret_cast<XInputGetStateFunc>( | 312 xinput_get_state_ = reinterpret_cast<XInputGetStateFunc>( |
| 296 xinput_dll_.GetFunctionPointer("XInputGetState")); | 313 xinput_dll_.GetFunctionPointer("XInputGetState")); |
| 297 if (!xinput_get_state_) | 314 if (!xinput_get_state_) |
| 298 return false; | 315 return false; |
| 299 xinput_enable_(true); | 316 xinput_enable_(true); |
| 300 return true; | 317 return true; |
| 301 } | 318 } |
| 302 | 319 |
| 303 } // namespace content | 320 } // namespace content |
| OLD | NEW |