forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mojo: Add a C++-style SharedBuffer API.
Review-Url: https://codereview.chromium.org/2036053002 Cr-Commit-Position: refs/heads/master@{#397957}
- Loading branch information
Showing
6 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
source_set("system") { | ||
sources = [ | ||
"buffer.cc", | ||
"buffer.h", | ||
"core.h", | ||
"data_pipe.h", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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 "mojo/public/cpp/system/buffer.h" | ||
|
||
namespace mojo { | ||
|
||
ScopedSharedBufferHandle SharedBufferHandle::Clone( | ||
SharedBufferHandle::AccessMode access_mode) const { | ||
ScopedSharedBufferHandle result; | ||
if (!is_valid()) | ||
return result; | ||
|
||
MojoDuplicateBufferHandleOptions options = { | ||
sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}; | ||
if (access_mode == AccessMode::READ_ONLY) | ||
options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY; | ||
SharedBufferHandle result_handle; | ||
MojoDuplicateBufferHandle(value(), &options, result_handle.mutable_value()); | ||
result.reset(result_handle); | ||
return result; | ||
} | ||
|
||
ScopedSharedBufferMapping SharedBufferHandle::Map(uint64_t size) const { | ||
return MapAtOffset(size, 0); | ||
} | ||
|
||
ScopedSharedBufferMapping SharedBufferHandle::MapAtOffset( | ||
uint64_t size, | ||
uint64_t offset) const { | ||
void* buffer = nullptr; | ||
MojoMapBuffer(value(), offset, size, &buffer, MOJO_MAP_BUFFER_FLAG_NONE); | ||
return ScopedSharedBufferMapping(buffer); | ||
} | ||
|
||
} // namespace mojo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters