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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/system/platform_handle.cc
diff --git a/mojo/public/cpp/system/platform_handle.cc b/mojo/public/cpp/system/platform_handle.cc
index e4a6088a2e3aa9ae4aae71e10f545cd0b6e16c2c..51dfc0ec898bf5fb05db34d4744d16e7463c4598 100644
--- a/mojo/public/cpp/system/platform_handle.cc
+++ b/mojo/public/cpp/system/platform_handle.cc
@@ -4,6 +4,11 @@
#include "mojo/public/cpp/system/platform_handle.h"
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+#include <mach/mach.h>
+#include "base/mac/mach_logging.h"
+#endif
+
namespace mojo {
namespace {
@@ -126,4 +131,39 @@ MojoResult UnwrapSharedMemoryHandle(ScopedSharedBufferHandle handle,
return MOJO_RESULT_OK;
}
+#if defined(OS_MACOSX) && !defined(OS_IOS)
+ScopedHandle WrapMachPort(mach_port_t port) {
+ kern_return_t kr =
+ 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
+ MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr)
+ << "MachPortAttachmentMac mach_port_mod_refs";
+ if (kr != KERN_SUCCESS)
+ return ScopedHandle();
+
+ MojoPlatformHandle platform_handle;
+ platform_handle.struct_size = sizeof(MojoPlatformHandle);
+ platform_handle.type = MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT;
+ platform_handle.value = static_cast<uint64_t>(port);
+
+ MojoHandle mojo_handle;
+ MojoResult result = MojoWrapPlatformHandle(&platform_handle, &mojo_handle);
+ CHECK_EQ(result, MOJO_RESULT_OK);
+
+ return ScopedHandle(Handle(mojo_handle));
+}
+
+MojoResult UnwrapMachPort(ScopedHandle handle, mach_port_t* port) {
+ MojoPlatformHandle platform_handle;
+ platform_handle.struct_size = sizeof(MojoPlatformHandle);
+ MojoResult result =
+ MojoUnwrapPlatformHandle(handle.release().value(), &platform_handle);
+ if (result != MOJO_RESULT_OK)
+ return result;
+
+ CHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT);
+ *port = static_cast<mach_port_t>(platform_handle.value);
+ return MOJO_RESULT_OK;
+}
+#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+
} // namespace mojo
« 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