Commit 538adf15 authored by Khushal's avatar Khushal Committed by Commit Bot

content: Set up Discardable memory in the GPU process.

With skia running in the GPU process for OOP raster, it needs to be
able to make discardable memory allocations. Set up a connection to
the discardable memory service from the GPU process.

R=piman@chromium.org

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel
Change-Id: I5cbd5677c5c6bffd3f7492862b1825d186b19a9d
Reviewed-on: https://chromium-review.googlesource.com/923208
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539029}
parent efb6eca4
......@@ -17,6 +17,8 @@ source_set("main") {
deps = [
"//cc",
"//components/discardable_memory/client",
"//components/discardable_memory/public/interfaces",
"//components/viz/service",
"//gpu/ipc:gl_in_process_context",
"//gpu/ipc/common",
......
# Please consult components/viz/README.md about allowable dependencies.
include_rules = [
"+components/discardable_memory/client",
"+components/viz/service",
"+gpu/command_buffer",
"+gpu/config",
......
......@@ -138,9 +138,7 @@ VizMainImpl::VizMainImpl(Delegate* delegate,
CreateUkmRecorderIfNeeded(dependencies.connector);
gpu_service_ = std::make_unique<GpuServiceImpl>(
gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(),
io_thread_ ? io_thread_->task_runner()
: dependencies_.io_thread_task_runner,
gpu_init_->gpu_info(), gpu_init_->TakeWatchdogThread(), io_task_runner(),
gpu_init_->gpu_feature_info(), gpu_init_->gpu_preferences());
}
......@@ -185,6 +183,8 @@ void VizMainImpl::BindAssociated(mojom::VizMainAssociatedRequest request) {
void VizMainImpl::CreateGpuService(
mojom::GpuServiceRequest request,
mojom::GpuHostPtr gpu_host,
discardable_memory::mojom::DiscardableSharedMemoryManagerPtr
discardable_memory_manager,
mojo::ScopedSharedBufferHandle activity_flags) {
DCHECK(gpu_thread_task_runner_->BelongsToCurrentThread());
gpu_service_->UpdateGPUInfo();
......@@ -200,6 +200,16 @@ void VizMainImpl::CreateGpuService(
return;
}
if (!gpu_init_->gpu_info().in_process_gpu) {
// If the GPU is running in the browser process, discardable memory manager
// has already been initialized.
discardable_shared_memory_manager_ = std::make_unique<
discardable_memory::ClientDiscardableSharedMemoryManager>(
std::move(discardable_memory_manager), io_task_runner());
base::DiscardableMemoryAllocator::SetInstance(
discardable_shared_memory_manager_.get());
}
gpu_service_->Bind(std::move(request));
gpu_service_->InitializeWithHost(
std::move(gpu_host),
......
......@@ -7,6 +7,7 @@
#include "base/power_monitor/power_monitor.h"
#include "base/threading/thread.h"
#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "gpu/ipc/service/gpu_init.h"
#include "mojo/public/cpp/bindings/associated_binding_set.h"
......@@ -79,9 +80,12 @@ class VizMainImpl : public gpu::GpuSandboxHelper, public mojom::VizMain {
void BindAssociated(mojom::VizMainAssociatedRequest request);
// mojom::VizMain implementation:
void CreateGpuService(mojom::GpuServiceRequest request,
mojom::GpuHostPtr gpu_host,
mojo::ScopedSharedBufferHandle activity_flags) override;
void CreateGpuService(
mojom::GpuServiceRequest request,
mojom::GpuHostPtr gpu_host,
discardable_memory::mojom::DiscardableSharedMemoryManagerPtr
discardable_memory_manager,
mojo::ScopedSharedBufferHandle activity_flags) override;
void CreateFrameSinkManager(mojom::FrameSinkManagerParamsPtr params) override;
GpuServiceImpl* gpu_service() { return gpu_service_.get(); }
......@@ -103,6 +107,11 @@ class VizMainImpl : public gpu::GpuSandboxHelper, public mojom::VizMain {
const gpu::GPUInfo* gpu_info,
const gpu::GpuPreferences& gpu_prefs) override;
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const {
return io_thread_ ? io_thread_->task_runner()
: dependencies_.io_thread_task_runner;
}
Delegate* const delegate_;
const ExternalDependencies dependencies_;
......@@ -141,6 +150,9 @@ class VizMainImpl : public gpu::GpuSandboxHelper, public mojom::VizMain {
mojo::Binding<mojom::VizMain> binding_;
mojo::AssociatedBinding<mojom::VizMain> associated_binding_;
std::unique_ptr<discardable_memory::ClientDiscardableSharedMemoryManager>
discardable_shared_memory_manager_;
DISALLOW_COPY_AND_ASSIGN(VizMainImpl);
};
......
......@@ -28,6 +28,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "components/tracing/common/tracing_switches.h"
#include "components/viz/common/switches.h"
#include "content/browser/browser_child_process_host_impl.h"
......@@ -63,10 +64,13 @@
#include "media/media_features.h"
#include "mojo/edk/embedder/embedder.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/connector.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/runner/common/client_util.h"
#include "services/service_manager/sandbox/sandbox_type.h"
#include "services/service_manager/sandbox/switches.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/display_switches.h"
#include "ui/gfx/switches.h"
......@@ -376,6 +380,32 @@ void RecordAppContainerStatus(int error_code, bool crashed_before) {
}
#endif // defined(OS_WIN)
void BindDiscardableMemoryRequestOnIO(
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest request,
discardable_memory::DiscardableSharedMemoryManager* manager) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
service_manager::BindSourceInfo source_info;
manager->Bind(std::move(request), source_info);
}
void BindDiscardableMemoryRequestOnUI(
discardable_memory::mojom::DiscardableSharedMemoryManagerRequest request) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if defined(USE_AURA)
if (features::IsMusEnabled()) {
ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface(
ui::mojom::kServiceName, std::move(request));
return;
}
#endif
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(
&BindDiscardableMemoryRequestOnIO, std::move(request),
BrowserMainLoop::GetInstance()->discardable_shared_memory_manager()));
}
} // anonymous namespace
class GpuProcessHost::ConnectionFilterImpl : public ConnectionFilter {
......@@ -737,9 +767,17 @@ bool GpuProcessHost::Init() {
->GetRemoteAssociatedInterface(&gpu_main_ptr_);
viz::mojom::GpuHostPtr host_proxy;
gpu_host_binding_.Bind(mojo::MakeRequest(&host_proxy));
gpu_main_ptr_->CreateGpuService(mojo::MakeRequest(&gpu_service_ptr_),
std::move(host_proxy),
activity_flags_.CloneHandle());
discardable_memory::mojom::DiscardableSharedMemoryManagerPtr
discardable_manager_ptr;
auto discardable_request = mojo::MakeRequest(&discardable_manager_ptr);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::BindOnce(&BindDiscardableMemoryRequestOnUI,
std::move(discardable_request)));
gpu_main_ptr_->CreateGpuService(
mojo::MakeRequest(&gpu_service_ptr_), std::move(host_proxy),
std::move(discardable_manager_ptr), activity_flags_.CloneHandle());
#if defined(USE_OZONE)
InitOzone();
......
......@@ -19,6 +19,7 @@
"content::mojom::FontCacheWin"
],
"gpu": [
"discardable_memory::mojom::DiscardableSharedMemoryManager",
"media::mojom::AndroidOverlayProvider"
],
"plugin": [
......
......@@ -29,7 +29,8 @@
"gpu"
],
"device": [ "device:power_monitor" ],
"metrics": [ "url_keyed_metrics" ]
"metrics": [ "url_keyed_metrics" ],
"ui": [ "discardable_memory" ]
}
}
}
......
......@@ -277,11 +277,19 @@ void Service::OnStart() {
// so keep this line below both of those.
input_device_server_.RegisterAsObserver();
if (!discardable_shared_memory_manager_) {
owned_discardable_shared_memory_manager_ =
std::make_unique<discardable_memory::DiscardableSharedMemoryManager>();
discardable_shared_memory_manager_ =
owned_discardable_shared_memory_manager_.get();
}
window_server_ = base::MakeUnique<ws::WindowServer>(this, should_host_viz_);
if (should_host_viz_) {
std::unique_ptr<ws::GpuHost> gpu_host =
base::MakeUnique<ws::DefaultGpuHost>(window_server_.get(),
context()->connector());
base::MakeUnique<ws::DefaultGpuHost>(
window_server_.get(), context()->connector(),
discardable_shared_memory_manager_);
window_server_->SetGpuHost(std::move(gpu_host));
registry_.AddInterface<mojom::Gpu>(
......@@ -296,12 +304,6 @@ void Service::OnStart() {
ime_driver_.Init(context()->connector(), test_config_);
if (!discardable_shared_memory_manager_) {
owned_discardable_shared_memory_manager_ =
std::make_unique<discardable_memory::DiscardableSharedMemoryManager>();
discardable_shared_memory_manager_ =
owned_discardable_shared_memory_manager_.get();
}
registry_with_source_info_.AddInterface<mojom::AccessibilityManager>(
base::Bind(&Service::BindAccessibilityManagerRequest,
base::Unretained(this)));
......
......@@ -127,6 +127,7 @@ static_library("lib") {
]
deps = [
"//components/discardable_memory/service",
"//components/viz/service/main", # TODO(sad): Temporary until GPU process split.
"//gpu/command_buffer/client",
"//gpu/command_buffer/client:gles2_interface",
......@@ -298,6 +299,7 @@ source_set("tests") {
"//base/test:test_support",
"//cc:cc",
"//cc:test_support",
"//components/discardable_memory/service",
"//components/viz/service/main",
"//components/viz/test:test_support",
"//gpu/ipc/client",
......
......@@ -10,6 +10,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "components/viz/host/server_gpu_memory_buffer_manager.h"
#include "gpu/ipc/client/gpu_channel_host.h"
#include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h"
......@@ -46,13 +47,18 @@ bool HasSplitVizProcess() {
} // namespace
DefaultGpuHost::DefaultGpuHost(GpuHostDelegate* delegate,
service_manager::Connector* connector)
DefaultGpuHost::DefaultGpuHost(
GpuHostDelegate* delegate,
service_manager::Connector* connector,
discardable_memory::DiscardableSharedMemoryManager*
discardable_shared_memory_manager)
: delegate_(delegate),
next_client_id_(kInternalGpuChannelClientId + 1),
main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
gpu_host_binding_(this),
gpu_thread_("GpuThread") {
DCHECK(discardable_shared_memory_manager);
auto request = MakeRequest(&viz_main_);
if (connector && HasSplitVizProcess()) {
connector->BindInterface(viz::mojom::kVizServiceName, std::move(request));
......@@ -65,11 +71,17 @@ DefaultGpuHost::DefaultGpuHost(GpuHostDelegate* delegate,
base::Passed(MakeRequest(&viz_main_))));
}
discardable_memory::mojom::DiscardableSharedMemoryManagerPtr
discardable_manager_ptr;
service_manager::BindSourceInfo source_info;
discardable_shared_memory_manager->Bind(
mojo::MakeRequest(&discardable_manager_ptr), source_info);
viz::mojom::GpuHostPtr gpu_host_proxy;
gpu_host_binding_.Bind(mojo::MakeRequest(&gpu_host_proxy));
viz_main_->CreateGpuService(MakeRequest(&gpu_service_),
std::move(gpu_host_proxy),
mojo::ScopedSharedBufferHandle());
viz_main_->CreateGpuService(
MakeRequest(&gpu_service_), std::move(gpu_host_proxy),
std::move(discardable_manager_ptr), mojo::ScopedSharedBufferHandle());
gpu_memory_buffer_manager_ =
std::make_unique<viz::ServerGpuMemoryBufferManager>(gpu_service_.get(),
next_client_id_++);
......
......@@ -23,6 +23,10 @@
#include "services/ui/public/interfaces/arc.mojom.h"
#endif // defined(OS_CHROMEOS)
namespace discardable_memory {
class DiscardableSharedMemoryManager;
}
namespace service_manager {
class Connector;
}
......@@ -66,7 +70,9 @@ class GpuHost {
class DefaultGpuHost : public GpuHost, public viz::mojom::GpuHost {
public:
DefaultGpuHost(GpuHostDelegate* delegate,
service_manager::Connector* connector);
service_manager::Connector* connector,
discardable_memory::DiscardableSharedMemoryManager*
discardable_shared_memory_manager);
~DefaultGpuHost() override;
private:
......
......@@ -9,6 +9,7 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "components/discardable_memory/service/discardable_shared_memory_manager.h"
#include "components/viz/service/gl/gpu_service_impl.h"
#include "gpu/config/gpu_info.h"
#include "services/ui/public/interfaces/gpu.mojom.h"
......@@ -85,6 +86,8 @@ class GpuHostTest : public testing::Test {
base::Thread io_thread_;
TestGpuHostDelegate gpu_host_delegate_;
discardable_memory::DiscardableSharedMemoryManager
discardable_memory_manager_;
std::unique_ptr<TestGpuService> gpu_service_;
viz::mojom::GpuServicePtr gpu_service_ptr_;
std::unique_ptr<DefaultGpuHost> gpu_host_;
......@@ -103,7 +106,8 @@ void GpuHostTest::DestroyHost() {
void GpuHostTest::SetUp() {
testing::Test::SetUp();
gpu_host_ = std::make_unique<DefaultGpuHost>(&gpu_host_delegate_, nullptr);
gpu_host_ = std::make_unique<DefaultGpuHost>(&gpu_host_delegate_, nullptr,
&discardable_memory_manager_);
gpu_service_->Bind(mojo::MakeRequest(&gpu_service_ptr_));
gpu_host_->gpu_service_ = std::move(gpu_service_ptr_);
}
......
......@@ -10,6 +10,7 @@ mojom("interfaces") {
]
public_deps = [
"//components/discardable_memory/public/interfaces",
"//services/viz/privileged/interfaces/compositing",
"//services/viz/privileged/interfaces/gl",
"//services/viz/public/interfaces",
......
......@@ -5,6 +5,7 @@
module viz.mojom;
import "mojo/common/values.mojom";
import "components/discardable_memory/public/interfaces/discardable_shared_memory_manager.mojom";
import "services/viz/public/interfaces/compositing/compositing_mode_watcher.mojom";
import "services/viz/privileged/interfaces/compositing/frame_sink_manager.mojom";
import "services/viz/privileged/interfaces/gl/gpu_host.mojom";
......@@ -39,5 +40,6 @@ interface VizMain {
CreateGpuService(GpuService& gpu_service,
GpuHost gpu_host,
discardable_memory.mojom.DiscardableSharedMemoryManager discardable_memory_manager,
handle<shared_buffer>? activity_flags);
};
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