Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: components/mus/public/cpp/lib/gpu_service.cc

Issue 1976703003: Impl mus::mojom::GpuService to enable using Chrome IPC version gpu CmdBuf in mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/mus/public/cpp/gpu_service.h"
6
7 #include "base/command_line.h"
8 #include "components/mus/common/gpu_type_converters.h"
9 #include "components/mus/common/switches.h"
10 #include "components/mus/public/cpp/lib/gpu_memory_buffer_manager_mus.h"
11 #include "components/mus/public/interfaces/gpu_service.mojom.h"
12 #include "gpu/ipc/client/gpu_channel_host.h"
13 #include "services/shell/public/cpp/connector.h"
14
15 namespace mus {
16
17 namespace {
18
19 void GpuChannelEstablishCallback(int* client_id_out,
20 IPC::ChannelHandle* channel_handle_out,
21 gpu::GPUInfo* gpu_info_out,
22 int client_id,
23 mus::mojom::ChannelHandlePtr channel_handle,
24 mus::mojom::GpuInfoPtr gpu_info) {
25 *client_id_out = client_id;
26 *channel_handle_out = channel_handle.To<IPC::ChannelHandle>();
27 // TODO(penghuang): Get the gpu info.
28 }
29
30 base::LazyInstance<GpuService> g_gpu_service = LAZY_INSTANCE_INITIALIZER;
31 }
32
33 GpuService::GpuService()
34 : initialized_(false),
35 main_message_loop_(base::MessageLoop::current()),
36 shutdown_event_(false, false),
37 io_thread_("GPUIOThread") {}
Fady Samuel 2016/05/25 17:06:47 This seems odd. Why are we forcing a new thread up
Peng 2016/05/25 19:42:56 This class is used in client process. Every client
38
39 GpuService::~GpuService() {}
40
41 // static
42 bool GpuService::UseChromeGpuCommandBuffer() {
Fady Samuel 2016/05/25 17:06:47 Do we need this?
Peng 2016/05/25 19:42:56 Yes. Probably we can hide this switch in client si
43 return base::CommandLine::ForCurrentProcess()->HasSwitch(
44 switches::kUseChromeGpuCommandBufferInMus);
45 }
46
47 // static
48 void GpuService::Initialize(shell::Connector* connector) {
49 g_gpu_service.Get().Init(connector);
50 }
51
52 // static
53 GpuService* GpuService::GetInstance() {
54 DCHECK(!(g_gpu_service == nullptr));
55 return g_gpu_service.Pointer();
56 }
57
58 void GpuService::Init(shell::Connector* connector) {
59 if (initialized_)
60 return;
61 initialized_ = true;
62
63 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
64 thread_options.priority = base::ThreadPriority::NORMAL;
65 CHECK(io_thread_.StartWithOptions(thread_options));
66
67 mus::mojom::GpuServicePtr gpu_service;
68 connector->ConnectToInterface("mojo:mus", &gpu_service);
69
70 const bool preempts = false;
71 const bool allow_view_command_buffers = false;
72 const bool allow_real_time_streams = false;
73 int client_id = 0;
74 IPC::ChannelHandle channel_handle;
75 gpu::GPUInfo gpu_info;
76 gpu_service->EstablishGpuChannel(
77 preempts, allow_view_command_buffers, allow_real_time_streams,
78 base::Bind(&GpuChannelEstablishCallback, &client_id, &channel_handle,
79 &gpu_info));
80 CHECK(gpu_service.WaitForIncomingResponse());
piman 2016/05/24 22:46:54 I assume this can return false if the mus process
Peng 2016/05/25 19:42:56 I don't what should we do for it, so I just make i
piman 2016/05/25 22:53:17 In Chrome, in RenderThreadImpl, we create the chan
Peng 2016/05/31 14:24:03 I renamed the Init() to EstablishGpuChannel(), and
81 gpu_memory_buffer_manager_.reset(new mus::GpuMemoryBufferManagerMus());
82 gpu_channel_ = gpu::GpuChannelHost::Create(this, client_id, gpu_info,
83 channel_handle, &shutdown_event_,
84 gpu_memory_buffer_manager_.get());
85 }
86
87 bool GpuService::IsMainThread() {
88 return base::MessageLoop::current() == main_message_loop_;
89 }
90
91 scoped_refptr<base::SingleThreadTaskRunner>
92 GpuService::GetIOThreadTaskRunner() {
93 return io_thread_.task_runner();
94 }
95
96 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory(
97 size_t size) {
98 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
99 if (!shm->CreateAnonymous(size))
100 return std::unique_ptr<base::SharedMemory>();
101 return shm;
102 }
103
104 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698