Commit 8b9d29e9 authored by Mohsen Izadi's avatar Mohsen Izadi Committed by Commit Bot

Use HostGpuMemoryBufferManager in content

This change replaces usage of content::BrowserGpuMemoryBufferManager
with viz::HostGpuMemoryBufferManager.

With this change BrowserGpuMemoryBufferManager is not needed anymore and
code to handle buffer allocation in GpuProcessHost is also removed.

BUG=733482

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: I6a9387e2e33a5d98d4ed7559618f4995256bafa4
Reviewed-on: https://chromium-review.googlesource.com/1095815
Commit-Queue: Mohsen Izadi <mohsen@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584455}
parent 5f2d6d0e
......@@ -38,7 +38,6 @@ class Predictor;
}
namespace content {
class BrowserGpuChannelHostFactory;
class BrowserGpuMemoryBufferManager;
class BrowserMainLoop;
class BrowserProcessSubThread;
class BrowserShutdownProfileDumper;
......@@ -331,7 +330,6 @@ class BASE_EXPORT ScopedAllowBaseSyncPrimitives {
LaunchXdgUtilityScopedAllowBaseSyncPrimitives;
friend class webrtc::DesktopConfigurationMonitor;
friend class content::ServiceWorkerSubresourceLoader;
friend class viz::HostGpuMemoryBufferManager;
ScopedAllowBaseSyncPrimitives() EMPTY_BODY_IF_DCHECK_IS_OFF;
~ScopedAllowBaseSyncPrimitives() EMPTY_BODY_IF_DCHECK_IS_OFF;
......@@ -361,6 +359,7 @@ class BASE_EXPORT ScopedAllowBaseSyncPrimitivesOutsideBlockingScope {
friend class midi::TaskService; // https://crbug.com/796830
// Not used in production yet, https://crbug.com/844078.
friend class service_manager::ServiceProcessLauncher;
friend class viz::HostGpuMemoryBufferManager;
ScopedAllowBaseSyncPrimitivesOutsideBlockingScope()
EMPTY_BODY_IF_DCHECK_IS_OFF;
......@@ -488,8 +487,6 @@ class BASE_EXPORT ThreadRestrictions {
friend class chrome_browser_net::Predictor; // http://crbug.com/78451
friend class
content::BrowserGpuChannelHostFactory; // http://crbug.com/125248
friend class
content::BrowserGpuMemoryBufferManager; // http://crbug.com/420368
friend class content::TextInputClientMac; // http://crbug.com/121917
friend class dbus::Bus; // http://crbug.com/125222
friend class disk_cache::BackendImpl; // http://crbug.com/74623
......
......@@ -50,10 +50,15 @@ HostGpuMemoryBufferManager::HostGpuMemoryBufferManager(
native_configurations_(gpu::GetNativeGpuMemoryBufferConfigurations(
gpu_memory_buffer_support_.get())),
task_runner_(std::move(task_runner)),
weak_factory_(this) {}
weak_factory_(this) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "HostGpuMemoryBufferManager", task_runner_);
}
HostGpuMemoryBufferManager::~HostGpuMemoryBufferManager() {
DCHECK(task_runner_->BelongsToCurrentThread());
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
this);
}
void HostGpuMemoryBufferManager::DestroyGpuMemoryBuffer(
......@@ -115,10 +120,8 @@ void HostGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
if (!weak_ptr_)
weak_ptr_ = weak_factory_.GetWeakPtr();
if (gpu_memory_buffer_support_->GetNativeGpuMemoryBufferType() !=
gfx::EMPTY_BUFFER) {
const bool is_native = native_configurations_.find(std::make_pair(
format, usage)) != native_configurations_.end();
if (is_native) {
gfx::EMPTY_BUFFER &&
IsNativeGpuMemoryBufferConfiguration(format, usage)) {
if (auto* gpu_service = GetGpuService()) {
PendingBufferInfo buffer_info;
buffer_info.size = size;
......@@ -139,7 +142,6 @@ void HostGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
}
return;
}
}
gfx::GpuMemoryBufferHandle buffer_handle;
// The requests are coming in from untrusted clients. So verify that it is
......@@ -163,6 +165,14 @@ void HostGpuMemoryBufferManager::AllocateGpuMemoryBuffer(
FROM_HERE, base::BindOnce(std::move(callback), std::move(buffer_handle)));
}
bool HostGpuMemoryBufferManager::IsNativeGpuMemoryBufferConfiguration(
gfx::BufferFormat format,
gfx::BufferUsage usage) const {
DCHECK(task_runner_->BelongsToCurrentThread());
return native_configurations_.find(std::make_pair(format, usage)) !=
native_configurations_.end();
}
std::unique_ptr<gfx::GpuMemoryBuffer>
HostGpuMemoryBufferManager::CreateGpuMemoryBuffer(
const gfx::Size& size,
......@@ -189,7 +199,8 @@ HostGpuMemoryBufferManager::CreateGpuMemoryBuffer(
base::Unretained(this), id, client_id_, size, format,
usage, surface_handle, std::move(reply_callback));
task_runner_->PostTask(FROM_HERE, std::move(allocate_callback));
base::ScopedAllowBaseSyncPrimitives allow_base_sync_primitives;
base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope
allow_base_sync_primitives;
wait_event.Wait();
if (handle.is_null())
return nullptr;
......
......@@ -67,6 +67,9 @@ class VIZ_HOST_EXPORT HostGpuMemoryBufferManager
gpu::SurfaceHandle surface_handle,
base::OnceCallback<void(gfx::GpuMemoryBufferHandle)> callback);
bool IsNativeGpuMemoryBufferConfiguration(gfx::BufferFormat format,
gfx::BufferUsage usage) const;
// Overridden from gpu::GpuMemoryBufferManager:
std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
const gfx::Size& size,
......
......@@ -876,8 +876,6 @@ jumbo_source_set("browser") {
"gpu/browser_gpu_channel_host_factory.h",
"gpu/browser_gpu_client_delegate.cc",
"gpu/browser_gpu_client_delegate.h",
"gpu/browser_gpu_memory_buffer_manager.cc",
"gpu/browser_gpu_memory_buffer_manager.h",
"gpu/compositor_util.cc",
"gpu/compositor_util.h",
"gpu/gpu_client_delegate.h",
......@@ -893,6 +891,8 @@ jumbo_source_set("browser") {
"gpu/gpu_internals_ui.h",
"gpu/gpu_main_thread_factory.cc",
"gpu/gpu_main_thread_factory.h",
"gpu/gpu_memory_buffer_manager_singleton.cc",
"gpu/gpu_memory_buffer_manager_singleton.h",
"gpu/gpu_process_host.cc",
"gpu/gpu_process_host.h",
"gpu/shader_cache_factory.cc",
......
......@@ -68,7 +68,7 @@
#include "content/browser/download/download_resource_handler.h"
#include "content/browser/download/save_file_manager.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/browser_gpu_client_delegate.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_process_host.h"
......@@ -1124,9 +1124,8 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
device_monitor_mac_.reset();
#endif
if (BrowserGpuChannelHostFactory::instance()) {
if (BrowserGpuChannelHostFactory::instance())
BrowserGpuChannelHostFactory::instance()->CloseChannel();
}
// Shutdown the Service Manager and IPC.
service_manager_context_.reset();
......
......@@ -11,7 +11,6 @@
#include "base/trace_event/memory_dump_manager.h"
#include "content/browser/browser_child_process_host_impl.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/notification_service_impl.h"
#include "content/browser/utility_process_host.h"
#include "content/common/child_process_host_impl.h"
......@@ -222,10 +221,6 @@ void BrowserProcessSubThread::IOThreadCleanUp() {
// and delete the BrowserChildProcessHost instances to release whatever
// IO thread only resources they are referencing.
BrowserChildProcessHostImpl::TerminateAll();
// Unregister GpuMemoryBuffer dump provider before IO thread is shut down.
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
BrowserGpuMemoryBufferManager::current());
}
} // namespace content
......@@ -17,8 +17,8 @@
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/viz/common/features.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/gpu/shader_cache_factory.h"
#include "content/common/child_process_host_impl.h"
......@@ -228,14 +228,6 @@ void BrowserGpuChannelHostFactory::EstablishRequest::Cancel() {
established_callbacks_.clear();
}
void BrowserGpuChannelHostFactory::CloseChannel() {
DCHECK(instance_);
if (instance_->gpu_channel_) {
instance_->gpu_channel_->DestroyChannel();
instance_->gpu_channel_ = nullptr;
}
}
void BrowserGpuChannelHostFactory::Initialize(bool establish_gpu_channel) {
DCHECK(!instance_);
instance_ = new BrowserGpuChannelHostFactory();
......@@ -250,13 +242,20 @@ void BrowserGpuChannelHostFactory::Terminate() {
instance_ = nullptr;
}
void BrowserGpuChannelHostFactory::CloseChannel() {
if (gpu_channel_) {
gpu_channel_->DestroyChannel();
gpu_channel_ = nullptr;
}
gpu_memory_buffer_manager_ = nullptr;
}
BrowserGpuChannelHostFactory::BrowserGpuChannelHostFactory()
: gpu_client_id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
gpu_client_tracing_id_(
memory_instrumentation::mojom::kServiceTracingProcessId),
gpu_memory_buffer_manager_(
new BrowserGpuMemoryBufferManager(gpu_client_id_,
gpu_client_tracing_id_)) {
new GpuMemoryBufferManagerSingleton(gpu_client_id_)) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableGpuShaderDiskCache)) {
DCHECK(GetContentClient());
......
......@@ -17,11 +17,15 @@
#include "base/single_thread_task_runner.h"
#include "build/build_config.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "ipc/message_filter.h"
namespace gpu {
class GpuMemoryBufferManager;
}
namespace content {
class BrowserGpuMemoryBufferManager;
class CONTENT_EXPORT BrowserGpuChannelHostFactory
: public gpu::GpuChannelEstablishFactory {
......@@ -62,7 +66,8 @@ class CONTENT_EXPORT BrowserGpuChannelHostFactory
const int gpu_client_id_;
const uint64_t gpu_client_tracing_id_;
scoped_refptr<gpu::GpuChannelHost> gpu_channel_;
std::unique_ptr<BrowserGpuMemoryBufferManager> gpu_memory_buffer_manager_;
std::unique_ptr<gpu::GpuMemoryBufferManager, BrowserThread::DeleteOnIOThread>
gpu_memory_buffer_manager_;
scoped_refptr<EstablishRequest> pending_request_;
base::OneShotTimer timeout_;
......
......@@ -4,6 +4,7 @@
#include "content/browser/gpu/browser_gpu_client_delegate.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_info.h"
......@@ -69,4 +70,9 @@ void BrowserGpuClientDelegate::EstablishGpuChannel(
base::BindOnce(&OnEstablishGpuChannel, std::move(callback)));
}
viz::HostGpuMemoryBufferManager*
BrowserGpuClientDelegate::GetGpuMemoryBufferManager() {
return GpuMemoryBufferManagerSingleton::GetInstance();
}
} // namespace content
......@@ -19,6 +19,7 @@ class BrowserGpuClientDelegate : public GpuClientDelegate {
void EstablishGpuChannel(int client_id,
uint64_t client_tracing_id,
EstablishGpuChannelCallback callback) override;
viz::HostGpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
private:
DISALLOW_COPY_AND_ASSIGN(BrowserGpuClientDelegate);
......
// Copyright 2014 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 CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
#define CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/callback.h"
#include "base/containers/hash_tables.h"
#include "base/hash.h"
#include "base/macros.h"
#include "base/trace_event/memory_dump_provider.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/common/content_export.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
#include "gpu/ipc/common/surface_handle.h"
#include "gpu/ipc/host/gpu_memory_buffer_support.h"
namespace gpu {
class GpuMemoryBufferSupport;
}
namespace content {
class CONTENT_EXPORT BrowserGpuMemoryBufferManager
: public gpu::GpuMemoryBufferManager,
public base::trace_event::MemoryDumpProvider {
public:
using CreateCallback =
base::OnceCallback<void(gfx::GpuMemoryBufferHandle handle)>;
using AllocationCallback = CreateCallback;
BrowserGpuMemoryBufferManager(int gpu_client_id,
uint64_t gpu_client_tracing_id);
~BrowserGpuMemoryBufferManager() override;
static BrowserGpuMemoryBufferManager* current();
// Overridden from gpu::GpuMemoryBufferManager:
std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
gpu::SurfaceHandle surface_handle) override;
void SetDestructionSyncToken(gfx::GpuMemoryBuffer* buffer,
const gpu::SyncToken& sync_token) override;
// Overridden from base::trace_event::MemoryDumpProvider:
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;
void AllocateGpuMemoryBufferForChildProcess(gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int child_client_id,
AllocationCallback callback);
void ChildProcessDeletedGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
int child_client_id,
const gpu::SyncToken& sync_token);
void ProcessRemoved(int client_id);
bool IsNativeGpuMemoryBufferConfiguration(gfx::BufferFormat format,
gfx::BufferUsage usage) const;
private:
struct BufferInfo {
BufferInfo(const gfx::Size& size,
gfx::GpuMemoryBufferType type,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int gpu_host_id);
BufferInfo(const BufferInfo& other);
~BufferInfo();
gfx::Size size;
gfx::GpuMemoryBufferType type = gfx::EMPTY_BUFFER;
gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888;
gfx::BufferUsage usage = gfx::BufferUsage::GPU_READ;
int gpu_host_id = 0;
base::UnguessableToken shared_memory_guid;
};
struct CreateGpuMemoryBufferRequest;
std::unique_ptr<gfx::GpuMemoryBuffer> AllocateGpuMemoryBufferForSurface(
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
gpu::SurfaceHandle surface_handle);
// Functions that handle synchronous buffer creation requests.
void HandleCreateGpuMemoryBufferOnIO(CreateGpuMemoryBufferRequest* request);
void HandleGpuMemoryBufferCreatedOnIO(CreateGpuMemoryBufferRequest* request,
gfx::GpuMemoryBufferHandle handle);
// Functions that implement asynchronous buffer creation.
void CreateGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
gpu::SurfaceHandle surface_handle,
int client_id,
CreateCallback callback);
void GpuMemoryBufferCreatedOnIO(gfx::GpuMemoryBufferId id,
gpu::SurfaceHandle surface_handle,
int client_id,
int gpu_host_id,
CreateCallback callback,
gfx::GpuMemoryBufferHandle handle,
GpuProcessHost::BufferCreationStatus status);
void DestroyGpuMemoryBufferOnIO(gfx::GpuMemoryBufferId id,
int client_id,
const gpu::SyncToken& sync_token);
uint64_t ClientIdToTracingProcessId(int client_id) const;
std::unique_ptr<gpu::GpuMemoryBufferSupport> gpu_memory_buffer_support_;
const gpu::GpuMemoryBufferConfigurationSet native_configurations_;
const int gpu_client_id_;
const uint64_t gpu_client_tracing_id_;
int next_gpu_memory_id_ = 1;
// Stores info about buffers for all clients. This should only be accessed
// on the IO thread.
using BufferMap = base::hash_map<gfx::GpuMemoryBufferId, BufferInfo>;
using ClientMap = base::hash_map<int, BufferMap>;
ClientMap clients_;
DISALLOW_COPY_AND_ASSIGN(BrowserGpuMemoryBufferManager);
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_BROWSER_GPU_MEMORY_BUFFER_MANAGER_H_
......@@ -17,6 +17,8 @@ namespace viz {
namespace mojom {
class GpuService;
}
class HostGpuMemoryBufferManager;
} // namespace viz
namespace content {
......@@ -53,6 +55,9 @@ class GpuClientDelegate {
virtual void EstablishGpuChannel(int client_id,
uint64_t client_tracing_id,
EstablishGpuChannelCallback callback) = 0;
// Returns the current viz::HostGpuMemoryBufferManager instance.
virtual viz::HostGpuMemoryBufferManager* GetGpuMemoryBufferManager() = 0;
};
} // namespace content
......
......@@ -4,8 +4,8 @@
#include "content/browser/gpu/gpu_client_impl.h"
#include "components/viz/host/host_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/browser_gpu_client_delegate.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/common/child_process_host_impl.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl.h"
......@@ -61,11 +61,11 @@ void GpuClientImpl::Add(ui::mojom::GpuRequest request) {
void GpuClientImpl::OnError(ErrorReason reason) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
ClearCallback();
if (gpu_bindings_.empty()) {
BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager =
BrowserGpuMemoryBufferManager::current();
if (gpu_memory_buffer_manager)
gpu_memory_buffer_manager->ProcessRemoved(client_id_);
if (gpu_bindings_.empty() && delegate_) {
if (auto* gpu_memory_buffer_manager =
delegate_->GetGpuMemoryBufferManager()) {
gpu_memory_buffer_manager->DestroyAllGpuMemoryBufferForClient(client_id_);
}
}
if (reason == ErrorReason::kConnectionLost && connection_error_handler_)
std::move(connection_error_handler_).Run(this);
......@@ -179,7 +179,8 @@ void GpuClientImpl::CreateGpuMemoryBuffer(
gfx::BufferFormat format,
gfx::BufferUsage usage,
ui::mojom::GpuMemoryBufferFactory::CreateGpuMemoryBufferCallback callback) {
DCHECK(BrowserGpuMemoryBufferManager::current());
auto* gpu_memory_buffer_manager = delegate_->GetGpuMemoryBufferManager();
DCHECK(gpu_memory_buffer_manager);
base::CheckedNumeric<int> bytes = size.width();
bytes *= size.height();
......@@ -188,19 +189,19 @@ void GpuClientImpl::CreateGpuMemoryBuffer(
return;
}
BrowserGpuMemoryBufferManager::current()
->AllocateGpuMemoryBufferForChildProcess(
id, size, format, usage, client_id_,
gpu_memory_buffer_manager->AllocateGpuMemoryBuffer(
id, client_id_, size, format, usage, gpu::kNullSurfaceHandle,
base::BindOnce(&GpuClientImpl::OnCreateGpuMemoryBuffer,
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void GpuClientImpl::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
const gpu::SyncToken& sync_token) {
DCHECK(BrowserGpuMemoryBufferManager::current());
BrowserGpuMemoryBufferManager::current()->ChildProcessDeletedGpuMemoryBuffer(
id, client_id_, sync_token);
if (auto* gpu_memory_buffer_manager =
delegate_->GetGpuMemoryBufferManager()) {
gpu_memory_buffer_manager->DestroyGpuMemoryBuffer(id, client_id_,
sync_token);
}
}
void GpuClientImpl::CreateGpuMemoryBufferFactory(
......
......@@ -23,7 +23,7 @@
#include "build/build_config.h"
#include "cc/base/switches.h"
#include "components/viz/common/features.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/gpu_data_manager_observer.h"
......@@ -584,11 +584,10 @@ void GpuDataManagerImplPrivate::UpdateGpuPreferences(
gpu::GpuPreferences* gpu_preferences) const {
DCHECK(gpu_preferences);
BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager =
BrowserGpuMemoryBufferManager::current();
// For performance reasons, discourage storing VideoFrames in a biplanar
// GpuMemoryBuffer if this is not native, see https://crbug.com/791676.
if (gpu_memory_buffer_manager) {
if (auto* gpu_memory_buffer_manager =
GpuMemoryBufferManagerSingleton::GetInstance()) {
gpu_preferences->disable_biplanar_gpu_memory_buffers_for_video_frames =
!gpu_memory_buffer_manager->IsNativeGpuMemoryBufferConfiguration(
gfx::BufferFormat::YUV_420_BIPLANAR,
......
// Copyright 2018 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 "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "base/bind.h"
#include "base/logging.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/browser_thread.h"
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
namespace content {
namespace {
GpuMemoryBufferManagerSingleton* g_gpu_memory_buffer_manager;
viz::mojom::GpuService* GetGpuService(
base::OnceClosure connection_error_handler) {
if (auto* host = GpuProcessHost::Get()) {
host->AddConnectionErrorHandler(std::move(connection_error_handler));
return host->gpu_service();
}
return nullptr;
}
} // namespace
GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id)
: HostGpuMemoryBufferManager(
base::BindRepeating(&content::GetGpuService),
client_id,
std::make_unique<gpu::GpuMemoryBufferSupport>(),
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)) {
DCHECK(!g_gpu_memory_buffer_manager);
g_gpu_memory_buffer_manager = this;
}
GpuMemoryBufferManagerSingleton::~GpuMemoryBufferManagerSingleton() {
DCHECK_EQ(this, g_gpu_memory_buffer_manager);
g_gpu_memory_buffer_manager = nullptr;
}
// static
GpuMemoryBufferManagerSingleton*
GpuMemoryBufferManagerSingleton::GetInstance() {
return g_gpu_memory_buffer_manager;
}
} // namespace content
// Copyright 2018 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 CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_H_
#define CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_H_
#include "components/viz/host/host_gpu_memory_buffer_manager.h"
namespace content {
// This class ensures that there is at most one instance of
// |viz::HostGpuMemoryBufferManager| in content at any given time. Code in
// content must use this class to access the instance.
class GpuMemoryBufferManagerSingleton : public viz::HostGpuMemoryBufferManager {
public:
explicit GpuMemoryBufferManagerSingleton(int client_id);
~GpuMemoryBufferManagerSingleton() override;
static GpuMemoryBufferManagerSingleton* GetInstance();
private:
DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferManagerSingleton);
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_GPU_MEMORY_BUFFER_MANAGER_SINGLETON_H_
......@@ -41,6 +41,7 @@
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_data_manager_impl.h"
#include "content/browser/gpu/gpu_main_thread_factory.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "content/browser/gpu/shader_cache_factory.h"
#include "content/browser/memory/memory_coordinator_impl.h"
#include "content/browser/service_manager/service_manager_context.h"
......@@ -734,7 +735,7 @@ GpuProcessHost::~GpuProcessHost() {
if (in_process_gpu_thread_)
DCHECK(process_);
SendOutstandingReplies();
OnConnectionError();
#if defined(OS_MACOSX)
if (ca_transaction_gpu_coordinator_) {
......@@ -940,6 +941,8 @@ bool GpuProcessHost::Init() {
mojo::MakeRequest(&gpu_service_ptr_), std::move(host_proxy),
std::move(discardable_manager_ptr), activity_flags_.CloneHandle(),
GetFontRenderParamsOnIO().params.subpixel_rendering);
gpu_service_ptr_.set_connection_error_handler(base::BindOnce(
&GpuProcessHost::OnConnectionError, weak_ptr_factory_.GetWeakPtr()));
#if defined(USE_OZONE)
InitOzone();
......@@ -959,14 +962,14 @@ bool GpuProcessHost::Send(IPC::Message* msg) {
return true;
}
bool result = process_->Send(msg);
if (!result) {
// Channel is hosed, but we may not get destroyed for a while. Send
// outstanding channel creation failures now so that the caller can restart
// with a new process/channel without waiting.
return process_->Send(msg);
}
void GpuProcessHost::OnConnectionError() {
SendOutstandingReplies();
}
return result;
for (auto& handler : connection_error_handlers_)
std::move(handler).Run();
connection_error_handlers_.clear();
}
bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) {
......@@ -988,6 +991,10 @@ void GpuProcessHost::OnChannelConnected(int32_t peer_pid) {
}
}
void GpuProcessHost::AddConnectionErrorHandler(base::OnceClosure handler) {
connection_error_handlers_.push_back(std::move(handler));
}
void GpuProcessHost::EstablishGpuChannel(int client_id,
uint64_t client_tracing_id,
bool is_gpu_host,
......@@ -1038,31 +1045,6 @@ void GpuProcessHost::EstablishGpuChannel(int client_id,
}
}
void GpuProcessHost::CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int client_id,
gpu::SurfaceHandle surface_handle,
CreateGpuMemoryBufferCallback callback) {
TRACE_EVENT0("gpu", "GpuProcessHost::CreateGpuMemoryBuffer");
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
create_gpu_memory_buffer_requests_.push(std::move(callback));
gpu_service_ptr_->CreateGpuMemoryBuffer(
id, size, format, usage, client_id, surface_handle,
base::BindOnce(&GpuProcessHost::OnGpuMemoryBufferCreated,
weak_ptr_factory_.GetWeakPtr()));
}
void GpuProcessHost::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
int client_id,
const gpu::SyncToken& sync_token) {
TRACE_EVENT0("gpu", "GpuProcessHost::DestroyGpuMemoryBuffer");
gpu_service_ptr_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
}
void GpuProcessHost::ConnectFrameSinkManager(
viz::mojom::FrameSinkManagerRequest request,
viz::mojom::FrameSinkManagerClientPtrInfo client) {
......@@ -1111,16 +1093,6 @@ void GpuProcessHost::OnChannelEstablished(
gpu_data_manager->GetGpuFeatureInfo(), EstablishChannelStatus::SUCCESS);
}
void GpuProcessHost::OnGpuMemoryBufferCreated(
gfx::GpuMemoryBufferHandle handle) {
TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated");
DCHECK(!create_gpu_memory_buffer_requests_.empty());
auto callback = std::move(create_gpu_memory_buffer_requests_.front());
create_gpu_memory_buffer_requests_.pop();
std::move(callback).Run(std::move(handle), BufferCreationStatus::SUCCESS);
}
#if defined(OS_ANDROID)
void GpuProcessHost::OnDestroyingVideoSurfaceAck() {
TRACE_EVENT0("gpu", "GpuProcessHost::OnDestroyingVideoSurfaceAck");
......@@ -1174,7 +1146,6 @@ void GpuProcessHost::OnProcessCrashed(int exit_code) {
cache_key.first, base::Time(), base::Time::Max(), base::Bind([] {}));
}
}
SendOutstandingReplies();
ChildProcessTerminationInfo info =
process_->GetTerminationInfo(true /* known_dead */);
......@@ -1472,13 +1443,6 @@ void GpuProcessHost::SendOutstandingReplies() {
EstablishChannelStatus::GPU_HOST_INVALID);
}
while (!create_gpu_memory_buffer_requests_.empty()) {
auto callback = std::move(create_gpu_memory_buffer_requests_.front());
create_gpu_memory_buffer_requests_.pop();
std::move(callback).Run(gfx::GpuMemoryBufferHandle(),
BufferCreationStatus::GPU_HOST_INVALID);
}
if (!send_destroying_video_surface_done_cb_.is_null())
base::ResetAndReturn(&send_destroying_video_surface_done_cb_).Run();
}
......
......@@ -11,6 +11,7 @@
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/atomicops.h"
#include "base/callback.h"
......@@ -36,8 +37,6 @@
#include "services/viz/privileged/interfaces/gl/gpu_host.mojom.h"
#include "services/viz/privileged/interfaces/gl/gpu_service.mojom.h"
#include "services/viz/privileged/interfaces/viz_main.mojom.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gpu_memory_buffer.h"
#include "url/gurl.h"
namespace base {
......@@ -50,7 +49,6 @@ struct FontRenderParams;
namespace gpu {
class ShaderDiskCache;
struct SyncToken;
}
namespace content {
......@@ -84,14 +82,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
const gpu::GpuFeatureInfo&,
EstablishChannelStatus status)>;
enum class BufferCreationStatus {
GPU_HOST_INVALID,
SUCCESS,
};
using CreateGpuMemoryBufferCallback =
base::OnceCallback<void(gfx::GpuMemoryBufferHandle handle,
BufferCreationStatus status)>;
using RequestHDRStatusCallback = base::RepeatingCallback<void(bool)>;
static int GetGpuCrashCount();
......@@ -132,6 +122,9 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
// IPC::Sender implementation.
bool Send(IPC::Message* msg) override;
// Adds a connection error handler for the GpuService.
void AddConnectionErrorHandler(base::OnceClosure handler);
// Tells the GPU process to create a new channel for communication with a
// client. Once the GPU process responds asynchronously with the IPC handle
// and GPUInfo, we call the callback.
......@@ -140,20 +133,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
bool is_gpu_host,
EstablishChannelCallback callback);
// Tells the GPU process to create a new GPU memory buffer.
void CreateGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
gfx::BufferUsage usage,
int client_id,
gpu::SurfaceHandle surface_handle,
CreateGpuMemoryBufferCallback callback);
// Tells the GPU process to destroy GPU memory buffer.
void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
int client_id,
const gpu::SyncToken& sync_token);
// Connects to FrameSinkManager running in the viz process. In this
// configuration the display compositor runs in the viz process and the
// browser must submit CompositorFrames over IPC.
......@@ -206,6 +185,9 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
void InitOzone();
#endif // defined(USE_OZONE)
// Called when GpuService connection is lost.
void OnConnectionError();
// BrowserChildProcessHostDelegate implementation.
bool OnMessageReceived(const IPC::Message& message) override;
void OnChannelConnected(int32_t peer_pid) override;
......@@ -240,7 +222,6 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
void OnChannelEstablished(int client_id,
mojo::ScopedMessagePipeHandle channel_handle);
void OnGpuMemoryBufferCreated(gfx::GpuMemoryBufferHandle handle);
// Message handlers.
#if defined(OS_ANDROID)
......@@ -264,13 +245,13 @@ class GpuProcessHost : public BrowserChildProcessHostDelegate,
// The serial number of the GpuProcessHost / GpuProcessHostUIShim pair.
int host_id_;
// List of connection error handlers for the GpuService.
std::vector<base::OnceClosure> connection_error_handlers_;
// These are the channel requests that we have already sent to
// the GPU process, but haven't heard back about yet.
base::queue<EstablishChannelCallback> channel_requests_;
// The pending create gpu memory buffer requests we need to reply to.
base::queue<CreateGpuMemoryBufferCallback> create_gpu_memory_buffer_requests_;
// A callback to signal the completion of a SendDestroyingVideoSurface call.
base::Closure send_destroying_video_surface_done_cb_;
......
......@@ -28,7 +28,6 @@
#include "base/threading/thread_local.h"
#include "build/build_config.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/renderer_host/media/audio_input_device_manager.h"
#include "content/browser/renderer_host/media/audio_service_listener.h"
......@@ -71,6 +70,7 @@
#if defined(OS_CHROMEOS)
#include "chromeos/audio/cras_audio_handler.h"
#include "content/browser/gpu/gpu_memory_buffer_manager_singleton.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/public/cros_features.h"
#include "media/capture/video/chromeos/video_capture_device_factory_chromeos.h"
......@@ -482,7 +482,7 @@ MediaStreamManager::MediaStreamManager(
#if defined(OS_CHROMEOS)
if (media::ShouldUseCrosCameraService()) {
media::VideoCaptureDeviceFactoryChromeOS::SetGpuBufferManager(
BrowserGpuMemoryBufferManager::current());
GpuMemoryBufferManagerSingleton::GetInstance());
media::CameraHalDispatcherImpl::GetInstance()->Start(
base::BindRepeating(
&VideoCaptureDependencies::CreateJpegDecodeAccelerator),
......
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