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

Side by Side Diff: content/browser/gamepad/gamepad_provider.cc

Issue 133943002: Gamepad API support for chrome on android (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2014, NVIDIA CORPORATION. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 4 // found in the LICENSE file.
4 5
5 #include <cmath> 6 #include <cmath>
6 #include <set> 7 #include <set>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/time/time.h"
15 #include "content/browser/gamepad/gamepad_data_fetcher.h" 17 #include "content/browser/gamepad/gamepad_data_fetcher.h"
16 #include "content/browser/gamepad/gamepad_platform_data_fetcher.h" 18 #include "content/browser/gamepad/gamepad_platform_data_fetcher.h"
17 #include "content/browser/gamepad/gamepad_provider.h" 19 #include "content/browser/gamepad/gamepad_provider.h"
20 #include "content/browser/gamepad/gamepad_service.h"
18 #include "content/common/gamepad_hardware_buffer.h" 21 #include "content/common/gamepad_hardware_buffer.h"
19 #include "content/common/gamepad_messages.h" 22 #include "content/common/gamepad_messages.h"
20 #include "content/common/gamepad_user_gesture.h" 23 #include "content/common/gamepad_user_gesture.h"
21 24
22 namespace content { 25 namespace content {
26 #if defined(OS_ANDROID)
27 const int64 GamepadProvider::max_timestamp_before_pause_ = 500;
28 #endif
23 29
24 GamepadProvider::ClosureAndThread::ClosureAndThread( 30 GamepadProvider::ClosureAndThread::ClosureAndThread(
25 const base::Closure& c, 31 const base::Closure& c,
26 const scoped_refptr<base::MessageLoopProxy>& m) 32 const scoped_refptr<base::MessageLoopProxy>& m)
27 : closure(c), 33 : closure(c),
28 message_loop(m) { 34 message_loop(m) {
29 } 35 }
30 36
31 GamepadProvider::ClosureAndThread::~ClosureAndThread() { 37 GamepadProvider::ClosureAndThread::~ClosureAndThread() {
32 } 38 }
(...skipping 23 matching lines...) Expand all
56 data_fetcher_.reset(); 62 data_fetcher_.reset();
57 } 63 }
58 64
59 base::SharedMemoryHandle GamepadProvider::GetSharedMemoryHandleForProcess( 65 base::SharedMemoryHandle GamepadProvider::GetSharedMemoryHandleForProcess(
60 base::ProcessHandle process) { 66 base::ProcessHandle process) {
61 base::SharedMemoryHandle renderer_handle; 67 base::SharedMemoryHandle renderer_handle;
62 gamepad_shared_memory_.ShareToProcess(process, &renderer_handle); 68 gamepad_shared_memory_.ShareToProcess(process, &renderer_handle);
63 return renderer_handle; 69 return renderer_handle;
64 } 70 }
65 71
72 #if defined(OS_ANDROID)
73 bool GamepadProvider::GetPollState() {
74 return is_paused_;
75 }
76 #endif
77
66 void GamepadProvider::Pause() { 78 void GamepadProvider::Pause() {
67 { 79 {
68 base::AutoLock lock(is_paused_lock_); 80 base::AutoLock lock(is_paused_lock_);
69 is_paused_ = true; 81 is_paused_ = true;
70 } 82 }
71 base::MessageLoop* polling_loop = polling_thread_->message_loop(); 83 base::MessageLoop* polling_loop = polling_thread_->message_loop();
72 polling_loop->PostTask( 84 polling_loop->PostTask(
73 FROM_HERE, 85 FROM_HERE,
74 base::Bind(&GamepadProvider::SendPauseHint, Unretained(this), true)); 86 base::Bind(&GamepadProvider::SendPauseHint, Unretained(this), true));
75 } 87 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 &hwbuf->buffer, 172 &hwbuf->buffer,
161 sizeof(blink::WebGamepads), 173 sizeof(blink::WebGamepads),
162 "Racey reads are discarded"); 174 "Racey reads are discarded");
163 175
164 { 176 {
165 base::AutoLock lock(devices_changed_lock_); 177 base::AutoLock lock(devices_changed_lock_);
166 changed = devices_changed_; 178 changed = devices_changed_;
167 devices_changed_ = false; 179 devices_changed_ = false;
168 } 180 }
169 181
182 #if defined(OS_ANDROID)
183 base::TimeDelta timestamp =
184 (base::Time::NowFromSystemTime()) - (
185 GamepadService::GetInstance()->GetGamepadAccessTimestamp());
186
187 if (timestamp.InMilliseconds() > max_timestamp_before_pause_) {
188 Pause();
189 return;
190 }
191 #endif
192
170 // Acquire the SeqLock. There is only ever one writer to this data. 193 // Acquire the SeqLock. There is only ever one writer to this data.
171 // See gamepad_hardware_buffer.h. 194 // See gamepad_hardware_buffer.h.
172 hwbuf->sequence.WriteBegin(); 195 hwbuf->sequence.WriteBegin();
173 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed); 196 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed);
174 hwbuf->sequence.WriteEnd(); 197 hwbuf->sequence.WriteEnd();
175 198
176 CheckForUserGesture(); 199 CheckForUserGesture();
177 200
178 // Schedule our next interval of polling. 201 // Schedule our next interval of polling.
179 ScheduleDoPoll(); 202 ScheduleDoPoll();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) { 234 if (GamepadsHaveUserGesture(SharedMemoryAsHardwareBuffer()->buffer)) {
212 for (size_t i = 0; i < user_gesture_observers_.size(); i++) { 235 for (size_t i = 0; i < user_gesture_observers_.size(); i++) {
213 user_gesture_observers_[i].message_loop->PostTask(FROM_HERE, 236 user_gesture_observers_[i].message_loop->PostTask(FROM_HERE,
214 user_gesture_observers_[i].closure); 237 user_gesture_observers_[i].closure);
215 } 238 }
216 user_gesture_observers_.clear(); 239 user_gesture_observers_.clear();
217 } 240 }
218 } 241 }
219 242
220 } // namespace content 243 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698