Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Unified Diff: content/browser/gamepad/gamepad_platform_data_fetcher_android.cc

Issue 133943002: Gamepad API support for chrome on android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/gamepad/gamepad_platform_data_fetcher_android.cc
diff --git a/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc b/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fbab10401f29a3596cc660630c347ab3004fbd69
--- /dev/null
+++ b/content/browser/gamepad/gamepad_platform_data_fetcher_android.cc
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of NVIDIA CORPORATION nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/browser/gamepad/gamepad_platform_data_fetcher_android.h"
+#include "third_party/WebKit/public/platform/WebGamepads.h"
+
+#if defined(OS_ANDROID)
+
+namespace content {
+
+GamepadPlatformDataFetcherAndroid::GamepadPlatformDataFetcherAndroid() {
+}
+
+void GamepadPlatformDataFetcherAndroid::GetGamepadData(
+ blink::WebGamepads* pads, bool) {
+
+ GamepadsReader* m_gamepadsReader = GamepadsReader::GetInstance();
+
+ pads->length = m_gamepadsReader->updateGamepadsCount();
+ if (pads->length == 0)
+ return;
+
+ for (unsigned int i = 0; i < WebGamepads::itemsLengthCap; i++) {
+ bool ifDeviceConnected = m_gamepadsReader->isDeviceConnected(i);
+ if (ifDeviceConnected) {
+
+ // Set connected flag to true for all the gamepad devices that are
+ // attached.
+ pads->items[i].connected = true;
+
+ // Map the Gamepad DeviceName String to the WebGamepad Id and then
+ // convert the utf-8 id string to WebUChar.
+ // Ideally it should be mapped to vendor and product information
+ // but it is only available at kernel level and it can not be
+ // queried using class android.hardware.input.InputManager.
+
+ std::string string1 = m_gamepadsReader->getDeviceName(i);
+ base::TruncateUTF8ToByteSize(string1, WebGamepad::idLengthCap - 1,
+ &string1);
+ base::string16 tmp16 = base::UTF8ToUTF16(string1);
+ memset(pads->items[i].id, 0, sizeof(pads->items[i].id));
+ tmp16.copy(pads->items[i].id, arraysize(pads->items[i].id) - 1);
+
+ // timestamp is queried from GamepadReader.
+ pads->items[i].timestamp = m_gamepadsReader->getDeviceTimestamp(i);
+
+ // A float vector is queried from GamepadReader that stores the
+ // state of axeses.
+ std::vector<float> axes = m_gamepadsReader->getDeviceAxes(i);
+
+ // Set WebGamepad axeslength to total number of axes on the gamepad
+ // device.
+ pads->items[i].axesLength = axes.size();
+
+ // A float vector is queried from GamepadReader that stores the
+ // button's state.
+ std::vector<float> buttons = m_gamepadsReader->getDeviceButtons(i);
+
+ // Set WebGamepad buttonslength to total numbers of buttons on the
+ // gamepad device.
+ pads->items[i].buttonsLength = buttons.size();
+
+ // Set WebGamepad connected flag to false if buttonslength or
+ // axeslength returned by
+ // JNI are larger than permitted value.
+ if (pads->items[i].axesLength > WebGamepad::axesLengthCap ||
+ pads->items[i].buttonsLength >
+ WebGamepad::buttonsLengthCap) {
+ pads->items[i].connected = false;
+ } else {
+ // Copy axes state to the WebGamepad axes[].
+ for (unsigned int j = 0; j < pads->items[i].axesLength; j++)
+ pads->items[i].axes[j] = axes[j];
+
+ // Copy buttons state to the WebGamepad buttons[].
+ for (unsigned int j = 0; j < pads->items[i].buttonsLength; j++)
+ pads->items[i].buttons[j] = buttons[j];
+ }
+ } else {
+ // Set connected flag to flase for all the gamepad devices that are
+ // not attached.
+ pads->items[i].connected = false;
+ }
+ }
+}
+
+void GamepadPlatformDataFetcherAndroid::PauseHint(bool isaccesspaused) {
+ GamepadsReader::GetInstance()->notifyForGamepadsAccess(isaccesspaused);
+}
+
+GamepadPlatformDataFetcherAndroid::~GamepadPlatformDataFetcherAndroid() {
+}
+
+} // namespace content
+#endif

Powered by Google App Engine
This is Rietveld 408576698