OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/raw_input_data_fetcher_win.h" | 5 #include "content/browser/gamepad/raw_input_data_fetcher_win.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "content/common/gamepad_hardware_buffer.h" | 8 #include "content/common/gamepad_hardware_buffer.h" |
9 #include "content/common/gamepad_messages.h" | 9 #include "content/common/gamepad_messages.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 ClearControllers(); | 51 ClearControllers(); |
52 DCHECK(!window_); | 52 DCHECK(!window_); |
53 DCHECK(!events_monitored_); | 53 DCHECK(!events_monitored_); |
54 } | 54 } |
55 | 55 |
56 void RawInputDataFetcher::WillDestroyCurrentMessageLoop() { | 56 void RawInputDataFetcher::WillDestroyCurrentMessageLoop() { |
57 StopMonitor(); | 57 StopMonitor(); |
58 } | 58 } |
59 | 59 |
60 RAWINPUTDEVICE* RawInputDataFetcher::GetRawInputDevices(DWORD flags) { | 60 RAWINPUTDEVICE* RawInputDataFetcher::GetRawInputDevices(DWORD flags) { |
61 int usage_count = arraysize(DeviceUsages); | 61 size_t usage_count = arraysize(DeviceUsages); |
62 scoped_ptr<RAWINPUTDEVICE[]> devices(new RAWINPUTDEVICE[usage_count]); | 62 scoped_ptr<RAWINPUTDEVICE[]> devices(new RAWINPUTDEVICE[usage_count]); |
63 for (int i = 0; i < usage_count; ++i) { | 63 for (size_t i = 0; i < usage_count; ++i) { |
64 devices[i].dwFlags = flags; | 64 devices[i].dwFlags = flags; |
65 devices[i].usUsagePage = 1; | 65 devices[i].usUsagePage = 1; |
66 devices[i].usUsage = DeviceUsages[i]; | 66 devices[i].usUsage = DeviceUsages[i]; |
67 devices[i].hwndTarget = (flags & RIDEV_REMOVE) ? 0 : window_->hwnd(); | 67 devices[i].hwndTarget = (flags & RIDEV_REMOVE) ? 0 : window_->hwnd(); |
68 } | 68 } |
69 return devices.release(); | 69 return devices.release(); |
70 } | 70 } |
71 | 71 |
72 void RawInputDataFetcher::StartMonitor() { | 72 void RawInputDataFetcher::StartMonitor() { |
73 if (!rawinput_available_ || events_monitored_) | 73 if (!rawinput_available_ || events_monitored_) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, | 193 result = GetRawInputDeviceInfo(hDevice, RIDI_DEVICEINFO, |
194 di_buffer.get(), &size); | 194 di_buffer.get(), &size); |
195 if (result == static_cast<UINT>(-1)) { | 195 if (result == static_cast<UINT>(-1)) { |
196 PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; | 196 PLOG(ERROR) << "GetRawInputDeviceInfo() failed"; |
197 return NULL; | 197 return NULL; |
198 } | 198 } |
199 DCHECK_EQ(size, result); | 199 DCHECK_EQ(size, result); |
200 | 200 |
201 // Make sure this device is of a type that we want to observe. | 201 // Make sure this device is of a type that we want to observe. |
202 bool valid_type = false; | 202 bool valid_type = false; |
203 for (int i = 0; i < arraysize(DeviceUsages); ++i) { | 203 for (USHORT device_usage : DeviceUsages) { |
204 if (device_info->hid.usUsage == DeviceUsages[i]) { | 204 if (device_info->hid.usUsage == device_usage) { |
205 valid_type = true; | 205 valid_type = true; |
206 break; | 206 break; |
207 } | 207 } |
208 } | 208 } |
209 | 209 |
210 if (!valid_type) | 210 if (!valid_type) |
211 return NULL; | 211 return NULL; |
212 | 212 |
213 scoped_ptr<RawGamepadInfo> gamepad_info(new RawGamepadInfo); | 213 scoped_ptr<RawGamepadInfo> gamepad_info(new RawGamepadInfo); |
214 gamepad_info->handle = hDevice; | 214 gamepad_info->handle = hDevice; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 &buttons_length, | 382 &buttons_length, |
383 gamepad_info->preparsed_data, | 383 gamepad_info->preparsed_data, |
384 reinterpret_cast<PCHAR>(input->data.hid.bRawData), | 384 reinterpret_cast<PCHAR>(input->data.hid.bRawData), |
385 input->data.hid.dwSizeHid); | 385 input->data.hid.dwSizeHid); |
386 | 386 |
387 if (status == HIDP_STATUS_SUCCESS) { | 387 if (status == HIDP_STATUS_SUCCESS) { |
388 // Set each reported button to true. | 388 // Set each reported button to true. |
389 for (uint32_t j = 0; j < buttons_length; j++) { | 389 for (uint32_t j = 0; j < buttons_length; j++) { |
390 int32_t button_index = usages[j].Usage - 1; | 390 int32_t button_index = usages[j].Usage - 1; |
391 if (button_index >= 0 && | 391 if (button_index >= 0 && |
392 button_index < blink::WebGamepad::buttonsLengthCap) | 392 button_index < |
| 393 static_cast<int>(blink::WebGamepad::buttonsLengthCap)) { |
393 gamepad_info->buttons[button_index] = true; | 394 gamepad_info->buttons[button_index] = true; |
| 395 } |
394 } | 396 } |
395 } | 397 } |
396 } | 398 } |
397 | 399 |
398 // Query axis state. | 400 // Query axis state. |
399 ULONG axis_value = 0; | 401 ULONG axis_value = 0; |
400 LONG scaled_axis_value = 0; | 402 LONG scaled_axis_value = 0; |
401 for (uint32_t i = 0; i < gamepad_info->axes_length; i++) { | 403 for (uint32_t i = 0; i < gamepad_info->axes_length; i++) { |
402 RawGamepadAxis* axis = &gamepad_info->axes[i]; | 404 RawGamepadAxis* axis = &gamepad_info->axes[i]; |
403 | 405 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 return false; | 513 return false; |
512 hidd_get_product_string_ = reinterpret_cast<HidDGetStringFunc>( | 514 hidd_get_product_string_ = reinterpret_cast<HidDGetStringFunc>( |
513 hid_dll_.GetFunctionPointer("HidD_GetProductString")); | 515 hid_dll_.GetFunctionPointer("HidD_GetProductString")); |
514 if (!hidd_get_product_string_) | 516 if (!hidd_get_product_string_) |
515 return false; | 517 return false; |
516 | 518 |
517 return true; | 519 return true; |
518 } | 520 } |
519 | 521 |
520 } // namespace content | 522 } // namespace content |
OLD | NEW |