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

Unified Diff: content/browser/gamepad/gamepad_provider.h

Issue 1627643002: Revert of Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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: content/browser/gamepad/gamepad_provider.h
diff --git a/content/browser/gamepad/gamepad_provider.h b/content/browser/gamepad/gamepad_provider.h
index 2113bcac1429f902e64d1b8228b0d62f1a8f46d6..f2dcad245bbef162bf847f520b4f83f274df9400 100644
--- a/content/browser/gamepad/gamepad_provider.h
+++ b/content/browser/gamepad/gamepad_provider.h
@@ -5,7 +5,6 @@
#ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_
#define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PROVIDER_H_
-#include <stdint.h>
#include <utility>
#include <vector>
@@ -14,9 +13,9 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/shared_memory.h"
+#include "base/memory/weak_ptr.h"
#include "base/synchronization/lock.h"
#include "base/system_monitor/system_monitor.h"
-#include "content/browser/gamepad/gamepad_standard_mappings.h"
#include "content/common/content_export.h"
#include "third_party/WebKit/public/platform/WebGamepads.h"
@@ -29,58 +28,6 @@
class GamepadDataFetcher;
struct GamepadHardwareBuffer;
-
-enum GamepadSource {
- GAMEPAD_SOURCE_NONE = 0,
- GAMEPAD_SOURCE_ANDROID,
- GAMEPAD_SOURCE_LINUX_UDEV,
- GAMEPAD_SOURCE_MAC_HID,
- GAMEPAD_SOURCE_MAC_XBOX,
- GAMEPAD_SOURCE_TEST,
- GAMEPAD_SOURCE_WIN_XINPUT,
- GAMEPAD_SOURCE_WIN_RAW,
-};
-
-enum GamepadActiveState {
- GAMEPAD_INACTIVE = 0,
- GAMEPAD_ACTIVE,
- GAMEPAD_NEWLY_ACTIVE,
-};
-
-struct PadState {
- // Which data fetcher provided this gamepad's data.
- GamepadSource source;
-
- // Data fetcher-specific identifier for this gamepad.
- int source_id;
-
- // Indicates whether or not the gamepad is actively being updated
- GamepadActiveState active_state;
-
- // Gamepad data, unmapped.
- blink::WebGamepad data;
-
- // Functions to map from device data to standard layout, if available. May
- // be null if no mapping is available or needed.
- GamepadStandardMappingFunction mapper;
-
- // Sanitization masks
- // axis_mask and button_mask are bitfields that represent the reset state of
- // each input. If a button or axis has ever reported 0 in the past the
- // corresponding bit will be set to 1.
-
- // If we ever increase the max axis count this will need to be updated.
- static_assert(blink::WebGamepad::axesLengthCap <=
- std::numeric_limits<uint32_t>::digits,
- "axis_mask is not large enough");
- uint32_t axis_mask;
-
- // If we ever increase the max button count this will need to be updated.
- static_assert(blink::WebGamepad::buttonsLengthCap <=
- std::numeric_limits<uint32_t>::digits,
- "button_mask is not large enough");
- uint32_t button_mask;
-};
class CONTENT_EXPORT GamepadProvider :
public base::SystemMonitor::DevicesChangedObserver {
@@ -111,20 +58,12 @@
// base::SystemMonitor::DevicesChangedObserver implementation.
void OnDevicesChanged(base::SystemMonitor::DeviceType type) override;
- // Add a gamepad data fetcher. Takes ownership of |fetcher|.
- void AddGamepadDataFetcher(scoped_ptr<GamepadDataFetcher> fetcher);
-
- // Gets a PadState object for the given source and id. If the device hasn't
- // been encountered before one of the remaining slots will be reserved for it.
- // If no slots are available will return NULL.
- PadState* GetPadState(GamepadSource source, int source_id);
-
- void SetSanitizationEnabled(bool sanitize) { sanitize_ = sanitize; }
-
private:
void Initialize(scoped_ptr<GamepadDataFetcher> fetcher);
- void DoAddGamepadDataFetcher(scoped_ptr<GamepadDataFetcher> fetcher);
+ // Method for setting up the platform-specific data fetcher. Takes ownership
+ // of |fetcher|.
+ void DoInitializePollingThread(scoped_ptr<GamepadDataFetcher> fetcher);
// Method for sending pause hints to the low-level data fetcher. Runs on
// polling_thread_.
@@ -145,10 +84,6 @@
// Checks the gamepad state to see if the user has interacted with it.
void CheckForUserGesture();
- void ClearPadState(PadState& state);
-
- void MapAndSanitizeGamepadData(PadState* pad_state,
- blink::WebGamepad* pad);
enum { kDesiredSamplingIntervalMs = 16 };
@@ -157,7 +92,7 @@
base::Lock is_paused_lock_;
bool is_paused_;
- // Keep track of when a polling task is scheduled, so as to prevent us from
+ // Keep track of when a polling task is schedlued, so as to prevent us from
// accidentally scheduling more than one at any time, when rapidly toggling
// |is_paused_|.
bool have_scheduled_do_poll_;
@@ -188,14 +123,33 @@
bool devices_changed_;
bool ever_had_user_gesture_;
- bool sanitize_;
- // Tracks the state of each gamepad slot.
+ class PadState {
+ public:
+ PadState() {
+ SetDisconnected();
+ }
+
+ bool Match(const blink::WebGamepad& pad) const;
+ void SetPad(const blink::WebGamepad& pad);
+ void SetDisconnected();
+ void AsWebGamepad(blink::WebGamepad* pad);
+
+ bool connected() const { return connected_; }
+
+ private:
+ bool connected_;
+ unsigned axes_length_;
+ unsigned buttons_length_;
+ blink::WebUChar id_[blink::WebGamepad::idLengthCap];
+ blink::WebUChar mapping_[blink::WebGamepad::mappingLengthCap];
+ };
+
+ // Used to detect connections and disconnections.
scoped_ptr<PadState[]> pad_states_;
// Only used on the polling thread.
- typedef std::vector<scoped_ptr<GamepadDataFetcher>> GamepadFetcherVector;
- GamepadFetcherVector data_fetchers_;
+ scoped_ptr<GamepadDataFetcher> data_fetcher_;
base::Lock shared_memory_lock_;
base::SharedMemory gamepad_shared_memory_;
@@ -203,6 +157,8 @@
// Polling is done on this background thread.
scoped_ptr<base::Thread> polling_thread_;
+ static GamepadProvider* instance_;
+
DISALLOW_COPY_AND_ASSIGN(GamepadProvider);
};
« no previous file with comments | « content/browser/gamepad/gamepad_platform_data_fetcher_win.cc ('k') | content/browser/gamepad/gamepad_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698