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); |
50 if (gpu_channel_) | 51 if (gpu_channel_) |
51 gpu_channel_->DestroyChannel(); | 52 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; | |
64 g_gpu_service = nullptr; | 53 g_gpu_service = nullptr; |
65 } | 54 } |
66 | 55 |
67 // static | 56 // 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 |
68 GpuService* GpuService::GetInstance() { | 65 GpuService* GpuService::GetInstance() { |
69 DCHECK(g_gpu_service); | 66 DCHECK(g_gpu_service); |
70 return g_gpu_service; | 67 return g_gpu_service; |
71 } | 68 } |
72 | 69 |
73 void GpuService::EstablishGpuChannel(const base::Closure& callback) { | 70 void GpuService::EstablishGpuChannel(const base::Closure& callback) { |
74 base::AutoLock auto_lock(lock_); | 71 base::AutoLock auto_lock(lock_); |
75 auto runner = base::ThreadTaskRunnerHandle::Get(); | 72 auto runner = base::ThreadTaskRunnerHandle::Get(); |
76 if (GetGpuChannelLocked()) { | 73 if (GetGpuChannelLocked()) { |
77 runner->PostTask(FROM_HERE, callback); | 74 runner->PostTask(FROM_HERE, callback); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 MojoResult result = mojo::UnwrapSharedMemoryHandle( | 229 MojoResult result = mojo::UnwrapSharedMemoryHandle( |
233 std::move(handle), &platform_handle, &shared_memory_size, &readonly); | 230 std::move(handle), &platform_handle, &shared_memory_size, &readonly); |
234 if (result != MOJO_RESULT_OK) | 231 if (result != MOJO_RESULT_OK) |
235 return nullptr; | 232 return nullptr; |
236 DCHECK_EQ(shared_memory_size, size); | 233 DCHECK_EQ(shared_memory_size, size); |
237 | 234 |
238 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); | 235 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); |
239 } | 236 } |
240 | 237 |
241 } // namespace ui | 238 } // namespace ui |
OLD | NEW |