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

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, 10 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..133b36173ece23f159c2fdd0462d2a7dd050469b
--- /dev/null
+++ b/content/browser/android/gamepad_reader_impl.h
@@ -0,0 +1,76 @@
+// 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"
+#include "third_party/WebKit/public/platform/WebGamepads.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 made calls to GamepadList.
+
+class GamepadsReader {
+ public:
+ // Registers the JNI methods for GamepadsReader.
+ static bool RegisterGamepadsReader(JNIEnv* env);
+ // Returns our singleton.
+ static GamepadsReader* GetInstance();
+
+ // Native methods that are called from GamepadList.
+ void SetGamepadData(JNIEnv* env,
+ jobject obj,
+ int index,
+ bool connected,
+ jstring devicename,
+ int64 timestamp,
+ jfloatArray jaxes,
+ jfloatArray jbuttons);
+
+ void UpdateDeviceCount(JNIEnv* env, jobject obj, int devicecount);
+
+ // Called on Polling thread.
+ void GetGamepadData(blink::WebGamepads* pads);
+
+ // Called to update GamepadList for Gamepad access and release by
+ // low level gamepad data fetcher.
+ void NotifyForGamepadsAccess(bool isaccesspaused);
+
+ private:
+ friend struct DefaultSingletonTraits<GamepadsReader>;
+ GamepadsReader();
+ ~GamepadsReader();
+
+ void CreateJavaObject(JNIEnv* env);
+
+ // Data to fetch into.
+ blink::WebGamepads* gamepads_data_;
+
+ 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