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

Unified Diff: content/browser/android/gamepad_reader_impl.h

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/android/gamepad_reader_impl.h
diff --git a/content/browser/android/gamepad_reader_impl.h b/content/browser/android/gamepad_reader_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..b5e63378b05c7576fffb62a7b59a6a91d60a3e1e
--- /dev/null
+++ b/content/browser/android/gamepad_reader_impl.h
@@ -0,0 +1,67 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_
+#define CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_
+
+#include <jni.h>
+#include <string>
+#include <vector>
+
+#include "base/android/jni_array.h"
+#include "base/android/jni_helper.h"
+#include "base/android/scoped_java_ref.h"
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/singleton.h"
+
+namespace content {
+using std::string;
+// This class interacts with JNI and calls GamepadList. It creates a
+// GamepadsReader java object and pings GamepadList for updates.
+
+// The simplified flow is:
+// 1. GamepadDataFetcher runs on a Polling Thread and it tries to fetch data
+// via low-level data fetcher from the framework for android platform.
+// 2. GamepadPlatformDataFetcherAndroid access a singleton GamepadsReader
+// GamepadsReader makes JNI calls and uses singleton GamepadList on the java
+// side to get the updated gamepad state. We then bounce these updates to the
+// GamepadProvider which writes to GamepadHardwareBuffer.
+
+// Note that GamepadsReader is a singleton and there's at most only
+// one GamepadsReader that has called updateGamepadList().
+
+class GamepadsReader {
+ public:
+ // Registers the JNI methods for GamepadsReader.
+ static bool RegisterGamepadsReader(JNIEnv* env);
+ // Returns our singleton.
+ static GamepadsReader* GetInstance();
+
+ // Methods called to update GamepadList for Gamepad access and release by
+ // navigator object.
+ void NotifyForGamepadsAccess(bool isaccesspaused);
+ // Methods called on the Polling thread.
+ int UpdateGamepadsCount();
+ bool IsDeviceConnected(int Index);
+ std::string GetDeviceName(int Index);
+ int64 GetDeviceTimestamp(int Index);
+ std::vector<float> GetDeviceAxes(int Index);
+ std::vector<float> GetDeviceButtons(int Index);
+ bool IsGamepadLayoutKnown(int Index);
+
+ private:
+ friend struct DefaultSingletonTraits<GamepadsReader>;
+ GamepadsReader();
+ ~GamepadsReader();
+
+ void CreateJavaObject(JNIEnv* env);
+
+ base::android::ScopedJavaGlobalRef<jobject>
+ java_gamepadList_object_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_

Powered by Google App Engine
This is Rietveld 408576698