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") { ...@@ -23,6 +23,10 @@ mojom("mojo") {
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//ui/gfx/geometry/mojo", "//ui/gfx/geometry/mojo",
] ]
if (is_linux || is_chromeos) {
enabled_features = [ "supports_native_pixmap" ]
}
} }
mojom("test_interfaces") { mojom("test_interfaces") {
......
...@@ -46,22 +46,13 @@ struct BufferUsageAndFormat { ...@@ -46,22 +46,13 @@ struct BufferUsageAndFormat {
BufferFormat format; BufferFormat format;
}; };
// gfx::GpuMemoryBufferType
enum GpuMemoryBufferType {
EMPTY_BUFFER,
SHARED_MEMORY_BUFFER,
IO_SURFACE_BUFFER,
NATIVE_PIXMAP,
DXGI_SHARED_HANDLE,
ANDROID_HARDWARE_BUFFER,
};
// gfx::GpuMemoryBufferId // gfx::GpuMemoryBufferId
struct GpuMemoryBufferId { struct GpuMemoryBufferId {
int32 id; int32 id;
}; };
// gfx::NativePixmapPlane // gfx::NativePixmapPlane
[EnableIf=supports_native_pixmap]
struct NativePixmapPlane { struct NativePixmapPlane {
uint32 stride; uint32 stride;
int32 offset; int32 offset;
...@@ -70,6 +61,7 @@ struct NativePixmapPlane { ...@@ -70,6 +61,7 @@ struct NativePixmapPlane {
}; };
// gfx::NativePixmapHandle // gfx::NativePixmapHandle
[EnableIf=supports_native_pixmap]
struct NativePixmapHandle { struct NativePixmapHandle {
// A file descriptor for the underlying memory object (usually dmabuf). // A file descriptor for the underlying memory object (usually dmabuf).
array<handle> fds; array<handle> fds;
...@@ -92,10 +84,12 @@ struct AHardwareBufferHandle { ...@@ -92,10 +84,12 @@ struct AHardwareBufferHandle {
}; };
union GpuMemoryBufferPlatformHandle { union GpuMemoryBufferPlatformHandle {
// TODO(676224): Use preprocessor to restrict platform-specific members to
// desired platform.
mojo_base.mojom.UnsafeSharedMemoryRegion shared_memory_handle; mojo_base.mojom.UnsafeSharedMemoryRegion shared_memory_handle;
[EnableIf=supports_native_pixmap]
NativePixmapHandle native_pixmap_handle; NativePixmapHandle native_pixmap_handle;
[EnableIf=is_mac]
handle mach_port; handle mach_port;
[EnableIf=is_win] [EnableIf=is_win]
......
...@@ -28,14 +28,13 @@ bool StructTraits<gfx::mojom::BufferUsageAndFormatDataView, ...@@ -28,14 +28,13 @@ bool StructTraits<gfx::mojom::BufferUsageAndFormatDataView,
return data.ReadUsage(&out->usage) && data.ReadFormat(&out->format); return data.ReadUsage(&out->usage) && data.ReadFormat(&out->format);
} }
#if defined(OS_LINUX)
std::vector<mojo::ScopedHandle> std::vector<mojo::ScopedHandle>
StructTraits<gfx::mojom::NativePixmapHandleDataView, gfx::NativePixmapHandle>:: StructTraits<gfx::mojom::NativePixmapHandleDataView, gfx::NativePixmapHandle>::
fds(const gfx::NativePixmapHandle& pixmap_handle) { fds(const gfx::NativePixmapHandle& pixmap_handle) {
std::vector<mojo::ScopedHandle> handles; std::vector<mojo::ScopedHandle> handles;
#if defined(OS_LINUX)
for (const base::FileDescriptor& fd : pixmap_handle.fds) for (const base::FileDescriptor& fd : pixmap_handle.fds)
handles.emplace_back(mojo::WrapPlatformFile(fd.fd)); handles.emplace_back(mojo::WrapPlatformFile(fd.fd));
#endif // defined(OS_LINUX)
return handles; return handles;
} }
...@@ -43,7 +42,6 @@ bool StructTraits< ...@@ -43,7 +42,6 @@ bool StructTraits<
gfx::mojom::NativePixmapHandleDataView, gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data, gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data,
gfx::NativePixmapHandle* out) { gfx::NativePixmapHandle* out) {
#if defined(OS_LINUX)
mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view; mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view;
data.GetFdsDataView(&handles_data_view); data.GetFdsDataView(&handles_data_view);
for (size_t i = 0; i < handles_data_view.size(); ++i) { for (size_t i = 0; i < handles_data_view.size(); ++i) {
...@@ -56,10 +54,8 @@ bool StructTraits< ...@@ -56,10 +54,8 @@ bool StructTraits<
out->fds.push_back(base::FileDescriptor(platform_file, auto_close)); out->fds.push_back(base::FileDescriptor(platform_file, auto_close));
} }
return data.ReadPlanes(&out->planes); return data.ReadPlanes(&out->planes);
#else
return false;
#endif
} }
#endif // defined(OS_LINUX)
gfx::mojom::GpuMemoryBufferPlatformHandlePtr StructTraits< gfx::mojom::GpuMemoryBufferPlatformHandlePtr StructTraits<
gfx::mojom::GpuMemoryBufferHandleDataView, gfx::mojom::GpuMemoryBufferHandleDataView,
...@@ -71,16 +67,13 @@ gfx::mojom::GpuMemoryBufferPlatformHandlePtr StructTraits< ...@@ -71,16 +67,13 @@ gfx::mojom::GpuMemoryBufferPlatformHandlePtr StructTraits<
case gfx::SHARED_MEMORY_BUFFER: case gfx::SHARED_MEMORY_BUFFER:
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewSharedMemoryHandle( return gfx::mojom::GpuMemoryBufferPlatformHandle::NewSharedMemoryHandle(
std::move(handle.region)); std::move(handle.region));
case gfx::NATIVE_PIXMAP: { case gfx::NATIVE_PIXMAP:
#if defined(OS_LINUX) #if defined(OS_LINUX)
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewNativePixmapHandle( return gfx::mojom::GpuMemoryBufferPlatformHandle::NewNativePixmapHandle(
handle.native_pixmap_handle); handle.native_pixmap_handle);
#else #else
static base::NoDestructor<gfx::NativePixmapHandle> pixmap_handle; break;
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewNativePixmapHandle(
*pixmap_handle);
#endif #endif
}
case gfx::IO_SURFACE_BUFFER: case gfx::IO_SURFACE_BUFFER:
#if defined(OS_MACOSX) && !defined(OS_IOS) #if defined(OS_MACOSX) && !defined(OS_IOS)
return gfx::mojom::GpuMemoryBufferPlatformHandle::NewMachPort( return gfx::mojom::GpuMemoryBufferPlatformHandle::NewMachPort(
...@@ -151,17 +144,14 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, ...@@ -151,17 +144,14 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
out->type = gfx::SHARED_MEMORY_BUFFER; out->type = gfx::SHARED_MEMORY_BUFFER;
out->region = std::move(platform_handle->get_shared_memory_handle()); out->region = std::move(platform_handle->get_shared_memory_handle());
return true; return true;
#if defined(OS_LINUX)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag:: case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::
NATIVE_PIXMAP_HANDLE: NATIVE_PIXMAP_HANDLE:
#if defined(OS_LINUX)
out->type = gfx::NATIVE_PIXMAP; out->type = gfx::NATIVE_PIXMAP;
out->native_pixmap_handle = platform_handle->get_native_pixmap_handle(); out->native_pixmap_handle = platform_handle->get_native_pixmap_handle();
return true; return true;
#else #elif defined(OS_MACOSX) && !defined(OS_IOS)
return false;
#endif
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::MACH_PORT: { case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::MACH_PORT: {
#if defined(OS_MACOSX) && !defined(OS_IOS)
out->type = gfx::IO_SURFACE_BUFFER; out->type = gfx::IO_SURFACE_BUFFER;
mach_port_t mach_port; mach_port_t mach_port;
MojoResult unwrap_result = mojo::UnwrapMachPort( MojoResult unwrap_result = mojo::UnwrapMachPort(
...@@ -170,11 +160,8 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, ...@@ -170,11 +160,8 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
return false; return false;
out->mach_port.reset(mach_port); out->mach_port.reset(mach_port);
return true; return true;
#else
return false;
#endif
} }
#if defined(OS_WIN) #elif defined(OS_WIN)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::DXGI_HANDLE: { case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::DXGI_HANDLE: {
out->type = gfx::DXGI_SHARED_HANDLE; out->type = gfx::DXGI_SHARED_HANDLE;
HANDLE handle; HANDLE handle;
...@@ -185,8 +172,7 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, ...@@ -185,8 +172,7 @@ bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
out->dxgi_handle = IPC::PlatformFileForTransit(handle); out->dxgi_handle = IPC::PlatformFileForTransit(handle);
return true; return true;
} }
#endif #elif defined(OS_ANDROID)
#if defined(OS_ANDROID)
case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag:: case gfx::mojom::GpuMemoryBufferPlatformHandleDataView::Tag::
ANDROID_HARDWARE_BUFFER_HANDLE: { ANDROID_HARDWARE_BUFFER_HANDLE: {
out->type = gfx::ANDROID_HARDWARE_BUFFER; out->type = gfx::ANDROID_HARDWARE_BUFFER;
......
...@@ -189,6 +189,7 @@ struct StructTraits<gfx::mojom::GpuMemoryBufferIdDataView, ...@@ -189,6 +189,7 @@ struct StructTraits<gfx::mojom::GpuMemoryBufferIdDataView,
} }
}; };
#if defined(OS_LINUX)
template <> template <>
struct StructTraits<gfx::mojom::NativePixmapPlaneDataView, struct StructTraits<gfx::mojom::NativePixmapPlaneDataView,
gfx::NativePixmapPlane> { gfx::NativePixmapPlane> {
...@@ -217,14 +218,6 @@ struct StructTraits<gfx::mojom::NativePixmapPlaneDataView, ...@@ -217,14 +218,6 @@ struct StructTraits<gfx::mojom::NativePixmapPlaneDataView,
template <> template <>
struct StructTraits<gfx::mojom::NativePixmapHandleDataView, struct StructTraits<gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle> { 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( static std::vector<mojo::ScopedHandle> fds(
const gfx::NativePixmapHandle& pixmap_handle); const gfx::NativePixmapHandle& pixmap_handle);
...@@ -236,6 +229,7 @@ struct StructTraits<gfx::mojom::NativePixmapHandleDataView, ...@@ -236,6 +229,7 @@ struct StructTraits<gfx::mojom::NativePixmapHandleDataView,
static bool Read(gfx::mojom::NativePixmapHandleDataView data, static bool Read(gfx::mojom::NativePixmapHandleDataView data,
gfx::NativePixmapHandle* out); gfx::NativePixmapHandle* out);
}; };
#endif // defined(OS_LINUX)
template <> template <>
struct StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView, 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