Commit 5569cc1d authored by sadrul's avatar sadrul Committed by Commit bot

gfx: Struct traits for GpuMemoryBufferHandle.

The remaining type-converter is for GpuMemoryBufferHandle. So introduce a
struct-trait for it instead. It also needs struct-traits for
NativePixmapPlane and NativePixmapHandle. Remove the type-converters,
since they are no longer needed. Also, expose NativePixmapPlane and
NativePixmapHandle types to non-ozone platforms, so we don't need some
special ozone-only mojom API.

BUG=637923
TBR=reveman@ for trivial components/exo change

Review-Url: https://codereview.chromium.org/2298003002
Cr-Commit-Position: refs/heads/master@{#416362}
parent 60fb6b0f
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "base/files/scoped_file.h" #include "base/files/scoped_file.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#endif #endif
namespace gfx { namespace gfx {
......
...@@ -12,8 +12,6 @@ source_set("mus_common") { ...@@ -12,8 +12,6 @@ source_set("mus_common") {
"event_matcher_util.h", "event_matcher_util.h",
"generic_shared_memory_id_generator.cc", "generic_shared_memory_id_generator.cc",
"generic_shared_memory_id_generator.h", "generic_shared_memory_id_generator.h",
"gpu_type_converters.cc",
"gpu_type_converters.h",
"switches.cc", "switches.cc",
"switches.h", "switches.h",
"transient_window_utils.h", "transient_window_utils.h",
...@@ -57,27 +55,3 @@ source_set("run_all_shelltests") { ...@@ -57,27 +55,3 @@ source_set("run_all_shelltests") {
deps += [ "//ui/ozone" ] deps += [ "//ui/ozone" ]
} }
} }
test("mus_common_unittests") {
sources = [
"gpu_type_converters_unittest.cc",
]
public_deps = [
":mus_common",
]
deps = [
":run_all_shelltests",
"//base",
"//base/test:test_config",
"//ipc:ipc",
"//services/ui/public/interfaces",
"//testing/gtest",
"//ui/gfx:test_support",
"//ui/gfx/ipc",
]
}
service_manifest("mus_common_unittests_app_manifest") {
name = "mus_common_unittests_app"
source = "mus_common_unittests_app_manifest.json"
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/ui/common/gpu_type_converters.h"
#include "build/build_config.h"
#include "gpu/config/gpu_info.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "ui/gfx/gpu_memory_buffer.h"
#if defined(USE_OZONE)
#include "ui/gfx/native_pixmap_handle_ozone.h"
#endif
namespace mojo {
#if defined(USE_OZONE)
// static
ui::mojom::NativePixmapHandlePtr TypeConverter<
ui::mojom::NativePixmapHandlePtr,
gfx::NativePixmapHandle>::Convert(const gfx::NativePixmapHandle& handle) {
// TODO(penghuang); support NativePixmapHandle.
ui::mojom::NativePixmapHandlePtr result =
ui::mojom::NativePixmapHandle::New();
return result;
}
// static
gfx::NativePixmapHandle
TypeConverter<gfx::NativePixmapHandle, ui::mojom::NativePixmapHandlePtr>::
Convert(const ui::mojom::NativePixmapHandlePtr& handle) {
// TODO(penghuang); support NativePixmapHandle.
gfx::NativePixmapHandle result;
return result;
}
#endif
// static
ui::mojom::GpuMemoryBufferHandlePtr
TypeConverter<ui::mojom::GpuMemoryBufferHandlePtr, gfx::GpuMemoryBufferHandle>::
Convert(const gfx::GpuMemoryBufferHandle& handle) {
DCHECK(handle.type == gfx::SHARED_MEMORY_BUFFER);
ui::mojom::GpuMemoryBufferHandlePtr result =
ui::mojom::GpuMemoryBufferHandle::New();
result->type = handle.type;
result->id = handle.id;
base::PlatformFile platform_file;
#if defined(OS_WIN)
platform_file = handle.handle.GetHandle();
#else
DCHECK(handle.handle.auto_close || handle.handle.fd == -1);
platform_file = handle.handle.fd;
#endif
result->buffer_handle = mojo::WrapPlatformFile(platform_file);
result->offset = handle.offset;
result->stride = handle.stride;
#if defined(USE_OZONE)
result->native_pixmap_handle =
ui::mojom::NativePixmapHandle::From(handle.native_pixmap_handle);
#endif
return result;
}
// static
gfx::GpuMemoryBufferHandle
TypeConverter<gfx::GpuMemoryBufferHandle, ui::mojom::GpuMemoryBufferHandlePtr>::
Convert(const ui::mojom::GpuMemoryBufferHandlePtr& handle) {
DCHECK_EQ(handle->type, gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER);
gfx::GpuMemoryBufferHandle result;
result.type = handle->type;
result.id = handle->id;
base::PlatformFile platform_file;
MojoResult unwrap_result = mojo::UnwrapPlatformFile(
std::move(handle->buffer_handle), &platform_file);
if (unwrap_result == MOJO_RESULT_OK) {
#if defined(OS_WIN)
result.handle =
base::SharedMemoryHandle(platform_file, base::GetCurrentProcId());
#else
result.handle = base::SharedMemoryHandle(platform_file, true);
#endif
}
result.offset = handle->offset;
result.stride = handle->stride;
#if defined(USE_OZONE)
result.native_pixmap_handle =
handle->native_pixmap_handle.To<gfx::NativePixmapHandle>();
#else
DCHECK(handle->native_pixmap_handle.is_null());
#endif
return result;
}
} // namespace mojo
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_UI_COMMON_GPU_TYPE_CONVERTERS_H_
#define SERVICES_UI_COMMON_GPU_TYPE_CONVERTERS_H_
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/type_converter.h"
#include "services/ui/public/interfaces/gpu_memory_buffer.mojom.h"
namespace gfx {
struct GpuMemoryBufferHandle;
class GenericSharedMemoryId;
using GpuMemoryBufferId = GenericSharedMemoryId;
struct NativePixmapHandle;
}
namespace mojo {
#if defined(USE_OZONE)
template <>
struct TypeConverter<ui::mojom::NativePixmapHandlePtr,
gfx::NativePixmapHandle> {
static ui::mojom::NativePixmapHandlePtr Convert(
const gfx::NativePixmapHandle& handle);
};
template <>
struct TypeConverter<gfx::NativePixmapHandle,
ui::mojom::NativePixmapHandlePtr> {
static gfx::NativePixmapHandle Convert(
const ui::mojom::NativePixmapHandlePtr& handle);
};
#endif
template <>
struct TypeConverter<ui::mojom::GpuMemoryBufferHandlePtr,
gfx::GpuMemoryBufferHandle> {
static ui::mojom::GpuMemoryBufferHandlePtr Convert(
const gfx::GpuMemoryBufferHandle& handle);
};
template <>
struct TypeConverter<gfx::GpuMemoryBufferHandle,
ui::mojom::GpuMemoryBufferHandlePtr> {
static gfx::GpuMemoryBufferHandle Convert(
const ui::mojom::GpuMemoryBufferHandlePtr& handle);
};
} // namespace mojo
#endif // SERVICES_UI_COMMON_GPU_TYPE_CONVERTERS_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/files/scoped_file.h"
#include "build/build_config.h"
#include "services/ui/common/gpu_type_converters.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_memory_buffer.h"
// Test for mojo TypeConverter of ui::mojom::GpuMemoryBufferHandle
TEST(MusGpuTypeConvertersTest, GpuMemoryBufferHandle) {
const gfx::GpuMemoryBufferId kId(99);
const uint32_t kOffset = 126;
const int32_t kStride = 256;
base::SharedMemory shared_memory;
ASSERT_TRUE(shared_memory.CreateAnonymous(1024));
ASSERT_TRUE(shared_memory.Map(1024));
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.id = kId;
handle.handle = base::SharedMemory::DuplicateHandle(shared_memory.handle());
handle.offset = kOffset;
handle.stride = kStride;
ui::mojom::GpuMemoryBufferHandlePtr gpu_handle =
ui::mojom::GpuMemoryBufferHandle::From<gfx::GpuMemoryBufferHandle>(
handle);
ASSERT_EQ(gpu_handle->type, gfx::GpuMemoryBufferType::SHARED_MEMORY_BUFFER);
ASSERT_EQ(gpu_handle->id.id, 99);
ASSERT_EQ(gpu_handle->offset, kOffset);
ASSERT_EQ(gpu_handle->stride, kStride);
handle = gpu_handle.To<gfx::GpuMemoryBufferHandle>();
ASSERT_EQ(handle.type, gfx::SHARED_MEMORY_BUFFER);
ASSERT_EQ(handle.id, kId);
ASSERT_EQ(handle.offset, kOffset);
ASSERT_EQ(handle.stride, kStride);
base::SharedMemory shared_memory1(handle.handle, true);
ASSERT_TRUE(shared_memory1.Map(1024));
}
{
"manifest_version": 1,
"name": "mojo:mus_common_unittests_app",
"display_name": "Mus Common Unittests",
"capabilities": {
"required": {
"*": { "classes": [ "app" ] }
}
}
}
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "mojo/public/cpp/bindings/sync_call_restrictions.h" #include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "mojo/public/cpp/system/platform_handle.h" #include "mojo/public/cpp/system/platform_handle.h"
#include "services/shell/public/cpp/connector.h" #include "services/shell/public/cpp/connector.h"
#include "services/ui/common/gpu_type_converters.h"
#include "services/ui/common/switches.h" #include "services/ui/common/switches.h"
#include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h" #include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h"
#include "services/ui/public/interfaces/gpu_service.mojom.h" #include "services/ui/public/interfaces/gpu_service.mojom.h"
......
...@@ -25,7 +25,7 @@ interface GpuService { ...@@ -25,7 +25,7 @@ interface GpuService {
gfx.mojom.BufferFormat format, gfx.mojom.BufferFormat format,
gfx.mojom.BufferUsage usage, gfx.mojom.BufferUsage usage,
uint64 surface_id) uint64 surface_id)
=> (GpuMemoryBufferHandle buffer_handle); => (gfx.mojom.GpuMemoryBufferHandle buffer_handle);
// Tells the GPU process to destroy GPU memory buffer. // Tells the GPU process to destroy GPU memory buffer.
DestroyGpuMemoryBuffer(gfx.mojom.GpuMemoryBufferId id, DestroyGpuMemoryBuffer(gfx.mojom.GpuMemoryBufferId id,
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "gpu/ipc/client/gpu_channel_host.h" #include "gpu/ipc/client/gpu_channel_host.h"
#include "services/shell/public/cpp/connection.h" #include "services/shell/public/cpp/connection.h"
#include "services/ui/common/gpu_type_converters.h"
#include "services/ui/gpu/gpu_service_internal.h" #include "services/ui/gpu/gpu_service_internal.h"
#include "services/ui/ws/gpu_service_proxy_delegate.h" #include "services/ui/ws/gpu_service_proxy_delegate.h"
#include "services/ui/ws/mus_gpu_memory_buffer_manager.h" #include "services/ui/ws/mus_gpu_memory_buffer_manager.h"
......
...@@ -304,7 +304,6 @@ WHITELIST = { ...@@ -304,7 +304,6 @@ WHITELIST = {
'mojo_public_system_unittests.exe', 'mojo_public_system_unittests.exe',
'mojo_system_unittests.exe', 'mojo_system_unittests.exe',
'mus_clipboard_unittests.exe', 'mus_clipboard_unittests.exe',
'mus_common_unittests.exe',
'mus_demo_library.dll', 'mus_demo_library.dll',
'mus_demo_unittests.exe', 'mus_demo_unittests.exe',
'mus_gpu_unittests.exe', 'mus_gpu_unittests.exe',
......
...@@ -489,6 +489,8 @@ source_set("memory_buffer_sources") { ...@@ -489,6 +489,8 @@ source_set("memory_buffer_sources") {
"gfx_export.h", "gfx_export.h",
"mac/io_surface.cc", "mac/io_surface.cc",
"mac/io_surface.h", "mac/io_surface.h",
"native_pixmap_handle.cc",
"native_pixmap_handle.h",
] ]
if (!is_ios) { if (!is_ios) {
...@@ -498,13 +500,6 @@ source_set("memory_buffer_sources") { ...@@ -498,13 +500,6 @@ source_set("memory_buffer_sources") {
] ]
} }
if (use_ozone) {
sources += [
"native_pixmap_handle_ozone.cc",
"native_pixmap_handle_ozone.h",
]
}
defines = [ "GFX_IMPLEMENTATION" ] defines = [ "GFX_IMPLEMENTATION" ]
deps = [ deps = [
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#elif defined(OS_MACOSX) && !defined(OS_IOS) #elif defined(OS_MACOSX) && !defined(OS_IOS)
#include "ui/gfx/mac/io_surface.h" #include "ui/gfx/mac/io_surface.h"
#endif #endif
......
...@@ -8,15 +8,15 @@ ...@@ -8,15 +8,15 @@
#ifndef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ #ifndef UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_
#define UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_ #define UI_GFX_IPC_GFX_PARAM_TRAITS_MACROS_H_
#include "ipc/ipc_message_macros.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
#include "ui/gfx/gpu_memory_buffer.h" #include "ui/gfx/gpu_memory_buffer.h"
#include "ui/gfx/ipc/gfx_ipc_export.h" #include "ui/gfx/ipc/gfx_ipc_export.h"
#include "ui/gfx/selection_bound.h" #include "ui/gfx/selection_bound.h"
#include "ui/gfx/swap_result.h" #include "ui/gfx/swap_result.h"
#include "ipc/ipc_message_macros.h"
#if defined(USE_OZONE) #if defined(USE_OZONE)
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#endif #endif
#undef IPC_MESSAGE_EXPORT #undef IPC_MESSAGE_EXPORT
......
...@@ -49,3 +49,29 @@ enum GpuMemoryBufferType { ...@@ -49,3 +49,29 @@ enum GpuMemoryBufferType {
struct GpuMemoryBufferId { struct GpuMemoryBufferId {
int32 id; int32 id;
}; };
// gfx::NativePixmapPlane
struct NativePixmapPlane {
uint32 stride;
int32 offset;
uint64 modifier;
};
// gfx::NativePixmapHandle
struct NativePixmapHandle {
// A file descriptor for the underlying memory object (usually dmabuf).
array<handle> fds;
array<NativePixmapPlane> planes;
};
// gfx::GpuMemoryBufferHandle
struct GpuMemoryBufferHandle {
GpuMemoryBufferType type;
GpuMemoryBufferId id;
handle shared_memory_handle;
uint32 offset;
uint32 stride;
NativePixmapHandle? native_pixmap_handle;
// TODO: Add support for mach_port on mac.
};
...@@ -6,14 +6,21 @@ mojom = "//ui/gfx/mojo/buffer_types.mojom" ...@@ -6,14 +6,21 @@ mojom = "//ui/gfx/mojo/buffer_types.mojom"
public_headers = [ public_headers = [
"//ui/gfx/buffer_types.h", "//ui/gfx/buffer_types.h",
"//ui/gfx/gpu_memory_buffer.h", "//ui/gfx/gpu_memory_buffer.h",
"//ui/gfx/native_pixmap_handle.h",
] ]
traits_headers = [ "//ui/gfx/mojo/buffer_types_traits.h" ] traits_headers = [ "//ui/gfx/mojo/buffer_types_traits.h" ]
sources = [
"//ui/gfx/mojo/buffer_types_traits.cc",
]
public_deps = [ public_deps = [
"//ui/gfx", "//ui/gfx",
] ]
type_mappings = [ type_mappings = [
"gfx.mojom.BufferFormat=gfx::BufferFormat", "gfx.mojom.BufferFormat=gfx::BufferFormat",
"gfx.mojom.BufferUsage=gfx::BufferUsage", "gfx.mojom.BufferUsage=gfx::BufferUsage",
"gfx.mojom.GpuMemoryBufferHandle=gfx::GpuMemoryBufferHandle",
"gfx.mojom.GpuMemoryBufferId=gfx::GpuMemoryBufferId[copyable_pass_by_value]", "gfx.mojom.GpuMemoryBufferId=gfx::GpuMemoryBufferId[copyable_pass_by_value]",
"gfx.mojom.GpuMemoryBufferType=gfx::GpuMemoryBufferType", "gfx.mojom.GpuMemoryBufferType=gfx::GpuMemoryBufferType",
"gfx.mojom.NativePixmapHandle=gfx::NativePixmapHandle",
"gfx.mojom.NativePixmapPlane=gfx::NativePixmapPlane",
] ]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/mojo/buffer_types_traits.h"
#include "mojo/public/cpp/system/platform_handle.h"
namespace mojo {
std::vector<mojo::ScopedHandle>
StructTraits<gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle>::fds(const gfx::NativePixmapHandle&
pixmap_handle) {
std::vector<mojo::ScopedHandle> handles;
#if defined(USE_OZONE)
for (const base::FileDescriptor& fd : pixmap_handle.fds) {
base::PlatformFile platform_file = fd.fd;
handles.push_back(mojo::WrapPlatformFile(platform_file));
}
#endif // defined(USE_OZONE)
return handles;
}
bool StructTraits<
gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle>::Read(gfx::mojom::NativePixmapHandleDataView data,
gfx::NativePixmapHandle* out) {
#if defined(USE_OZONE)
mojo::ArrayDataView<mojo::ScopedHandle> handles_data_view;
data.GetFdsDataView(&handles_data_view);
for (size_t i = 0; i < handles_data_view.size(); ++i) {
mojo::ScopedHandle handle = handles_data_view.Take(i);
out->fds.push_back(base::FileDescriptor(handle.release().value(), true));
}
return data.ReadPlanes(&out->planes);
#else
return false;
#endif
}
mojo::ScopedHandle StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
gfx::GpuMemoryBufferHandle>::
shared_memory_handle(const gfx::GpuMemoryBufferHandle& handle) {
base::PlatformFile platform_file = base::kInvalidPlatformFile;
#if defined(OS_WIN)
platform_file = handle.handle.GetHandle();
#elif defined(OS_MACOSX) || defined(OS_IOS)
NOTIMPLEMENTED();
#else
DCHECK(handle.handle.auto_close || handle.handle.fd == -1);
platform_file = handle.handle.fd;
#endif
return mojo::WrapPlatformFile(platform_file);
}
const gfx::NativePixmapHandle&
StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
gfx::GpuMemoryBufferHandle>::
native_pixmap_handle(const gfx::GpuMemoryBufferHandle& handle) {
#if defined(USE_OZONE)
return handle.native_pixmap_handle;
#else
static gfx::NativePixmapHandle pixmap_handle;
return pixmap_handle;
#endif
}
bool StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
gfx::GpuMemoryBufferHandle>::
Read(gfx::mojom::GpuMemoryBufferHandleDataView data,
gfx::GpuMemoryBufferHandle* out) {
if (!data.ReadType(&out->type) || !data.ReadId(&out->id))
return false;
base::PlatformFile platform_file;
MojoResult unwrap_result = mojo::UnwrapPlatformFile(
data.TakeSharedMemoryHandle(), &platform_file);
if (unwrap_result != MOJO_RESULT_OK)
return false;
#if defined(OS_WIN)
out->handle =
base::SharedMemoryHandle(platform_file, base::GetCurrentProcId());
#elif defined(OS_MACOSX) || defined(OS_IOS)
// TODO: Add support for mach_port on mac.
out->handle = base::SharedMemoryHandle();
#else
out->handle = base::SharedMemoryHandle(platform_file, true);
#endif
out->offset = data.offset();
out->stride = data.stride();
#if defined(USE_OZONE)
if (!data.ReadNativePixmapHandle(&out->native_pixmap_handle))
return false;
#endif
return true;
}
} // namespace mojo
...@@ -195,6 +195,74 @@ struct StructTraits<gfx::mojom::GpuMemoryBufferIdDataView, ...@@ -195,6 +195,74 @@ struct StructTraits<gfx::mojom::GpuMemoryBufferIdDataView,
} }
}; };
template <>
struct StructTraits<gfx::mojom::NativePixmapPlaneDataView,
gfx::NativePixmapPlane> {
static uint32_t stride(const gfx::NativePixmapPlane& plane) {
return plane.stride;
}
static int32_t offset(const gfx::NativePixmapPlane& plane) {
return plane.offset;
}
static uint64_t modifier(const gfx::NativePixmapPlane& plane) {
return plane.modifier;
}
static bool Read(gfx::mojom::NativePixmapPlaneDataView data,
gfx::NativePixmapPlane* out) {
out->stride = data.stride();
out->offset = data.offset();
out->modifier = data.modifier();
return true;
}
};
template <>
struct StructTraits<gfx::mojom::NativePixmapHandleDataView,
gfx::NativePixmapHandle> {
static bool IsNull(const gfx::NativePixmapHandle& handle) {
#if defined(USE_OZONE)
return false;
#else
// NativePixmapHandle are not used on non-ozone platforms.
return true;
#endif
}
static std::vector<mojo::ScopedHandle> fds(
const gfx::NativePixmapHandle& pixmap_handle);
static const std::vector<gfx::NativePixmapPlane>& planes(
const gfx::NativePixmapHandle& pixmap_handle) {
return pixmap_handle.planes;
}
static bool Read(gfx::mojom::NativePixmapHandleDataView data,
gfx::NativePixmapHandle* out);
};
template <>
struct StructTraits<gfx::mojom::GpuMemoryBufferHandleDataView,
gfx::GpuMemoryBufferHandle> {
static gfx::GpuMemoryBufferType type(
const gfx::GpuMemoryBufferHandle& handle) {
return handle.type;
}
static gfx::GpuMemoryBufferId id(const gfx::GpuMemoryBufferHandle& handle) {
return handle.id;
}
static mojo::ScopedHandle shared_memory_handle(
const gfx::GpuMemoryBufferHandle& handle);
static uint32_t offset(const gfx::GpuMemoryBufferHandle& handle) {
return handle.offset;
}
static uint32_t stride(const gfx::GpuMemoryBufferHandle& handle) {
return handle.stride;
}
static const gfx::NativePixmapHandle& native_pixmap_handle(
const gfx::GpuMemoryBufferHandle& handle);
static bool Read(gfx::mojom::GpuMemoryBufferHandleDataView data,
gfx::GpuMemoryBufferHandle* handle);
};
} // namespace mojo } // namespace mojo
#endif // UI_GFX_MOJO_BUFFER_TYPES_TRAITS_H_ #endif // UI_GFX_MOJO_BUFFER_TYPES_TRAITS_H_
...@@ -49,6 +49,12 @@ class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { ...@@ -49,6 +49,12 @@ class StructTraitsTest : public testing::Test, public mojom::TraitsTestService {
callback.Run(t); callback.Run(t);
} }
void EchoGpuMemoryBufferHandle(
const GpuMemoryBufferHandle& handle,
const EchoGpuMemoryBufferHandleCallback& callback) override {
callback.Run(handle);
}
base::MessageLoop loop_; base::MessageLoop loop_;
mojo::BindingSet<TraitsTestService> traits_test_bindings_; mojo::BindingSet<TraitsTestService> traits_test_bindings_;
...@@ -134,4 +140,33 @@ TEST_F(StructTraitsTest, MAYBE_AcceleratedWidget) { ...@@ -134,4 +140,33 @@ TEST_F(StructTraitsTest, MAYBE_AcceleratedWidget) {
EXPECT_EQ(input, output); EXPECT_EQ(input, output);
} }
TEST_F(StructTraitsTest, GpuMemoryBufferHandle) {
const gfx::GpuMemoryBufferId kId(99);
const uint32_t kOffset = 126;
const int32_t kStride = 256;
base::SharedMemory shared_memory;
ASSERT_TRUE(shared_memory.CreateAnonymous(1024));
ASSERT_TRUE(shared_memory.Map(1024));
gfx::GpuMemoryBufferHandle handle;
handle.type = gfx::SHARED_MEMORY_BUFFER;
handle.id = kId;
handle.handle = base::SharedMemory::DuplicateHandle(shared_memory.handle());
handle.offset = kOffset;
handle.stride = kStride;
mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
gfx::GpuMemoryBufferHandle output;
proxy->EchoGpuMemoryBufferHandle(handle, &output);
EXPECT_EQ(gfx::SHARED_MEMORY_BUFFER, output.type);
EXPECT_EQ(kId, output.id);
EXPECT_EQ(kOffset, output.offset);
EXPECT_EQ(kStride, output.stride);
#if !defined(OS_MACOSX) && !defined(OS_IOS)
// TODO: Add support for mach_port on mac.
base::SharedMemory output_memory(output.handle, true);
EXPECT_TRUE(output_memory.Map(1024));
#endif
}
} // namespace gfx } // namespace gfx
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
module gfx.mojom; module gfx.mojom;
import "ui/gfx/mojo/accelerated_widget.mojom"; import "ui/gfx/mojo/accelerated_widget.mojom";
import "ui/gfx/mojo/buffer_types.mojom";
import "ui/gfx/mojo/selection_bound.mojom"; import "ui/gfx/mojo/selection_bound.mojom";
import "ui/gfx/mojo/transform.mojom"; import "ui/gfx/mojo/transform.mojom";
...@@ -19,4 +20,8 @@ interface TraitsTestService { ...@@ -19,4 +20,8 @@ interface TraitsTestService {
[Sync] [Sync]
EchoTransform(Transform t) => (Transform pass); EchoTransform(Transform t) => (Transform pass);
[Sync]
EchoGpuMemoryBufferHandle(GpuMemoryBufferHandle g)
=> (GpuMemoryBufferHandle pass);
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
namespace gfx { namespace gfx {
......
...@@ -2,15 +2,18 @@ ...@@ -2,15 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef UI_GFX_NATIVE_PIXMAP_HANDLE_OZONE_H_ #ifndef UI_GFX_NATIVE_PIXMAP_HANDLE_H_
#define UI_GFX_NATIVE_PIXMAP_HANDLE_OZONE_H_ #define UI_GFX_NATIVE_PIXMAP_HANDLE_H_
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include "base/file_descriptor_posix.h"
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
#if defined(USE_OZONE)
#include "base/file_descriptor_posix.h"
#endif
namespace gfx { namespace gfx {
// NativePixmapPlane is used to carry the plane related information for GBM // NativePixmapPlane is used to carry the plane related information for GBM
...@@ -36,12 +39,14 @@ struct GFX_EXPORT NativePixmapHandle { ...@@ -36,12 +39,14 @@ struct GFX_EXPORT NativePixmapHandle {
NativePixmapHandle(const NativePixmapHandle& other); NativePixmapHandle(const NativePixmapHandle& other);
~NativePixmapHandle(); ~NativePixmapHandle();
#if defined(USE_OZONE)
// File descriptors for the underlying memory objects (usually dmabufs). // File descriptors for the underlying memory objects (usually dmabufs).
std::vector<base::FileDescriptor> fds; std::vector<base::FileDescriptor> fds;
#endif
std::vector<NativePixmapPlane> planes; std::vector<NativePixmapPlane> planes;
}; };
} // namespace gfx } // namespace gfx
#endif // UI_GFX_NATIVE_PIXMAP_HANDLE_OZONE_H_ #endif // UI_GFX_NATIVE_PIXMAP_HANDLE_H_
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h" #include "ui/ozone/platform/drm/common/client_native_pixmap_dmabuf.h"
#include "ui/ozone/public/client_native_pixmap_factory.h" #include "ui/ozone/public/client_native_pixmap_factory.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "services/shell/public/cpp/connection.h" #include "services/shell/public/cpp/connection.h"
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/vsync_provider.h" #include "ui/gfx/vsync_provider.h"
#include "ui/ozone/common/gpu/ozone_gpu_message_params.h" #include "ui/ozone/common/gpu/ozone_gpu_message_params.h"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/geometry/size_conversions.h" #include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#include "ui/ozone/platform/drm/common/drm_util.h" #include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_window.h" #include "ui/ozone/platform/drm/gpu/drm_window.h"
#include "ui/ozone/platform/drm/gpu/gbm_device.h" #include "ui/ozone/platform/drm/gpu/gbm_device.h"
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "ui/gfx/native_pixmap_handle_ozone.h" #include "ui/gfx/native_pixmap_handle.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/overlay_transform.h" #include "ui/gfx/overlay_transform.h"
......
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