Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: services/ui/common/gpu_service.cc

Issue 2233003003: services/ui: Inject GpuService instance where needed, instead of singleton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/common/gpu_service.h ('k') | services/ui/demo/mus_demo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10 matching lines...) Expand all
21 namespace { 21 namespace {
22 22
23 void PostTask(scoped_refptr<base::SingleThreadTaskRunner> runner, 23 void PostTask(scoped_refptr<base::SingleThreadTaskRunner> runner,
24 const tracked_objects::Location& from_here, 24 const tracked_objects::Location& from_here,
25 const gpu::GpuChannelEstablishedCallback& callback, 25 const gpu::GpuChannelEstablishedCallback& callback,
26 scoped_refptr<gpu::GpuChannelHost> established_channel_host) { 26 scoped_refptr<gpu::GpuChannelHost> established_channel_host) {
27 runner->PostTask(from_here, 27 runner->PostTask(from_here,
28 base::Bind(callback, std::move(established_channel_host))); 28 base::Bind(callback, std::move(established_channel_host)));
29 } 29 }
30 30
31 GpuService* g_gpu_service = nullptr;
32 } 31 }
33 32
34 GpuService::GpuService(shell::Connector* connector) 33 GpuService::GpuService(shell::Connector* connector)
35 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 34 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
36 connector_(connector), 35 connector_(connector),
37 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 36 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
38 base::WaitableEvent::InitialState::NOT_SIGNALED), 37 base::WaitableEvent::InitialState::NOT_SIGNALED),
39 io_thread_("GPUIOThread"), 38 io_thread_("GPUIOThread"),
40 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager), 39 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager),
41 is_establishing_(false), 40 is_establishing_(false),
42 establishing_condition_(&lock_) { 41 establishing_condition_(&lock_) {
43 DCHECK(main_task_runner_); 42 DCHECK(main_task_runner_);
44 DCHECK(connector_); 43 DCHECK(connector_);
45 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); 44 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
46 thread_options.priority = base::ThreadPriority::NORMAL; 45 thread_options.priority = base::ThreadPriority::NORMAL;
47 CHECK(io_thread_.StartWithOptions(thread_options)); 46 CHECK(io_thread_.StartWithOptions(thread_options));
48 } 47 }
49 48
50 GpuService::~GpuService() { 49 GpuService::~GpuService() {
51 DCHECK(IsMainThread()); 50 DCHECK(IsMainThread());
52 DCHECK_EQ(this, g_gpu_service);
53 if (gpu_channel_) 51 if (gpu_channel_)
54 gpu_channel_->DestroyChannel(); 52 gpu_channel_->DestroyChannel();
55 g_gpu_service = nullptr;
56 } 53 }
57 54
58 // static 55 // static
59 std::unique_ptr<GpuService> GpuService::Initialize( 56 std::unique_ptr<GpuService> GpuService::Initialize(
60 shell::Connector* connector) { 57 shell::Connector* connector) {
61 DCHECK(!g_gpu_service); 58 return base::WrapUnique(new GpuService(connector));
62 g_gpu_service = new GpuService(connector);
63 return base::WrapUnique(g_gpu_service);
64 }
65
66 // static
67 GpuService* GpuService::GetInstance() {
68 DCHECK(g_gpu_service);
69 return g_gpu_service;
70 } 59 }
71 60
72 void GpuService::EstablishGpuChannel( 61 void GpuService::EstablishGpuChannel(
73 const gpu::GpuChannelEstablishedCallback& callback) { 62 const gpu::GpuChannelEstablishedCallback& callback) {
74 base::AutoLock auto_lock(lock_); 63 base::AutoLock auto_lock(lock_);
75 auto runner = base::ThreadTaskRunnerHandle::Get(); 64 auto runner = base::ThreadTaskRunnerHandle::Get();
76 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannelLocked(); 65 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannelLocked();
77 if (channel) { 66 if (channel) {
78 PostTask(runner, FROM_HERE, callback, std::move(channel)); 67 PostTask(runner, FROM_HERE, callback, std::move(channel));
79 return; 68 return;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 MojoResult result = mojo::UnwrapSharedMemoryHandle( 217 MojoResult result = mojo::UnwrapSharedMemoryHandle(
229 std::move(handle), &platform_handle, &shared_memory_size, &readonly); 218 std::move(handle), &platform_handle, &shared_memory_size, &readonly);
230 if (result != MOJO_RESULT_OK) 219 if (result != MOJO_RESULT_OK)
231 return nullptr; 220 return nullptr;
232 DCHECK_EQ(shared_memory_size, size); 221 DCHECK_EQ(shared_memory_size, size);
233 222
234 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); 223 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
235 } 224 }
236 225
237 } // namespace ui 226 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/common/gpu_service.h ('k') | services/ui/demo/mus_demo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698