Commit 3c5af67e authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

Exposes public factory function for creating GpuClient

BUG=837689
TEST=none

Change-Id: Ie04f4e48afd0f6a33bc66b5f7921f83b79e1729d
Reviewed-on: https://chromium-review.googlesource.com/1033915Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#555115}
parent da336908
......@@ -834,8 +834,8 @@ jumbo_source_set("browser") {
"gpu/browser_gpu_memory_buffer_manager.h",
"gpu/compositor_util.cc",
"gpu/compositor_util.h",
"gpu/gpu_client.cc",
"gpu/gpu_client.h",
"gpu/gpu_client_impl.cc",
"gpu/gpu_client_impl.h",
"gpu/gpu_data_manager_impl.cc",
"gpu/gpu_data_manager_impl.h",
"gpu/gpu_data_manager_impl_private.cc",
......
......@@ -2,7 +2,7 @@
// 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_client.h"
#include "content/browser/gpu/gpu_client_impl.h"
#include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
#include "content/browser/gpu/gpu_process_host.h"
......@@ -14,41 +14,60 @@
namespace content {
GpuClient::GpuClient(int render_process_id)
// static
std::unique_ptr<GpuClient, BrowserThread::DeleteOnIOThread> GpuClient::Create(
ui::mojom::GpuRequest request,
ConnectionErrorHandlerClosure connection_error_handler) {
std::unique_ptr<GpuClientImpl, BrowserThread::DeleteOnIOThread> gpu_client(
new GpuClientImpl(ChildProcessHostImpl::GenerateChildProcessUniqueId()));
gpu_client->SetConnectionErrorHandler(std::move(connection_error_handler));
gpu_client->Add(std::move(request));
return gpu_client;
}
GpuClientImpl::GpuClientImpl(int render_process_id)
: render_process_id_(render_process_id), weak_factory_(this) {
bindings_.set_connection_error_handler(
base::Bind(&GpuClient::OnError, base::Unretained(this)));
base::Bind(&GpuClientImpl::OnError, base::Unretained(this),
ErrorReason::kConnectionLost));
}
GpuClient::~GpuClient() {
GpuClientImpl::~GpuClientImpl() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
bindings_.CloseAllBindings();
OnError();
OnError(ErrorReason::kInDestructor);
}
void GpuClient::Add(ui::mojom::GpuRequest request) {
void GpuClientImpl::Add(ui::mojom::GpuRequest request) {
bindings_.AddBinding(this, std::move(request));
}
void GpuClient::OnError() {
void GpuClientImpl::OnError(ErrorReason reason) {
ClearCallback();
if (!bindings_.empty())
return;
BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager =
BrowserGpuMemoryBufferManager::current();
if (gpu_memory_buffer_manager)
gpu_memory_buffer_manager->ProcessRemoved(render_process_id_);
if (bindings_.empty()) {
BrowserGpuMemoryBufferManager* gpu_memory_buffer_manager =
BrowserGpuMemoryBufferManager::current();
if (gpu_memory_buffer_manager)
gpu_memory_buffer_manager->ProcessRemoved(render_process_id_);
}
if (reason == ErrorReason::kConnectionLost && connection_error_handler_)
std::move(connection_error_handler_).Run(this);
}
void GpuClient::PreEstablishGpuChannel() {
void GpuClientImpl::PreEstablishGpuChannel() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&GpuClient::EstablishGpuChannel, base::Unretained(this),
EstablishGpuChannelCallback()));
base::BindOnce(&GpuClientImpl::EstablishGpuChannel,
base::Unretained(this), EstablishGpuChannelCallback()));
}
void GpuClientImpl::SetConnectionErrorHandler(
ConnectionErrorHandlerClosure connection_error_handler) {
connection_error_handler_ = std::move(connection_error_handler);
}
void GpuClient::OnEstablishGpuChannel(
void GpuClientImpl::OnEstablishGpuChannel(
mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info,
......@@ -79,13 +98,13 @@ void GpuClient::OnEstablishGpuChannel(
}
}
void GpuClient::OnCreateGpuMemoryBuffer(
void GpuClientImpl::OnCreateGpuMemoryBuffer(
CreateGpuMemoryBufferCallback callback,
const gfx::GpuMemoryBufferHandle& handle) {
std::move(callback).Run(handle);
}
void GpuClient::ClearCallback() {
void GpuClientImpl::ClearCallback() {
if (!callback_)
return;
EstablishGpuChannelCallback callback = std::move(callback_);
......@@ -94,7 +113,7 @@ void GpuClient::ClearCallback() {
DCHECK(!callback_);
}
void GpuClient::EstablishGpuChannel(EstablishGpuChannelCallback callback) {
void GpuClientImpl::EstablishGpuChannel(EstablishGpuChannelCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
// At most one channel should be requested. So clear previous request first.
ClearCallback();
......@@ -131,18 +150,18 @@ void GpuClient::EstablishGpuChannel(EstablishGpuChannelCallback callback) {
ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId(
render_process_id_),
preempts, allow_view_command_buffers, allow_real_time_streams,
base::Bind(&GpuClient::OnEstablishGpuChannel,
base::Bind(&GpuClientImpl::OnEstablishGpuChannel,
weak_factory_.GetWeakPtr()));
}
void GpuClient::CreateJpegDecodeAccelerator(
void GpuClientImpl::CreateJpegDecodeAccelerator(
media::mojom::JpegDecodeAcceleratorRequest jda_request) {
GpuProcessHost* host = GpuProcessHost::Get();
if (host)
host->gpu_service()->CreateJpegDecodeAccelerator(std::move(jda_request));
}
void GpuClient::CreateVideoEncodeAcceleratorProvider(
void GpuClientImpl::CreateVideoEncodeAcceleratorProvider(
media::mojom::VideoEncodeAcceleratorProviderRequest vea_provider_request) {
GpuProcessHost* host = GpuProcessHost::Get();
if (!host)
......@@ -151,7 +170,7 @@ void GpuClient::CreateVideoEncodeAcceleratorProvider(
std::move(vea_provider_request));
}
void GpuClient::CreateGpuMemoryBuffer(
void GpuClientImpl::CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
const gfx::Size& size,
gfx::BufferFormat format,
......@@ -169,12 +188,12 @@ void GpuClient::CreateGpuMemoryBuffer(
BrowserGpuMemoryBufferManager::current()
->AllocateGpuMemoryBufferForChildProcess(
id, size, format, usage, render_process_id_,
base::BindOnce(&GpuClient::OnCreateGpuMemoryBuffer,
base::BindOnce(&GpuClientImpl::OnCreateGpuMemoryBuffer,
weak_factory_.GetWeakPtr(), std::move(callback)));
}
void GpuClient::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
const gpu::SyncToken& sync_token) {
void GpuClientImpl::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
const gpu::SyncToken& sync_token) {
DCHECK(BrowserGpuMemoryBufferManager::current());
BrowserGpuMemoryBufferManager::current()->ChildProcessDeletedGpuMemoryBuffer(
......
......@@ -2,27 +2,37 @@
// 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_CLIENT_H_
#define CONTENT_BROWSER_GPU_GPU_CLIENT_H_
#ifndef CONTENT_BROWSER_GPU_GPU_CLIENT_IMPL_H_
#define CONTENT_BROWSER_GPU_GPU_CLIENT_IMPL_H_
#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/public/browser/gpu_client.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
namespace content {
class GpuClient : public ui::mojom::Gpu {
class GpuClientImpl : public ui::mojom::Gpu, public GpuClient {
public:
explicit GpuClient(int render_process_id);
~GpuClient() override;
explicit GpuClientImpl(int render_process_id);
~GpuClientImpl() override;
void Add(ui::mojom::GpuRequest request);
void PreEstablishGpuChannel();
void SetConnectionErrorHandler(
ConnectionErrorHandlerClosure connection_error_handler);
private:
void OnError();
enum class ErrorReason {
// OnError() is being called from the destructor.
kInDestructor,
// OnError() is being called because the connection was lost.
kConnectionLost
};
void OnError(ErrorReason reason);
void OnEstablishGpuChannel(mojo::ScopedMessagePipeHandle channel_handle,
const gpu::GPUInfo& gpu_info,
const gpu::GpuFeatureInfo& gpu_feature_info,
......@@ -54,11 +64,12 @@ class GpuClient : public ui::mojom::Gpu {
mojo::ScopedMessagePipeHandle channel_handle_;
gpu::GPUInfo gpu_info_;
gpu::GpuFeatureInfo gpu_feature_info_;
base::WeakPtrFactory<GpuClient> weak_factory_;
ConnectionErrorHandlerClosure connection_error_handler_;
base::WeakPtrFactory<GpuClientImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(GpuClient);
DISALLOW_COPY_AND_ASSIGN(GpuClientImpl);
};
} // namespace content
#endif // CONTENT_BROWSER_GPU_GPU_CLIENT_H_
#endif // CONTENT_BROWSER_GPU_GPU_CLIENT_IMPL_H_
......@@ -89,7 +89,7 @@
#include "content/browser/fileapi/fileapi_message_filter.h"
#include "content/browser/frame_host/render_frame_message_filter.h"
#include "content/browser/gpu/compositor_util.h"
#include "content/browser/gpu/gpu_client.h"
#include "content/browser/gpu/gpu_client_impl.h"
#include "content/browser/gpu/gpu_process_host.h"
#include "content/browser/gpu/shader_cache_factory.h"
#include "content/browser/histogram_controller.h"
......@@ -1463,7 +1463,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
InitializeChannelProxy();
if (!base::FeatureList::IsEnabled(features::kMash))
gpu_client_.reset(new GpuClient(GetID()));
gpu_client_.reset(new GpuClientImpl(GetID()));
GetMemoryDumpProvider().AddHost(this);
}
......@@ -1983,7 +1983,7 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
// |gpu_client_| outlives the registry, because its destruction is posted to
// IO thread from the destructor of |this|.
registry->AddInterface(
base::Bind(&GpuClient::Add, base::Unretained(gpu_client_.get())));
base::Bind(&GpuClientImpl::Add, base::Unretained(gpu_client_.get())));
}
registry->AddInterface(
......
......@@ -72,7 +72,7 @@ class SharedPersistentMemoryAllocator;
namespace content {
class BrowserPluginMessageFilter;
class ChildConnection;
class GpuClient;
class GpuClientImpl;
class IndexedDBDispatcherHost;
class InProcessChildThreadParams;
class NotificationMessageFilter;
......@@ -814,7 +814,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
#endif
scoped_refptr<ResourceMessageFilter> resource_message_filter_;
std::unique_ptr<GpuClient, BrowserThread::DeleteOnIOThread> gpu_client_;
std::unique_ptr<GpuClientImpl, BrowserThread::DeleteOnIOThread> gpu_client_;
std::unique_ptr<PushMessagingManager, BrowserThread::DeleteOnIOThread>
push_messaging_manager_;
......
......@@ -121,6 +121,7 @@ jumbo_source_set("browser_sources") {
"font_list_async.h",
"frame_service_base.h",
"global_request_id.h",
"gpu_client.h",
"gpu_data_manager.h",
"gpu_data_manager_observer.h",
"gpu_feature_checker.cc",
......@@ -321,6 +322,7 @@ jumbo_source_set("browser_sources") {
"//services/resource_coordinator/public/cpp:resource_coordinator_cpp",
"//services/service_manager/public/cpp",
"//services/tracing/public/cpp",
"//services/ui/public/interfaces",
# We expose skia headers in the public API.
"//skia",
......
......@@ -9,6 +9,7 @@ include_rules = [
"+services/network/public/cpp",
"+services/service_manager/sandbox",
"+services/resource_coordinator/public",
"+services/ui/public/interfaces",
]
specific_include_rules = {
......
// 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_PUBLIC_BROWSER_GPU_CLIENT_H_
#define CONTENT_PUBLIC_BROWSER_GPU_CLIENT_H_
#include <memory>
#include "base/callback_forward.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_thread.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
namespace content {
// GpuClient provides an implementation of ui::mojom::Gpu.
class CONTENT_EXPORT GpuClient {
public:
virtual ~GpuClient() {}
using ConnectionErrorHandlerClosure =
base::OnceCallback<void(GpuClient* client)>;
static std::unique_ptr<GpuClient, BrowserThread::DeleteOnIOThread> Create(
ui::mojom::GpuRequest request,
ConnectionErrorHandlerClosure connection_error_handler);
};
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_GPU_CLIENT_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