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

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

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 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
« no previous file with comments | « device/gamepad/gamepad_monitor.cc ('k') | device/gamepad/gamepad_pad_state_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_ 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_
6 #define DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_ 6 #define DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 #include <memory> 11 #include <memory>
12 12
13 #include "device/gamepad/gamepad_export.h" 13 #include "device/gamepad/gamepad_export.h"
14 #include "device/gamepad/gamepad_standard_mappings.h" 14 #include "device/gamepad/gamepad_standard_mappings.h"
15 #include "third_party/WebKit/public/platform/WebGamepad.h" 15 #include "device/gamepad/public/cpp/gamepad.h"
16 16
17 namespace device { 17 namespace device {
18 18
19 class GamepadDataFetcher; 19 class GamepadDataFetcher;
20 20
21 enum GamepadSource { 21 enum GamepadSource {
22 GAMEPAD_SOURCE_NONE = 0, 22 GAMEPAD_SOURCE_NONE = 0,
23 GAMEPAD_SOURCE_ANDROID, 23 GAMEPAD_SOURCE_ANDROID,
24 GAMEPAD_SOURCE_GVR, 24 GAMEPAD_SOURCE_GVR,
25 GAMEPAD_SOURCE_LINUX_UDEV, 25 GAMEPAD_SOURCE_LINUX_UDEV,
(...skipping 14 matching lines...) Expand all
40 struct PadState { 40 struct PadState {
41 // Which data fetcher provided this gamepad's data. 41 // Which data fetcher provided this gamepad's data.
42 GamepadSource source; 42 GamepadSource source;
43 // Data fetcher-specific identifier for this gamepad. 43 // Data fetcher-specific identifier for this gamepad.
44 int source_id; 44 int source_id;
45 45
46 // Indicates whether or not the gamepad is actively being updated 46 // Indicates whether or not the gamepad is actively being updated
47 GamepadActiveState active_state; 47 GamepadActiveState active_state;
48 48
49 // Gamepad data, unmapped. 49 // Gamepad data, unmapped.
50 blink::WebGamepad data; 50 Gamepad data;
51 51
52 // Functions to map from device data to standard layout, if available. May 52 // Functions to map from device data to standard layout, if available. May
53 // be null if no mapping is available or needed. 53 // be null if no mapping is available or needed.
54 GamepadStandardMappingFunction mapper; 54 GamepadStandardMappingFunction mapper;
55 55
56 // Sanitization masks 56 // Sanitization masks
57 // axis_mask and button_mask are bitfields that represent the reset state of 57 // axis_mask and button_mask are bitfields that represent the reset state of
58 // each input. If a button or axis has ever reported 0 in the past the 58 // each input. If a button or axis has ever reported 0 in the past the
59 // corresponding bit will be set to 1. 59 // corresponding bit will be set to 1.
60 60
61 // If we ever increase the max axis count this will need to be updated. 61 // If we ever increase the max axis count this will need to be updated.
62 static_assert(blink::WebGamepad::kAxesLengthCap <= 62 static_assert(Gamepad::kAxesLengthCap <=
63 std::numeric_limits<uint32_t>::digits, 63 std::numeric_limits<uint32_t>::digits,
64 "axis_mask is not large enough"); 64 "axis_mask is not large enough");
65 uint32_t axis_mask; 65 uint32_t axis_mask;
66 66
67 // If we ever increase the max button count this will need to be updated. 67 // If we ever increase the max button count this will need to be updated.
68 static_assert(blink::WebGamepad::kButtonsLengthCap <= 68 static_assert(Gamepad::kButtonsLengthCap <=
69 std::numeric_limits<uint32_t>::digits, 69 std::numeric_limits<uint32_t>::digits,
70 "button_mask is not large enough"); 70 "button_mask is not large enough");
71 uint32_t button_mask; 71 uint32_t button_mask;
72 }; 72 };
73 73
74 class DEVICE_GAMEPAD_EXPORT GamepadPadStateProvider { 74 class DEVICE_GAMEPAD_EXPORT GamepadPadStateProvider {
75 public: 75 public:
76 GamepadPadStateProvider(); 76 GamepadPadStateProvider();
77 virtual ~GamepadPadStateProvider(); 77 virtual ~GamepadPadStateProvider();
78 78
79 // Gets a PadState object for the given source and id. If the device hasn't 79 // Gets a PadState object for the given source and id. If the device hasn't
80 // been encountered before one of the remaining slots will be reserved for it. 80 // been encountered before one of the remaining slots will be reserved for it.
81 // If no slots are available will return NULL. 81 // If no slots are available will return NULL.
82 PadState* GetPadState(GamepadSource source, int source_id); 82 PadState* GetPadState(GamepadSource source, int source_id);
83 83
84 protected: 84 protected:
85 void ClearPadState(PadState& state); 85 void ClearPadState(PadState& state);
86 86
87 void InitializeDataFetcher(GamepadDataFetcher* fetcher); 87 void InitializeDataFetcher(GamepadDataFetcher* fetcher);
88 88
89 void MapAndSanitizeGamepadData(PadState* pad_state, 89 void MapAndSanitizeGamepadData(PadState* pad_state,
90 blink::WebGamepad* pad, 90 Gamepad* pad,
91 bool sanitize); 91 bool sanitize);
92 92
93 // Tracks the state of each gamepad slot. 93 // Tracks the state of each gamepad slot.
94 std::unique_ptr<PadState[]> pad_states_; 94 std::unique_ptr<PadState[]> pad_states_;
95 }; 95 };
96 96
97 } // namespace device 97 } // namespace device
98 98
99 #endif // DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_ 99 #endif // DEVICE_GAMEPAD_GAMEPAD_PAD_STATE_PROVIDER_H_
OLDNEW
« no previous file with comments | « device/gamepad/gamepad_monitor.cc ('k') | device/gamepad/gamepad_pad_state_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698