Commit c374ad0a authored by Alexandr Ilin's avatar Alexandr Ilin Committed by Commit Bot

gfx: Make all GpuMemoryBufferTypes platform scoped

Some GpuMemoryBufferPlatformHandle union members are used only on one
platform but are defined for all platforms. This CL restricts
platform-specific members to desired platform.

Bug: 863011
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I6c09e49db157d9d91dc5caeac939ca334f9054ba
Reviewed-on: https://chromium-review.googlesource.com/c/1290917Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Alexandr Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604049}
parent b1da81df
......@@ -23,6 +23,10 @@ mojom("mojo") {
"//mojo/public/mojom/base",
"//ui/gfx/geometry/mojo",
]
if (is_linux || is_chromeos) {
enabled_features = [ "supports_native_pixmap" ]
}
}
mojom("test_interfaces") {
......
......@@ -46,22 +46,13 @@ struct BufferUsageAndFormat {
BufferFormat format;
};
// gfx::GpuMemoryBufferType
enum GpuMemoryBufferType {
EMPTY_BUFFER,
SHARED_MEMORY_BUFFER,
IO_SURFACE_BUFFER,
NATIVE_PIXMAP,
DXGI_SHARED_HANDLE,
ANDROID_HARDWARE_BUFFER,
};
// gfx::GpuMemoryBufferId
struct GpuMemoryBufferId {
int32 id;
};
// gfx::NativePixmapPlane
[EnableIf=supports_native_pixmap]
struct NativePixmapPlane {
uint32 stride;
int32 offset;
......@@ -70,6 +61,7 @@ struct NativePixmapPlane {
};
// gfx::NativePixmapHandle
[EnableIf=supports_native_pixmap]
struct NativePixmapHandle {
// A file descriptor for the underlying memory object (usually dmabuf).
array<handle> fds;
......@@ -92,10 +84,12 @@ struct AHardwareBufferHandle {
};
union GpuMemoryBufferPlatformHandle {
// TODO(676224): Use preprocessor to restrict platform-specific members to
// desired platform.
mojo_base.mojom.UnsafeSharedMemoryRegion shared_memory_handle;
[EnableIf=supports_native_pixmap]
NativePixmapHandle native_pixmap_handle;
[EnableIf=is_mac]
handle mach_port;
[EnableIf=is_win]
......
......@@ -28,14 +28,13 @@ bool StructTraits<gfx::mojom::BufferUsageAndFormatDataView,
return data.ReadUsage(&out->usage) && data.ReadFormat(&out->format);
}
#if defined(OS_LINUX)
std::vector<mojo::ScopedHandle>
StructTraits<gfx::mojom::NativePixmapHandleDataView, gfx::NativePixmapHandle>::
fds(const gfx::NativePixmapHandle& pixmap_handle) {
std::vector<mojo::ScopedHandle> handles;
#if defined(OS_LINUX)
for (const base::FileDescriptor& fd : pixmap_handle.fds)
handles.emplace_back(mojo::WrapPlatformFile(fd.fd));
#endif // defined(OS_LINUX)
return handles;
}
......@@ -43,7 +42,6 @@ bool StructTraits<
gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data,
gfx::NativePixmapHandle* out) {
#if defined(OS_LINUX)
mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view;
data.GetFdsDataView(&handles_data_view);
for (size_t i = 0; i < handles_data_view.size(); ++i) {
......@@ -56,10 +54,8 @@ bool StructTraits<
out->fds.push_back(base::FileDescriptor(platform_file, auto_close));
}
return data.ReadPlanes(&out->planes);
#else
return false;
#endif
}
#endif // defined(OS_LINUX)
gfx::mojom::GpuMemoryBufferPlatformHandlePtr StructTraits<
gfx::mojom::GpuMemoryBufferHandleDataView,
......@@ -71,16 +67,13 @@ gfx::mojom::GpuMemoryBufferPlatformHandlePtr StructTraits<
case gfx::SHARED_MEMORY_BUFFER:
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewSharedMemoryHandle(
std::move(handle.region));
case gfx::NATIVE_PIXMAP: {
case gfx::NATIVE_PIXMAP:
#if defined(OS_LINUX)
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewNativePixmapHandle(
handle.native_pixmap_handle);
#else
static base::NoDestructor<gfx::NativePixmapHandle> pixmap_handle;
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewNativePixmapHandle(
*pixmap_handle);
break;
#endif
}
case gfx::IO_SURFACE_BUFFER:
#if defined(OS_MACOSX) && !defined(OS_IOS)
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewMachPort(
......@@ -151,17 +144,14 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
out->type = gfx::SHARED_MEMORY_BUFFER;
out->region = std::move(platform_handle->get_shared_memory_handle());
return true;
#if defined(OS_LINUX)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::
NATIVE_PIXMAP_HANDLE:
#if defined(OS_LINUX)
out->type = gfx::NATIVE_PIXMAP;
out->native_pixmap_handle = platform_handle->get_native_pixmap_handle();
return true;
#else
return false;
#endif
#elif defined(OS_MACOSX) && !defined(OS_IOS)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::MACH_PORT: {
#if defined(OS_MACOSX) && !defined(OS_IOS)
out->type = gfx::IO_SURFACE_BUFFER;
mach_port_t mach_port;
MojoResult unwrap_result = mojo::UnwrapMachPort(
......@@ -170,11 +160,8 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
return false;
out->mach_port.reset(mach_port);
return true;
#else
return false;
#endif
}
#if defined(OS_WIN)
#elif defined(OS_WIN)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::DXGI_HANDLE: {
out->type = gfx::DXGI_SHARED_HANDLE;
HANDLE handle;
......@@ -185,8 +172,7 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
out->dxgi_handle = IPC::PlatformFileForTransit(handle);
return true;
}
#endif
#if defined(OS_ANDROID)
#elif defined(OS_ANDROID)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::
ANDROID_HARDWARE_BUFFER_HANDLE: {
out->type = gfx::ANDROID_HARDWARE_BUFFER;
......
......@@ -189,6 +189,7 @@ struct StructTraits<gfx::mojom::GpuMemoryBufferIdDataView,
}
};
#if defined(OS_LINUX)
template <>
struct StructTraits<gfx::mojom::NativePixmapPlaneDataView,
gfx::NativePixmapPlane> {
......@@ -217,14 +218,6 @@ struct StructTraits<gfx::mojom::NativePixmapPlaneDataView,
template <>
struct StructTraits<gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle> {
static bool IsNull(const gfx::NativePixmapHandle& handle) {
#if defined(OS_LINUX)
return false;
#else
// NativePixmapHandle are not used on non-linux platforms.
return true;
#endif
}
static std::vector<mojo::ScopedHandle> fds(
const gfx::NativePixmapHandle& pixmap_handle);
......@@ -236,6 +229,7 @@ struct StructTraits<gfx::mojom::NativePixmapHandleDataView,
static bool Read(gfx::mojom::NativePixmapHandleDataView data,
gfx::NativePixmapHandle* out);
};
#endif // defined(OS_LINUX)
template <>
struct StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment