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/common/gpu_service.h" | 5 #include "services/ui/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 "build/build_config.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 establishing_condition_(&lock_) { | 40 establishing_condition_(&lock_) { |
41 DCHECK(main_task_runner_); | 41 DCHECK(main_task_runner_); |
42 DCHECK(connector_); | 42 DCHECK(connector_); |
43 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 43 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
44 thread_options.priority = base::ThreadPriority::NORMAL; | 44 thread_options.priority = base::ThreadPriority::NORMAL; |
45 CHECK(io_thread_.StartWithOptions(thread_options)); | 45 CHECK(io_thread_.StartWithOptions(thread_options)); |
46 } | 46 } |
47 | 47 |
48 GpuService::~GpuService() { | 48 GpuService::~GpuService() { |
49 DCHECK(IsMainThread()); | 49 DCHECK(IsMainThread()); |
50 DCHECK_EQ(this, g_gpu_service); | |
51 if (gpu_channel_) | 50 if (gpu_channel_) |
52 gpu_channel_->DestroyChannel(); | 51 gpu_channel_->DestroyChannel(); |
| 52 } |
| 53 |
| 54 // static |
| 55 void GpuService::Initialize(shell::Connector* connector) { |
| 56 DCHECK(!g_gpu_service); |
| 57 g_gpu_service = new GpuService(connector); |
| 58 } |
| 59 |
| 60 // static |
| 61 void GpuService::Terminate() { |
| 62 DCHECK(g_gpu_service); |
| 63 delete g_gpu_service; |
53 g_gpu_service = nullptr; | 64 g_gpu_service = nullptr; |
54 } | 65 } |
55 | 66 |
56 // static | 67 // static |
57 std::unique_ptr<GpuService> GpuService::Initialize( | |
58 shell::Connector* connector) { | |
59 DCHECK(!g_gpu_service); | |
60 g_gpu_service = new GpuService(connector); | |
61 return base::WrapUnique(g_gpu_service); | |
62 } | |
63 | |
64 // static | |
65 GpuService* GpuService::GetInstance() { | 68 GpuService* GpuService::GetInstance() { |
66 DCHECK(g_gpu_service); | 69 DCHECK(g_gpu_service); |
67 return g_gpu_service; | 70 return g_gpu_service; |
68 } | 71 } |
69 | 72 |
70 void GpuService::EstablishGpuChannel(const base::Closure& callback) { | 73 void GpuService::EstablishGpuChannel(const base::Closure& callback) { |
71 base::AutoLock auto_lock(lock_); | 74 base::AutoLock auto_lock(lock_); |
72 auto runner = base::ThreadTaskRunnerHandle::Get(); | 75 auto runner = base::ThreadTaskRunnerHandle::Get(); |
73 if (GetGpuChannelLocked()) { | 76 if (GetGpuChannelLocked()) { |
74 runner->PostTask(FROM_HERE, callback); | 77 runner->PostTask(FROM_HERE, callback); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 232 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
230 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 233 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
231 if (result != MOJO_RESULT_OK) | 234 if (result != MOJO_RESULT_OK) |
232 return nullptr; | 235 return nullptr; |
233 DCHECK_EQ(shared_memory_size, size); | 236 DCHECK_EQ(shared_memory_size, size); |
234 | 237 |
235 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 238 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
236 } | 239 } |
237 | 240 |
238 } // namespace ui | 241 } // namespace ui |
OLD | NEW |