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 "services/ui/public/cpp/gpu_service.h" | 5 #include "services/ui/public/cpp/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 "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" | 11 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
12 #include "mojo/public/cpp/system/platform_handle.h" | 12 #include "mojo/public/cpp/system/platform_handle.h" |
13 #include "services/service_manager/public/cpp/connector.h" | 13 #include "services/service_manager/public/cpp/connector.h" |
14 #include "services/ui/common/switches.h" | 14 #include "services/ui/common/switches.h" |
15 #include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h" | 15 #include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h" |
16 #include "services/ui/public/interfaces/gpu_service.mojom.h" | 16 #include "services/ui/public/interfaces/gpu_service.mojom.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 GpuService::GpuService(shell::Connector* connector, | 20 GpuService::GpuService(service_manager::Connector* connector, |
21 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
22 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 22 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
23 io_task_runner_(std::move(task_runner)), | 23 io_task_runner_(std::move(task_runner)), |
24 connector_(connector), | 24 connector_(connector), |
25 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 25 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
26 base::WaitableEvent::InitialState::NOT_SIGNALED), | 26 base::WaitableEvent::InitialState::NOT_SIGNALED), |
27 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { | 27 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { |
28 DCHECK(main_task_runner_); | 28 DCHECK(main_task_runner_); |
29 DCHECK(connector_); | 29 DCHECK(connector_); |
30 if (!io_task_runner_) { | 30 if (!io_task_runner_) { |
31 io_thread_.reset(new base::Thread("GPUIOThread")); | 31 io_thread_.reset(new base::Thread("GPUIOThread")); |
32 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 32 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
33 thread_options.priority = base::ThreadPriority::NORMAL; | 33 thread_options.priority = base::ThreadPriority::NORMAL; |
34 CHECK(io_thread_->StartWithOptions(thread_options)); | 34 CHECK(io_thread_->StartWithOptions(thread_options)); |
35 io_task_runner_ = io_thread_->task_runner(); | 35 io_task_runner_ = io_thread_->task_runner(); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 GpuService::~GpuService() { | 39 GpuService::~GpuService() { |
40 DCHECK(IsMainThread()); | 40 DCHECK(IsMainThread()); |
41 for (const auto& callback : establish_callbacks_) | 41 for (const auto& callback : establish_callbacks_) |
42 callback.Run(nullptr); | 42 callback.Run(nullptr); |
43 shutdown_event_.Signal(); | 43 shutdown_event_.Signal(); |
44 if (gpu_channel_) | 44 if (gpu_channel_) |
45 gpu_channel_->DestroyChannel(); | 45 gpu_channel_->DestroyChannel(); |
46 } | 46 } |
47 | 47 |
48 // static | 48 // static |
49 std::unique_ptr<GpuService> GpuService::Create( | 49 std::unique_ptr<GpuService> GpuService::Create( |
50 shell::Connector* connector, | 50 service_manager::Connector* connector, |
51 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
52 return base::WrapUnique(new GpuService(connector, std::move(task_runner))); | 52 return base::WrapUnique(new GpuService(connector, std::move(task_runner))); |
53 } | 53 } |
54 | 54 |
55 void GpuService::EstablishGpuChannel( | 55 void GpuService::EstablishGpuChannel( |
56 const gpu::GpuChannelEstablishedCallback& callback) { | 56 const gpu::GpuChannelEstablishedCallback& callback) { |
57 DCHECK(IsMainThread()); | 57 DCHECK(IsMainThread()); |
58 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); | 58 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); |
59 if (channel) { | 59 if (channel) { |
60 main_task_runner_->PostTask(FROM_HERE, | 60 main_task_runner_->PostTask(FROM_HERE, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 146 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
147 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 147 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
148 if (result != MOJO_RESULT_OK) | 148 if (result != MOJO_RESULT_OK) |
149 return nullptr; | 149 return nullptr; |
150 DCHECK_EQ(shared_memory_size, size); | 150 DCHECK_EQ(shared_memory_size, size); |
151 | 151 |
152 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 152 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
153 } | 153 } |
154 | 154 |
155 } // namespace ui | 155 } // namespace ui |
OLD | NEW |