Commit 763bd590 authored by sadrul's avatar sadrul Committed by Commit bot

services/ui: Add mojom API for creating/destroying gpu memory buffer.

Add struct-traits for gpu::SurfaceHandle, and use that to provide mojom API
for creating/destroying gpu memory buffer. This allows removing the direct
dependency of gpu code from ws code (which is a pre-requisite for the gpu
process split).

BUG=637923
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2360203003
Cr-Commit-Position: refs/heads/master@{#421201}
parent 3a042526
...@@ -29,6 +29,7 @@ component("display_compositor") { ...@@ -29,6 +29,7 @@ component("display_compositor") {
"//gpu/command_buffer/client", "//gpu/command_buffer/client",
"//gpu/command_buffer/client:gles2_interface", "//gpu/command_buffer/client:gles2_interface",
"//gpu/command_buffer/common", "//gpu/command_buffer/common",
"//gpu/ipc/common:surface_handle_type",
"//skia", "//skia",
"//ui/display/types", "//ui/display/types",
"//ui/gfx", "//ui/gfx",
......
...@@ -66,6 +66,7 @@ source_set("client_sources") { ...@@ -66,6 +66,7 @@ source_set("client_sources") {
] ]
deps = [ deps = [
"//gpu/command_buffer/common:common_sources", "//gpu/command_buffer/common:common_sources",
"//gpu/ipc/common:surface_handle_type",
"//ui/gfx:memory_buffer", "//ui/gfx:memory_buffer",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
......
...@@ -165,6 +165,7 @@ target(link_target_type, "service_sources") { ...@@ -165,6 +165,7 @@ target(link_target_type, "service_sources") {
"//gpu/command_buffer/client:client_sources", "//gpu/command_buffer/client:client_sources",
"//gpu/command_buffer/common:gles2_utils", "//gpu/command_buffer/common:gles2_utils",
"//gpu/config:config_sources", "//gpu/config:config_sources",
"//gpu/ipc/common:surface_handle_type",
"//third_party/angle:angle_image_util", "//third_party/angle:angle_image_util",
"//third_party/angle:commit_id", "//third_party/angle:commit_id",
"//third_party/angle:translator", "//third_party/angle:translator",
......
...@@ -87,6 +87,7 @@ source_set("ipc_common_sources") { ...@@ -87,6 +87,7 @@ source_set("ipc_common_sources") {
public_deps = [ public_deps = [
":command_buffer_traits_sources", ":command_buffer_traits_sources",
":surface_handle_type",
"//gpu/command_buffer/common:gles2_utils", "//gpu/command_buffer/common:gles2_utils",
] ]
...@@ -119,6 +120,17 @@ source_set("ipc_common_sources") { ...@@ -119,6 +120,17 @@ source_set("ipc_common_sources") {
} }
} }
# Depend on this to use surface_handle.h without pulling in all of gpu ipc.
source_set("surface_handle_type") {
public = [
"surface_handle.h",
]
public_deps = [
"//ui/gfx:native_widget_types",
]
}
mojom("interfaces") { mojom("interfaces") {
sources = [ sources = [
"capabilities.mojom", "capabilities.mojom",
...@@ -126,6 +138,7 @@ mojom("interfaces") { ...@@ -126,6 +138,7 @@ mojom("interfaces") {
"gpu_info.mojom", "gpu_info.mojom",
"mailbox.mojom", "mailbox.mojom",
"mailbox_holder.mojom", "mailbox_holder.mojom",
"surface_handle.mojom",
"sync_token.mojom", "sync_token.mojom",
] ]
...@@ -150,10 +163,12 @@ source_set("struct_traits") { ...@@ -150,10 +163,12 @@ source_set("struct_traits") {
sources = [ sources = [
"mailbox_holder_struct_traits.h", "mailbox_holder_struct_traits.h",
"mailbox_struct_traits.h", "mailbox_struct_traits.h",
"surface_handle_struct_traits.h",
"sync_token_struct_traits.h", "sync_token_struct_traits.h",
] ]
deps = [ deps = [
":interfaces_shared_cpp_sources", ":interfaces_shared_cpp_sources",
":surface_handle_type",
"//gpu/command_buffer/common", "//gpu/command_buffer/common",
"//mojo/public/cpp/bindings:bindings", "//mojo/public/cpp/bindings:bindings",
] ]
......
// 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.
module gpu.mojom;
// See gpu/ipc/common/surface_handle.h
struct SurfaceHandle {
uint64 surface_handle;
};
# 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.
mojom = "//gpu/ipc/common/surface_handle.mojom"
public_headers = [ "//gpu/ipc/common/surface_handle.h" ]
traits_headers = [ "//gpu/ipc/common/surface_handle_struct_traits.h" ]
public_deps = [
"//ui/gfx:native_widget_types",
]
type_mappings =
[ "gpu.mojom.SurfaceHandle=::gpu::SurfaceHandle[copyable_pass_by_value]" ]
// 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 GPU_IPC_COMMON_SURFACE_HANDLE_STRUCT_TRAITS_H_
#define GPU_IPC_COMMON_SURFACE_HANDLE_STRUCT_TRAITS_H_
#include "gpu/ipc/common/surface_handle.h"
#include "gpu/ipc/common/surface_handle.mojom-shared.h"
namespace mojo {
template <>
struct StructTraits<gpu::mojom::SurfaceHandleDataView, gpu::SurfaceHandle> {
static uint64_t surface_handle(const gpu::SurfaceHandle& handle) {
#if defined(OS_WIN)
return reinterpret_cast<uint64_t>(handle);
#else
return static_cast<uint64_t>(handle);
#endif
}
static bool Read(gpu::mojom::SurfaceHandleDataView data,
gpu::SurfaceHandle* out) {
uint64_t handle = data.surface_handle();
#if defined(OS_WIN)
*out = reinterpret_cast<gpu::SurfaceHandle>(handle);
#else
*out = static_cast<gpu::SurfaceHandle>(handle);
#endif
return true;
}
};
} // namespace mojo
#endif // GPU_IPC_COMMON_SURFACE_HANDLE_STRUCT_TRAITS_H_
...@@ -8,5 +8,6 @@ typemaps = [ ...@@ -8,5 +8,6 @@ typemaps = [
"//gpu/ipc/common/dx_diag_node.typemap", "//gpu/ipc/common/dx_diag_node.typemap",
"//gpu/ipc/common/mailbox.typemap", "//gpu/ipc/common/mailbox.typemap",
"//gpu/ipc/common/mailbox_holder.typemap", "//gpu/ipc/common/mailbox_holder.typemap",
"//gpu/ipc/common/surface_handle.typemap",
"//gpu/ipc/common/sync_token.typemap", "//gpu/ipc/common/sync_token.typemap",
] ]
...@@ -61,16 +61,17 @@ void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) { ...@@ -61,16 +61,17 @@ void GpuServiceInternal::Add(mojom::GpuServiceInternalRequest request) {
binding_.Bind(std::move(request)); binding_.Bind(std::move(request));
} }
gfx::GpuMemoryBufferHandle GpuServiceInternal::CreateGpuMemoryBuffer( void GpuServiceInternal::CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id, gfx::GpuMemoryBufferId id,
const gfx::Size& size, const gfx::Size& size,
gfx::BufferFormat format, gfx::BufferFormat format,
gfx::BufferUsage usage, gfx::BufferUsage usage,
int client_id, int client_id,
gpu::SurfaceHandle surface_handle) { gpu::SurfaceHandle surface_handle,
const CreateGpuMemoryBufferCallback& callback) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
return gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
id, size, format, usage, client_id, surface_handle); id, size, format, usage, client_id, surface_handle));
} }
void GpuServiceInternal::DestroyGpuMemoryBuffer( void GpuServiceInternal::DestroyGpuMemoryBuffer(
......
...@@ -47,18 +47,6 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate, ...@@ -47,18 +47,6 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate,
void Add(mojom::GpuServiceInternalRequest request); void Add(mojom::GpuServiceInternalRequest request);
// TODO(sad): These should be mojom API.
gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int client_id,
gpu::SurfaceHandle surface_handle);
void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
int client_id,
const gpu::SyncToken& sync_token);
private: private:
friend class GpuMain; friend class GpuMain;
...@@ -98,6 +86,17 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate, ...@@ -98,6 +86,17 @@ class GpuServiceInternal : public gpu::GpuChannelManagerDelegate,
uint64_t client_tracing_id, uint64_t client_tracing_id,
bool is_gpu_host, bool is_gpu_host,
const EstablishGpuChannelCallback& callback) override; const EstablishGpuChannelCallback& callback) override;
void CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int client_id,
gpu::SurfaceHandle surface_handle,
const CreateGpuMemoryBufferCallback& callback) override;
void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
int client_id,
const gpu::SyncToken& sync_token) override;
scoped_refptr<base::SingleThreadTaskRunner> io_runner_; scoped_refptr<base::SingleThreadTaskRunner> io_runner_;
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
module ui.mojom; module ui.mojom;
import "gpu/ipc/common/gpu_info.mojom"; import "gpu/ipc/common/gpu_info.mojom";
import "gpu/ipc/common/surface_handle.mojom";
import "gpu/ipc/common/sync_token.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom"; import "ui/gfx/geometry/mojo/geometry.mojom";
import "ui/gfx/mojo/buffer_types.mojom"; import "ui/gfx/mojo/buffer_types.mojom";
...@@ -17,4 +19,17 @@ interface GpuServiceInternal { ...@@ -17,4 +19,17 @@ interface GpuServiceInternal {
uint64 client_tracing_id, uint64 client_tracing_id,
bool is_gpu_host) bool is_gpu_host)
=> (handle<message_pipe> channel_handle); => (handle<message_pipe> channel_handle);
[Sync]
CreateGpuMemoryBuffer(gfx.mojom.GpuMemoryBufferId id,
gfx.mojom.Size size,
gfx.mojom.BufferFormat format,
gfx.mojom.BufferUsage usage,
int32 client_id,
gpu.mojom.SurfaceHandle surface_handle)
=> (gfx.mojom.GpuMemoryBufferHandle buffer_handle);
DestroyGpuMemoryBuffer(gfx.mojom.GpuMemoryBufferId id,
int32 client_id,
gpu.mojom.SyncToken sync_token);
}; };
...@@ -10,8 +10,4 @@ specific_include_rules = { ...@@ -10,8 +10,4 @@ specific_include_rules = {
"gpu_service_proxy.h": [ "gpu_service_proxy.h": [
"+services/ui/gpu/gpu_main.h", "+services/ui/gpu/gpu_main.h",
], ],
# This should be removed. crbug.com/637923
"mus_gpu_memory_buffer_manager.cc": [
"+services/ui/gpu/gpu_service_internal.h",
]
} }
...@@ -65,7 +65,7 @@ void GpuServiceProxy::OnInternalGpuChannelEstablished( ...@@ -65,7 +65,7 @@ void GpuServiceProxy::OnInternalGpuChannelEstablished(
CHECK(io_thread_->StartWithOptions(thread_options)); CHECK(io_thread_->StartWithOptions(thread_options));
gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>( gpu_memory_buffer_manager_ = base::MakeUnique<MusGpuMemoryBufferManager>(
gpu_main_.gpu_service(), kInternalGpuChannelClientId); gpu_service_.get(), kInternalGpuChannelClientId);
gpu_channel_ = gpu::GpuChannelHost::Create( gpu_channel_ = gpu::GpuChannelHost::Create(
this, kInternalGpuChannelClientId, gpu_info_, this, kInternalGpuChannelClientId, gpu_info_,
IPC::ChannelHandle(channel_handle.release()), &shutdown_event_, IPC::ChannelHandle(channel_handle.release()), &shutdown_event_,
......
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
#include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h" #include "gpu/ipc/common/gpu_memory_buffer_support.h"
#include "services/ui/common/generic_shared_memory_id_generator.h" #include "services/ui/common/generic_shared_memory_id_generator.h"
#include "services/ui/gpu/gpu_service_internal.h" #include "services/ui/gpu/interfaces/gpu_service_internal.mojom.h"
namespace ui { namespace ui {
namespace ws { namespace ws {
MusGpuMemoryBufferManager::MusGpuMemoryBufferManager( MusGpuMemoryBufferManager::MusGpuMemoryBufferManager(
GpuServiceInternal* gpu_service, mojom::GpuServiceInternal* gpu_service,
int client_id) int client_id)
: gpu_service_(gpu_service), client_id_(client_id), weak_factory_(this) {} : gpu_service_(gpu_service), client_id_(client_id), weak_factory_(this) {}
...@@ -32,8 +32,9 @@ MusGpuMemoryBufferManager::AllocateGpuMemoryBuffer( ...@@ -32,8 +32,9 @@ MusGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
const bool is_native = const bool is_native =
gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage); gpu::IsNativeGpuMemoryBufferConfigurationSupported(format, usage);
if (is_native) { if (is_native) {
gfx::GpuMemoryBufferHandle handle = gpu_service_->CreateGpuMemoryBuffer( gfx::GpuMemoryBufferHandle handle;
id, size, format, usage, client_id_, surface_handle); gpu_service_->CreateGpuMemoryBuffer(id, size, format, usage, client_id_,
surface_handle, &handle);
if (handle.is_null()) if (handle.is_null())
return nullptr; return nullptr;
return gpu::GpuMemoryBufferImpl::CreateFromHandle( return gpu::GpuMemoryBufferImpl::CreateFromHandle(
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
namespace ui { namespace ui {
namespace mojom {
class GpuServiceInternal; class GpuServiceInternal;
}
namespace ws { namespace ws {
...@@ -21,7 +23,8 @@ namespace ws { ...@@ -21,7 +23,8 @@ namespace ws {
// mus locally. // mus locally.
class MusGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager { class MusGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager {
public: public:
MusGpuMemoryBufferManager(GpuServiceInternal* gpu_service, int client_id); MusGpuMemoryBufferManager(mojom::GpuServiceInternal* gpu_service,
int client_id);
~MusGpuMemoryBufferManager() override; ~MusGpuMemoryBufferManager() override;
// Overridden from gpu::GpuMemoryBufferManager: // Overridden from gpu::GpuMemoryBufferManager:
...@@ -47,7 +50,7 @@ class MusGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager { ...@@ -47,7 +50,7 @@ class MusGpuMemoryBufferManager : public gpu::GpuMemoryBufferManager {
bool is_native, bool is_native,
const gpu::SyncToken& sync_token); const gpu::SyncToken& sync_token);
GpuServiceInternal* gpu_service_; mojom::GpuServiceInternal* gpu_service_;
const int client_id_; const int client_id_;
base::WeakPtrFactory<MusGpuMemoryBufferManager> weak_factory_; base::WeakPtrFactory<MusGpuMemoryBufferManager> weak_factory_;
}; };
......
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