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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 const base::Callback<void(const Param&)>& callback) { | 67 const base::Callback<void(const Param&)>& callback) { |
68 return base::Bind( | 68 return base::Bind( |
69 [](scoped_refptr<base::SingleThreadTaskRunner> runner, | 69 [](scoped_refptr<base::SingleThreadTaskRunner> runner, |
70 const base::Callback<void(const Param&)>& callback, | 70 const base::Callback<void(const Param&)>& callback, |
71 const Param& param) { | 71 const Param& param) { |
72 runner->PostTask(FROM_HERE, base::Bind(callback, param)); | 72 runner->PostTask(FROM_HERE, base::Bind(callback, param)); |
73 }, | 73 }, |
74 runner, callback); | 74 runner, callback); |
75 } | 75 } |
76 | 76 |
| 77 void DestroyBinding( |
| 78 std::unique_ptr<mojo::BindingSet<mojom::GpuService>> binding) { |
| 79 binding->CloseAllBindings(); |
| 80 } |
| 81 |
77 } // namespace | 82 } // namespace |
78 | 83 |
79 GpuService::GpuService(const gpu::GPUInfo& gpu_info, | 84 GpuService::GpuService(const gpu::GPUInfo& gpu_info, |
80 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, | 85 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
81 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, | 86 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, |
82 scoped_refptr<base::SingleThreadTaskRunner> io_runner, | 87 scoped_refptr<base::SingleThreadTaskRunner> io_runner, |
83 const gpu::GpuFeatureInfo& gpu_feature_info) | 88 const gpu::GpuFeatureInfo& gpu_feature_info) |
84 : main_runner_(base::ThreadTaskRunnerHandle::Get()), | 89 : main_runner_(base::ThreadTaskRunnerHandle::Get()), |
85 io_runner_(std::move(io_runner)), | 90 io_runner_(std::move(io_runner)), |
86 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 91 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
87 base::WaitableEvent::InitialState::NOT_SIGNALED), | 92 base::WaitableEvent::InitialState::NOT_SIGNALED), |
88 watchdog_thread_(std::move(watchdog_thread)), | 93 watchdog_thread_(std::move(watchdog_thread)), |
89 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), | 94 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), |
90 gpu_info_(gpu_info), | 95 gpu_info_(gpu_info), |
91 gpu_feature_info_(gpu_feature_info), | 96 gpu_feature_info_(gpu_feature_info), |
92 sync_point_manager_(nullptr), | 97 sync_point_manager_(nullptr), |
93 weak_ptr_factory_(this) { | 98 weak_ptr_factory_(this) { |
94 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); | 99 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
95 } | 100 } |
96 | 101 |
97 GpuService::~GpuService() { | 102 GpuService::~GpuService() { |
98 DCHECK(main_runner_->BelongsToCurrentThread()); | 103 DCHECK(main_runner_->BelongsToCurrentThread()); |
99 logging::SetLogMessageHandler(nullptr); | 104 logging::SetLogMessageHandler(nullptr); |
100 g_log_callback.Get() = | 105 g_log_callback.Get() = |
101 base::Callback<void(int, size_t, const std::string&)>(); | 106 base::Callback<void(int, size_t, const std::string&)>(); |
102 bindings_.CloseAllBindings(); | 107 if (bindings_) { |
| 108 io_runner_->PostTask(FROM_HERE, |
| 109 base::Bind(&DestroyBinding, base::Passed(&bindings_))); |
| 110 } |
103 media_gpu_channel_manager_.reset(); | 111 media_gpu_channel_manager_.reset(); |
104 gpu_channel_manager_.reset(); | 112 gpu_channel_manager_.reset(); |
105 owned_sync_point_manager_.reset(); | 113 owned_sync_point_manager_.reset(); |
106 | 114 |
107 // Signal this event before destroying the child process. That way all | 115 // Signal this event before destroying the child process. That way all |
108 // background threads can cleanup. | 116 // background threads can cleanup. |
109 // For example, in the renderer the RenderThread instances will be able to | 117 // For example, in the renderer the RenderThread instances will be able to |
110 // notice shutdown before the render process begins waiting for them to exit. | 118 // notice shutdown before the render process begins waiting for them to exit. |
111 shutdown_event_.Signal(); | 119 shutdown_event_.Signal(); |
112 } | 120 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 watchdog_thread()->AddPowerObserver(); | 175 watchdog_thread()->AddPowerObserver(); |
168 } | 176 } |
169 | 177 |
170 void GpuService::Bind(mojom::GpuServiceRequest request) { | 178 void GpuService::Bind(mojom::GpuServiceRequest request) { |
171 if (main_runner_->BelongsToCurrentThread()) { | 179 if (main_runner_->BelongsToCurrentThread()) { |
172 io_runner_->PostTask(FROM_HERE, | 180 io_runner_->PostTask(FROM_HERE, |
173 base::Bind(&GpuService::Bind, base::Unretained(this), | 181 base::Bind(&GpuService::Bind, base::Unretained(this), |
174 base::Passed(std::move(request)))); | 182 base::Passed(std::move(request)))); |
175 return; | 183 return; |
176 } | 184 } |
177 bindings_.AddBinding(this, std::move(request)); | 185 if (!bindings_) |
| 186 bindings_ = base::MakeUnique<mojo::BindingSet<mojom::GpuService>>(); |
| 187 bindings_->AddBinding(this, std::move(request)); |
178 } | 188 } |
179 | 189 |
180 void GpuService::RecordLogMessage(int severity, | 190 void GpuService::RecordLogMessage(int severity, |
181 size_t message_start, | 191 size_t message_start, |
182 const std::string& str) { | 192 const std::string& str) { |
183 // This can be run from any thread. | 193 // This can be run from any thread. |
184 std::string header = str.substr(0, message_start); | 194 std::string header = str.substr(0, message_start); |
185 std::string message = str.substr(message_start); | 195 std::string message = str.substr(message_start); |
186 (*gpu_host_)->RecordLogMessage(severity, header, message); | 196 (*gpu_host_)->RecordLogMessage(severity, header, message); |
187 } | 197 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 351 } |
342 | 352 |
343 void GpuService::EstablishGpuChannel( | 353 void GpuService::EstablishGpuChannel( |
344 int32_t client_id, | 354 int32_t client_id, |
345 uint64_t client_tracing_id, | 355 uint64_t client_tracing_id, |
346 bool is_gpu_host, | 356 bool is_gpu_host, |
347 const EstablishGpuChannelCallback& callback) { | 357 const EstablishGpuChannelCallback& callback) { |
348 if (io_runner_->BelongsToCurrentThread()) { | 358 if (io_runner_->BelongsToCurrentThread()) { |
349 EstablishGpuChannelCallback wrap_callback = base::Bind( | 359 EstablishGpuChannelCallback wrap_callback = base::Bind( |
350 [](scoped_refptr<base::SingleThreadTaskRunner> runner, | 360 [](scoped_refptr<base::SingleThreadTaskRunner> runner, |
351 const EstablishGpuChannelCallback& callback, | 361 const EstablishGpuChannelCallback& cb, |
352 mojo::ScopedMessagePipeHandle handle) { | 362 mojo::ScopedMessagePipeHandle handle) { |
353 runner->PostTask( | 363 runner->PostTask(FROM_HERE, |
354 FROM_HERE, base::Bind(callback, base::Passed(std::move(handle)))); | 364 base::Bind(cb, base::Passed(std::move(handle)))); |
355 }, | 365 }, |
356 io_runner_, callback); | 366 io_runner_, callback); |
357 main_runner_->PostTask( | 367 main_runner_->PostTask( |
358 FROM_HERE, | 368 FROM_HERE, |
359 base::Bind(&GpuService::EstablishGpuChannel, weak_ptr_, client_id, | 369 base::Bind(&GpuService::EstablishGpuChannel, weak_ptr_, client_id, |
360 client_tracing_id, is_gpu_host, wrap_callback)); | 370 client_tracing_id, is_gpu_host, wrap_callback)); |
361 return; | 371 return; |
362 } | 372 } |
363 | 373 |
364 if (!gpu_channel_manager_) { | 374 if (!gpu_channel_manager_) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 495 |
486 void GpuService::Stop(const StopCallback& callback) { | 496 void GpuService::Stop(const StopCallback& callback) { |
487 DCHECK(io_runner_->BelongsToCurrentThread()); | 497 DCHECK(io_runner_->BelongsToCurrentThread()); |
488 main_runner_->PostTaskAndReply(FROM_HERE, base::Bind([] { | 498 main_runner_->PostTaskAndReply(FROM_HERE, base::Bind([] { |
489 base::MessageLoop::current()->QuitWhenIdle(); | 499 base::MessageLoop::current()->QuitWhenIdle(); |
490 }), | 500 }), |
491 callback); | 501 callback); |
492 } | 502 } |
493 | 503 |
494 } // namespace ui | 504 } // namespace ui |
OLD | NEW |