OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "device/gamepad/gamepad_provider.h" | 5 #include "device/gamepad/gamepad_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <cmath> | 9 #include <cmath> |
10 #include <set> | 10 #include <set> |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 #endif | 152 #endif |
153 polling_thread_->StartWithOptions(base::Thread::Options(kMessageLoopType, 0)); | 153 polling_thread_->StartWithOptions(base::Thread::Options(kMessageLoopType, 0)); |
154 | 154 |
155 polling_thread_->task_runner()->PostTask( | 155 polling_thread_->task_runner()->PostTask( |
156 FROM_HERE, base::Bind(&GamepadProvider::DoInitializePollingThread, | 156 FROM_HERE, base::Bind(&GamepadProvider::DoInitializePollingThread, |
157 base::Unretained(this), base::Passed(&fetcher))); | 157 base::Unretained(this), base::Passed(&fetcher))); |
158 } | 158 } |
159 | 159 |
160 void GamepadProvider::DoInitializePollingThread( | 160 void GamepadProvider::DoInitializePollingThread( |
161 std::unique_ptr<GamepadDataFetcher> fetcher) { | 161 std::unique_ptr<GamepadDataFetcher> fetcher) { |
162 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); | 162 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread()); |
163 DCHECK(!data_fetcher_.get()); // Should only initialize once. | 163 DCHECK(!data_fetcher_.get()); // Should only initialize once. |
164 | 164 |
165 if (!fetcher) | 165 if (!fetcher) |
166 fetcher.reset(new GamepadPlatformDataFetcher); | 166 fetcher.reset(new GamepadPlatformDataFetcher); |
167 data_fetcher_ = std::move(fetcher); | 167 data_fetcher_ = std::move(fetcher); |
168 } | 168 } |
169 | 169 |
170 void GamepadProvider::SendPauseHint(bool paused) { | 170 void GamepadProvider::SendPauseHint(bool paused) { |
171 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); | 171 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread()); |
172 if (data_fetcher_) | 172 if (data_fetcher_) |
173 data_fetcher_->PauseHint(paused); | 173 data_fetcher_->PauseHint(paused); |
174 } | 174 } |
175 | 175 |
176 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { | 176 bool GamepadProvider::PadState::Match(const WebGamepad& pad) const { |
177 return connected_ == pad.connected && axes_length_ == pad.axesLength && | 177 return connected_ == pad.connected && axes_length_ == pad.axesLength && |
178 buttons_length_ == pad.buttonsLength && | 178 buttons_length_ == pad.buttonsLength && |
179 memcmp(id_, pad.id, sizeof(id_)) == 0 && | 179 memcmp(id_, pad.id, sizeof(id_)) == 0 && |
180 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0; | 180 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0; |
181 } | 181 } |
(...skipping 18 matching lines...) Expand all Loading... |
200 pad->connected = connected_; | 200 pad->connected = connected_; |
201 pad->axesLength = axes_length_; | 201 pad->axesLength = axes_length_; |
202 pad->buttonsLength = buttons_length_; | 202 pad->buttonsLength = buttons_length_; |
203 memcpy(pad->id, id_, sizeof(id_)); | 203 memcpy(pad->id, id_, sizeof(id_)); |
204 memcpy(pad->mapping, mapping_, sizeof(mapping_)); | 204 memcpy(pad->mapping, mapping_, sizeof(mapping_)); |
205 memset(pad->axes, 0, sizeof(pad->axes)); | 205 memset(pad->axes, 0, sizeof(pad->axes)); |
206 memset(pad->buttons, 0, sizeof(pad->buttons)); | 206 memset(pad->buttons, 0, sizeof(pad->buttons)); |
207 } | 207 } |
208 | 208 |
209 void GamepadProvider::DoPoll() { | 209 void GamepadProvider::DoPoll() { |
210 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); | 210 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread()); |
211 DCHECK(have_scheduled_do_poll_); | 211 DCHECK(have_scheduled_do_poll_); |
212 have_scheduled_do_poll_ = false; | 212 have_scheduled_do_poll_ = false; |
213 | 213 |
214 bool changed; | 214 bool changed; |
215 | 215 |
216 ANNOTATE_BENIGN_RACE_SIZED(gamepad_shared_buffer_->buffer(), | 216 ANNOTATE_BENIGN_RACE_SIZED(gamepad_shared_buffer_->buffer(), |
217 sizeof(WebGamepads), "Racey reads are discarded"); | 217 sizeof(WebGamepads), "Racey reads are discarded"); |
218 | 218 |
219 { | 219 { |
220 base::AutoLock lock(devices_changed_lock_); | 220 base::AutoLock lock(devices_changed_lock_); |
(...skipping 28 matching lines...) Expand all Loading... |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 CheckForUserGesture(); | 252 CheckForUserGesture(); |
253 | 253 |
254 // Schedule our next interval of polling. | 254 // Schedule our next interval of polling. |
255 ScheduleDoPoll(); | 255 ScheduleDoPoll(); |
256 } | 256 } |
257 | 257 |
258 void GamepadProvider::ScheduleDoPoll() { | 258 void GamepadProvider::ScheduleDoPoll() { |
259 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); | 259 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread()); |
260 if (have_scheduled_do_poll_) | 260 if (have_scheduled_do_poll_) |
261 return; | 261 return; |
262 | 262 |
263 { | 263 { |
264 base::AutoLock lock(is_paused_lock_); | 264 base::AutoLock lock(is_paused_lock_); |
265 if (is_paused_) | 265 if (is_paused_) |
266 return; | 266 return; |
267 } | 267 } |
268 | 268 |
269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 } | 302 } |
303 if (!had_gesture_before && ever_had_user_gesture_) { | 303 if (!had_gesture_before && ever_had_user_gesture_) { |
304 // Initialize pad_states_ for the first time. | 304 // Initialize pad_states_ for the first time. |
305 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 305 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
306 pad_states_.get()[i].SetPad(pads->items[i]); | 306 pad_states_.get()[i].SetPad(pads->items[i]); |
307 } | 307 } |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 } // namespace device | 311 } // namespace device |
OLD | NEW |