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

Side by Side Diff: content/browser/gamepad/gamepad_data_fetcher.h

Issue 1586663006: Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid crash on Android content_unittests 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_data_fetcher.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
7 7
8 #include <stdint.h> 8 #include "content/browser/gamepad/gamepad_provider.h"
9 9 #include "content/common/content_export.h"
10 #include "build/build_config.h"
11 #include "content/browser/gamepad/gamepad_standard_mappings.h"
12 #include "third_party/WebKit/public/platform/WebGamepads.h"
13 10
14 namespace content { 11 namespace content {
15 12
16 // Abstract interface for imlementing platform- (and test-) specific behaviro 13 // Abstract interface for imlementing platform- (and test-) specific behavior
17 // for getting the gamepad data. 14 // for getting the gamepad data.
18 class GamepadDataFetcher { 15 class CONTENT_EXPORT GamepadDataFetcher {
19 public: 16 public:
17 GamepadDataFetcher();
20 virtual ~GamepadDataFetcher() {} 18 virtual ~GamepadDataFetcher() {}
21 virtual void GetGamepadData(blink::WebGamepads* pads, 19
22 bool devices_changed_hint) = 0; 20 virtual void GetGamepadData(bool devices_changed_hint) = 0;
23 virtual void PauseHint(bool paused) {} 21 virtual void PauseHint(bool paused) {}
24 22
25 #if !defined(OS_ANDROID) 23 GamepadProvider* provider() { return provider_; }
26 struct PadState {
27 // Gamepad data, unmapped.
28 blink::WebGamepad data;
29
30 // Functions to map from device data to standard layout, if available. May
31 // be null if no mapping is available.
32 GamepadStandardMappingFunction mapper;
33
34 // Sanitization masks
35 // axis_mask and button_mask are bitfields that represent the reset state of
36 // each input. If a button or axis has ever reported 0 in the past the
37 // corresponding bit will be set to 1.
38
39 // If we ever increase the max axis count this will need to be updated.
40 static_assert(blink::WebGamepad::axesLengthCap <=
41 std::numeric_limits<uint32_t>::digits,
42 "axis_mask is not large enough");
43 uint32_t axis_mask;
44
45 // If we ever increase the max button count this will need to be updated.
46 static_assert(blink::WebGamepad::buttonsLengthCap <=
47 std::numeric_limits<uint32_t>::digits,
48 "button_mask is not large enough");
49 uint32_t button_mask;
50 };
51
52 void MapAndSanitizeGamepadData(PadState* pad_state, blink::WebGamepad* pad);
53 24
54 protected: 25 protected:
55 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; 26 friend GamepadProvider;
56 #endif 27
28 // To be called by the GamepadProvider on the polling thread;
29 void InitializeProvider(GamepadProvider* provider);
30
31 // This call will happen on the gamepad polling thread. Any initialization
32 // that needs to happen on that thread should be done here, not in the
33 // constructor.
34 virtual void OnAddedToProvider() {}
35
36 private:
37 GamepadProvider* provider_;
57 }; 38 };
58 39
59 } // namespace content 40 } // namespace content
60 41
61 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 42 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/gamepad/gamepad_data_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698