| 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/gpu/gpu_service_mus.h" | 5 #include "components/mus/gpu/gpu_service_mus.h" |
| 6 | 6 |
| 7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 void EstablishGpuChannelDone( | 43 void EstablishGpuChannelDone( |
| 44 int client_id, | 44 int client_id, |
| 45 const IPC::ChannelHandle* channel_handle, | 45 const IPC::ChannelHandle* channel_handle, |
| 46 const GpuServiceMus::EstablishGpuChannelCallback& callback) { | 46 const GpuServiceMus::EstablishGpuChannelCallback& callback) { |
| 47 callback.Run(channel_handle ? client_id : -1, *channel_handle); | 47 callback.Run(channel_handle ? client_id : -1, *channel_handle); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 GpuServiceMus::GpuServiceMus() | 51 GpuServiceMus::GpuServiceMus() |
| 52 : next_client_id_(kLocalGpuChannelClientId), | 52 : next_client_id_(kLocalGpuChannelClientId), |
| 53 main_message_loop_(base::MessageLoop::current()), | 53 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 54 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 55 base::WaitableEvent::InitialState::NOT_SIGNALED), | 55 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 56 gpu_thread_("GpuThread"), | 56 gpu_thread_("GpuThread"), |
| 57 io_thread_("GpuIOThread") { | 57 io_thread_("GpuIOThread") { |
| 58 Initialize(); | 58 Initialize(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 GpuServiceMus::~GpuServiceMus() { | 61 GpuServiceMus::~GpuServiceMus() { |
| 62 // Signal this event before destroying the child process. That way all | 62 // Signal this event before destroying the child process. That way all |
| 63 // background threads can cleanup. | 63 // background threads can cleanup. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 IPC::ChannelHandle* channel_handle) { | 253 IPC::ChannelHandle* channel_handle) { |
| 254 if (gpu_channel_manager_) { | 254 if (gpu_channel_manager_) { |
| 255 *channel_handle = gpu_channel_manager_->EstablishChannel( | 255 *channel_handle = gpu_channel_manager_->EstablishChannel( |
| 256 client_id, client_tracing_id, preempts, allow_view_command_buffers, | 256 client_id, client_tracing_id, preempts, allow_view_command_buffers, |
| 257 allow_real_time_streams); | 257 allow_real_time_streams); |
| 258 media_service_->AddChannel(client_id); | 258 media_service_->AddChannel(client_id); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool GpuServiceMus::IsMainThread() { | 262 bool GpuServiceMus::IsMainThread() { |
| 263 return main_message_loop_ == base::MessageLoop::current(); | 263 return main_task_runner_->BelongsToCurrentThread(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 scoped_refptr<base::SingleThreadTaskRunner> | 266 scoped_refptr<base::SingleThreadTaskRunner> |
| 267 GpuServiceMus::GetIOThreadTaskRunner() { | 267 GpuServiceMus::GetIOThreadTaskRunner() { |
| 268 return io_thread_.task_runner(); | 268 return io_thread_.task_runner(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory( | 271 std::unique_ptr<base::SharedMemory> GpuServiceMus::AllocateSharedMemory( |
| 272 size_t size) { | 272 size_t size) { |
| 273 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); | 273 std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory()); |
| 274 if (!shm->CreateAnonymous(size)) | 274 if (!shm->CreateAnonymous(size)) |
| 275 return std::unique_ptr<base::SharedMemory>(); | 275 return std::unique_ptr<base::SharedMemory>(); |
| 276 return shm; | 276 return shm; |
| 277 } | 277 } |
| 278 | 278 |
| 279 // static | 279 // static |
| 280 GpuServiceMus* GpuServiceMus::GetInstance() { | 280 GpuServiceMus* GpuServiceMus::GetInstance() { |
| 281 return base::Singleton<GpuServiceMus, | 281 return base::Singleton<GpuServiceMus, |
| 282 base::LeakySingletonTraits<GpuServiceMus>>::get(); | 282 base::LeakySingletonTraits<GpuServiceMus>>::get(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 } // namespace mus | 285 } // namespace mus |
| OLD | NEW |