| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/mus/common/gpu_service.h" | 5 #include "components/mus/common/gpu_service.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "components/mus/common/gpu_type_converters.h" | 9 #include "components/mus/common/gpu_type_converters.h" |
| 10 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" | 10 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" |
| 11 #include "components/mus/common/switches.h" | 11 #include "components/mus/common/switches.h" |
| 12 #include "components/mus/public/interfaces/gpu_service.mojom.h" | 12 #include "components/mus/public/interfaces/gpu_service.mojom.h" |
| 13 #include "services/shell/public/cpp/connector.h" | 13 #include "services/shell/public/cpp/connector.h" |
| 14 | 14 |
| 15 namespace mus { | 15 namespace mus { |
| 16 | 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 | |
| 31 GpuService::GpuService() | 17 GpuService::GpuService() |
| 32 : main_message_loop_(base::MessageLoop::current()), | 18 : main_message_loop_(base::MessageLoop::current()), |
| 33 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 19 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 34 base::WaitableEvent::InitialState::NOT_SIGNALED), | 20 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 35 io_thread_("GPUIOThread"), | 21 io_thread_("GPUIOThread"), |
| 36 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { | 22 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { |
| 37 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 23 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 38 thread_options.priority = base::ThreadPriority::NORMAL; | 24 thread_options.priority = base::ThreadPriority::NORMAL; |
| 39 CHECK(io_thread_.StartWithOptions(thread_options)); | 25 CHECK(io_thread_.StartWithOptions(thread_options)); |
| 40 } | 26 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 61 gpu_channel_ = nullptr; | 47 gpu_channel_ = nullptr; |
| 62 } | 48 } |
| 63 | 49 |
| 64 if (gpu_channel_) | 50 if (gpu_channel_) |
| 65 return gpu_channel_; | 51 return gpu_channel_; |
| 66 | 52 |
| 67 mus::mojom::GpuServicePtr gpu_service; | 53 mus::mojom::GpuServicePtr gpu_service; |
| 68 connector->ConnectToInterface("mojo:mus", &gpu_service); | 54 connector->ConnectToInterface("mojo:mus", &gpu_service); |
| 69 | 55 |
| 70 int client_id = 0; | 56 int client_id = 0; |
| 71 IPC::ChannelHandle channel_handle; | 57 mojom::ChannelHandlePtr channel_handle; |
| 72 gpu::GPUInfo gpu_info; | 58 mojom::GpuInfoPtr gpu_info; |
| 73 gpu_service->EstablishGpuChannel(base::Bind( | 59 if (!gpu_service->EstablishGpuChannel(&client_id, &channel_handle, |
| 74 &GpuChannelEstablishCallback, &client_id, &channel_handle, &gpu_info)); | 60 &gpu_info)) { |
| 75 if (!gpu_service.WaitForIncomingResponse()) { | |
| 76 DLOG(WARNING) | 61 DLOG(WARNING) |
| 77 << "Channel encountered error while establishing gpu channel."; | 62 << "Channel encountered error while establishing gpu channel."; |
| 78 return nullptr; | 63 return nullptr; |
| 79 } | 64 } |
| 80 gpu_channel_ = gpu::GpuChannelHost::Create(this, client_id, gpu_info, | 65 |
| 81 channel_handle, &shutdown_event_, | 66 // TODO(penghuang): Get the real gpu info from mus. |
| 82 gpu_memory_buffer_manager_.get()); | 67 gpu_channel_ = gpu::GpuChannelHost::Create( |
| 68 this, client_id, gpu::GPUInfo(), channel_handle.To<IPC::ChannelHandle>(), |
| 69 &shutdown_event_, gpu_memory_buffer_manager_.get()); |
| 83 return gpu_channel_; | 70 return gpu_channel_; |
| 84 } | 71 } |
| 85 | 72 |
| 86 bool GpuService::IsMainThread() { | 73 bool GpuService::IsMainThread() { |
| 87 return base::MessageLoop::current() == main_message_loop_; | 74 return base::MessageLoop::current() == main_message_loop_; |
| 88 } | 75 } |
| 89 | 76 |
| 90 scoped_refptr<base::SingleThreadTaskRunner> | 77 scoped_refptr<base::SingleThreadTaskRunner> |
| 91 GpuService::GetIOThreadTaskRunner() { | 78 GpuService::GetIOThreadTaskRunner() { |
| 92 return io_thread_.task_runner(); | 79 return io_thread_.task_runner(); |
| 93 } | 80 } |
| 94 | 81 |
| 95 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( | 82 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( |
| 96 size_t size) { | 83 size_t size) { |
| 97 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 84 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 98 if (!shm->CreateAnonymous(size)) | 85 if (!shm->CreateAnonymous(size)) |
| 99 return std::unique_ptr<base::SharedMemory>(); | 86 return std::unique_ptr<base::SharedMemory>(); |
| 100 return shm; | 87 return shm; |
| 101 } | 88 } |
| 102 | 89 |
| 103 } // namespace mus | 90 } // namespace mus |
| OLD | NEW |