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

Unified Diff: ui/gfx/mojo/buffer_types_struct_traits.cc

Issue 2970353002: Add GpuMemoryBuffer support for DXGI handles.
Patch Set: update build config Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/mojo/buffer_types_struct_traits.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/mojo/buffer_types_struct_traits.cc
diff --git a/ui/gfx/mojo/buffer_types_struct_traits.cc b/ui/gfx/mojo/buffer_types_struct_traits.cc
index 186e2eb5502b4f7359053243413dca8e9996e5ed..354f8e7e5b0fa602ac3eeb08ca68bf4b05b398f3 100644
--- a/ui/gfx/mojo/buffer_types_struct_traits.cc
+++ b/ui/gfx/mojo/buffer_types_struct_traits.cc
@@ -64,6 +64,30 @@ StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
false);
}
+mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
+ gfx::GpuMemoryBufferHandle>::
+ win32_handle(const gfx::GpuMemoryBufferHandle& handle) {
+ if (handle.type != gfx::DXGI_HANDLE)
+ return mojo::ScopedHandle();
+
+#if defined(OS_WIN)
+ DCHECK(handle.handle.OwnershipPassesToIPC());
+ MojoPlatformHandle mojo_platform_handle;
+ mojo_platform_handle.struct_size = sizeof(mojo_platform_handle);
+ mojo_platform_handle.type = MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE;
+ mojo_platform_handle.value =
+ reinterpret_cast<uint64_t>(handle.handle.GetHandle());
+ mojo::Handle mojo_handle;
+ MojoResult result = MojoWrapPlatformHandle(&mojo_platform_handle,
+ mojo_handle.mutable_value());
+ if (result != MOJO_RESULT_OK)
+ return mojo::ScopedHandle();
+ return mojo::MakeScopedHandle(mojo_handle);
+#else
+ return mojo::ScopedHandle();
+#endif
+}
+
const gfx::NativePixmapHandle&
StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
gfx::GpuMemoryBufferHandle>::
@@ -122,6 +146,26 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
out->mach_port.reset(mach_port);
}
#endif
+#if defined(OS_WIN)
+ if (out->type == gfx::DXGI_HANDLE) {
+ mojo::ScopedHandle handle = data.TakeWin32Handle();
+ if (handle.is_valid()) {
+ MojoPlatformHandle platform_handle;
+ platform_handle.struct_size = sizeof(platform_handle);
+ MojoResult unwrap_result =
+ MojoUnwrapPlatformHandle(handle.release().value(), &platform_handle);
+
+ if (unwrap_result != MOJO_RESULT_OK)
+ return false;
+ DCHECK_EQ(platform_handle.type, MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE);
+ out->handle = base::SharedMemoryHandle(
+ reinterpret_cast<HANDLE>(platform_handle.value), 0,
+ base::UnguessableToken::Create());
+ }
+
+ out->array_level = data.array_level();
+ }
+#endif
return true;
}
« no previous file with comments | « ui/gfx/mojo/buffer_types_struct_traits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698