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

Unified Diff: device/gamepad/gamepad_pad_state_provider.cc

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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/gamepad/gamepad_pad_state_provider.h ('k') | device/gamepad/gamepad_platform_data_fetcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/gamepad/gamepad_pad_state_provider.cc
diff --git a/device/gamepad/gamepad_data_fetcher.cc b/device/gamepad/gamepad_pad_state_provider.cc
similarity index 57%
copy from device/gamepad/gamepad_data_fetcher.cc
copy to device/gamepad/gamepad_pad_state_provider.cc
index 749a6f3df1aef6097aa88673201c6f4ee5ab7db1..892fd4d0c10c8828e73b9a118f0efa4c2638acc4 100644
--- a/device/gamepad/gamepad_data_fetcher.cc
+++ b/device/gamepad/gamepad_pad_state_provider.cc
@@ -1,33 +1,68 @@
-// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "device/gamepad/gamepad_data_fetcher.h"
-
-#include <stddef.h>
-#include <string.h>
+#include "device/gamepad/gamepad_pad_state_provider.h"
#include <cmath>
-#include "base/logging.h"
-#include "build/build_config.h"
+#include "device/gamepad/gamepad_data_fetcher.h"
+#include "third_party/WebKit/public/platform/WebGamepads.h"
+
+using blink::WebGamepad;
+using blink::WebGamepads;
+
+namespace device {
namespace {
-#if !defined(OS_ANDROID)
const float kMinAxisResetValue = 0.1f;
-#endif
} // namespace
-namespace device {
+GamepadPadStateProvider::GamepadPadStateProvider() {
+ pad_states_.reset(new PadState[WebGamepads::itemsLengthCap]);
-using blink::WebGamepad;
-using blink::WebGamepads;
+ for (unsigned i = 0; i < WebGamepads::itemsLengthCap; ++i)
+ ClearPadState(pad_states_.get()[i]);
+}
-#if !defined(OS_ANDROID)
-void GamepadDataFetcher::MapAndSanitizeGamepadData(PadState* pad_state,
- WebGamepad* pad) {
+GamepadPadStateProvider::~GamepadPadStateProvider() {}
+
+PadState* GamepadPadStateProvider::GetPadState(GamepadSource source,
+ int source_id) {
+ // Check to see if the device already has a reserved slot
+ PadState* empty_slot = nullptr;
+ for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) {
+ PadState& state = pad_states_.get()[i];
+ if (state.source == source && state.source_id == source_id) {
+ // Retrieving the pad state marks this gamepad as active.
+ state.active_state = GAMEPAD_ACTIVE;
+ return &state;
+ }
+ if (!empty_slot && state.source == GAMEPAD_SOURCE_NONE)
+ empty_slot = &state;
+ }
+ if (empty_slot) {
+ empty_slot->source = source;
+ empty_slot->source_id = source_id;
+ empty_slot->active_state = GAMEPAD_NEWLY_ACTIVE;
+ }
+ return empty_slot;
+}
+
+void GamepadPadStateProvider::ClearPadState(PadState& state) {
+ memset(&state, 0, sizeof(PadState));
+}
+
+void GamepadPadStateProvider::InitializeDataFetcher(
+ GamepadDataFetcher* fetcher) {
+ fetcher->InitializeProvider(this);
+}
+
+void GamepadPadStateProvider::MapAndSanitizeGamepadData(PadState* pad_state,
+ WebGamepad* pad,
+ bool sanitize) {
DCHECK(pad_state);
DCHECK(pad);
@@ -43,6 +78,11 @@ void GamepadDataFetcher::MapAndSanitizeGamepadData(PadState* pad_state,
else
*pad = pad_state->data;
+ pad->connected = true;
+
+ if (!sanitize)
+ return;
+
// 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
@@ -82,6 +122,5 @@ void GamepadDataFetcher::MapAndSanitizeGamepadData(PadState* pad_state,
}
}
}
-#endif
-} // namespace device
+} // namespace device
« no previous file with comments | « device/gamepad/gamepad_pad_state_provider.h ('k') | device/gamepad/gamepad_platform_data_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698