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

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

Issue 2970353002: Add GpuMemoryBuffer support for DXGI handles.
Patch Set: add image texture target Created 3 years, 5 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
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 6eb14953be589bc056068fcc2cdf7ae44014d092..1f5be8dc3a586a1dca27cfb5436b7e698fa9deba 100644
--- a/ui/gfx/mojo/buffer_types_struct_traits.cc
+++ b/ui/gfx/mojo/buffer_types_struct_traits.cc
@@ -70,6 +70,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);
dcheng 2017/07/12 08:46:19 Maybe this can just use WrapSharedMemoryHandle? O
dcheng 2017/07/12 21:58:46 OK I asked rockot@ and it turns out that Mojo spec
yzshen1 2017/07/12 23:38:49 Sorry I didn't see this comment earlier. Yes, gett
+#else
+ return mojo::ScopedHandle();
+#endif
+}
+
const gfx::NativePixmapHandle&
StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
gfx::GpuMemoryBufferHandle>::
@@ -128,6 +152,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;
}
« ui/gfx/mojo/buffer_types_struct_traits.h ('K') | « 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