| Index: components/mus/public/cpp/lib/gpu_service.cc
|
| diff --git a/components/mus/public/cpp/lib/gpu_service.cc b/components/mus/public/cpp/lib/gpu_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..93e641c73385982528c292fb2b3c0fd1a9629888
|
| --- /dev/null
|
| +++ b/components/mus/public/cpp/lib/gpu_service.cc
|
| @@ -0,0 +1,99 @@
|
| +// 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 "components/mus/public/cpp/gpu_service.h"
|
| +
|
| +#include "base/command_line.h"
|
| +#include "components/mus/common/gpu_type_converters.h"
|
| +#include "components/mus/common/switches.h"
|
| +#include "components/mus/public/cpp/lib/gpu_memory_buffer_manager_mus.h"
|
| +#include "components/mus/public/interfaces/gpu_service.mojom.h"
|
| +#include "gpu/ipc/client/gpu_channel_host.h"
|
| +#include "services/shell/public/cpp/connector.h"
|
| +
|
| +namespace mus {
|
| +
|
| +namespace {
|
| +
|
| +void GpuChannelEstablishCallback(int* client_id_out,
|
| + IPC::ChannelHandle* channel_handle_out,
|
| + gpu::GPUInfo* gpu_info_out,
|
| + int client_id,
|
| + mus::mojom::ChannelHandlePtr channel_handle,
|
| + mus::mojom::GpuInfoPtr gpu_info) {
|
| + *client_id_out = client_id;
|
| + *channel_handle_out = channel_handle.To<IPC::ChannelHandle>();
|
| + // TODO(penghuang): Get the gpu info.
|
| +}
|
| +
|
| +base::LazyInstance<GpuService> g_gpu_service = LAZY_INSTANCE_INITIALIZER;
|
| +}
|
| +
|
| +GpuService::GpuService()
|
| + : initialized_(false),
|
| + main_message_loop_(base::MessageLoop::current()),
|
| + shutdown_event_(false, false),
|
| + io_thread_("GPUIOThread") {}
|
| +
|
| +GpuService::~GpuService() {}
|
| +
|
| +// static
|
| +bool GpuService::UseChromeGpuCommandBuffer() {
|
| + return base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kUseChromeGpuCommandBufferInMus);
|
| +}
|
| +
|
| +// static
|
| +void GpuService::Initialize(shell::Connector* connector) {
|
| + g_gpu_service.Get().Init(connector);
|
| +}
|
| +
|
| +// static
|
| +GpuService* GpuService::GetInstance() {
|
| + DCHECK(!(g_gpu_service == nullptr));
|
| + return g_gpu_service.Pointer();
|
| +}
|
| +
|
| +void GpuService::Init(shell::Connector* connector) {
|
| + if (initialized_)
|
| + return;
|
| + initialized_ = true;
|
| +
|
| + base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
|
| + thread_options.priority = base::ThreadPriority::NORMAL;
|
| + CHECK(io_thread_.StartWithOptions(thread_options));
|
| +
|
| + mus::mojom::GpuServicePtr gpu_service;
|
| + connector->ConnectToInterface("mojo:mus", &gpu_service);
|
| +
|
| + int client_id = 0;
|
| + IPC::ChannelHandle channel_handle;
|
| + gpu::GPUInfo gpu_info;
|
| + gpu_service->EstablishGpuChannel(base::Bind(
|
| + &GpuChannelEstablishCallback, &client_id, &channel_handle, &gpu_info));
|
| + CHECK(gpu_service.WaitForIncomingResponse());
|
| + gpu_memory_buffer_manager_.reset(new mus::GpuMemoryBufferManagerMus());
|
| + gpu_channel_ = gpu::GpuChannelHost::Create(this, client_id, gpu_info,
|
| + channel_handle, &shutdown_event_,
|
| + gpu_memory_buffer_manager_.get());
|
| +}
|
| +
|
| +bool GpuService::IsMainThread() {
|
| + return base::MessageLoop::current() == main_message_loop_;
|
| +}
|
| +
|
| +scoped_refptr<base::SingleThreadTaskRunner>
|
| +GpuService::GetIOThreadTaskRunner() {
|
| + return io_thread_.task_runner();
|
| +}
|
| +
|
| +std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory(
|
| + size_t size) {
|
| + std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
|
| + if (!shm->CreateAnonymous(size))
|
| + return std::unique_ptr<base::SharedMemory>();
|
| + return shm;
|
| +}
|
| +
|
| +} // namespace mus
|
|
|