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

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

Issue 2900773003: Allow gaming_seat to use ozone gamepad as back-end (Closed)
Patch Set: Allow gaming_seat to use ozone gamepad as backend Created 3 years, 6 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
« no previous file with comments | « components/exo/BUILD.gn ('k') | components/exo/gaming_seat.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_EXO_GAMING_SEAT_H_ 5 #ifndef COMPONENTS_EXO_GAMING_SEAT_H_
6 #define COMPONENTS_EXO_GAMING_SEAT_H_ 6 #define COMPONENTS_EXO_GAMING_SEAT_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/containers/flat_map.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
16 #include "components/exo/wm_helper.h" 17 #include "components/exo/wm_helper.h"
17 #include "device/gamepad/gamepad_data_fetcher.h" 18 #include "device/gamepad/gamepad_data_fetcher.h"
18 #include "ui/aura/client/focus_change_observer.h" 19 #include "ui/aura/client/focus_change_observer.h"
19 20
21 #if defined(USE_OZONE_GAMEPAD)
22 #include "ui/events/ozone/gamepad/gamepad_observer.h"
23 #endif
24
20 namespace exo { 25 namespace exo {
21 class GamingSeatDelegate; 26 class GamingSeatDelegate;
22 class GamepadDelegate; 27 class GamepadDelegate;
23 28
24 using CreateGamepadDataFetcherCallback = 29 using CreateGamepadDataFetcherCallback =
25 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; 30 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>;
26 31
27 // This class represents one gaming seat, it uses a background thread 32 // TODO(jkwang): always use ozone_gamepad when ozone is default for all Chrome
28 // for polling gamepad devices and notifies the corresponding GampadDelegate of 33 // OS builds. https://crbug.com/717246
29 // any changes. 34 // This class represents one gaming seat. It uses /device/gamepad or
30 class GamingSeat : public WMHelper::FocusObserver { 35 // ozone/gamepad as backend and notifies corresponding GamepadDelegate of any
36 // gamepad changes.
37 class GamingSeat : public WMHelper::FocusObserver
38 #if defined(USE_OZONE_GAMEPAD)
39 ,
40 public ui::GamepadObserver
41 #endif
42 {
31 public: 43 public:
32 // This class will post tasks to invoke the delegate on the thread runner 44 // This class will monitor gamepad connection changes and manage gamepad
33 // which is associated with the thread that is creating this instance. 45 // returned by gaming_seat_delegate.
34 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, 46 GamingSeat(GamingSeatDelegate* gaming_seat_delegate,
35 base::SingleThreadTaskRunner* polling_task_runner); 47 base::SingleThreadTaskRunner* polling_task_runner);
36 48
37 // Allows test cases to specify a CreateGamepadDataFetcherCallback that
38 // overrides the default GamepadPlatformDataFetcher.
39 GamingSeat(GamingSeatDelegate* gaming_seat_delegate,
40 base::SingleThreadTaskRunner* polling_task_runner,
41 CreateGamepadDataFetcherCallback create_fetcher_callback);
42
43 ~GamingSeat() override; 49 ~GamingSeat() override;
44 50
45 // Overridden WMHelper::FocusObserver: 51 // Overridden from WMHelper::FocusObserver:
46 void OnWindowFocused(aura::Window* gained_focus, 52 void OnWindowFocused(aura::Window* gained_focus,
47 aura::Window* lost_focus) override; 53 aura::Window* lost_focus) override;
48 54
55 #if defined(USE_OZONE_GAMEPAD)
56 // Overridden from ui::GamepadObserver:
57 void OnGamepadDevicesUpdated() override;
58 void OnGamepadEvent(const ui::GamepadEvent& event) override;
59 #endif
60
49 private: 61 private:
62 // The delegate that handles gamepad_added.
63 GamingSeatDelegate* const delegate_;
64
65 #if defined(USE_OZONE_GAMEPAD)
66 // Contains the delegate for each gamepad device.
67 base::flat_map<int, GamepadDelegate*> gamepads_;
68 #else
50 class ThreadSafeGamepadChangeFetcher; 69 class ThreadSafeGamepadChangeFetcher;
51 70
52 // Processes updates of gamepad data and passes changes on to delegate. 71 // Processes updates of gamepad data and passes changes on to delegate.
53 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); 72 void ProcessGamepadChanges(int index, const device::Gamepad new_pad);
54 73
55 // Private implementation of methods and resources that are used on the 74 // Private implementation of methods and resources that are used on the
56 // polling thread. 75 // polling thread.
57 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; 76 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_;
58 77
59 // The delegate that handles gamepad_added.
60 GamingSeatDelegate* const delegate_;
61
62 // The delegate instances that all other events are dispatched to. 78 // The delegate instances that all other events are dispatched to.
63 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; 79 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap];
64 80
65 // The current state of the gamepad represented by this instance. 81 // The current state of the gamepad represented by this instance.
66 device::Gamepads pad_state_; 82 device::Gamepads pad_state_;
67 83
68 // ThreadChecker for the origin thread. 84 // ThreadChecker for the origin thread.
69 base::ThreadChecker thread_checker_; 85 THREAD_CHECKER(thread_checker_);
70 86
71 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; 87 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_;
88 #endif
72 89
73 DISALLOW_COPY_AND_ASSIGN(GamingSeat); 90 DISALLOW_COPY_AND_ASSIGN(GamingSeat);
74 }; 91 };
75 92
76 } // namespace exo 93 } // namespace exo
77 94
78 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ 95 #endif // COMPONENTS_EXO_GAMING_SEAT_H_
OLDNEW
« no previous file with comments | « components/exo/BUILD.gn ('k') | components/exo/gaming_seat.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698