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

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: Fixed unit test issue and Mac XBoxDataFetcher constructor Created 4 years, 5 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
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 9 #include "device/gamepad/gamepad_export.h"
10 #include <limits> 10 #include "device/gamepad/gamepad_provider.h"
11
12 #include "build/build_config.h"
13 #include "device/gamepad/gamepad_standard_mappings.h"
14 #include "third_party/WebKit/public/platform/WebGamepads.h"
15 11
16 namespace device { 12 namespace device {
17 13
18 // Abstract interface for imlementing platform- (and test-) specific behaviro 14 // Abstract interface for imlementing platform- (and test-) specific behavior
19 // for getting the gamepad data. 15 // for getting the gamepad data.
20 class GamepadDataFetcher { 16 class DEVICE_GAMEPAD_EXPORT GamepadDataFetcher {
21 public: 17 public:
18 GamepadDataFetcher();
denniskempin 2016/07/11 22:44:50 Since the GamepadDataFetcher is now constructed on
22 virtual ~GamepadDataFetcher() {} 19 virtual ~GamepadDataFetcher() {}
23 virtual void GetGamepadData(blink::WebGamepads* pads, 20 virtual void GetGamepadData(bool devices_changed_hint) = 0;
24 bool devices_changed_hint) = 0;
25 virtual void PauseHint(bool paused) {} 21 virtual void PauseHint(bool paused) {}
26 22
27 #if !defined(OS_ANDROID) 23 virtual GamepadSource source() = 0;
28 struct PadState { 24 GamepadProvider* provider() { return provider_; }
29 // Gamepad data, unmapped.
30 blink::WebGamepad data;
31 25
32 // Functions to map from device data to standard layout, if available. May 26 PadState* GetPadState(int source_id) {
33 // be null if no mapping is available. 27 if (!provider_)
34 GamepadStandardMappingFunction mapper; 28 return nullptr;
35 29
36 // Sanitization masks 30 return provider_->GetPadState(source(), source_id);
37 // axis_mask and button_mask are bitfields that represent the reset state of 31 }
38 // each input. If a button or axis has ever reported 0 in the past the
39 // corresponding bit will be set to 1.
40
41 // If we ever increase the max axis count this will need to be updated.
42 static_assert(blink::WebGamepad::axesLengthCap <=
43 std::numeric_limits<uint32_t>::digits,
44 "axis_mask is not large enough");
45 uint32_t axis_mask;
46
47 // If we ever increase the max button count this will need to be updated.
48 static_assert(blink::WebGamepad::buttonsLengthCap <=
49 std::numeric_limits<uint32_t>::digits,
50 "button_mask is not large enough");
51 uint32_t button_mask;
52 };
53
54 void MapAndSanitizeGamepadData(PadState* pad_state, blink::WebGamepad* pad);
55 32
56 protected: 33 protected:
57 PadState pad_state_[blink::WebGamepads::itemsLengthCap]; 34 friend GamepadProvider;
58 #endif 35
36 // To be called by the GamepadProvider on the polling thread;
37 void InitializeProvider(GamepadProvider* 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 GamepadProvider* 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; }
59 }; 69 };
60 70
61 } // namespace device 71 } // namespace device
62 72
63 #endif // DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_ 73 #endif // DEVICE_GAMEPAD_GAMEPAD_DATA_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698