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

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

Issue 1711533002: Decouple browser-specific GPU IPC messages from GPU service IPCs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Mark's nit Created 4 years, 10 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
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/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/threading/worker_pool.h" 12 #include "base/threading/worker_pool.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/child/child_process.h" 14 #include "content/child/child_process.h"
15 #include "content/child/thread_safe_sender.h" 15 #include "content/child/thread_safe_sender.h"
16 #include "content/common/gpu/establish_channel_params.h"
17 #include "content/common/gpu/gpu_browser_messages.h"
16 #include "content/common/gpu/gpu_memory_buffer_factory.h" 18 #include "content/common/gpu/gpu_memory_buffer_factory.h"
17 #include "content/common/gpu/gpu_messages.h"
18 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" 19 #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
19 #include "content/gpu/gpu_process_control_impl.h" 20 #include "content/gpu/gpu_process_control_impl.h"
20 #include "content/gpu/gpu_watchdog_thread.h" 21 #include "content/gpu/gpu_watchdog_thread.h"
21 #include "content/public/common/content_client.h" 22 #include "content/public/common/content_client.h"
22 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
23 #include "content/public/gpu/content_gpu_client.h" 24 #include "content/public/gpu/content_gpu_client.h"
24 #include "gpu/config/gpu_info_collector.h" 25 #include "gpu/config/gpu_info_collector.h"
25 #include "ipc/ipc_channel_handle.h" 26 #include "ipc/ipc_channel_handle.h"
26 #include "ipc/ipc_sync_message_filter.h" 27 #include "ipc/ipc_sync_message_filter.h"
27 #include "ui/gl/gl_implementation.h" 28 #include "ui/gl/gl_implementation.h"
(...skipping 10 matching lines...) Expand all
38 static base::LazyInstance<scoped_refptr<ThreadSafeSender> > 39 static base::LazyInstance<scoped_refptr<ThreadSafeSender> >
39 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER; 40 g_thread_safe_sender = LAZY_INSTANCE_INITIALIZER;
40 41
41 bool GpuProcessLogMessageHandler(int severity, 42 bool GpuProcessLogMessageHandler(int severity,
42 const char* file, int line, 43 const char* file, int line,
43 size_t message_start, 44 size_t message_start,
44 const std::string& str) { 45 const std::string& str) {
45 std::string header = str.substr(0, message_start); 46 std::string header = str.substr(0, message_start);
46 std::string message = str.substr(message_start); 47 std::string message = str.substr(message_start);
47 48
48 g_thread_safe_sender.Get()->Send(new GpuHostMsg_OnLogMessage( 49 g_thread_safe_sender.Get()->Send(
49 severity, header, message)); 50 new GpuHostMsg_OnLogMessage(severity, header, message));
50 51
51 return false; 52 return false;
52 } 53 }
53 54
54 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages on 55 // Message filter used to to handle GpuMsg_CreateGpuMemoryBuffer messages
56 // on
no sievers 2016/02/19 19:46:23 nit: formatting
Fady Samuel 2016/02/19 20:33:30 Done.
55 // the IO thread. This allows the UI thread in the browser process to remain 57 // the IO thread. This allows the UI thread in the browser process to remain
56 // fast at all times. 58 // fast at all times.
57 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { 59 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
58 public: 60 public:
59 explicit GpuMemoryBufferMessageFilter( 61 explicit GpuMemoryBufferMessageFilter(
60 GpuMemoryBufferFactory* gpu_memory_buffer_factory) 62 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
61 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 63 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
62 sender_(nullptr) {} 64 sender_(nullptr) {}
63 65
64 // Overridden from IPC::MessageFilter: 66 // Overridden from IPC::MessageFilter:
65 void OnFilterAdded(IPC::Sender* sender) override { 67 void OnFilterAdded(IPC::Sender* sender) override {
66 DCHECK(!sender_); 68 DCHECK(!sender_);
67 sender_ = sender; 69 sender_ = sender;
68 } 70 }
69 void OnFilterRemoved() override { 71 void OnFilterRemoved() override {
70 DCHECK(sender_); 72 DCHECK(sender_);
71 sender_ = nullptr; 73 sender_ = nullptr;
72 } 74 }
73 bool OnMessageReceived(const IPC::Message& message) override { 75 bool OnMessageReceived(const IPC::Message& message) override {
74 DCHECK(sender_); 76 DCHECK(sender_);
75 bool handled = true; 77 bool handled = true;
76 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message) 78 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message)
77 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) 79 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
78 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBufferFromHandle, 80 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBufferFromHandle,
79 OnCreateGpuMemoryBufferFromHandle) 81 OnCreateGpuMemoryBufferFromHandle)
80 IPC_MESSAGE_UNHANDLED(handled = false) 82 IPC_MESSAGE_UNHANDLED(handled = false)
81 IPC_END_MESSAGE_MAP() 83 IPC_END_MESSAGE_MAP()
82 return handled; 84 return handled;
83 } 85 }
84 86
85 protected: 87 protected:
86 ~GpuMemoryBufferMessageFilter() override {} 88 ~GpuMemoryBufferMessageFilter() override {}
87 89
88 void OnCreateGpuMemoryBuffer( 90 void OnCreateGpuMemoryBuffer(
89 const GpuMsg_CreateGpuMemoryBuffer_Params& params) { 91 const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
90 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer", 92 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer",
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return true; 247 return true;
246 #endif 248 #endif
247 249
248 return false; 250 return false;
249 } 251 }
250 252
251 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) { 253 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) {
252 if (ChildThreadImpl::OnMessageReceived(msg)) 254 if (ChildThreadImpl::OnMessageReceived(msg))
253 return true; 255 return true;
254 256
257 bool handled = true;
258 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg)
259 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel)
260 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
261 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
262 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
263 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState)
264 #if defined(OS_ANDROID)
265 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu);
266 #endif
267 IPC_MESSAGE_UNHANDLED(handled = false)
268 IPC_END_MESSAGE_MAP()
269 if (handled)
270 return true;
271
255 return gpu_channel_manager_.get() && 272 return gpu_channel_manager_.get() &&
256 gpu_channel_manager_->OnMessageReceived(msg); 273 gpu_channel_manager_->OnMessageReceived(msg);
257 } 274 }
258 275
276 void GpuChildThread::AddSubscription(int32_t client_id, unsigned int target) {
277 Send(new GpuHostMsg_AddSubscription(client_id, target));
278 }
279
280 void GpuChildThread::ChannelEstablished(
281 const IPC::ChannelHandle& channel_handle) {
282 Send(new GpuHostMsg_ChannelEstablished(channel_handle));
283 }
284
285 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) {
286 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url));
287 }
288
289 void GpuChildThread::DidDestroyChannel(int client_id) {
290 Send(new GpuHostMsg_DestroyChannel(client_id));
291 }
292
293 void GpuChildThread::DidDestroyOffscreenContext(const GURL& active_url) {
294 Send(new GpuHostMsg_DidDestroyOffscreenContext(active_url));
295 }
296
297 void GpuChildThread::DidLoseContext(bool offscreen,
298 gpu::error::ContextLostReason reason,
299 const GURL& active_url) {
300 Send(new GpuHostMsg_DidLoseContext(offscreen, reason, active_url));
301 }
302
303 void GpuChildThread::GpuMemoryUmaStats(const GPUMemoryUmaStats& params) {
304 Send(new GpuHostMsg_GpuMemoryUmaStats(params));
305 }
306
307 void GpuChildThread::RemoveSubscription(int32_t client_id,
308 unsigned int target) {
309 Send(new GpuHostMsg_RemoveSubscription(client_id, target));
310 }
311
312 void GpuChildThread::StoreShaderToDisk(int32_t client_id,
313 const std::string& key,
314 const std::string& shader) {
315 Send(new GpuHostMsg_CacheShader(client_id, key, shader));
316 }
317
259 void GpuChildThread::OnInitialize() { 318 void GpuChildThread::OnInitialize() {
260 // Record initialization only after collecting the GPU info because that can 319 // Record initialization only after collecting the GPU info because that can
261 // take a significant amount of time. 320 // take a significant amount of time.
262 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; 321 gpu_info_.initialization_time = base::Time::Now() - process_start_time_;
263 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); 322 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_));
264 while (!deferred_messages_.empty()) { 323 while (!deferred_messages_.empty()) {
265 Send(deferred_messages_.front()); 324 Send(deferred_messages_.front());
266 deferred_messages_.pop(); 325 deferred_messages_.pop();
267 } 326 }
268 327
269 if (dead_on_arrival_) { 328 if (dead_on_arrival_) {
270 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; 329 LOG(ERROR) << "Exiting GPU process due to errors during initialization";
271 base::MessageLoop::current()->QuitWhenIdle(); 330 base::MessageLoop::current()->QuitWhenIdle();
272 return; 331 return;
273 } 332 }
274 333
275 // We don't need to pipe log messages if we are running the GPU thread in 334 // We don't need to pipe log messages if we are running the GPU thread in
276 // the browser process. 335 // the browser process.
277 if (!in_browser_process_) 336 if (!in_browser_process_)
278 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); 337 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
279 338
280 // Defer creation of the render thread. This is to prevent it from handling 339 // Defer creation of the render thread. This is to prevent it from handling
281 // IPC messages before the sandbox has been enabled and all other necessary 340 // IPC messages before the sandbox has been enabled and all other necessary
282 // initialization has succeeded. 341 // initialization has succeeded.
283 gpu_channel_manager_.reset( 342 gpu_channel_manager_.reset(
284 new GpuChannelManager(channel(), watchdog_thread_.get(), 343 new GpuChannelManager(this, channel(), watchdog_thread_.get(),
no sievers 2016/02/19 19:46:23 no need to pass channel() anymore
Fady Samuel 2016/02/19 20:33:30 Done.
285 base::ThreadTaskRunnerHandle::Get().get(), 344 base::ThreadTaskRunnerHandle::Get().get(),
286 ChildProcess::current()->io_task_runner(), 345 ChildProcess::current()->io_task_runner(),
287 ChildProcess::current()->GetShutDownEvent(), 346 ChildProcess::current()->GetShutDownEvent(),
288 sync_point_manager_, gpu_memory_buffer_factory_)); 347 sync_point_manager_, gpu_memory_buffer_factory_));
289 348
290 #if defined(USE_OZONE) 349 #if defined(USE_OZONE)
291 ui::OzonePlatform::GetInstance() 350 ui::OzonePlatform::GetInstance()
292 ->GetGpuPlatformSupport() 351 ->GetGpuPlatformSupport()
293 ->OnChannelEstablished(this); 352 ->OnChannelEstablished(this);
294 #endif 353 #endif
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 GPUVideoMemoryUsageStats video_memory_usage_stats; 413 GPUVideoMemoryUsageStats video_memory_usage_stats;
355 if (gpu_channel_manager_) 414 if (gpu_channel_manager_)
356 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( 415 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats(
357 &video_memory_usage_stats); 416 &video_memory_usage_stats);
358 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats)); 417 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats));
359 } 418 }
360 419
361 void GpuChildThread::OnClean() { 420 void GpuChildThread::OnClean() {
362 DVLOG(1) << "GPU: Removing all contexts"; 421 DVLOG(1) << "GPU: Removing all contexts";
363 if (gpu_channel_manager_) 422 if (gpu_channel_manager_)
364 gpu_channel_manager_->LoseAllContexts(); 423 gpu_channel_manager_->DestroyAllChannels();
365 } 424 }
366 425
367 void GpuChildThread::OnCrash() { 426 void GpuChildThread::OnCrash() {
368 DVLOG(1) << "GPU: Simulating GPU crash"; 427 DVLOG(1) << "GPU: Simulating GPU crash";
369 // Good bye, cruel world. 428 // Good bye, cruel world.
370 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; 429 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL;
371 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; 430 *it_s_the_end_of_the_world_as_we_know_it = 0xdead;
372 } 431 }
373 432
374 void GpuChildThread::OnHang() { 433 void GpuChildThread::OnHang() {
(...skipping 15 matching lines...) Expand all
390 watchdog_thread_->Stop(); 449 watchdog_thread_->Stop();
391 } 450 }
392 } 451 }
393 452
394 void GpuChildThread::OnGpuSwitched() { 453 void GpuChildThread::OnGpuSwitched() {
395 DVLOG(1) << "GPU: GPU has switched"; 454 DVLOG(1) << "GPU: GPU has switched";
396 // Notify observers in the GPU process. 455 // Notify observers in the GPU process.
397 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); 456 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched();
398 } 457 }
399 458
459 void GpuChildThread::OnEstablishChannel(const EstablishChannelParams& params) {
460 if (gpu_channel_manager_)
461 gpu_channel_manager_->EstablishChannel(params);
462 }
463
464 void GpuChildThread::OnCloseChannel(const IPC::ChannelHandle& channel_handle) {
465 if (gpu_channel_manager_)
466 gpu_channel_manager_->CloseChannel(channel_handle);
467 }
468
469 void GpuChildThread::OnLoadedShader(const std::string& shader) {
470 if (gpu_channel_manager_)
471 gpu_channel_manager_->PopulateShaderCache(shader);
472 }
473
474 void GpuChildThread::OnDestroyGpuMemoryBuffer(
475 gfx::GpuMemoryBufferId id,
476 int client_id,
477 const gpu::SyncToken& sync_token) {
478 if (gpu_channel_manager_)
479 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
480 }
481
482 void GpuChildThread::OnUpdateValueState(int client_id,
483 unsigned int target,
484 const gpu::ValueState& state) {
485 if (gpu_channel_manager_)
486 gpu_channel_manager_->UpdateValueState(client_id, target, state);
487 }
488
489 #if defined(OS_ANDROID)
490 void GpuChildThread::OnWakeUpGpu() {
491 if (gpu_channel_manager_)
492 gpu_channel_manager_->WakeUpGpu();
493 }
494 #endif
495
496 void GpuChildThread::OnLoseAllContexts() {
497 if (gpu_channel_manager_)
498 gpu_channel_manager_->DestroyAllChannels();
499 }
500
400 void GpuChildThread::BindProcessControlRequest( 501 void GpuChildThread::BindProcessControlRequest(
401 mojo::InterfaceRequest<ProcessControl> request) { 502 mojo::InterfaceRequest<ProcessControl> request) {
402 DVLOG(1) << "GPU: Binding ProcessControl request"; 503 DVLOG(1) << "GPU: Binding ProcessControl request";
403 DCHECK(process_control_); 504 DCHECK(process_control_);
404 process_control_bindings_.AddBinding(process_control_.get(), 505 process_control_bindings_.AddBinding(process_control_.get(),
405 std::move(request)); 506 std::move(request));
406 } 507 }
407 508
408 } // namespace content 509 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698