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

Side by Side Diff: services/ui/public/cpp/gpu_service.cc

Issue 2249413004: services/ui: Allow injecting the IO thread task runner for gpu channel. (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/public/cpp/gpu_service.h ('k') | ui/views/mus/window_manager_connection.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/public/cpp/gpu_service.h" 5 #include "services/ui/public/cpp/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 17 matching lines...) Expand all
28 base::Bind(callback, std::move(established_channel_host))); 28 base::Bind(callback, std::move(established_channel_host)));
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 GpuService::GpuService(shell::Connector* connector) 33 GpuService::GpuService(shell::Connector* connector)
34 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 34 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
35 connector_(connector), 35 connector_(connector),
36 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 36 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
37 base::WaitableEvent::InitialState::NOT_SIGNALED), 37 base::WaitableEvent::InitialState::NOT_SIGNALED),
38 io_thread_("GPUIOThread"),
39 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager), 38 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager),
40 is_establishing_(false), 39 is_establishing_(false),
41 establishing_condition_(&lock_) { 40 establishing_condition_(&lock_) {
42 DCHECK(main_task_runner_); 41 DCHECK(main_task_runner_);
43 DCHECK(connector_); 42 DCHECK(connector_);
44 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
45 thread_options.priority = base::ThreadPriority::NORMAL;
46 CHECK(io_thread_.StartWithOptions(thread_options));
47 } 43 }
48 44
49 GpuService::~GpuService() { 45 GpuService::~GpuService() {
50 DCHECK(IsMainThread()); 46 DCHECK(IsMainThread());
51 if (gpu_channel_) 47 if (gpu_channel_)
52 gpu_channel_->DestroyChannel(); 48 gpu_channel_->DestroyChannel();
53 } 49 }
54 50
55 // static 51 // static
56 std::unique_ptr<GpuService> GpuService::Initialize( 52 std::unique_ptr<GpuService> GpuService::Create(
57 shell::Connector* connector) { 53 shell::Connector* connector) {
58 return base::WrapUnique(new GpuService(connector)); 54 return base::WrapUnique(new GpuService(connector));
59 } 55 }
60 56
57 void GpuService::SetIOThreadTaskRunner(
58 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) {
59 DCHECK(!io_task_runner_)
piman 2016/08/22 19:42:03 Would it make sense instead to pass the task runne
sadrul 2016/08/22 20:05:54 Ah, interesting. Yes, Fady brought up the issue ea
piman 2016/08/22 20:31:50 I feel like plumbing the task runner through Windo
sadrul 2016/08/22 21:20:38 Agreed. And contrary to popular meme, obviously co
60 << "The task runner cannot be changed once set.";
61 DCHECK(io_task_runner);
62 io_task_runner_ = std::move(io_task_runner);
63 }
64
61 void GpuService::EstablishGpuChannel( 65 void GpuService::EstablishGpuChannel(
62 const gpu::GpuChannelEstablishedCallback& callback) { 66 const gpu::GpuChannelEstablishedCallback& callback) {
63 base::AutoLock auto_lock(lock_); 67 base::AutoLock auto_lock(lock_);
64 auto runner = base::ThreadTaskRunnerHandle::Get(); 68 auto runner = base::ThreadTaskRunnerHandle::Get();
65 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannelLocked(); 69 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannelLocked();
66 if (channel) { 70 if (channel) {
67 PostTask(runner, FROM_HERE, callback, std::move(channel)); 71 PostTask(runner, FROM_HERE, callback, std::move(channel));
68 return; 72 return;
69 } 73 }
70 establish_callbacks_.push_back( 74 establish_callbacks_.push_back(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 i.Run(gpu_channel_); 202 i.Run(gpu_channel_);
199 establish_callbacks_.clear(); 203 establish_callbacks_.clear();
200 } 204 }
201 205
202 bool GpuService::IsMainThread() { 206 bool GpuService::IsMainThread() {
203 return main_task_runner_->BelongsToCurrentThread(); 207 return main_task_runner_->BelongsToCurrentThread();
204 } 208 }
205 209
206 scoped_refptr<base::SingleThreadTaskRunner> 210 scoped_refptr<base::SingleThreadTaskRunner>
207 GpuService::GetIOThreadTaskRunner() { 211 GpuService::GetIOThreadTaskRunner() {
208 return io_thread_.task_runner(); 212 if (!io_task_runner_) {
213 io_thread_.reset(new base::Thread("GPUIOThread"));
214 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
215 thread_options.priority = base::ThreadPriority::NORMAL;
216 CHECK(io_thread_->StartWithOptions(thread_options));
217 io_task_runner_ = io_thread_->task_runner();
218 }
219 return io_task_runner_;
209 } 220 }
210 221
211 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory( 222 std::unique_ptr<base::SharedMemory> GpuService::AllocateSharedMemory(
212 size_t size) { 223 size_t size) {
213 mojo::ScopedSharedBufferHandle handle = 224 mojo::ScopedSharedBufferHandle handle =
214 mojo::SharedBufferHandle::Create(size); 225 mojo::SharedBufferHandle::Create(size);
215 if (!handle.is_valid()) 226 if (!handle.is_valid())
216 return nullptr; 227 return nullptr;
217 228
218 base::SharedMemoryHandle platform_handle; 229 base::SharedMemoryHandle platform_handle;
219 size_t shared_memory_size; 230 size_t shared_memory_size;
220 bool readonly; 231 bool readonly;
221 MojoResult result = mojo::UnwrapSharedMemoryHandle( 232 MojoResult result = mojo::UnwrapSharedMemoryHandle(
222 std::move(handle), &platform_handle, &shared_memory_size, &readonly); 233 std::move(handle), &platform_handle, &shared_memory_size, &readonly);
223 if (result != MOJO_RESULT_OK) 234 if (result != MOJO_RESULT_OK)
224 return nullptr; 235 return nullptr;
225 DCHECK_EQ(shared_memory_size, size); 236 DCHECK_EQ(shared_memory_size, size);
226 237
227 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); 238 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
228 } 239 }
229 240
230 } // namespace ui 241 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/gpu_service.h ('k') | ui/views/mus/window_manager_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698