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

Side by Side Diff: content/gpu/gpu_child_thread.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 | « content/gpu/gpu_child_thread.h ('k') | content/public/browser/render_process_host.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/gpu/gpu_child_thread.h" 5 #include "content/gpu/gpu_child_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/threading/thread_local.h" 14 #include "base/threading/thread_local.h"
15 #include "base/threading/worker_pool.h" 15 #include "base/threading/worker_pool.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "content/child/child_process.h" 17 #include "content/child/child_process.h"
18 #include "content/child/thread_safe_sender.h" 18 #include "content/child/thread_safe_sender.h"
19 #include "content/common/establish_channel_params.h" 19 #include "content/common/establish_channel_params.h"
20 #include "content/common/gpu_host_messages.h" 20 #include "content/common/gpu_host_messages.h"
21 #include "content/common/process_control.mojom.h"
21 #include "content/gpu/gpu_process_control_impl.h" 22 #include "content/gpu/gpu_process_control_impl.h"
22 #include "content/gpu/gpu_watchdog_thread.h" 23 #include "content/gpu/gpu_watchdog_thread.h"
24 #include "content/public/common/connection_filter.h"
23 #include "content/public/common/content_client.h" 25 #include "content/public/common/content_client.h"
24 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
27 #include "content/public/common/mojo_shell_connection.h"
25 #include "content/public/gpu/content_gpu_client.h" 28 #include "content/public/gpu/content_gpu_client.h"
26 #include "gpu/command_buffer/service/gpu_switches.h" 29 #include "gpu/command_buffer/service/gpu_switches.h"
27 #include "gpu/command_buffer/service/sync_point_manager.h" 30 #include "gpu/command_buffer/service/sync_point_manager.h"
28 #include "gpu/config/gpu_info_collector.h" 31 #include "gpu/config/gpu_info_collector.h"
29 #include "gpu/config/gpu_switches.h" 32 #include "gpu/config/gpu_switches.h"
30 #include "gpu/config/gpu_util.h" 33 #include "gpu/config/gpu_util.h"
31 #include "gpu/ipc/common/memory_stats.h" 34 #include "gpu/ipc/common/memory_stats.h"
32 #include "gpu/ipc/service/gpu_memory_buffer_factory.h" 35 #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
33 #include "ipc/ipc_channel_handle.h" 36 #include "ipc/ipc_channel_handle.h"
34 #include "ipc/ipc_sync_message_filter.h" 37 #include "ipc/ipc_sync_message_filter.h"
35 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h" 38 #include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
36 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" 39 #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h"
37 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h" 40 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
38 #include "media/gpu/ipc/service/media_service.h" 41 #include "media/gpu/ipc/service/media_service.h"
42 #include "mojo/public/cpp/bindings/binding_set.h"
43 #include "services/shell/public/cpp/connection.h"
44 #include "services/shell/public/cpp/interface_factory.h"
45 #include "services/shell/public/cpp/interface_registry.h"
39 #include "ui/gl/gl_implementation.h" 46 #include "ui/gl/gl_implementation.h"
40 #include "ui/gl/gl_switches.h" 47 #include "ui/gl/gl_switches.h"
41 #include "ui/gl/gpu_switching_manager.h" 48 #include "ui/gl/gpu_switching_manager.h"
42 #include "ui/gl/init/gl_factory.h" 49 #include "ui/gl/init/gl_factory.h"
43 #include "url/gurl.h" 50 #include "url/gurl.h"
44 51
45 #if defined(USE_OZONE) 52 #if defined(USE_OZONE)
46 #include "ui/ozone/public/gpu_platform_support.h" 53 #include "ui/ozone/public/gpu_platform_support.h"
47 #include "ui/ozone/public/ozone_platform.h" 54 #include "ui/ozone/public/ozone_platform.h"
48 #endif 55 #endif
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance() 140 IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance()
134 ->GetGpuPlatformSupport() 141 ->GetGpuPlatformSupport()
135 ->GetMessageFilter(); 142 ->GetMessageFilter();
136 if (message_filter) 143 if (message_filter)
137 builder.AddStartupFilter(message_filter); 144 builder.AddStartupFilter(message_filter);
138 #endif 145 #endif
139 146
140 return builder.Build(); 147 return builder.Build();
141 } 148 }
142 149
150 // Connection filter for incoming connections from other shell clients.
151 class GpuConnectionFilter
152 : public ConnectionFilter,
153 public shell::InterfaceFactory<mojom::ProcessControl> {
154 public:
155 GpuConnectionFilter() {}
156 ~GpuConnectionFilter() override {}
157
158 private:
159 // ConnectionFilter:
160 bool OnConnect(shell::Connection* connection,
161 shell::Connector* connector) override {
162 connection->AddInterface<mojom::ProcessControl>(this);
163 return true;
164 }
165
166 // shell::InterfaceFactory<mojom::ProcessControl>:
167 void Create(shell::Connection* connection,
168 mojom::ProcessControlRequest request) override {
169 process_control_bindings_.AddBinding(&process_control_, std::move(request));
170 }
171
172 // Process control for Mojo application hosting.
173 //
174 // TODO(rockot): Remove this. To host mojo:media in the gpu process, we should
175 // simply package mojo:media in exe:content_gpu and use the ShellClientFactory
176 // idiom.
177 GpuProcessControlImpl process_control_;
178
179 // Bindings to the mojom::ProcessControl impl.
180 mojo::BindingSet<mojom::ProcessControl> process_control_bindings_;
181
182 DISALLOW_COPY_AND_ASSIGN(GpuConnectionFilter);
183 };
184
143 } // namespace 185 } // namespace
144 186
145 // static 187 // static
146 GpuChildThread* GpuChildThread::current() { 188 GpuChildThread* GpuChildThread::current() {
147 return g_lazy_tls.Pointer()->Get(); 189 return g_lazy_tls.Pointer()->Get();
148 } 190 }
149 191
150 GpuChildThread::GpuChildThread( 192 GpuChildThread::GpuChildThread(
151 GpuWatchdogThread* watchdog_thread, 193 GpuWatchdogThread* watchdog_thread,
152 bool dead_on_arrival, 194 bool dead_on_arrival,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void GpuChildThread::Init(const base::Time& process_start_time) { 253 void GpuChildThread::Init(const base::Time& process_start_time) {
212 process_start_time_ = process_start_time; 254 process_start_time_ = process_start_time;
213 255
214 #if defined(OS_ANDROID) 256 #if defined(OS_ANDROID)
215 // When running in in-process mode, this has been set in the browser at 257 // When running in in-process mode, this has been set in the browser at
216 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun(). 258 // ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun().
217 if (!in_browser_process_) 259 if (!in_browser_process_)
218 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid()); 260 media::SetMediaClientAndroid(GetContentClient()->GetMediaClientAndroid());
219 #endif 261 #endif
220 262
221 // Only set once per process instance. 263 if (GetContentClient()->gpu()) { // NULL in tests.
222 process_control_.reset(new GpuProcessControlImpl()); 264 GetContentClient()->gpu()->ExposeInterfacesToBrowser(
265 GetInterfaceRegistry());
266 }
267
268 // We don't want to process any incoming interface requests until
269 // OnInitialize() is invoked.
270 GetInterfaceRegistry()->PauseBinding();
piman 2016/07/08 22:42:19 drive-by, IIUC, this CL makes GpuConnectionFilter
223 271
224 if (GetContentClient()->gpu()) // NULL in tests. 272 if (GetContentClient()->gpu()) // NULL in tests.
225 GetContentClient()->gpu()->Initialize(this); 273 GetContentClient()->gpu()->Initialize(this);
226 } 274 }
227 275
228 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name, 276 void GpuChildThread::OnFieldTrialGroupFinalized(const std::string& trial_name,
229 const std::string& group_name) { 277 const std::string& group_name) {
230 Send(new GpuHostMsg_FieldTrialActivated(trial_name)); 278 Send(new GpuHostMsg_FieldTrialActivated(trial_name));
231 } 279 }
232 280
281 void GpuChildThread::AddConnectionFilters(MojoShellConnection* connection) {
282 connection->AddConnectionFilter(base::MakeUnique<GpuConnectionFilter>());
283 }
284
233 bool GpuChildThread::Send(IPC::Message* msg) { 285 bool GpuChildThread::Send(IPC::Message* msg) {
234 // The GPU process must never send a synchronous IPC message to the browser 286 // The GPU process must never send a synchronous IPC message to the browser
235 // process. This could result in deadlock. 287 // process. This could result in deadlock.
236 DCHECK(!msg->is_sync()); 288 DCHECK(!msg->is_sync());
237 289
238 return ChildThreadImpl::Send(msg); 290 return ChildThreadImpl::Send(msg);
239 } 291 }
240 292
241 bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) { 293 bool GpuChildThread::OnControlMessageReceived(const IPC::Message& msg) {
242 bool handled = true; 294 bool handled = true;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 OnDestroyingVideoSurface); 335 OnDestroyingVideoSurface);
284 #endif 336 #endif
285 IPC_MESSAGE_UNHANDLED(handled = false) 337 IPC_MESSAGE_UNHANDLED(handled = false)
286 IPC_END_MESSAGE_MAP() 338 IPC_END_MESSAGE_MAP()
287 if (handled) 339 if (handled)
288 return true; 340 return true;
289 341
290 return false; 342 return false;
291 } 343 }
292 344
293 bool GpuChildThread::OnConnect(shell::Connection* connection) {
294 // Use of base::Unretained(this) is safe here because |service_registry()|
295 // will be destroyed before GpuChildThread is destructed.
296 connection->GetInterfaceRegistry()->AddInterface(base::Bind(
297 &GpuChildThread::BindProcessControlRequest, base::Unretained(this)));
298
299 if (GetContentClient()->gpu()) { // NULL in tests.
300 GetContentClient()->gpu()->ExposeInterfacesToBrowser(
301 connection->GetInterfaceRegistry());
302 }
303
304 // We don't want to process any incoming interface requests until
305 // OnInitialize().
306 if (!gpu_channel_manager_) {
307 connection->GetInterfaceRegistry()->PauseBinding();
308 resume_interface_bindings_callback_ = base::Bind(
309 &shell::InterfaceRegistry::ResumeBinding,
310 connection->GetInterfaceRegistry()->GetWeakPtr());
311 }
312
313 return true;
314 }
315
316 shell::InterfaceRegistry* GpuChildThread::GetInterfaceRegistryForConnection() {
317 return nullptr;
318 }
319
320 shell::InterfaceProvider* GpuChildThread::GetInterfaceProviderForConnection() {
321 return nullptr;
322 }
323
324 void GpuChildThread::SetActiveURL(const GURL& url) { 345 void GpuChildThread::SetActiveURL(const GURL& url) {
325 GetContentClient()->SetActiveURL(url); 346 GetContentClient()->SetActiveURL(url);
326 } 347 }
327 348
328 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) { 349 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) {
329 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url)); 350 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url));
330 } 351 }
331 352
332 void GpuChildThread::DidDestroyChannel(int client_id) { 353 void GpuChildThread::DidDestroyChannel(int client_id) {
333 media_service_->RemoveChannel(client_id); 354 media_service_->RemoveChannel(client_id);
(...skipping 23 matching lines...) Expand all
357 } 378 }
358 #endif 379 #endif
359 380
360 void GpuChildThread::StoreShaderToDisk(int32_t client_id, 381 void GpuChildThread::StoreShaderToDisk(int32_t client_id,
361 const std::string& key, 382 const std::string& key,
362 const std::string& shader) { 383 const std::string& shader) {
363 Send(new GpuHostMsg_CacheShader(client_id, key, shader)); 384 Send(new GpuHostMsg_CacheShader(client_id, key, shader));
364 } 385 }
365 386
366 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) { 387 void GpuChildThread::OnInitialize(const gpu::GpuPreferences& gpu_preferences) {
367 if (!resume_interface_bindings_callback_.is_null()) 388 GetInterfaceRegistry()->ResumeBinding();
368 base::ResetAndReturn(&resume_interface_bindings_callback_).Run();
369 389
370 gpu_preferences_ = gpu_preferences; 390 gpu_preferences_ = gpu_preferences;
371 391
372 gpu_info_.video_decode_accelerator_capabilities = 392 gpu_info_.video_decode_accelerator_capabilities =
373 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 393 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
374 gpu_info_.video_encode_accelerator_supported_profiles = 394 gpu_info_.video_encode_accelerator_supported_profiles =
375 media::GpuVideoEncodeAccelerator::GetSupportedProfiles( 395 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(
376 gpu_preferences_); 396 gpu_preferences_);
377 gpu_info_.jpeg_decode_accelerator_supported = 397 gpu_info_.jpeg_decode_accelerator_supported =
378 media::GpuJpegDecodeAccelerator::IsSupported(); 398 media::GpuJpegDecodeAccelerator::IsSupported();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } 596 }
577 #endif 597 #endif
578 598
579 void GpuChildThread::OnLoseAllContexts() { 599 void GpuChildThread::OnLoseAllContexts() {
580 if (gpu_channel_manager_) { 600 if (gpu_channel_manager_) {
581 gpu_channel_manager_->DestroyAllChannels(); 601 gpu_channel_manager_->DestroyAllChannels();
582 media_service_->DestroyAllChannels(); 602 media_service_->DestroyAllChannels();
583 } 603 }
584 } 604 }
585 605
586 void GpuChildThread::BindProcessControlRequest(
587 mojo::InterfaceRequest<mojom::ProcessControl> request) {
588 DVLOG(1) << "GPU: Binding ProcessControl request";
589 DCHECK(process_control_);
590 process_control_bindings_.AddBinding(process_control_.get(),
591 std::move(request));
592 }
593
594 } // namespace content 606 } // namespace content
OLDNEW
« no previous file with comments | « content/gpu/gpu_child_thread.h ('k') | content/public/browser/render_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698