| 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" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 base::Bind(callback, std::move(established_channel_host))); | 28 base::Bind(callback, std::move(established_channel_host))); |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 GpuService::GpuService(shell::Connector* connector) | 33 GpuService::GpuService(shell::Connector* connector) |
| 34 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 34 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 35 connector_(connector), | 35 connector_(connector), |
| 36 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 36 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 37 base::WaitableEvent::InitialState::NOT_SIGNALED), | 37 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 38 io_thread_("GPUIOThread"), | |
| 39 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager), | 38 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager), |
| 40 is_establishing_(false), | 39 is_establishing_(false), |
| 41 establishing_condition_(&lock_) { | 40 establishing_condition_(&lock_) { |
| 42 DCHECK(main_task_runner_); | 41 DCHECK(main_task_runner_); |
| 43 DCHECK(connector_); | 42 DCHECK(connector_); |
| 44 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | |
| 45 thread_options.priority = base::ThreadPriority::NORMAL; | |
| 46 CHECK(io_thread_.StartWithOptions(thread_options)); | |
| 47 } | 43 } |
| 48 | 44 |
| 49 GpuService::~GpuService() { | 45 GpuService::~GpuService() { |
| 50 DCHECK(IsMainThread()); | 46 DCHECK(IsMainThread()); |
| 51 if (gpu_channel_) | 47 if (gpu_channel_) |
| 52 gpu_channel_->DestroyChannel(); | 48 gpu_channel_->DestroyChannel(); |
| 53 } | 49 } |
| 54 | 50 |
| 55 // static | 51 // static |
| 56 std::unique_ptr<GpuService> GpuService::Initialize( | 52 std::unique_ptr<GpuService> GpuService::Initialize( |
| 57 shell::Connector* connector) { | 53 shell::Connector* connector) { |
| 58 return base::WrapUnique(new GpuService(connector)); | 54 return base::WrapUnique(new GpuService(connector)); |
| 59 } | 55 } |
| 60 | 56 |
| 57 void GpuService::SetIOThreadTaskRunner( |
| 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 59 DCHECK(!io_task_runner_); |
| 60 io_task_runner_ = std::move(task_runner); |
| 61 } |
| 62 |
| 61 void GpuService::EstablishGpuChannel( | 63 void GpuService::EstablishGpuChannel( |
| 62 const gpu::GpuChannelEstablishedCallback& callback) { | 64 const gpu::GpuChannelEstablishedCallback& callback) { |
| 63 base::AutoLock auto_lock(lock_); | 65 base::AutoLock auto_lock(lock_); |
| 64 auto runner = base::ThreadTaskRunnerHandle::Get(); | 66 auto runner = base::ThreadTaskRunnerHandle::Get(); |
| 65 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannelLocked(); | 67 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannelLocked(); |
| 66 if (channel) { | 68 if (channel) { |
| 67 PostTask(runner, FROM_HERE, callback, std::move(channel)); | 69 PostTask(runner, FROM_HERE, callback, std::move(channel)); |
| 68 return; | 70 return; |
| 69 } | 71 } |
| 70 establish_callbacks_.push_back( | 72 establish_callbacks_.push_back( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 i.Run(gpu_channel_); | 200 i.Run(gpu_channel_); |
| 199 establish_callbacks_.clear(); | 201 establish_callbacks_.clear(); |
| 200 } | 202 } |
| 201 | 203 |
| 202 bool GpuService::IsMainThread() { | 204 bool GpuService::IsMainThread() { |
| 203 return main_task_runner_->BelongsToCurrentThread(); | 205 return main_task_runner_->BelongsToCurrentThread(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 scoped_refptr<base::SingleThreadTaskRunner> | 208 scoped_refptr<base::SingleThreadTaskRunner> |
| 207 GpuService::GetIOThreadTaskRunner() { | 209 GpuService::GetIOThreadTaskRunner() { |
| 208 return io_thread_.task_runner(); | 210 if (!io_task_runner_) { |
| 211 io_thread_.reset(new base::Thread("GPUIOThread")); |
| 212 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 213 thread_options.priority = base::ThreadPriority::NORMAL; |
| 214 CHECK(io_thread_->StartWithOptions(thread_options)); |
| 215 io_task_runner_ = io_thread_->task_runner(); |
| 216 } |
| 217 return io_task_runner_; |
| 209 } | 218 } |
| 210 | 219 |
| 211 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( | 220 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( |
| 212 size_t size) { | 221 size_t size) { |
| 213 mojo::ScopedSharedBufferHandle handle = | 222 mojo::ScopedSharedBufferHandle handle = |
| 214 mojo::SharedBufferHandle::Create(size); | 223 mojo::SharedBufferHandle::Create(size); |
| 215 if (!handle.is_valid()) | 224 if (!handle.is_valid()) |
| 216 return nullptr; | 225 return nullptr; |
| 217 | 226 |
| 218 base::SharedMemoryHandle platform_handle; | 227 base::SharedMemoryHandle platform_handle; |
| 219 size_t shared_memory_size; | 228 size_t shared_memory_size; |
| 220 bool readonly; | 229 bool readonly; |
| 221 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 230 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 222 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 231 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
| 223 if (result != MOJO_RESULT_OK) | 232 if (result != MOJO_RESULT_OK) |
| 224 return nullptr; | 233 return nullptr; |
| 225 DCHECK_EQ(shared_memory_size, size); | 234 DCHECK_EQ(shared_memory_size, size); |
| 226 | 235 |
| 227 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 236 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
| 228 } | 237 } |
| 229 | 238 |
| 230 } // namespace ui | 239 } // namespace ui |
| OLD | NEW |