Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | |
| 24 namespace ui { | |
| 25 class GamepadProviderOzone; | |
| 26 } | |
| 27 #endif | |
| 28 | |
| 29 namespace base { | |
| 30 class Thread; | |
| 31 } | |
| 32 | |
| 20 namespace exo { | 33 namespace exo { |
| 21 class GamingSeatDelegate; | 34 class GamingSeatDelegate; |
| 22 class GamepadDelegate; | 35 class GamepadDelegate; |
| 23 | 36 |
| 24 using CreateGamepadDataFetcherCallback = | 37 using CreateGamepadDataFetcherCallback = |
| 25 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; | 38 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; |
| 26 | 39 |
| 27 // This class represents one gaming seat, it uses a background thread | 40 // TODO(jkwang) always use ozone_gamepad when ozone is default for all chrome os |
|
reveman
2017/06/06 21:58:55
Please keep a class description here in some form.
jkwang
2017/06/07 18:03:19
Done.
|
reveman
2017/06/06 21:58:55
nit: s/TODO(jkwang)/TODO(jkwang):", s/chrome os/Ch
jkwang
2017/06/07 18:03:19
Done.
|
| 28 // for polling gamepad devices and notifies the corresponding GampadDelegate of | 41 // build. |
|
reveman
2017/06/06 21:58:55
nit: s/build/builds/
jkwang
2017/06/07 18:03:19
Done.
| |
| 29 // any changes. | 42 class GamingSeat : public WMHelper::FocusObserver |
| 30 class GamingSeat : public WMHelper::FocusObserver { | 43 #if defined(USE_OZONE_GAMEPAD) |
| 44 , | |
| 45 public ui::GamepadObserver | |
| 46 #endif | |
| 47 { | |
| 31 public: | 48 public: |
| 32 // This class will post tasks to invoke the delegate on the thread runner | 49 // This class will monitor gamepad connection change and manage gamepad |
|
reveman
2017/06/06 21:58:55
s/change/changes/
jkwang
2017/06/07 18:03:18
Done.
| |
| 33 // which is associated with the thread that is creating this instance. | 50 // returned by gaming_seat_delegate. |
| 34 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | 51 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, |
| 35 base::SingleThreadTaskRunner* polling_task_runner); | 52 base::SingleThreadTaskRunner* polling_task_runner); |
| 36 | 53 |
| 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; | 54 ~GamingSeat() override; |
| 44 | 55 |
| 45 // Overridden WMHelper::FocusObserver: | 56 // Overridden from WMHelper::FocusObserver: |
| 46 void OnWindowFocused(aura::Window* gained_focus, | 57 void OnWindowFocused(aura::Window* gained_focus, |
| 47 aura::Window* lost_focus) override; | 58 aura::Window* lost_focus) override; |
| 48 | 59 |
| 60 #if defined(USE_OZONE_GAMEPAD) | |
| 61 // Overridden from ui::GamepadObserver: | |
| 62 void OnGamepadDevicesUpdated() override; | |
| 63 void OnGamepadEvent(const ui::GamepadEvent& event) override; | |
| 64 #endif | |
| 65 | |
| 49 private: | 66 private: |
| 67 // The delegate that handles gamepad_added. | |
| 68 GamingSeatDelegate* const delegate_; | |
| 69 | |
| 70 #if defined(USE_OZONE_GAMEPAD) | |
| 71 // Contains the delegate for each gamepad device. | |
| 72 base::flat_map<int, GamepadDelegate*> gamepads_; | |
| 73 | |
| 74 // Cached pointer to GamepadProviderOzone. | |
| 75 ui::GamepadProviderOzone* gamepad_provider_; | |
|
reveman
2017/06/06 21:58:55
why do we need this? please avoid caching a simple
jkwang
2017/06/07 18:03:19
It is suggested here.
https://cs.chromium.org/chro
reveman
2017/06/07 20:29:45
16ns on my P4/2.8GHz is not worth micro optimizing
jkwang
2017/06/07 22:01:45
Done.
| |
| 76 #else | |
| 50 class ThreadSafeGamepadChangeFetcher; | 77 class ThreadSafeGamepadChangeFetcher; |
| 51 | 78 |
| 52 // Processes updates of gamepad data and passes changes on to delegate. | 79 // Processes updates of gamepad data and passes changes on to delegate. |
| 53 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); | 80 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); |
| 54 | 81 |
| 55 // Private implementation of methods and resources that are used on the | 82 // Private implementation of methods and resources that are used on the |
| 56 // polling thread. | 83 // polling thread. |
| 57 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; | 84 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; |
| 58 | 85 |
| 59 // The delegate that handles gamepad_added. | |
| 60 GamingSeatDelegate* const delegate_; | |
| 61 | |
| 62 // The delegate instances that all other events are dispatched to. | 86 // The delegate instances that all other events are dispatched to. |
| 63 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; | 87 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; |
| 64 | 88 |
| 65 // The current state of the gamepad represented by this instance. | 89 // The current state of the gamepad represented by this instance. |
| 66 device::Gamepads pad_state_; | 90 device::Gamepads pad_state_; |
| 67 | 91 |
| 68 // ThreadChecker for the origin thread. | 92 // ThreadChecker for the origin thread. |
| 69 base::ThreadChecker thread_checker_; | 93 THREAD_CHECKER(thread_checker_); |
| 70 | 94 |
| 71 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; | 95 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; |
| 96 #endif | |
| 72 | 97 |
| 73 DISALLOW_COPY_AND_ASSIGN(GamingSeat); | 98 DISALLOW_COPY_AND_ASSIGN(GamingSeat); |
| 74 }; | 99 }; |
| 75 | 100 |
| 76 } // namespace exo | 101 } // namespace exo |
| 77 | 102 |
| 78 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ | 103 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ |
| OLD | NEW |