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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: components/exo/gamepad.h
diff --git a/components/exo/gamepad.h b/components/exo/gamepad.h
new file mode 100644
index 0000000000000000000000000000000000000000..68f41afd1de16be7507e80a5d80a44657fc86356
--- /dev/null
+++ b/components/exo/gamepad.h
@@ -0,0 +1,97 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_EXO_GAMEPAD_H_
+#define COMPONENTS_EXO_GAMEPAD_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "base/sequenced_task_runner.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "device/gamepad/gamepad_data_fetcher.h"
+#include "ui/aura/client/focus_change_observer.h"
+
+namespace exo {
+class GamepadDelegate;
+
+// This class represents one or more gamepads, it implements a background thread
+// for polling gamepad devices and notifies the GamepadDelegate of any
+// changes.
+class Gamepad : public aura::client::FocusChangeObserver {
+ public:
+ // This class will post tasks to invoke the delegate on the thread runner
+ // which is associated with the thread that is creating this instance.
+ explicit Gamepad(GamepadDelegate* delegate);
+ // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad
+ // data.
+ Gamepad(GamepadDelegate* delegate,
+ std::unique_ptr<device::GamepadDataFetcher> fetcher);
+ ~Gamepad() override;
+
+ // Overridden aura::client::FocusChangeObserver:
+ void OnWindowFocused(aura::Window* gained_focus,
+ aura::Window* lost_focus) override;
+
+ private:
+ // Schedules a poll on the polling thread. Can be called from any thread.
+ void ScheduleOnPoll();
+
+ // Polls devices for new data and posts delegate updates.
+ // Can only be called on the polling thread.
+ void OnPoll();
+
+ // Initializes the underlying gamepad data fetcher.
+ // Can only be called on the polling thread.
+ void InitializePollingThread();
+
+ // Posts updates of gamepad data to delegate. Can only be called on the
+ // origin thread.
+ void PostGamepadChanges(const blink::WebGamepad new_pad);
+
+ // The delegate instance that all events are dispatched to.
+ GamepadDelegate* const delegate_;
+
+ // The current state of the gamepad represented by this instance.
+ blink::WebGamepad pad_state_;
+
+ // 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.
+ bool exo_focused_{false};
reveman 2016/06/30 18:06:11 nit: remove exo_ prefix
denniskempin 2016/07/01 02:34:35 Done.
+
+ // Reference to the task runner of the thread that created this instance.
+ scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_;
+
+ // ThreadChecker for the origin thread
+ base::ThreadChecker origin_thread_checker_;
+
+ // The thread on which the polling is executed. It accesses only the variables
+ // below, which are marked as only used by the polling thread.
+ std::unique_ptr<base::Thread> polling_thread_;
+
+ // Implements the logic to fetch gamepad information from connected devices.
+ // Only used by polling thread.
+ std::unique_ptr<device::GamepadDataFetcher> fetcher_;
+
+ // The current state of all gamepads. Only used by polling thread.
+ blink::WebGamepads state_;
+
+ // ThreadChecker for the polling thread.
+ base::ThreadChecker polling_thread_checker_;
+
+ // Weak pointer to this, created during construction on origin thread, but
+ // only used by polling thread to post tasks back to the origin thread.
+ 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.
+
+ // Weak pointer factory to create the above weak pointer.
+ base::WeakPtrFactory<Gamepad> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(Gamepad);
+};
+
+} // namespace exo
+
+#endif // COMPONENTS_EXO_GAMEPAD_H_
« 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