| 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_JOYDEV_H_ |
| 6 #define COMPONENTS_EXO_GAMING_SEAT_H_ | 6 #define COMPONENTS_EXO_GAMING_SEAT_JOYDEV_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "components/exo/gaming_seat.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 |
| 20 namespace exo { | 21 namespace exo { |
| 21 class GamingSeatDelegate; | 22 class GamingSeatDelegate; |
| 22 class GamepadDelegate; | 23 class GamepadDelegate; |
| 23 | 24 |
| 24 using CreateGamepadDataFetcherCallback = | 25 using CreateGamepadDataFetcherCallback = |
| 25 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; | 26 base::Callback<std::unique_ptr<device::GamepadDataFetcher>()>; |
| 26 | 27 |
| 27 // This class represents one gaming seat, it uses a background thread | 28 // This class represents one gaming seat, it uses a background thread |
| 28 // for polling gamepad devices and notifies the corresponding GampadDelegate of | 29 // for polling gamepad devices and notifies the corresponding GampadDelegate of |
| 29 // any changes. | 30 // any changes. This gaming seat read gamepad events from joydev interface. |
| 30 class GamingSeat : public WMHelper::FocusObserver { | 31 class GamingSeatJoydev : public GamingSeat { |
| 31 public: | 32 public: |
| 32 // This class will post tasks to invoke the delegate on the thread runner | 33 // This class will post tasks to invoke the delegate on the thread runner |
| 33 // which is associated with the thread that is creating this instance. | 34 // which is associated with the thread that is creating this instance. |
| 34 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | 35 GamingSeatJoydev(GamingSeatDelegate* gaming_seat_delegate, |
| 35 base::SingleThreadTaskRunner* polling_task_runner); | 36 base::SingleThreadTaskRunner* polling_task_runner); |
| 36 | 37 |
| 37 // Allows test cases to specify a CreateGamepadDataFetcherCallback that | 38 // Allows test cases to specify a CreateGamepadDataFetcherCallback that |
| 38 // overrides the default GamepadPlatformDataFetcher. | 39 // overrides the default GamepadPlatformDataFetcher. |
| 39 GamingSeat(GamingSeatDelegate* gaming_seat_delegate, | 40 GamingSeatJoydev(GamingSeatDelegate* gaming_seat_delegate, |
| 40 base::SingleThreadTaskRunner* polling_task_runner, | 41 base::SingleThreadTaskRunner* polling_task_runner, |
| 41 CreateGamepadDataFetcherCallback create_fetcher_callback); | 42 CreateGamepadDataFetcherCallback create_fetcher_callback); |
| 42 | 43 |
| 43 ~GamingSeat() override; | 44 ~GamingSeatJoydev() override; |
| 44 | 45 |
| 45 // Overridden WMHelper::FocusObserver: | 46 // Overridden WMHelper::FocusObserver: |
| 46 void OnWindowFocused(aura::Window* gained_focus, | 47 void OnWindowFocused(aura::Window* gained_focus, |
| 47 aura::Window* lost_focus) override; | 48 aura::Window* lost_focus) override; |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 class ThreadSafeGamepadChangeFetcher; | 51 class ThreadSafeGamepadChangeFetcher; |
| 51 | 52 |
| 52 // Processes updates of gamepad data and passes changes on to delegate. | 53 // Processes updates of gamepad data and passes changes on to delegate. |
| 53 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); | 54 void ProcessGamepadChanges(int index, const device::Gamepad new_pad); |
| 54 | 55 |
| 55 // Private implementation of methods and resources that are used on the | 56 // Private implementation of methods and resources that are used on the |
| 56 // polling thread. | 57 // polling thread. |
| 57 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; | 58 scoped_refptr<ThreadSafeGamepadChangeFetcher> gamepad_change_fetcher_; |
| 58 | 59 |
| 59 // The delegate that handles gamepad_added. | 60 // The delegate that handles gamepad_added. |
| 60 GamingSeatDelegate* const delegate_; | 61 GamingSeatDelegate* const delegate_; |
| 61 | 62 |
| 62 // The delegate instances that all other events are dispatched to. | 63 // The delegate instances that all other events are dispatched to. |
| 63 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; | 64 GamepadDelegate* gamepad_delegates_[device::Gamepads::kItemsLengthCap]; |
| 64 | 65 |
| 65 // The current state of the gamepad represented by this instance. | 66 // The current state of the gamepad represented by this instance. |
| 66 device::Gamepads pad_state_; | 67 device::Gamepads pad_state_; |
| 67 | 68 |
| 68 // ThreadChecker for the origin thread. | 69 // ThreadChecker for the origin thread. |
| 69 base::ThreadChecker thread_checker_; | 70 THREAD_CHECKER(thread_checker_); |
| 70 | 71 |
| 71 base::WeakPtrFactory<GamingSeat> weak_ptr_factory_; | 72 base::WeakPtrFactory<GamingSeatJoydev> weak_ptr_factory_; |
| 72 | 73 |
| 73 DISALLOW_COPY_AND_ASSIGN(GamingSeat); | 74 DISALLOW_COPY_AND_ASSIGN(GamingSeatJoydev); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // namespace exo | 77 } // namespace exo |
| 77 | 78 |
| 78 #endif // COMPONENTS_EXO_GAMING_SEAT_H_ | 79 #endif // COMPONENTS_EXO_GAMING_SEAT_JOYDEV_H_ |
| OLD | NEW |