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

Side by Side Diff: components/exo/gamepad.h

Issue 2076013002: exo: Implement wayland gamepad support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serv
Patch Set: Focus handling. Process gamepad delta on origin thread. Add focus unittest. Created 4 years, 5 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 // Copyright 2016 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 COMPONENTS_EXO_GAMEPAD_H_
6 #define COMPONENTS_EXO_GAMEPAD_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread.h"
15 #include "base/threading/thread_task_runner_handle.h"
16 #include "device/gamepad/gamepad_data_fetcher.h"
17 #include "ui/aura/client/focus_change_observer.h"
18
19 namespace exo {
20 class GamepadDelegate;
21
22 // This class represents one or more gamepads, it implements a background thread
23 // for polling gamepad devices and notifies the GamepadDelegate of any
24 // changes.
25 class Gamepad : public aura::client::FocusChangeObserver {
26 public:
27 // This class will post tasks to invoke the delegate on the thread runner
28 // which is associated with the thread that is creating this instance.
29 explicit Gamepad(GamepadDelegate* delegate);
30 // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad
31 // data.
32 Gamepad(GamepadDelegate* delegate,
33 std::unique_ptr<device::GamepadDataFetcher> fetcher);
34 ~Gamepad() override;
35
36 // Overridden aura::client::FocusChangeObserver:
37 void OnWindowFocused(aura::Window* gained_focus,
38 aura::Window* lost_focus) override;
39
40 private:
41 // Schedules a poll on the polling thread. Can be called from any thread.
42 void ScheduleOnPoll();
43
44 // Polls devices for new data and posts delegate updates.
45 // Can only be called on the polling thread.
46 void OnPoll();
47
48 // Initializes the underlying gamepad data fetcher.
49 // Can only be called on the polling thread.
50 void InitializePollingThread();
51
52 // Posts updates of gamepad data to delegate. Can only be called on the
53 // origin thread.
54 void PostGamepadChanges(const blink::WebGamepad new_pad);
55
56 // The delegate instance that all events are dispatched to.
57 GamepadDelegate* const delegate_;
58
59 // The current state of the gamepad represented by this instance.
60 blink::WebGamepad pad_state_;
61
62 // True if an exosphere window is currently focused.
reveman 2016/06/30 18:06:11 s/an exosphere window/a client surface/
denniskempin 2016/07/01 02:34:35 Done.
63 bool exo_focused_{false};
reveman 2016/06/30 18:06:11 nit: remove exo_ prefix
denniskempin 2016/07/01 02:34:35 Done.
64
65 // Reference to the task runner of the thread that created this instance.
66 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
67
68 // ThreadChecker for the origin thread
69 base::ThreadChecker origin_thread_checker_;
70
71 // The thread on which the polling is executed. It accesses only the variables
72 // below, which are marked as only used by the polling thread.
73 std::unique_ptr<base::Thread> polling_thread_;
74
75 // Implements the logic to fetch gamepad information from connected devices.
76 // Only used by polling thread.
77 std::unique_ptr<device::GamepadDataFetcher> fetcher_;
78
79 // The current state of all gamepads. Only used by polling thread.
80 blink::WebGamepads state_;
81
82 // ThreadChecker for the polling thread.
83 base::ThreadChecker polling_thread_checker_;
84
85 // Weak pointer to this, created during construction on origin thread, but
86 // only used by polling thread to post tasks back to the origin thread.
87 base::WeakPtr<Gamepad> weak_this_;
reveman 2016/06/30 18:06:11 Chromium code will typically keep a callbacks that
denniskempin 2016/07/01 02:34:35 Done.
88
89 // Weak pointer factory to create the above weak pointer.
90 base::WeakPtrFactory<Gamepad> weak_factory_;
91
92 DISALLOW_COPY_AND_ASSIGN(Gamepad);
93 };
94
95 } // namespace exo
96
97 #endif // COMPONENTS_EXO_GAMEPAD_H_
OLDNEW
« no previous file with comments | « components/exo/DEPS ('k') | components/exo/gamepad.cc » ('j') | components/exo/gamepad.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698