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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 test_data.items[0].axes[0] = -1.f; | 103 test_data.items[0].axes[0] = -1.f; |
104 test_data.items[0].axes[1] = .5f; | 104 test_data.items[0].axes[1] = .5f; |
105 | 105 |
106 GamepadProvider* provider = CreateProvider(test_data); | 106 GamepadProvider* provider = CreateProvider(test_data); |
107 provider->SetSanitizationEnabled(false); | 107 provider->SetSanitizationEnabled(false); |
108 provider->Resume(); | 108 provider->Resume(); |
109 | 109 |
110 base::RunLoop().RunUntilIdle(); | 110 base::RunLoop().RunUntilIdle(); |
111 | 111 |
112 // Renderer-side, pull data out of poll buffer. | 112 // Renderer-side, pull data out of poll buffer. |
113 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( | 113 base::SharedMemoryHandle handle = provider->DuplicateSharedMemoryHandle(); |
114 base::GetCurrentProcessHandle()); | |
115 std::unique_ptr<base::SharedMemory> shared_memory( | 114 std::unique_ptr<base::SharedMemory> shared_memory( |
116 new base::SharedMemory(handle, true)); | 115 new base::SharedMemory(handle, true)); |
117 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); | 116 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); |
118 | 117 |
119 GamepadHardwareBuffer* buffer = | 118 GamepadHardwareBuffer* buffer = |
120 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); | 119 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); |
121 | 120 |
122 // Wait until the shared memory buffer has been written at least once. | 121 // Wait until the shared memory buffer has been written at least once. |
123 WaitForData(buffer); | 122 WaitForData(buffer); |
124 | 123 |
(...skipping 29 matching lines...) Expand all Loading... |
154 test_data_onedisconnected.items[1].axes[0] = 1.f; | 153 test_data_onedisconnected.items[1].axes[0] = 1.f; |
155 test_data_onedisconnected.items[1].axes[1] = -.5f; | 154 test_data_onedisconnected.items[1].axes[1] = -.5f; |
156 | 155 |
157 GamepadProvider* provider = CreateProvider(test_data); | 156 GamepadProvider* provider = CreateProvider(test_data); |
158 provider->SetSanitizationEnabled(false); | 157 provider->SetSanitizationEnabled(false); |
159 provider->Resume(); | 158 provider->Resume(); |
160 | 159 |
161 base::RunLoop().RunUntilIdle(); | 160 base::RunLoop().RunUntilIdle(); |
162 | 161 |
163 // Renderer-side, pull data out of poll buffer. | 162 // Renderer-side, pull data out of poll buffer. |
164 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( | 163 base::SharedMemoryHandle handle = provider->DuplicateSharedMemoryHandle(); |
165 base::GetCurrentProcessHandle()); | |
166 std::unique_ptr<base::SharedMemory> shared_memory( | 164 std::unique_ptr<base::SharedMemory> shared_memory( |
167 new base::SharedMemory(handle, true)); | 165 new base::SharedMemory(handle, true)); |
168 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); | 166 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); |
169 | 167 |
170 GamepadHardwareBuffer* buffer = | 168 GamepadHardwareBuffer* buffer = |
171 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); | 169 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); |
172 | 170 |
173 // Wait until the shared memory buffer has been written at least once. | 171 // Wait until the shared memory buffer has been written at least once. |
174 WaitForData(buffer); | 172 WaitForData(buffer); |
175 | 173 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 UserGestureListener listener; | 212 UserGestureListener listener; |
215 GamepadProvider* provider = CreateProvider(no_button_data); | 213 GamepadProvider* provider = CreateProvider(no_button_data); |
216 provider->SetSanitizationEnabled(false); | 214 provider->SetSanitizationEnabled(false); |
217 provider->Resume(); | 215 provider->Resume(); |
218 | 216 |
219 provider->RegisterForUserGesture(listener.GetClosure()); | 217 provider->RegisterForUserGesture(listener.GetClosure()); |
220 | 218 |
221 base::RunLoop().RunUntilIdle(); | 219 base::RunLoop().RunUntilIdle(); |
222 | 220 |
223 // Renderer-side, pull data out of poll buffer. | 221 // Renderer-side, pull data out of poll buffer. |
224 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( | 222 base::SharedMemoryHandle handle = provider->DuplicateSharedMemoryHandle(); |
225 base::GetCurrentProcessHandle()); | |
226 std::unique_ptr<base::SharedMemory> shared_memory( | 223 std::unique_ptr<base::SharedMemory> shared_memory( |
227 new base::SharedMemory(handle, true)); | 224 new base::SharedMemory(handle, true)); |
228 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); | 225 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); |
229 | 226 |
230 GamepadHardwareBuffer* buffer = | 227 GamepadHardwareBuffer* buffer = |
231 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); | 228 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); |
232 | 229 |
233 // Wait until the shared memory buffer has been written at least once. | 230 // Wait until the shared memory buffer has been written at least once. |
234 WaitForData(buffer); | 231 WaitForData(buffer); |
235 | 232 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 zero_data.items[0].axes[0] = 0.f; | 266 zero_data.items[0].axes[0] = 0.f; |
270 | 267 |
271 UserGestureListener listener; | 268 UserGestureListener listener; |
272 GamepadProvider* provider = CreateProvider(active_data); | 269 GamepadProvider* provider = CreateProvider(active_data); |
273 provider->SetSanitizationEnabled(true); | 270 provider->SetSanitizationEnabled(true); |
274 provider->Resume(); | 271 provider->Resume(); |
275 | 272 |
276 base::RunLoop().RunUntilIdle(); | 273 base::RunLoop().RunUntilIdle(); |
277 | 274 |
278 // Renderer-side, pull data out of poll buffer. | 275 // Renderer-side, pull data out of poll buffer. |
279 base::SharedMemoryHandle handle = provider->GetSharedMemoryHandleForProcess( | 276 base::SharedMemoryHandle handle = provider->DuplicateSharedMemoryHandle(); |
280 base::GetCurrentProcessHandle()); | |
281 std::unique_ptr<base::SharedMemory> shared_memory( | 277 std::unique_ptr<base::SharedMemory> shared_memory( |
282 new base::SharedMemory(handle, true)); | 278 new base::SharedMemory(handle, true)); |
283 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); | 279 EXPECT_TRUE(shared_memory->Map(sizeof(GamepadHardwareBuffer))); |
284 | 280 |
285 GamepadHardwareBuffer* buffer = | 281 GamepadHardwareBuffer* buffer = |
286 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); | 282 static_cast<GamepadHardwareBuffer*>(shared_memory->memory()); |
287 | 283 |
288 // Wait until the shared memory buffer has been written at least once. | 284 // Wait until the shared memory buffer has been written at least once. |
289 WaitForData(buffer); | 285 WaitForData(buffer); |
290 | 286 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 EXPECT_EQ(1u, output.items[0].buttons_length); | 322 EXPECT_EQ(1u, output.items[0].buttons_length); |
327 EXPECT_EQ(1.f, output.items[0].buttons[0].value); | 323 EXPECT_EQ(1.f, output.items[0].buttons[0].value); |
328 EXPECT_TRUE(output.items[0].buttons[0].pressed); | 324 EXPECT_TRUE(output.items[0].buttons[0].pressed); |
329 EXPECT_EQ(1u, output.items[0].axes_length); | 325 EXPECT_EQ(1u, output.items[0].axes_length); |
330 EXPECT_EQ(-1.f, output.items[0].axes[0]); | 326 EXPECT_EQ(-1.f, output.items[0].axes[0]); |
331 } | 327 } |
332 | 328 |
333 } // namespace | 329 } // namespace |
334 | 330 |
335 } // namespace device | 331 } // namespace device |
OLD | NEW |