Index: content/browser/gamepad/gamepad_shared_buffer_impl.cc |
diff --git a/content/browser/gamepad/gamepad_shared_buffer_impl.cc b/content/browser/gamepad/gamepad_shared_buffer_impl.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3c0224902391a0e5a4cb8e88307b4b9aa1550900 |
--- /dev/null |
+++ b/content/browser/gamepad/gamepad_shared_buffer_impl.cc |
@@ -0,0 +1,51 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/gamepad/gamepad_shared_buffer_impl.h" |
+ |
+#include "content/common/gamepad_hardware_buffer.h" |
+ |
+namespace content { |
+ |
+GamepadSharedBufferImpl::GamepadSharedBufferImpl() { |
+ size_t data_size = sizeof(GamepadHardwareBuffer); |
+ bool res = shared_memory_.CreateAndMapAnonymous(data_size); |
+ CHECK(res); |
+ |
+ void* mem = shared_memory_.memory(); |
+ DCHECK(mem); |
+ // Placement new |
+ new (mem) GamepadHardwareBuffer(); |
+ |
+ //GamepadHardwareBuffer* hwbuf = hardware_buffer(); |
+ //memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); |
+} |
+ |
+GamepadSharedBufferImpl::~GamepadSharedBufferImpl() { |
+ |
+} |
+ |
+base::SharedMemory* GamepadSharedBufferImpl::shared_memory() { |
+ return &shared_memory_; |
+} |
+ |
+blink::WebGamepads* GamepadSharedBufferImpl::buffer() { |
+ return &(hardware_buffer()->buffer); |
+} |
+ |
+GamepadHardwareBuffer* GamepadSharedBufferImpl::hardware_buffer() { |
+ void* mem = shared_memory_.memory(); |
+ DCHECK(mem); |
+ return static_cast<GamepadHardwareBuffer*>(mem); |
+} |
+ |
+void GamepadSharedBufferImpl::WriteBegin() { |
+ hardware_buffer()->sequence.WriteBegin(); |
+} |
+ |
+void GamepadSharedBufferImpl::WriteEnd() { |
+ hardware_buffer()->sequence.WriteEnd(); |
+} |
+ |
+} // namespace content |