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/gamepad_platform_data_fetcher_android.h" | 5 #include "device/gamepad/gamepad_platform_data_fetcher_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
16 | 16 |
17 #include "jni/GamepadList_jni.h" | 17 #include "jni/GamepadList_jni.h" |
18 | 18 |
19 #include "third_party/WebKit/public/platform/WebGamepads.h" | 19 #include "third_party/WebKit/public/platform/WebGamepads.h" |
20 | 20 |
21 using base::android::AttachCurrentThread; | 21 using base::android::AttachCurrentThread; |
22 using base::android::CheckException; | 22 using base::android::CheckException; |
23 using base::android::ClearException; | 23 using base::android::ClearException; |
24 using base::android::ConvertJavaStringToUTF8; | 24 using base::android::ConvertJavaStringToUTF8; |
25 using base::android::ScopedJavaLocalRef; | 25 using base::android::ScopedJavaLocalRef; |
26 using blink::WebGamepad; | 26 using blink::WebGamepad; |
27 using blink::WebGamepads; | 27 using blink::WebGamepads; |
28 | 28 |
29 namespace content { | 29 namespace device { |
30 | 30 |
31 bool | 31 bool GamepadPlatformDataFetcherAndroid:: |
32 GamepadPlatformDataFetcherAndroid::RegisterGamepadPlatformDataFetcherAndroid( | 32 RegisterGamepadPlatformDataFetcherAndroid(JNIEnv* env) { |
33 JNIEnv* env) { | |
34 return RegisterNativesImpl(env); | 33 return RegisterNativesImpl(env); |
35 } | 34 } |
36 | 35 |
37 GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() { | 36 GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() { |
38 PauseHint(false); | 37 PauseHint(false); |
39 } | 38 } |
40 | 39 |
41 GamepadPlatformDataFetcherAndroid::~GamepadPlatformDataFetcherAndroid() { | 40 GamepadPlatformDataFetcherAndroid::~GamepadPlatformDataFetcherAndroid() { |
42 PauseHint(true); | 41 PauseHint(true); |
43 } | 42 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // be mapped to vendor and product information but it is only available at | 95 // be mapped to vendor and product information but it is only available at |
97 // kernel level and it can not be queried using class | 96 // kernel level and it can not be queried using class |
98 // android.hardware.input.InputManager. | 97 // android.hardware.input.InputManager. |
99 // TODO(SaurabhK): Store a cached WebGamePad object in | 98 // TODO(SaurabhK): Store a cached WebGamePad object in |
100 // GamepadPlatformDataFetcherAndroid and only update constant WebGamepad | 99 // GamepadPlatformDataFetcherAndroid and only update constant WebGamepad |
101 // values when a device has changed. | 100 // values when a device has changed. |
102 base::string16 device_name; | 101 base::string16 device_name; |
103 base::android::ConvertJavaStringToUTF16(env, devicename, &device_name); | 102 base::android::ConvertJavaStringToUTF16(env, devicename, &device_name); |
104 const size_t name_to_copy = | 103 const size_t name_to_copy = |
105 std::min(device_name.size(), WebGamepad::idLengthCap - 1); | 104 std::min(device_name.size(), WebGamepad::idLengthCap - 1); |
106 memcpy(pad.id, | 105 memcpy(pad.id, device_name.data(), |
107 device_name.data(), | |
108 name_to_copy * sizeof(base::string16::value_type)); | 106 name_to_copy * sizeof(base::string16::value_type)); |
109 pad.id[name_to_copy] = 0; | 107 pad.id[name_to_copy] = 0; |
110 | 108 |
111 base::string16 mapping_name = base::UTF8ToUTF16(mapping ? "standard" : ""); | 109 base::string16 mapping_name = base::UTF8ToUTF16(mapping ? "standard" : ""); |
112 const size_t mapping_to_copy = | 110 const size_t mapping_to_copy = |
113 std::min(mapping_name.size(), WebGamepad::mappingLengthCap - 1); | 111 std::min(mapping_name.size(), WebGamepad::mappingLengthCap - 1); |
114 memcpy(pad.mapping, | 112 memcpy(pad.mapping, mapping_name.data(), |
115 mapping_name.data(), | |
116 mapping_to_copy * sizeof(base::string16::value_type)); | 113 mapping_to_copy * sizeof(base::string16::value_type)); |
117 pad.mapping[mapping_to_copy] = 0; | 114 pad.mapping[mapping_to_copy] = 0; |
118 | 115 |
119 pad.timestamp = timestamp; | 116 pad.timestamp = timestamp; |
120 | 117 |
121 std::vector<float> axes; | 118 std::vector<float> axes; |
122 base::android::JavaFloatArrayToFloatVector(env, jaxes, &axes); | 119 base::android::JavaFloatArrayToFloatVector(env, jaxes, &axes); |
123 | 120 |
124 // Set WebGamepad axeslength to total number of axes on the gamepad device. | 121 // Set WebGamepad axeslength to total number of axes on the gamepad device. |
125 // Only return the first axesLengthCap if axeslength captured by GamepadList | 122 // Only return the first axesLengthCap if axeslength captured by GamepadList |
(...skipping 15 matching lines...) Expand all Loading... |
141 pad.buttonsLength = std::min(static_cast<int>(buttons.size()), | 138 pad.buttonsLength = std::min(static_cast<int>(buttons.size()), |
142 static_cast<int>(WebGamepad::buttonsLengthCap)); | 139 static_cast<int>(WebGamepad::buttonsLengthCap)); |
143 | 140 |
144 // Copy buttons state to the WebGamepad buttons[]. | 141 // Copy buttons state to the WebGamepad buttons[]. |
145 for (unsigned int j = 0; j < pad.buttonsLength; j++) { | 142 for (unsigned int j = 0; j < pad.buttonsLength; j++) { |
146 pad.buttons[j].pressed = buttons[j]; | 143 pad.buttons[j].pressed = buttons[j]; |
147 pad.buttons[j].value = buttons[j]; | 144 pad.buttons[j].value = buttons[j]; |
148 } | 145 } |
149 } | 146 } |
150 | 147 |
151 } // namespace content | 148 } // namespace device |
OLD | NEW |