| 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/common/gpu_service.h" | 5 #include "components/mus/common/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 "components/mus/common/gpu_type_converters.h" | 10 #include "components/mus/common/gpu_type_converters.h" |
| 10 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" | 11 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" |
| 11 #include "components/mus/common/switches.h" | 12 #include "components/mus/common/switches.h" |
| 12 #include "components/mus/public/interfaces/gpu_service.mojom.h" | 13 #include "components/mus/public/interfaces/gpu_service.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" | 14 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
| 14 #include "mojo/public/cpp/system/platform_handle.h" | 15 #include "mojo/public/cpp/system/platform_handle.h" |
| 15 #include "services/shell/public/cpp/connector.h" | 16 #include "services/shell/public/cpp/connector.h" |
| 16 | 17 |
| 17 namespace mus { | 18 namespace mus { |
| 18 | 19 |
| 19 GpuService::GpuService() | 20 GpuService::GpuService() |
| 20 : main_message_loop_(base::MessageLoop::current()), | 21 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 21 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 22 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 22 base::WaitableEvent::InitialState::NOT_SIGNALED), | 23 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 23 io_thread_("GPUIOThread"), | 24 io_thread_("GPUIOThread"), |
| 24 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { | 25 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { |
| 25 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 26 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 26 thread_options.priority = base::ThreadPriority::NORMAL; | 27 thread_options.priority = base::ThreadPriority::NORMAL; |
| 27 CHECK(io_thread_.StartWithOptions(thread_options)); | 28 CHECK(io_thread_.StartWithOptions(thread_options)); |
| 28 } | 29 } |
| 29 | 30 |
| 30 GpuService::~GpuService() {} | 31 GpuService::~GpuService() {} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 72 } |
| 72 | 73 |
| 73 // TODO(penghuang): Get the real gpu info from mus. | 74 // TODO(penghuang): Get the real gpu info from mus. |
| 74 gpu_channel_ = gpu::GpuChannelHost::Create( | 75 gpu_channel_ = gpu::GpuChannelHost::Create( |
| 75 this, client_id, gpu::GPUInfo(), channel_handle.To<IPC::ChannelHandle>(), | 76 this, client_id, gpu::GPUInfo(), channel_handle.To<IPC::ChannelHandle>(), |
| 76 &shutdown_event_, gpu_memory_buffer_manager_.get()); | 77 &shutdown_event_, gpu_memory_buffer_manager_.get()); |
| 77 return gpu_channel_; | 78 return gpu_channel_; |
| 78 } | 79 } |
| 79 | 80 |
| 80 bool GpuService::IsMainThread() { | 81 bool GpuService::IsMainThread() { |
| 81 return base::MessageLoop::current() == main_message_loop_; | 82 return main_task_runner_->BelongsToCurrentThread(); |
| 82 } | 83 } |
| 83 | 84 |
| 84 scoped_refptr<base::SingleThreadTaskRunner> | 85 scoped_refptr<base::SingleThreadTaskRunner> |
| 85 GpuService::GetIOThreadTaskRunner() { | 86 GpuService::GetIOThreadTaskRunner() { |
| 86 return io_thread_.task_runner(); | 87 return io_thread_.task_runner(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( | 90 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( |
| 90 size_t size) { | 91 size_t size) { |
| 91 mojo::ScopedSharedBufferHandle handle = | 92 mojo::ScopedSharedBufferHandle handle = |
| 92 mojo::SharedBufferHandle::Create(size); | 93 mojo::SharedBufferHandle::Create(size); |
| 93 if (!handle.is_valid()) | 94 if (!handle.is_valid()) |
| 94 return nullptr; | 95 return nullptr; |
| 95 | 96 |
| 96 base::SharedMemoryHandle platform_handle; | 97 base::SharedMemoryHandle platform_handle; |
| 97 size_t shared_memory_size; | 98 size_t shared_memory_size; |
| 98 bool readonly; | 99 bool readonly; |
| 99 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 100 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 100 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 101 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
| 101 if (result != MOJO_RESULT_OK) | 102 if (result != MOJO_RESULT_OK) |
| 102 return nullptr; | 103 return nullptr; |
| 103 DCHECK_EQ(shared_memory_size, size); | 104 DCHECK_EQ(shared_memory_size, size); |
| 104 | 105 |
| 105 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 106 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
| 106 } | 107 } |
| 107 | 108 |
| 108 } // namespace mus | 109 } // namespace mus |
| OLD | NEW |