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/public/cpp/lib/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/switches.h" | 11 #include "components/mus/common/switches.h" |
11 #include "components/mus/public/cpp/lib/gpu_memory_buffer_manager_mus.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 { | 17 namespace { |
18 | 18 |
19 void GpuChannelEstablishCallback(int* client_id_out, | 19 void GpuChannelEstablishCallback(int* client_id_out, |
20 IPC::ChannelHandle* channel_handle_out, | 20 IPC::ChannelHandle* channel_handle_out, |
21 gpu::GPUInfo* gpu_info_out, | 21 gpu::GPUInfo* gpu_info_out, |
22 int client_id, | 22 int client_id, |
23 mus::mojom::ChannelHandlePtr channel_handle, | 23 mus::mojom::ChannelHandlePtr channel_handle, |
24 mus::mojom::GpuInfoPtr gpu_info) { | 24 mus::mojom::GpuInfoPtr gpu_info) { |
25 *client_id_out = client_id; | 25 *client_id_out = client_id; |
26 *channel_handle_out = channel_handle.To<IPC::ChannelHandle>(); | 26 *channel_handle_out = channel_handle.To<IPC::ChannelHandle>(); |
27 // TODO(penghuang): Get the gpu info. | 27 // TODO(penghuang): Get the gpu info. |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 GpuService::GpuService() | 31 GpuService::GpuService() |
32 : main_message_loop_(base::MessageLoop::current()), | 32 : main_message_loop_(base::MessageLoop::current()), |
33 shutdown_event_(false, false), | 33 shutdown_event_(false, false), |
34 io_thread_("GPUIOThread"), | 34 io_thread_("GPUIOThread"), |
35 gpu_memory_buffer_manager_(new mus::GpuMemoryBufferManagerMus) { | 35 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { |
36 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 36 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
37 thread_options.priority = base::ThreadPriority::NORMAL; | 37 thread_options.priority = base::ThreadPriority::NORMAL; |
38 CHECK(io_thread_.StartWithOptions(thread_options)); | 38 CHECK(io_thread_.StartWithOptions(thread_options)); |
39 } | 39 } |
40 | 40 |
41 GpuService::~GpuService() {} | 41 GpuService::~GpuService() {} |
42 | 42 |
43 // static | 43 // static |
44 bool GpuService::UseChromeGpuCommandBuffer() { | 44 bool GpuService::UseChromeGpuCommandBuffer() { |
45 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 45 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
46 switches::kUseChromeGpuCommandBufferInMus); | 46 switches::kUseChromeGpuCommandBufferInMus); |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 GpuService* GpuService::GetInstance() { | 50 GpuService* GpuService::GetInstance() { |
51 return base::Singleton<GpuService, | 51 return base::Singleton<GpuService, |
52 base::LeakySingletonTraits<GpuService>>::get(); | 52 base::LeakySingletonTraits<GpuService>>::get(); |
53 } | 53 } |
54 | 54 |
55 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannel( | 55 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannel( |
56 shell::Connector* connector) { | 56 shell::Connector* connector) { |
| 57 base::AutoLock auto_lock(lock_); |
57 if (gpu_channel_ && gpu_channel_->IsLost()) { | 58 if (gpu_channel_ && gpu_channel_->IsLost()) { |
58 gpu_channel_->DestroyChannel(); | 59 gpu_channel_->DestroyChannel(); |
59 gpu_channel_ = nullptr; | 60 gpu_channel_ = nullptr; |
60 } | 61 } |
61 | 62 |
62 if (gpu_channel_) | 63 if (gpu_channel_) |
63 return gpu_channel_; | 64 return gpu_channel_; |
64 | 65 |
65 mus::mojom::GpuServicePtr gpu_service; | 66 mus::mojom::GpuServicePtr gpu_service; |
66 connector->ConnectToInterface("mojo:mus", &gpu_service); | 67 connector->ConnectToInterface("mojo:mus", &gpu_service); |
(...skipping 25 matching lines...) Expand all Loading... |
92 | 93 |
93 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( | 94 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( |
94 size_t size) { | 95 size_t size) { |
95 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 96 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
96 if (!shm->CreateAnonymous(size)) | 97 if (!shm->CreateAnonymous(size)) |
97 return std::unique_ptr<base::SharedMemory>(); | 98 return std::unique_ptr<base::SharedMemory>(); |
98 return shm; | 99 return shm; |
99 } | 100 } |
100 | 101 |
101 } // namespace mus | 102 } // namespace mus |
OLD | NEW |