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 "mojo/public/cpp/system/buffer.h" |
| 6 |
| 7 namespace mojo { |
| 8 |
| 9 ScopedSharedBufferHandle SharedBufferHandle::Clone( |
| 10 SharedBufferHandle::AccessMode access_mode) const { |
| 11 ScopedSharedBufferHandle result; |
| 12 if (!is_valid()) |
| 13 return result; |
| 14 |
| 15 MojoDuplicateBufferHandleOptions options = { |
| 16 sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}; |
| 17 if (access_mode == AccessMode::READ_ONLY) |
| 18 options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY; |
| 19 SharedBufferHandle result_handle; |
| 20 MojoDuplicateBufferHandle(value(), &options, result_handle.mutable_value()); |
| 21 result.reset(result_handle); |
| 22 return result; |
| 23 } |
| 24 |
| 25 ScopedSharedBufferMapping SharedBufferHandle::Map(uint64_t size) const { |
| 26 return MapAtOffset(size, 0); |
| 27 } |
| 28 |
| 29 ScopedSharedBufferMapping SharedBufferHandle::MapAtOffset( |
| 30 uint64_t size, |
| 31 uint64_t offset) const { |
| 32 void* buffer = nullptr; |
| 33 MojoMapBuffer(value(), offset, size, &buffer, MOJO_MAP_BUFFER_FLAG_NONE); |
| 34 return ScopedSharedBufferMapping(buffer); |
| 35 } |
| 36 |
| 37 } // namespace mojo |
OLD | NEW |