OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/gamepad/gamepad_shared_buffer_impl.h" |
| 6 |
| 7 #include "content/common/gamepad_hardware_buffer.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 GamepadSharedBufferImpl::GamepadSharedBufferImpl() { |
| 12 size_t data_size = sizeof(GamepadHardwareBuffer); |
| 13 bool res = shared_memory_.CreateAndMapAnonymous(data_size); |
| 14 CHECK(res); |
| 15 |
| 16 void* mem = shared_memory_.memory(); |
| 17 DCHECK(mem); |
| 18 // Placement new |
| 19 new (mem) GamepadHardwareBuffer(); |
| 20 |
| 21 //GamepadHardwareBuffer* hwbuf = hardware_buffer(); |
| 22 //memset(hwbuf, 0, sizeof(GamepadHardwareBuffer)); |
| 23 } |
| 24 |
| 25 GamepadSharedBufferImpl::~GamepadSharedBufferImpl() { |
| 26 |
| 27 } |
| 28 |
| 29 base::SharedMemory* GamepadSharedBufferImpl::shared_memory() { |
| 30 return &shared_memory_; |
| 31 } |
| 32 |
| 33 blink::WebGamepads* GamepadSharedBufferImpl::buffer() { |
| 34 return &(hardware_buffer()->buffer); |
| 35 } |
| 36 |
| 37 GamepadHardwareBuffer* GamepadSharedBufferImpl::hardware_buffer() { |
| 38 void* mem = shared_memory_.memory(); |
| 39 DCHECK(mem); |
| 40 return static_cast<GamepadHardwareBuffer*>(mem); |
| 41 } |
| 42 |
| 43 void GamepadSharedBufferImpl::WriteBegin() { |
| 44 hardware_buffer()->sequence.WriteBegin(); |
| 45 } |
| 46 |
| 47 void GamepadSharedBufferImpl::WriteEnd() { |
| 48 hardware_buffer()->sequence.WriteEnd(); |
| 49 } |
| 50 |
| 51 } // namespace content |
OLD | NEW |