OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/strings/string_number_conversions.h" | |
6 #include "base/strings/string_util.h" | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "content/browser/gamepad/gamepad_platform_data_fetcher_android.h" | |
9 #include "third_party/WebKit/public/platform/WebGamepads.h" | |
10 | |
11 #if defined(OS_ANDROID) | |
scottmg
2014/02/06 21:17:07
Remove this, it shouldn't be compiled on other pla
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
12 | |
13 namespace content { | |
14 | |
15 GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() { | |
16 } | |
17 | |
18 void GamepadPlatformDataFetcherAndroid::GetGamepadData( | |
19 blink::WebGamepads* pads, bool) { | |
scottmg
2014/02/06 21:17:07
nit; this should be +4. git cl format or clang-for
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
20 GamepadsReader* m_gamepadsReader = GamepadsReader::GetInstance(); | |
scottmg
2014/02/06 21:17:07
No m_, and chromium C++ code should use hacker_sty
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
21 | |
22 pads->length = m_gamepadsReader->UpdateGamepadsCount(); | |
23 if (pads->length == 0) | |
24 return; | |
25 | |
26 for (unsigned int i = 0; i < WebGamepads::itemsLengthCap; i++) { | |
27 bool ifDeviceConnected = m_gamepadsReader->IsDeviceConnected(i); | |
28 if (ifDeviceConnected) { | |
29 // Set connected flag to true for all the gamepad devices that are | |
30 // attached. | |
31 pads->items[i].connected = true; | |
32 | |
33 // Map the Gamepad DeviceName String to the WebGamepad Id and then | |
34 // convert the utf-8 id string to WebUChar. | |
35 // Ideally it should be mapped to vendor and product information | |
36 // but it is only available at kernel level and it can not be | |
37 // queried using class android.hardware.input.InputManager. | |
scottmg
2014/02/06 21:17:07
Is it possible to correlate to a /dev/ or somethin
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
/dev/ is n
| |
38 | |
39 std::string string1 = m_gamepadsReader->GetDeviceName(i); | |
40 base::TruncateUTF8ToByteSize(string1, WebGamepad::idLengthCap - 1, | |
scottmg
2014/02/06 21:17:07
Why truncate the UTF8 rather than the UTF16? Is th
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Yes, it is
| |
41 &string1); | |
42 base::string16 tmp16 = base::UTF8ToUTF16(string1); | |
43 memset(pads->items[i].id, 0, sizeof(pads->items[i].id)); | |
44 tmp16.copy(pads->items[i].id, arraysize(pads->items[i].id) - 1); | |
45 | |
46 // timestamp is queried from GamepadReader. | |
47 pads->items[i].timestamp = m_gamepadsReader->GetDeviceTimestamp(i); | |
scottmg
2014/02/06 21:17:07
Is this the only place this is used? If so, it cou
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
The timest
| |
48 | |
49 // A float vector is queried from GamepadReader that stores the | |
50 // state of axeses. | |
scottmg
2014/02/06 21:17:07
nit; "axes"
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
51 std::vector<float> axes = m_gamepadsReader->GetDeviceAxes(i); | |
scottmg
2014/02/06 21:17:07
So many copies from kernel to content. :(
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
We are not
| |
52 | |
53 // Set WebGamepad axeslength to total number of axes on the gamepad | |
54 // device. | |
55 pads->items[i].axesLength = axes.size(); | |
56 | |
57 // A float vector is queried from GamepadReader that stores the | |
58 // button's state. | |
59 std::vector<float> buttons = m_gamepadsReader->GetDeviceButtons(i); | |
60 | |
61 // Set WebGamepad buttonslength to total numbers of buttons on the | |
62 // gamepad device. | |
63 pads->items[i].buttonsLength = buttons.size(); | |
64 | |
65 // Set WebGamepad connected flag to false if buttonslength or | |
66 // axeslength returned by | |
67 // JNI are larger than permitted value. | |
scottmg
2014/02/06 21:17:07
Is this really what we want? It would probably be
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
68 if (pads->items[i].axesLength > WebGamepad::axesLengthCap || | |
69 pads->items[i].buttonsLength > WebGamepad::buttonsLengthCap) { | |
scottmg
2014/02/06 21:17:07
nit; indent wrong
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
70 pads->items[i].connected = false; | |
71 } else { | |
72 // Copy axes state to the WebGamepad axes[]. | |
73 for (unsigned int j = 0; j < pads->items[i].axesLength; j++) | |
74 pads->items[i].axes[j] = axes[j]; | |
75 | |
76 // Copy buttons state to the WebGamepad buttons[]. | |
77 for (unsigned int j = 0; j < pads->items[i].buttonsLength; j++) | |
78 pads->items[i].buttons[j] = buttons[j]; | |
79 } | |
80 } else { | |
81 // Set connected flag to flase for all the gamepad devices that are | |
82 // not attached. | |
83 pads->items[i].connected = false; | |
84 } | |
85 } | |
86 } | |
87 | |
88 void GamepadPlatformDataFetcherAndroid::PauseHint(bool isaccesspaused) { | |
89 GamepadsReader::GetInstance()->NotifyForGamepadsAccess(isaccesspaused); | |
90 } | |
91 | |
92 GamepadPlatformDataFetcherAndroid::~GamepadPlatformDataFetcherAndroid() { | |
scottmg
2014/02/06 21:17:07
Move this up with the constructor to match the hea
SaurabhK
2014/02/10 12:50:47
On 2014/02/06 21:17:07, scottmg wrote:
Done.
| |
93 } | |
94 | |
95 } // namespace content | |
96 | |
97 #endif | |
OLD | NEW |