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

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

Issue 2448983003: gpu: Refactor memory buffer handling code out of content.
Patch Set: . Created 4 years, 1 month 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
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"
11 #include "mojo/public/cpp/bindings/sync_call_restrictions.h" 11 #include "mojo/public/cpp/bindings/sync_call_restrictions.h"
12 #include "mojo/public/cpp/system/platform_handle.h" 12 #include "mojo/public/cpp/system/platform_handle.h"
13 #include "services/service_manager/public/cpp/connector.h" 13 #include "services/service_manager/public/cpp/connector.h"
14 #include "services/ui/common/switches.h" 14 #include "services/ui/common/switches.h"
15 #include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h" 15 #include "services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h"
16 #include "services/ui/public/interfaces/gpu_service.mojom.h" 16 #include "services/ui/public/interfaces/gpu_service.mojom.h"
17 17
18 namespace ui { 18 namespace ui {
19 19
20 GpuService::GpuService(service_manager::Connector* connector, 20 GpuService::GpuService(service_manager::Connector* connector,
21 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 21 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
22 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), 22 : main_task_runner_(base::ThreadTaskRunnerHandle::Get()),
23 io_task_runner_(std::move(task_runner)), 23 io_task_runner_(std::move(task_runner)),
24 connector_(connector), 24 connector_(connector),
25 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 25 shutdown_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
26 base::WaitableEvent::InitialState::NOT_SIGNALED), 26 base::WaitableEvent::InitialState::NOT_SIGNALED) {
27 gpu_memory_buffer_manager_(new MojoGpuMemoryBufferManager) {
28 DCHECK(main_task_runner_); 27 DCHECK(main_task_runner_);
29 DCHECK(connector_); 28 DCHECK(connector_);
30 if (!io_task_runner_) { 29 if (!io_task_runner_) {
31 io_thread_.reset(new base::Thread("GPUIOThread")); 30 io_thread_.reset(new base::Thread("GPUIOThread"));
32 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); 31 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
33 thread_options.priority = base::ThreadPriority::NORMAL; 32 thread_options.priority = base::ThreadPriority::NORMAL;
34 CHECK(io_thread_->StartWithOptions(thread_options)); 33 CHECK(io_thread_->StartWithOptions(thread_options));
35 io_task_runner_ = io_thread_->task_runner(); 34 io_task_runner_ = io_thread_->task_runner();
36 } 35 }
37 } 36 }
38 37
39 GpuService::~GpuService() { 38 GpuService::~GpuService() {
40 DCHECK(IsMainThread()); 39 DCHECK(IsMainThread());
41 for (const auto& callback : establish_callbacks_) 40 for (const auto& callback : establish_callbacks_)
42 callback.Run(nullptr); 41 callback.Run(nullptr);
43 shutdown_event_.Signal(); 42 shutdown_event_.Signal();
44 if (gpu_channel_) 43 if (gpu_channel_)
45 gpu_channel_->DestroyChannel(); 44 gpu_channel_->DestroyChannel();
46 } 45 }
47 46
48 // static 47 // static
49 std::unique_ptr<GpuService> GpuService::Create( 48 std::unique_ptr<GpuService> GpuService::Create(
50 service_manager::Connector* connector, 49 service_manager::Connector* connector,
51 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 50 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
52 return base::WrapUnique(new GpuService(connector, std::move(task_runner))); 51 auto service =
52 base::WrapUnique(new GpuService(connector, std::move(task_runner)));
53 service->SetUpConnection();
54 return service;
55 }
56
57 void GpuService::SetUpConnection() {
58 connector_->ConnectToInterface("service:ui", &gpu_service_);
59 gpu_memory_buffer_manager_ =
60 base::MakeUnique<MojoGpuMemoryBufferManager>(gpu_service_.get());
53 } 61 }
54 62
55 void GpuService::EstablishGpuChannel( 63 void GpuService::EstablishGpuChannel(
56 const gpu::GpuChannelEstablishedCallback& callback) { 64 const gpu::GpuChannelEstablishedCallback& callback) {
57 DCHECK(IsMainThread()); 65 DCHECK(IsMainThread());
58 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel(); 66 scoped_refptr<gpu::GpuChannelHost> channel = GetGpuChannel();
59 if (channel) { 67 if (channel) {
60 main_task_runner_->PostTask(FROM_HERE, 68 main_task_runner_->PostTask(FROM_HERE,
61 base::Bind(callback, std::move(channel))); 69 base::Bind(callback, std::move(channel)));
62 return; 70 return;
63 } 71 }
64 establish_callbacks_.push_back(callback); 72 establish_callbacks_.push_back(callback);
65 if (gpu_service_)
66 return;
67
68 connector_->ConnectToInterface("service:ui", &gpu_service_);
69 gpu_service_->EstablishGpuChannel( 73 gpu_service_->EstablishGpuChannel(
70 base::Bind(&GpuService::OnEstablishedGpuChannel, base::Unretained(this))); 74 base::Bind(&GpuService::OnEstablishedGpuChannel, base::Unretained(this)));
71 } 75 }
72 76
73 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannelSync() { 77 scoped_refptr<gpu::GpuChannelHost> GpuService::EstablishGpuChannelSync() {
74 DCHECK(IsMainThread()); 78 DCHECK(IsMainThread());
75 if (GetGpuChannel()) 79 if (GetGpuChannel())
76 return gpu_channel_; 80 return gpu_channel_;
77 81
78 int client_id = 0; 82 int client_id = 0;
79 mojo::ScopedMessagePipeHandle channel_handle; 83 mojo::ScopedMessagePipeHandle channel_handle;
80 gpu::GPUInfo gpu_info; 84 gpu::GPUInfo gpu_info;
81 connector_->ConnectToInterface("service:ui", &gpu_service_); 85 // connector_->ConnectToInterface("service:ui", &gpu_service_);
82 86
83 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call; 87 mojo::SyncCallRestrictions::ScopedAllowSyncCall allow_sync_call;
84 if (!gpu_service_->EstablishGpuChannel(&client_id, &channel_handle, 88 if (!gpu_service_->EstablishGpuChannel(&client_id, &channel_handle,
85 &gpu_info)) { 89 &gpu_info)) {
86 DLOG(WARNING) 90 DLOG(WARNING)
87 << "Channel encountered error while establishing gpu channel."; 91 << "Channel encountered error while establishing gpu channel.";
88 return nullptr; 92 return nullptr;
89 } 93 }
90 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info); 94 OnEstablishedGpuChannel(client_id, std::move(channel_handle), gpu_info);
91 return gpu_channel_; 95 return gpu_channel_;
(...skipping 19 matching lines...) Expand all
111 DCHECK(IsMainThread()); 115 DCHECK(IsMainThread());
112 DCHECK(gpu_service_.get()); 116 DCHECK(gpu_service_.get());
113 DCHECK(!gpu_channel_); 117 DCHECK(!gpu_channel_);
114 118
115 if (client_id) { 119 if (client_id) {
116 gpu_channel_ = gpu::GpuChannelHost::Create( 120 gpu_channel_ = gpu::GpuChannelHost::Create(
117 this, client_id, gpu_info, IPC::ChannelHandle(channel_handle.release()), 121 this, client_id, gpu_info, IPC::ChannelHandle(channel_handle.release()),
118 &shutdown_event_, gpu_memory_buffer_manager_.get()); 122 &shutdown_event_, gpu_memory_buffer_manager_.get());
119 } 123 }
120 124
121 gpu_service_.reset();
122 for (const auto& i : establish_callbacks_) 125 for (const auto& i : establish_callbacks_)
123 i.Run(gpu_channel_); 126 i.Run(gpu_channel_);
124 establish_callbacks_.clear(); 127 establish_callbacks_.clear();
125 } 128 }
126 129
127 bool GpuService::IsMainThread() { 130 bool GpuService::IsMainThread() {
128 return main_task_runner_->BelongsToCurrentThread(); 131 return main_task_runner_->BelongsToCurrentThread();
129 } 132 }
130 133
131 scoped_refptr<base::SingleThreadTaskRunner> 134 scoped_refptr<base::SingleThreadTaskRunner>
(...skipping 14 matching lines...) Expand all
146 MojoResult result = mojo::UnwrapSharedMemoryHandle( 149 MojoResult result = mojo::UnwrapSharedMemoryHandle(
147 std::move(handle), &platform_handle, &shared_memory_size, &readonly); 150 std::move(handle), &platform_handle, &shared_memory_size, &readonly);
148 if (result != MOJO_RESULT_OK) 151 if (result != MOJO_RESULT_OK)
149 return nullptr; 152 return nullptr;
150 DCHECK_EQ(shared_memory_size, size); 153 DCHECK_EQ(shared_memory_size, size);
151 154
152 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly); 155 return base::MakeUnique<base::SharedMemory>(platform_handle, readonly);
153 } 156 }
154 157
155 } // namespace ui 158 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/gpu_service.h ('k') | services/ui/public/cpp/mojo_gpu_memory_buffer_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698