OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #ifndef DEVICE_GAMEPAD_SHARED_BUFFER_H_ | 5 #ifndef DEVICE_GAMEPAD_SHARED_BUFFER_H_ |
6 #define DEVICE_GAMEPAD_SHARED_BUFFER_H_ | 6 #define DEVICE_GAMEPAD_SHARED_BUFFER_H_ |
7 | 7 |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "device/base/synchronization/shared_memory_seqlock_buffer.h" |
9 #include "device/gamepad/gamepad_export.h" | 10 #include "device/gamepad/gamepad_export.h" |
10 #include "third_party/WebKit/public/platform/WebGamepads.h" | 11 #include "third_party/WebKit/public/platform/WebGamepads.h" |
11 | 12 |
12 namespace device { | 13 namespace device { |
13 | 14 |
| 15 /* |
| 16 |
| 17 GamepadHardwareBuffer is stored in shared memory that's shared between the |
| 18 browser which does the hardware polling, and the various consumers of the |
| 19 gamepad state (renderers and NaCl plugins). The performance characteristics are |
| 20 that we want low latency (so would like to avoid explicit communication via IPC |
| 21 between producer and consumer) and relatively large data size. |
| 22 |
| 23 Writer and reader operate on the same buffer assuming contention is low, and |
| 24 contention is detected by using the associated SeqLock. |
| 25 |
| 26 */ |
| 27 |
| 28 typedef SharedMemorySeqLockBuffer<blink::WebGamepads> GamepadHardwareBuffer; |
| 29 |
14 class DEVICE_GAMEPAD_EXPORT GamepadSharedBuffer { | 30 class DEVICE_GAMEPAD_EXPORT GamepadSharedBuffer { |
15 public: | 31 public: |
16 virtual ~GamepadSharedBuffer() {} | 32 GamepadSharedBuffer(); |
| 33 ~GamepadSharedBuffer(); |
17 | 34 |
18 virtual base::SharedMemory* shared_memory() = 0; | 35 base::SharedMemory* shared_memory(); |
19 virtual blink::WebGamepads* buffer() = 0; | 36 blink::WebGamepads* buffer(); |
| 37 GamepadHardwareBuffer* hardware_buffer(); |
20 | 38 |
21 virtual void WriteBegin() = 0; | 39 void WriteBegin(); |
22 virtual void WriteEnd() = 0; | 40 void WriteEnd(); |
| 41 |
| 42 private: |
| 43 base::SharedMemory shared_memory_; |
| 44 GamepadHardwareBuffer* hardware_buffer_; |
23 }; | 45 }; |
24 | 46 |
25 } // namespace device | 47 } // namespace device |
26 | 48 |
27 #endif // DEVICE_GAMEPAD_SHARED_BUFFER_H_ | 49 #endif // DEVICE_GAMEPAD_SHARED_BUFFER_H_ |
OLD | NEW |