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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_
30 #define CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_
31
32 #include <jni.h>
33 #include <vector>
34
35 #include "base/android/jni_array.h"
36 #include "base/android/jni_helper.h"
37 #include "base/android/scoped_java_ref.h"
38
39 #include "base/memory/ref_counted.h"
40 #include "base/memory/singleton.h"
41
42 namespace content {
43 using std::string;
44 // Interacts with JNI and calls GamepadList.
45 // This class creates a GamepadsReader java object and pings GamepadList for
46 // updates.
47 // The simplified flow is:
48 // GamepadDataFetcher runs on a Polling Thread and it tries to fetch data from
49 // the framework for android platform.
50 // GamepadPlatformDataFetcherAndroid access a singleton GamepadsReader
51 // GamepadsReader calls via JNI and uses the singleton GamepadList
52 // in the java side to get the updated gamepad state. We then bounce these
53 // updates to the GamepadProvider which writes to GamepadHardwareBuffer.
54 // GamepadHardwareBuffer structure is stored in shared memory that's shared
55 // between a writer that does hardware polling, and the various consumers of
56 // the gamepad.
57
58 // Note that GamepadsReader is a singleton and there's at most only
59 // one GamepadsReader that has called updateGamepadList().
60
61 class GamepadsReader{
scottmg 2014/01/13 19:42:43 There's a lot of code that doesn't follow the styl
SaurabhK 2014/01/15 16:57:08 WIll update in next patchset.
62 public:
63
64 // Registers the JNI methods for GamepadsReader.
65 static bool RegisterGamepadsReader(JNIEnv* env);
66
67 // Returns our singleton.
68 static GamepadsReader* GetInstance();
69
70 // Methods called to update GamepadList for Gamepad access and release by
71 // navigator object.
72 void notifyForGamepadsAccess(bool);
73 // Methods called on the Polling thread.
74 int updateGamepadsCount();
75 bool isDeviceConnected(int);
76 std::string getDeviceName(int);
77 long getDeviceTimestamp(int);
78 std::vector<float> getDeviceAxes(int);
79 std::vector<float> getDeviceButtons(int);
80 bool isGamepadLayoutKnown(int);
81
82 private:
83 friend struct DefaultSingletonTraits<GamepadsReader>;
84 GamepadsReader();
85 ~GamepadsReader();
86
87 void CreateJavaObject(JNIEnv* env);
88
89 base::android::ScopedJavaGlobalRef<jobject>
90 java_gamepadList_object_;
91 };
92
93 } // namespace content
94 #endif // CONTENT_BROWSER_ANDROID_GAMEPAD_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698