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/gpu/gpu_service.h" | 5 #include "services/ui/gpu/gpu_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/crash_logging.h" | 8 #include "base/debug/crash_logging.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 78 |
79 void DestroyBinding( | 79 void DestroyBinding( |
80 std::unique_ptr<mojo::BindingSet<mojom::GpuService>> binding) { | 80 std::unique_ptr<mojo::BindingSet<mojom::GpuService>> binding) { |
81 binding->CloseAllBindings(); | 81 binding->CloseAllBindings(); |
82 } | 82 } |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
86 GpuService::GpuService(const gpu::GPUInfo& gpu_info, | 86 GpuService::GpuService(const gpu::GPUInfo& gpu_info, |
87 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, | 87 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
88 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, | |
89 scoped_refptr<base::SingleThreadTaskRunner> io_runner, | 88 scoped_refptr<base::SingleThreadTaskRunner> io_runner, |
90 const gpu::GpuFeatureInfo& gpu_feature_info) | 89 const gpu::GpuFeatureInfo& gpu_feature_info) |
91 : main_runner_(base::ThreadTaskRunnerHandle::Get()), | 90 : main_runner_(base::ThreadTaskRunnerHandle::Get()), |
92 io_runner_(std::move(io_runner)), | 91 io_runner_(std::move(io_runner)), |
93 watchdog_thread_(std::move(watchdog_thread)), | 92 watchdog_thread_(std::move(watchdog_thread)), |
94 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 93 gpu_memory_buffer_factory_( |
| 94 gpu::GpuMemoryBufferFactory::CreateNativeType()), |
95 gpu_info_(gpu_info), | 95 gpu_info_(gpu_info), |
96 gpu_feature_info_(gpu_feature_info), | 96 gpu_feature_info_(gpu_feature_info), |
97 sync_point_manager_(nullptr), | 97 sync_point_manager_(nullptr), |
98 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
99 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 99 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
100 } | 100 } |
101 | 101 |
102 GpuService::~GpuService() { | 102 GpuService::~GpuService() { |
103 DCHECK(main_runner_->BelongsToCurrentThread()); | 103 DCHECK(main_runner_->BelongsToCurrentThread()); |
104 logging::SetLogMessageHandler(nullptr); | 104 logging::SetLogMessageHandler(nullptr); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 base::WaitableEvent::InitialState::NOT_SIGNALED); | 167 base::WaitableEvent::InitialState::NOT_SIGNALED); |
168 shutdown_event_ = owned_shutdown_event_.get(); | 168 shutdown_event_ = owned_shutdown_event_.get(); |
169 } | 169 } |
170 | 170 |
171 // Defer creation of the render thread. This is to prevent it from handling | 171 // Defer creation of the render thread. This is to prevent it from handling |
172 // IPC messages before the sandbox has been enabled and all other necessary | 172 // IPC messages before the sandbox has been enabled and all other necessary |
173 // initialization has succeeded. | 173 // initialization has succeeded. |
174 gpu_channel_manager_.reset(new gpu::GpuChannelManager( | 174 gpu_channel_manager_.reset(new gpu::GpuChannelManager( |
175 gpu_preferences_, this, watchdog_thread_.get(), | 175 gpu_preferences_, this, watchdog_thread_.get(), |
176 base::ThreadTaskRunnerHandle::Get(), io_runner_, sync_point_manager_, | 176 base::ThreadTaskRunnerHandle::Get(), io_runner_, sync_point_manager_, |
177 gpu_memory_buffer_factory_, gpu_feature_info_, | 177 gpu_memory_buffer_factory_.get(), gpu_feature_info_, |
178 std::move(activity_flags))); | 178 std::move(activity_flags))); |
179 | 179 |
180 media_gpu_channel_manager_.reset( | 180 media_gpu_channel_manager_.reset( |
181 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); | 181 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); |
182 if (watchdog_thread()) | 182 if (watchdog_thread()) |
183 watchdog_thread()->AddPowerObserver(); | 183 watchdog_thread()->AddPowerObserver(); |
184 } | 184 } |
185 | 185 |
186 void GpuService::Bind(mojom::GpuServiceRequest request) { | 186 void GpuService::Bind(mojom::GpuServiceRequest request) { |
187 if (main_runner_->BelongsToCurrentThread()) { | 187 if (main_runner_->BelongsToCurrentThread()) { |
188 io_runner_->PostTask(FROM_HERE, | 188 io_runner_->PostTask(FROM_HERE, |
189 base::Bind(&GpuService::Bind, base::Unretained(this), | 189 base::Bind(&GpuService::Bind, base::Unretained(this), |
190 base::Passed(std::move(request)))); | 190 base::Passed(std::move(request)))); |
191 return; | 191 return; |
192 } | 192 } |
193 if (!bindings_) | 193 if (!bindings_) |
194 bindings_ = base::MakeUnique<mojo::BindingSet<mojom::GpuService>>(); | 194 bindings_ = base::MakeUnique<mojo::BindingSet<mojom::GpuService>>(); |
195 bindings_->AddBinding(this, std::move(request)); | 195 bindings_->AddBinding(this, std::move(request)); |
196 } | 196 } |
197 | 197 |
| 198 gpu::ImageFactory* GpuService::gpu_image_factory() { |
| 199 return gpu_memory_buffer_factory_ |
| 200 ? gpu_memory_buffer_factory_->AsImageFactory() |
| 201 : nullptr; |
| 202 } |
| 203 |
198 void GpuService::RecordLogMessage(int severity, | 204 void GpuService::RecordLogMessage(int severity, |
199 size_t message_start, | 205 size_t message_start, |
200 const std::string& str) { | 206 const std::string& str) { |
201 // This can be run from any thread. | 207 // This can be run from any thread. |
202 std::string header = str.substr(0, message_start); | 208 std::string header = str.substr(0, message_start); |
203 std::string message = str.substr(message_start); | 209 std::string message = str.substr(message_start); |
204 (*gpu_host_)->RecordLogMessage(severity, header, message); | 210 (*gpu_host_)->RecordLogMessage(severity, header, message); |
205 } | 211 } |
206 | 212 |
207 void GpuService::CreateGpuMemoryBuffer( | 213 void GpuService::CreateGpuMemoryBuffer( |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 | 509 |
504 void GpuService::Stop(const StopCallback& callback) { | 510 void GpuService::Stop(const StopCallback& callback) { |
505 DCHECK(io_runner_->BelongsToCurrentThread()); | 511 DCHECK(io_runner_->BelongsToCurrentThread()); |
506 main_runner_->PostTaskAndReply(FROM_HERE, base::Bind([] { | 512 main_runner_->PostTaskAndReply(FROM_HERE, base::Bind([] { |
507 base::MessageLoop::current()->QuitWhenIdle(); | 513 base::MessageLoop::current()->QuitWhenIdle(); |
508 }), | 514 }), |
509 callback); | 515 callback); |
510 } | 516 } |
511 | 517 |
512 } // namespace ui | 518 } // namespace ui |
OLD | NEW |