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

Side by Side Diff: mojo/public/cpp/system/platform_handle.cc

Issue 2537423004: mus: Add support for sending IOSurface mach_ports over mojo. (Closed)
Patch Set: . Created 4 years 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
« no previous file with comments | « mojo/public/cpp/system/platform_handle.h ('k') | ui/gfx/mojo/buffer_types.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "mojo/public/cpp/system/platform_handle.h" 5 #include "mojo/public/cpp/system/platform_handle.h"
6 6
7 #if defined(OS_MACOSX) && !defined(OS_IOS)
8 #include <mach/mach.h>
9 #include "base/mac/mach_logging.h"
10 #endif
11
7 namespace mojo { 12 namespace mojo {
8 13
9 namespace { 14 namespace {
10 15
11 uint64_t PlatformHandleValueFromPlatformFile(base::PlatformFile file) { 16 uint64_t PlatformHandleValueFromPlatformFile(base::PlatformFile file) {
12 #if defined(OS_WIN) 17 #if defined(OS_WIN)
13 return reinterpret_cast<uint64_t>(file); 18 return reinterpret_cast<uint64_t>(file);
14 #else 19 #else
15 return static_cast<uint64_t>(file); 20 return static_cast<uint64_t>(file);
16 #endif 21 #endif
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 #elif defined(OS_WIN) 124 #elif defined(OS_WIN)
120 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE); 125 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE);
121 *memory_handle = base::SharedMemoryHandle( 126 *memory_handle = base::SharedMemoryHandle(
122 reinterpret_cast<HANDLE>(platform_handle.value), 127 reinterpret_cast<HANDLE>(platform_handle.value),
123 base::GetCurrentProcId()); 128 base::GetCurrentProcId());
124 #endif 129 #endif
125 130
126 return MOJO_RESULT_OK; 131 return MOJO_RESULT_OK;
127 } 132 }
128 133
134 #if defined(OS_MACOSX) && !defined(OS_IOS)
135 ScopedHandle WrapMachPort(mach_port_t port) {
136 kern_return_t kr =
137 mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, 1);
Robert Sesek 2016/12/01 18:51:34 I can't find it in the code, but maybe I'm not loo
138 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr)
139 << "MachPortAttachmentMac mach_port_mod_refs";
140 if (kr != KERN_SUCCESS)
141 return ScopedHandle();
142
143 MojoPlatformHandle platform_handle;
144 platform_handle.struct_size = sizeof(MojoPlatformHandle);
145 platform_handle.type = MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT;
146 platform_handle.value = static_cast<uint64_t>(port);
147
148 MojoHandle mojo_handle;
149 MojoResult result = MojoWrapPlatformHandle(&platform_handle, &mojo_handle);
150 CHECK_EQ(result, MOJO_RESULT_OK);
151
152 return ScopedHandle(Handle(mojo_handle));
153 }
154
155 MojoResult UnwrapMachPort(ScopedHandle handle, mach_port_t* port) {
156 MojoPlatformHandle platform_handle;
157 platform_handle.struct_size = sizeof(MojoPlatformHandle);
158 MojoResult result =
159 MojoUnwrapPlatformHandle(handle.release().value(), &platform_handle);
160 if (result != MOJO_RESULT_OK)
161 return result;
162
163 CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT);
164 *port = static_cast<mach_port_t>(platform_handle.value);
165 return MOJO_RESULT_OK;
166 }
167 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
168
129 } // namespace mojo 169 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/platform_handle.h ('k') | ui/gfx/mojo/buffer_types.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698