| 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 "base/threading/thread_task_runner_handle.h" |
| 10 #include "build/build_config.h" |
| 10 #include "components/mus/common/gpu_type_converters.h" | 11 #include "components/mus/common/gpu_type_converters.h" |
| 11 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" | 12 #include "components/mus/common/mojo_gpu_memory_buffer_manager.h" |
| 12 #include "components/mus/common/switches.h" | 13 #include "components/mus/common/switches.h" |
| 13 #include "components/mus/public/interfaces/gpu_service.mojom.h" | 14 #include "components/mus/public/interfaces/gpu_service.mojom.h" |
| 14 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" | 15 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" |
| 15 #include "mojo/public/cpp/system/platform_handle.h" | 16 #include "mojo/public/cpp/system/platform_handle.h" |
| 16 #include "services/shell/public/cpp/connector.h" | 17 #include "services/shell/public/cpp/connector.h" |
| 17 | 18 |
| 18 namespace mus { | 19 namespace mus { |
| 19 | 20 |
| 20 GpuService::GpuService() | 21 GpuService::GpuService() |
| 21 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 22 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 22 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 23 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 23 base::WaitableEvent::InitialState::NOT_SIGNALED), | 24 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 24 io_thread_("GPUIOThread"), | 25 io_thread_("GPUIOThread"), |
| 25 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { | 26 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) { |
| 26 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 27 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 27 thread_options.priority = base::ThreadPriority::NORMAL; | 28 thread_options.priority = base::ThreadPriority::NORMAL; |
| 28 CHECK(io_thread_.StartWithOptions(thread_options)); | 29 CHECK(io_thread_.StartWithOptions(thread_options)); |
| 29 } | 30 } |
| 30 | 31 |
| 31 GpuService::~GpuService() {} | 32 GpuService::~GpuService() {} |
| 32 | 33 |
| 33 // static | 34 // static |
| 34 bool GpuService::UseChromeGpuCommandBuffer() { | 35 bool GpuService::UseChromeGpuCommandBuffer() { |
| 35 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 36 // TODO(penghuang): Kludge: Running with Chrome GPU command buffer by default |
| 36 switches::kUseChromeGpuCommandBufferInMus); | 37 // breaks unit tests on Windows |
| 38 #if defined(OS_WIN) |
| 39 return false; |
| 40 #else |
| 41 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 42 switches::kUseMojoGpuCommandBufferInMus); |
| 43 #endif |
| 37 } | 44 } |
| 38 | 45 |
| 39 // static | 46 // static |
| 40 GpuService* GpuService::GetInstance() { | 47 GpuService* GpuService::GetInstance() { |
| 41 return base::Singleton<GpuService, | 48 return base::Singleton<GpuService, |
| 42 base::LeakySingletonTraits<GpuService>>::get(); | 49 base::LeakySingletonTraits<GpuService>>::get(); |
| 43 } | 50 } |
| 44 | 51 |
| 45 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannel( | 52 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannel( |
| 46 shell::Connector* connector) { | 53 shell::Connector* connector) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 107 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
| 101 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 108 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
| 102 if (result != MOJO_RESULT_OK) | 109 if (result != MOJO_RESULT_OK) |
| 103 return nullptr; | 110 return nullptr; |
| 104 DCHECK_EQ(shared_memory_size, size); | 111 DCHECK_EQ(shared_memory_size, size); |
| 105 | 112 |
| 106 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 113 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
| 107 } | 114 } |
| 108 | 115 |
| 109 } // namespace mus | 116 } // namespace mus |
| OLD | NEW |