Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: third_party/WebKit/Source/core/mojo/MojoHandle.cpp

Issue 2720873002: Implements JS bindings for mojo shared buffer. (Closed)
Patch Set: rebaseline2 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "core/mojo/MojoHandle.h" 5 #include "core/mojo/MojoHandle.h"
6 6
7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" 7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h"
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/dom/DOMArrayBuffer.h" 9 #include "core/dom/DOMArrayBuffer.h"
10 #include "core/dom/DOMArrayBufferView.h" 10 #include "core/dom/DOMArrayBufferView.h"
11 #include "core/mojo/MojoCreateSharedBufferResult.h"
12 #include "core/mojo/MojoDuplicateBufferHandleOptions.h"
13 #include "core/mojo/MojoMapBufferResult.h"
11 #include "core/mojo/MojoReadMessageFlags.h" 14 #include "core/mojo/MojoReadMessageFlags.h"
12 #include "core/mojo/MojoReadMessageResult.h" 15 #include "core/mojo/MojoReadMessageResult.h"
13 #include "core/mojo/MojoWatcher.h" 16 #include "core/mojo/MojoWatcher.h"
14 17
15 // Mojo messages typically do not contain many handles. In fact most 18 // Mojo messages typically do not contain many handles. In fact most
16 // messages do not contain any handle. An inline capacity of 4 should avoid 19 // messages do not contain any handle. An inline capacity of 4 should avoid
17 // heap allocation in vast majority of cases. 20 // heap allocation in vast majority of cases.
18 static const size_t kHandleVectorInlineCapacity = 4; 21 static const size_t kHandleVectorInlineCapacity = 4;
19 22
20 namespace blink { 23 namespace blink {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 for (size_t i = 0; i < numHandles; ++i) { 88 for (size_t i = 0; i < numHandles; ++i) {
86 handles[i] = 89 handles[i] =
87 MojoHandle::create(mojo::MakeScopedHandle(mojo::Handle(rawHandles[i]))); 90 MojoHandle::create(mojo::MakeScopedHandle(mojo::Handle(rawHandles[i])));
88 } 91 }
89 92
90 resultDict.setResult(result); 93 resultDict.setResult(result);
91 resultDict.setBuffer(buffer); 94 resultDict.setBuffer(buffer);
92 resultDict.setHandles(handles); 95 resultDict.setHandles(handles);
93 } 96 }
94 97
98 void MojoHandle::mapBuffer(unsigned offset,
99 unsigned numBytes,
100 MojoMapBufferResult& resultDict) {
101 void* data = nullptr;
102 MojoResult result = MojoMapBuffer(m_handle->value(), offset, numBytes, &data,
103 MOJO_MAP_BUFFER_FLAG_NONE);
104 resultDict.setResult(result);
105 if (result == MOJO_RESULT_OK) {
106 WTF::ArrayBufferContents::DataHandle dataHandle(data, [](void* buffer) {
107 MojoResult result = MojoUnmapBuffer(buffer);
108 DCHECK_EQ(result, MOJO_RESULT_OK);
109 });
110 WTF::ArrayBufferContents contents(std::move(dataHandle), numBytes,
111 WTF::ArrayBufferContents::NotShared);
112 resultDict.setBuffer(DOMArrayBuffer::create(contents));
113 }
114 }
115
116 void MojoHandle::duplicateBufferHandle(
117 const MojoDuplicateBufferHandleOptions& optionsDict,
118 MojoCreateSharedBufferResult& resultDict) {
119 ::MojoDuplicateBufferHandleOptions options = {
120 sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
121 if (optionsDict.readOnly())
122 options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
123
124 mojo::Handle handle;
125 MojoResult result = MojoDuplicateBufferHandle(m_handle->value(), &options,
126 handle.mutable_value());
127 resultDict.setResult(result);
128 if (result == MOJO_RESULT_OK) {
129 resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle)));
130 }
131 }
132
95 } // namespace blink 133 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/mojo/MojoHandle.h ('k') | third_party/WebKit/Source/core/mojo/MojoHandle.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698