| 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 "content/browser/gamepad/gamepad_provider.h" | 5 #include "content/browser/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(polling_thread_->task_runner()->BelongsToCurrentThread()); | 162 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); |
| 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(polling_thread_->task_runner()->BelongsToCurrentThread()); | 171 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); |
| 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 && | 177 return connected_ == pad.connected && |
| 178 axes_length_ == pad.axesLength && | 178 axes_length_ == pad.axesLength && |
| 179 buttons_length_ == pad.buttonsLength && | 179 buttons_length_ == pad.buttonsLength && |
| 180 memcmp(id_, pad.id, sizeof(id_)) == 0 && | 180 memcmp(id_, pad.id, sizeof(id_)) == 0 && |
| 181 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0; | 181 memcmp(mapping_, pad.mapping, sizeof(mapping_)) == 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 201 pad->connected = connected_; | 201 pad->connected = connected_; |
| 202 pad->axesLength = axes_length_; | 202 pad->axesLength = axes_length_; |
| 203 pad->buttonsLength = buttons_length_; | 203 pad->buttonsLength = buttons_length_; |
| 204 memcpy(pad->id, id_, sizeof(id_)); | 204 memcpy(pad->id, id_, sizeof(id_)); |
| 205 memcpy(pad->mapping, mapping_, sizeof(mapping_)); | 205 memcpy(pad->mapping, mapping_, sizeof(mapping_)); |
| 206 memset(pad->axes, 0, sizeof(pad->axes)); | 206 memset(pad->axes, 0, sizeof(pad->axes)); |
| 207 memset(pad->buttons, 0, sizeof(pad->buttons)); | 207 memset(pad->buttons, 0, sizeof(pad->buttons)); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void GamepadProvider::DoPoll() { | 210 void GamepadProvider::DoPoll() { |
| 211 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread()); | 211 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); |
| 212 DCHECK(have_scheduled_do_poll_); | 212 DCHECK(have_scheduled_do_poll_); |
| 213 have_scheduled_do_poll_ = false; | 213 have_scheduled_do_poll_ = false; |
| 214 | 214 |
| 215 bool changed; | 215 bool changed; |
| 216 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); | 216 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |
| 217 | 217 |
| 218 ANNOTATE_BENIGN_RACE_SIZED( | 218 ANNOTATE_BENIGN_RACE_SIZED( |
| 219 &hwbuf->buffer, | 219 &hwbuf->buffer, |
| 220 sizeof(WebGamepads), | 220 sizeof(WebGamepads), |
| 221 "Racey reads are discarded"); | 221 "Racey reads are discarded"); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 CheckForUserGesture(); | 256 CheckForUserGesture(); |
| 257 | 257 |
| 258 // Schedule our next interval of polling. | 258 // Schedule our next interval of polling. |
| 259 ScheduleDoPoll(); | 259 ScheduleDoPoll(); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void GamepadProvider::ScheduleDoPoll() { | 262 void GamepadProvider::ScheduleDoPoll() { |
| 263 DCHECK(polling_thread_->task_runner()->BelongsToCurrentThread()); | 263 DCHECK(base::MessageLoop::current() == polling_thread_->message_loop()); |
| 264 if (have_scheduled_do_poll_) | 264 if (have_scheduled_do_poll_) |
| 265 return; | 265 return; |
| 266 | 266 |
| 267 { | 267 { |
| 268 base::AutoLock lock(is_paused_lock_); | 268 base::AutoLock lock(is_paused_lock_); |
| 269 if (is_paused_) | 269 if (is_paused_) |
| 270 return; | 270 return; |
| 271 } | 271 } |
| 272 | 272 |
| 273 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 273 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 325 } |
| 326 if (!had_gesture_before && ever_had_user_gesture_) { | 326 if (!had_gesture_before && ever_had_user_gesture_) { |
| 327 // Initialize pad_states_ for the first time. | 327 // Initialize pad_states_ for the first time. |
| 328 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { | 328 for (size_t i = 0; i < WebGamepads::itemsLengthCap; ++i) { |
| 329 pad_states_.get()[i].SetPad(pads.items[i]); | 329 pad_states_.get()[i].SetPad(pads.items[i]); |
| 330 } | 330 } |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace content | 334 } // namespace content |
| OLD | NEW |