OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <cmath> | 5 #include <cmath> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 // Start polling. | 127 // Start polling. |
128 ScheduleDoPoll(); | 128 ScheduleDoPoll(); |
129 } | 129 } |
130 | 130 |
131 void GamepadProvider::DoPoll() { | 131 void GamepadProvider::DoPoll() { |
132 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); | 132 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); |
133 bool changed; | 133 bool changed; |
134 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); | 134 GamepadHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |
135 | 135 |
136 ANNOTATE_BENIGN_RACE_SIZED( | |
137 &hwbuf->buffer, | |
138 sizeof(WebKit::WebGamepads), | |
139 "Racey reads are discarded"); | |
140 | |
141 { | 136 { |
142 base::AutoLock lock(devices_changed_lock_); | 137 base::AutoLock lock(devices_changed_lock_); |
143 changed = devices_changed_; | 138 changed = devices_changed_; |
144 devices_changed_ = false; | 139 devices_changed_ = false; |
145 } | 140 } |
146 | 141 |
147 // Acquire the SeqLock. There is only ever one writer to this data. | 142 // Acquire the SeqLock. There is only ever one writer to this data. |
148 // See gamepad_hardware_buffer.h. | 143 // See gamepad_hardware_buffer.h. |
149 hwbuf->sequence.WriteBegin(); | 144 WebKit::WebGamepads tmp; |
150 data_fetcher_->GetGamepadData(&hwbuf->buffer, changed); | 145 data_fetcher_->GetGamepadData(&tmp, changed); |
151 hwbuf->sequence.WriteEnd(); | 146 hwbuf->gamepads.Write(tmp); |
152 | 147 |
153 // Schedule our next interval of polling. | 148 // Schedule our next interval of polling. |
154 ScheduleDoPoll(); | 149 ScheduleDoPoll(); |
155 } | 150 } |
156 | 151 |
157 void GamepadProvider::ScheduleDoPoll() { | 152 void GamepadProvider::ScheduleDoPoll() { |
158 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); | 153 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); |
159 | 154 |
160 { | 155 { |
161 base::AutoLock lock(is_paused_lock_); | 156 base::AutoLock lock(is_paused_lock_); |
162 if (is_paused_) | 157 if (is_paused_) |
163 return; | 158 return; |
164 } | 159 } |
165 | 160 |
166 MessageLoop::current()->PostDelayedTask( | 161 MessageLoop::current()->PostDelayedTask( |
167 FROM_HERE, | 162 FROM_HERE, |
168 base::Bind(&GamepadProvider::DoPoll, weak_factory_.GetWeakPtr()), | 163 base::Bind(&GamepadProvider::DoPoll, weak_factory_.GetWeakPtr()), |
169 kDesiredSamplingIntervalMs); | 164 kDesiredSamplingIntervalMs); |
170 } | 165 } |
171 | 166 |
172 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { | 167 GamepadHardwareBuffer* GamepadProvider::SharedMemoryAsHardwareBuffer() { |
173 void* mem = gamepad_shared_memory_.memory(); | 168 void* mem = gamepad_shared_memory_.memory(); |
174 DCHECK(mem); | 169 DCHECK(mem); |
175 return static_cast<GamepadHardwareBuffer*>(mem); | 170 return static_cast<GamepadHardwareBuffer*>(mem); |
176 } | 171 } |
177 | 172 |
178 } // namespace content | 173 } // namespace content |
OLD | NEW |