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

Unified Diff: device/gamepad/gamepad_data_fetcher.cc

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 side-by-side diff with in-line comments
Download patch
Index: device/gamepad/gamepad_data_fetcher.cc
diff --git a/device/gamepad/gamepad_data_fetcher.cc b/device/gamepad/gamepad_data_fetcher.cc
index 749a6f3df1aef6097aa88673201c6f4ee5ab7db1..8ea0598384b846b86bdb5657a6700c864bac4de6 100644
--- a/device/gamepad/gamepad_data_fetcher.cc
+++ b/device/gamepad/gamepad_data_fetcher.cc
@@ -4,84 +4,17 @@
#include "device/gamepad/gamepad_data_fetcher.h"
-#include <stddef.h>
-#include <string.h>
-
-#include <cmath>
-
-#include "base/logging.h"
-#include "build/build_config.h"
-
-namespace {
-
-#if !defined(OS_ANDROID)
-const float kMinAxisResetValue = 0.1f;
-#endif
-
-} // namespace
-
namespace device {
-using blink::WebGamepad;
-using blink::WebGamepads;
+GamepadDataFetcher::GamepadDataFetcher() : provider_(nullptr) {}
-#if !defined(OS_ANDROID)
-void GamepadDataFetcher::MapAndSanitizeGamepadData(PadState* pad_state,
- WebGamepad* pad) {
- DCHECK(pad_state);
- DCHECK(pad);
+void GamepadDataFetcher::InitializeProvider(GamepadProvider* provider) {
+ DCHECK(provider);
- if (!pad_state->data.connected) {
- memset(pad, 0, sizeof(WebGamepad));
- return;
- }
-
- // Copy the current state to the output buffer, using the mapping
- // function, if there is one available.
- if (pad_state->mapper)
- pad_state->mapper(pad_state->data, pad);
- else
- *pad = pad_state->data;
-
- // About sanitization: Gamepads may report input event if the user is not
- // interacting with it, due to hardware problems or environmental ones (pad
- // has something heavy leaning against an axis.) This may cause user gestures
- // to be detected erroniously, exposing gamepad information when the user had
- // no intention of doing so. To avoid this we require that each button or axis
- // report being at rest (zero) at least once before exposing its value to the
- // Gamepad API. This state is tracked by the axis_mask and button_mask
- // bitfields. If the bit for an axis or button is 0 it means the axis has
- // never reported being at rest, and the value will be forced to zero.
-
- // We can skip axis sanitation if all available axes have been masked.
- uint32_t full_axis_mask = (1 << pad->axesLength) - 1;
- if (pad_state->axis_mask != full_axis_mask) {
- for (size_t axis = 0; axis < pad->axesLength; ++axis) {
- if (!(pad_state->axis_mask & 1 << axis)) {
- if (fabs(pad->axes[axis]) < kMinAxisResetValue) {
- pad_state->axis_mask |= 1 << axis;
- } else {
- pad->axes[axis] = 0.0f;
- }
- }
- }
- }
-
- // We can skip button sanitation if all available buttons have been masked.
- uint32_t full_button_mask = (1 << pad->buttonsLength) - 1;
- if (pad_state->button_mask != full_button_mask) {
- for (size_t button = 0; button < pad->buttonsLength; ++button) {
- if (!(pad_state->button_mask & 1 << button)) {
- if (!pad->buttons[button].pressed) {
- pad_state->button_mask |= 1 << button;
- } else {
- pad->buttons[button].pressed = false;
- pad->buttons[button].value = 0.0f;
- }
- }
- }
- }
+ provider_ = provider;
+ OnAddedToProvider();
}
-#endif
+
+GamepadDataFetcherFactory::GamepadDataFetcherFactory() {}
} // namespace device

Powered by Google App Engine
This is Rietveld 408576698