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

Side by Side Diff: device/gamepad/gamepad_pad_state_provider.h

Issue 2129003002: Refactored gamepad polling to support dynamic sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disabled sanitization test on Android. Suffers from same bug as PollingAccess test Created 4 years, 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_
6 #define DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_
7
8 #include <stdint.h>
9
10 #include <limits>
11 #include <memory>
12
13 #include "device/gamepad/gamepad_export.h"
14 #include "device/gamepad/gamepad_standard_mappings.h"
15 #include "third_party/WebKit/public/platform/WebGamepad.h"
16
17 namespace device {
18
19 class GamepadDataFetcher;
20
21 enum GamepadSource {
22 GAMEPAD_SOURCE_NONE = 0,
23 GAMEPAD_SOURCE_ANDROID,
24 GAMEPAD_SOURCE_LINUX_UDEV,
25 GAMEPAD_SOURCE_MAC_HID,
26 GAMEPAD_SOURCE_MAC_XBOX,
27 GAMEPAD_SOURCE_TEST,
28 GAMEPAD_SOURCE_WIN_XINPUT,
29 GAMEPAD_SOURCE_WIN_RAW,
30 };
31
32 enum GamepadActiveState {
33 GAMEPAD_INACTIVE = 0,
34 GAMEPAD_ACTIVE,
35 GAMEPAD_NEWLY_ACTIVE,
36 };
37
38 struct PadState {
39 // Which data fetcher provided this gamepad's data.
40 GamepadSource source;
41 // Data fetcher-specific identifier for this gamepad.
42 int source_id;
43
44 // Indicates whether or not the gamepad is actively being updated
45 GamepadActiveState active_state;
46
47 // Gamepad data, unmapped.
48 blink::WebGamepad data;
49
50 // Functions to map from device data to standard layout, if available. May
51 // be null if no mapping is available or needed.
52 GamepadStandardMappingFunction mapper;
53
54 // Sanitization masks
55 // axis_mask and button_mask are bitfields that represent the reset state of
56 // each input. If a button or axis has ever reported 0 in the past the
57 // corresponding bit will be set to 1.
58
59 // If we ever increase the max axis count this will need to be updated.
60 static_assert(blink::WebGamepad::axesLengthCap <=
61 std::numeric_limits<uint32_t>::digits,
62 "axis_mask is not large enough");
63 uint32_t axis_mask;
64
65 // If we ever increase the max button count this will need to be updated.
66 static_assert(blink::WebGamepad::buttonsLengthCap <=
67 std::numeric_limits<uint32_t>::digits,
68 "button_mask is not large enough");
69 uint32_t button_mask;
70 };
71
72 class DEVICE_GAMEPAD_EXPORT GamepadPadStateProvider {
73 public:
74 GamepadPadStateProvider();
75 virtual ~GamepadPadStateProvider();
76
77 // Gets a PadState object for the given source and id. If the device hasn't
78 // been encountered before one of the remaining slots will be reserved for it.
79 // If no slots are available will return NULL.
80 PadState* GetPadState(GamepadSource source, int source_id);
81
82 protected:
83 void ClearPadState(PadState& state);
84
85 void InitializeDataFetcher(GamepadDataFetcher* fetcher);
86
87 void MapAndSanitizeGamepadData(PadState* pad_state,
88 blink::WebGamepad* pad,
89 bool sanitize);
90
91 // Tracks the state of each gamepad slot.
92 std::unique_ptr<PadState[]> pad_states_;
93 };
94
95 } // namespace device
96
97 #endif // DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_data_fetcher_manager.cc ('k') | device/gamepad/gamepad_pad_state_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698