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

Side by Side Diff: device/gamepad/gamepad_data_fetcher.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
« no previous file with comments | « device/gamepad/gamepad.gyp ('k') | device/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 DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 5 #ifndef DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
6 #define DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 6 #define DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
7 7
8 #include <stdint.h> 8 #include "device/gamepad/gamepad_data_fetcher_manager.h"
9
10 #include <limits>
11
12 #include "build/build_config.h"
13 #include "device/gamepad/gamepad_export.h" 9 #include "device/gamepad/gamepad_export.h"
14 #include "device/gamepad/gamepad_standard_mappings.h" 10 #include "device/gamepad/gamepad_pad_state_provider.h"
15 #include "third_party/WebKit/public/platform/WebGamepads.h"
16 11
17 namespace device { 12 namespace device {
18 13
19 // Abstract interface for imlementing platform- (and test-) specific behaviro 14 // Abstract interface for imlementing platform- (and test-) specific behavior
20 // for getting the gamepad data. 15 // for getting the gamepad data.
21 class DEVICE_GAMEPAD_EXPORT GamepadDataFetcher { 16 class DEVICE_GAMEPAD_EXPORT GamepadDataFetcher {
22 public: 17 public:
18 GamepadDataFetcher();
23 virtual ~GamepadDataFetcher() {} 19 virtual ~GamepadDataFetcher() {}
24 virtual void GetGamepadData(blink::WebGamepads* pads, 20 virtual void GetGamepadData(bool devices_changed_hint) = 0;
25 bool devices_changed_hint) = 0;
26 virtual void PauseHint(bool paused) {} 21 virtual void PauseHint(bool paused) {}
27 22
28 #if !defined(OS_ANDROID) 23 virtual GamepadSource source() = 0;
29 struct PadState { 24 GamepadPadStateProvider* provider() { return provider_; }
30 // Gamepad data, unmapped.
31 blink::WebGamepad data;
32 25
33 // Functions to map from device data to standard layout, if available. May 26 PadState* GetPadState(int source_id) {
34 // be null if no mapping is available. 27 if (!provider_)
35 GamepadStandardMappingFunction mapper; 28 return nullptr;
36 29
37 // Sanitization masks 30 return provider_->GetPadState(source(), source_id);
38 // axis_mask and button_mask are bitfields that represent the reset state of 31 }
39 // each input. If a button or axis has ever reported 0 in the past the
40 // corresponding bit will be set to 1.
41
42 // If we ever increase the max axis count this will need to be updated.
43 static_assert(blink::WebGamepad::axesLengthCap <=
44 std::numeric_limits<uint32_t>::digits,
45 "axis_mask is not large enough");
46 uint32_t axis_mask;
47
48 // If we ever increase the max button count this will need to be updated.
49 static_assert(blink::WebGamepad::buttonsLengthCap <=
50 std::numeric_limits<uint32_t>::digits,
51 "button_mask is not large enough");
52 uint32_t button_mask;
53 };
54
55 void MapAndSanitizeGamepadData(PadState* pad_state, blink::WebGamepad* pad);
56 32
57 protected: 33 protected:
58 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; 34 friend GamepadPadStateProvider;
59 #endif 35
36 // To be called by the GamepadPadStateProvider on the polling thread;
37 void InitializeProvider(GamepadPadStateProvider* provider);
38
39 // This call will happen on the gamepad polling thread. Any initialization
40 // that needs to happen on that thread should be done here, not in the
41 // constructor.
42 virtual void OnAddedToProvider(){};
43
44 private:
45 GamepadPadStateProvider* provider_;
46 };
47
48 // Factory class for creating a GamepadDataFetcher. Used by the
49 // GamepadDataFetcherManager.
50 class DEVICE_GAMEPAD_EXPORT GamepadDataFetcherFactory {
51 public:
52 GamepadDataFetcherFactory();
53 virtual ~GamepadDataFetcherFactory() {}
54 virtual std::unique_ptr<GamepadDataFetcher> CreateDataFetcher() = 0;
55 virtual GamepadSource source() = 0;
56 };
57
58 // Basic factory implementation for GamepadDataFetchers without a complex
59 // constructor.
60 template <typename DataFetcherType, GamepadSource DataFetcherSource>
61 class GamepadDataFetcherFactoryImpl : public GamepadDataFetcherFactory {
62 public:
63 ~GamepadDataFetcherFactoryImpl() override {}
64 std::unique_ptr<GamepadDataFetcher> CreateDataFetcher() override {
65 return std::unique_ptr<GamepadDataFetcher>(new DataFetcherType());
66 }
67 GamepadSource source() override { return DataFetcherSource; }
68 static GamepadSource static_source() { return DataFetcherSource; }
60 }; 69 };
61 70
62 } // namespace device 71 } // namespace device
63 72
64 #endif // DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 73 #endif // DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
OLDNEW
« no previous file with comments | « device/gamepad/gamepad.gyp ('k') | device/gamepad/gamepad_data_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698