OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/android/jni_array.h" |
| 13 #include "base/android/jni_helper.h" |
| 14 #include "base/android/scoped_java_ref.h" |
| 15 |
| 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/singleton.h" |
| 18 |
| 19 namespace content { |
| 20 using std::string; |
| 21 // This class interacts with JNI and calls GamepadList. It creates a |
| 22 // GamepadsReader java object and pings GamepadList for updates. |
| 23 |
| 24 // The simplified flow is: |
| 25 // 1. GamepadDataFetcher runs on a Polling Thread and it tries to fetch data |
| 26 // via low-level data fetcher from the framework for android platform. |
| 27 // 2. GamepadPlatformDataFetcherAndroid access a singleton GamepadsReader |
| 28 // GamepadsReader makes JNI calls and uses singleton GamepadList on the java |
| 29 // side to get the updated gamepad state. We then bounce these updates to the |
| 30 // GamepadProvider which writes to GamepadHardwareBuffer. |
| 31 |
| 32 // Note that GamepadsReader is a singleton and there's at most only |
| 33 // one GamepadsReader that has called updateGamepadList(). |
| 34 |
| 35 class GamepadsReader { |
| 36 public: |
| 37 // Registers the JNI methods for GamepadsReader. |
| 38 static bool RegisterGamepadsReader(JNIEnv* env); |
| 39 // Returns our singleton. |
| 40 static GamepadsReader* GetInstance(); |
| 41 |
| 42 // Methods called to update GamepadList for Gamepad access and release by |
| 43 // navigator object. |
| 44 void NotifyForGamepadsAccess(bool isaccesspaused); |
| 45 // Methods called on the Polling thread. |
| 46 int UpdateGamepadsCount(); |
| 47 bool IsDeviceConnected(int Index); |
| 48 std::string GetDeviceName(int Index); |
| 49 int64 GetDeviceTimestamp(int Index); |
| 50 std::vector<float> GetDeviceAxes(int Index); |
| 51 std::vector<float> GetDeviceButtons(int Index); |
| 52 bool IsGamepadLayoutKnown(int Index); |
| 53 |
| 54 private: |
| 55 friend struct DefaultSingletonTraits<GamepadsReader>; |
| 56 GamepadsReader(); |
| 57 ~GamepadsReader(); |
| 58 |
| 59 void CreateJavaObject(JNIEnv* env); |
| 60 |
| 61 base::android::ScopedJavaGlobalRef<jobject> |
| 62 java_gamepadList_object_; |
| 63 }; |
| 64 |
| 65 } // namespace content |
| 66 |
| 67 #endif // CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_ |
OLD | NEW |