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

Unified Diff: content/browser/gamepad/gamepad_data_fetcher.cc

Issue 1586663006: Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/gamepad/gamepad_data_fetcher.cc
diff --git a/content/browser/gamepad/gamepad_data_fetcher.cc b/content/browser/gamepad/gamepad_data_fetcher.cc
index 891722461e58f795129954f9e4489bb901547457..1bfbb5cbb380b8102f0f37063bf4f8779914b9a2 100644
--- a/content/browser/gamepad/gamepad_data_fetcher.cc
+++ b/content/browser/gamepad/gamepad_data_fetcher.cc
@@ -4,82 +4,16 @@
#include "content/browser/gamepad/gamepad_data_fetcher.h"
-#include <stddef.h>
-#include <string.h>
-
-#include "base/logging.h"
-#include "build/build_config.h"
-
-namespace {
-
-#if !defined(OS_ANDROID)
-const float kMinAxisResetValue = 0.1f;
-#endif
-
-} // namespace
-
namespace content {
-using blink::WebGamepad;
-using blink::WebGamepads;
-
-#if !defined(OS_ANDROID)
-void GamepadDataFetcher::MapAndSanitizeGamepadData(
- PadState* pad_state, WebGamepad* pad) {
- DCHECK(pad_state);
- DCHECK(pad);
-
- 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.
+GamepadDataFetcher::GamepadDataFetcher() : provider_(nullptr) {
+}
- // 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;
- }
- }
- }
- }
+void GamepadDataFetcher::InitializeProvider(GamepadProvider* provider) {
+ DCHECK(provider);
- // 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
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698