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

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: Fixed another Windows Build issue 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_host_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
55 // the IO thread. This allows the UI thread in the browser process to remain 56 // on the IO thread. This allows the UI thread in the browser process to remain
56 // fast at all times. 57 // fast at all times.
57 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter { 58 class GpuMemoryBufferMessageFilter : public IPC::MessageFilter {
58 public: 59 public:
59 explicit GpuMemoryBufferMessageFilter( 60 explicit GpuMemoryBufferMessageFilter(
60 GpuMemoryBufferFactory* gpu_memory_buffer_factory) 61 GpuMemoryBufferFactory* gpu_memory_buffer_factory)
61 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 62 : gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
62 sender_(nullptr) {} 63 sender_(nullptr) {}
63 64
64 // Overridden from IPC::MessageFilter: 65 // Overridden from IPC::MessageFilter:
65 void OnFilterAdded(IPC::Sender* sender) override { 66 void OnFilterAdded(IPC::Sender* sender) override {
66 DCHECK(!sender_); 67 DCHECK(!sender_);
67 sender_ = sender; 68 sender_ = sender;
68 } 69 }
69 void OnFilterRemoved() override { 70 void OnFilterRemoved() override {
70 DCHECK(sender_); 71 DCHECK(sender_);
71 sender_ = nullptr; 72 sender_ = nullptr;
72 } 73 }
73 bool OnMessageReceived(const IPC::Message& message) override { 74 bool OnMessageReceived(const IPC::Message& message) override {
74 DCHECK(sender_); 75 DCHECK(sender_);
75 bool handled = true; 76 bool handled = true;
76 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message) 77 IPC_BEGIN_MESSAGE_MAP(GpuMemoryBufferMessageFilter, message)
77 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer) 78 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBuffer, OnCreateGpuMemoryBuffer)
78 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBufferFromHandle, 79 IPC_MESSAGE_HANDLER(GpuMsg_CreateGpuMemoryBufferFromHandle,
79 OnCreateGpuMemoryBufferFromHandle) 80 OnCreateGpuMemoryBufferFromHandle)
80 IPC_MESSAGE_UNHANDLED(handled = false) 81 IPC_MESSAGE_UNHANDLED(handled = false)
81 IPC_END_MESSAGE_MAP() 82 IPC_END_MESSAGE_MAP()
82 return handled; 83 return handled;
83 } 84 }
84 85
85 protected: 86 protected:
86 ~GpuMemoryBufferMessageFilter() override {} 87 ~GpuMemoryBufferMessageFilter() override {}
87 88
88 void OnCreateGpuMemoryBuffer( 89 void OnCreateGpuMemoryBuffer(
89 const GpuMsg_CreateGpuMemoryBuffer_Params& params) { 90 const GpuMsg_CreateGpuMemoryBuffer_Params& params) {
90 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer", 91 TRACE_EVENT2("gpu", "GpuMemoryBufferMessageFilter::OnCreateGpuMemoryBuffer",
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 return true; 246 return true;
246 #endif 247 #endif
247 248
248 return false; 249 return false;
249 } 250 }
250 251
251 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) { 252 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) {
252 if (ChildThreadImpl::OnMessageReceived(msg)) 253 if (ChildThreadImpl::OnMessageReceived(msg))
253 return true; 254 return true;
254 255
255 return gpu_channel_manager_.get() && 256 bool handled = true;
256 gpu_channel_manager_->OnMessageReceived(msg); 257 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg)
258 #if defined(OS_MACOSX)
259 IPC_MESSAGE_HANDLER_GENERIC(AcceleratedSurfaceMsg_BufferPresented,
260 OnBufferPresented(msg));
261 #endif
262 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel)
263 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
264 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
265 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
266 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState)
267 #if defined(OS_ANDROID)
268 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu);
269 #endif
270 IPC_MESSAGE_UNHANDLED(handled = false)
271 IPC_END_MESSAGE_MAP()
272 if (handled)
273 return true;
274
275 return false;
276 }
277
278 void GpuChildThread::AddSubscription(int32_t client_id, unsigned int target) {
279 Send(new GpuHostMsg_AddSubscription(client_id, target));
280 }
281
282 void GpuChildThread::ChannelEstablished(
283 const IPC::ChannelHandle& channel_handle) {
284 Send(new GpuHostMsg_ChannelEstablished(channel_handle));
285 }
286
287 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) {
288 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url));
289 }
290
291 void GpuChildThread::DidDestroyChannel(int client_id) {
292 Send(new GpuHostMsg_DestroyChannel(client_id));
293 }
294
295 void GpuChildThread::DidDestroyOffscreenContext(const GURL& active_url) {
296 Send(new GpuHostMsg_DidDestroyOffscreenContext(active_url));
297 }
298
299 void GpuChildThread::DidLoseContext(bool offscreen,
300 gpu::error::ContextLostReason reason,
301 const GURL& active_url) {
302 Send(new GpuHostMsg_DidLoseContext(offscreen, reason, active_url));
303 }
304
305 void GpuChildThread::GpuMemoryUmaStats(const GPUMemoryUmaStats& params) {
306 Send(new GpuHostMsg_GpuMemoryUmaStats(params));
307 }
308
309 void GpuChildThread::RemoveSubscription(int32_t client_id,
310 unsigned int target) {
311 Send(new GpuHostMsg_RemoveSubscription(client_id, target));
312 }
313
314 #if defined(OS_MACOSX)
315 void GpuChildThread::SendAcceleratedSurfaceBuffersSwapped(
316 const AcceleratedSurfaceBuffersSwappedParams& params) {
317 Send(new GpuHostMsg_AcceleratedSurfaceBuffersSwapped(params));
318 }
319 #endif
320
321 #if defined(OS_WIN)
322 void GpuChildThread::SendAcceleratedSurfaceCreatedChildWindow(
323 const gfx::PluginWindowHandle& parent_window,
324 const gfx::PluginWindowHandle& child_window) {
325 Send(new GpuHostMsg_AcceleratedSurfaceCreatedChildWindow(parent_window,
326 child_window));
327 }
328 #endif
329
330 void GpuChildThread::StoreShaderToDisk(int32_t client_id,
331 const std::string& key,
332 const std::string& shader) {
333 Send(new GpuHostMsg_CacheShader(client_id, key, shader));
257 } 334 }
258 335
259 void GpuChildThread::OnInitialize() { 336 void GpuChildThread::OnInitialize() {
260 // Record initialization only after collecting the GPU info because that can 337 // Record initialization only after collecting the GPU info because that can
261 // take a significant amount of time. 338 // take a significant amount of time.
262 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; 339 gpu_info_.initialization_time = base::Time::Now() - process_start_time_;
263 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); 340 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_));
264 while (!deferred_messages_.empty()) { 341 while (!deferred_messages_.empty()) {
265 Send(deferred_messages_.front()); 342 Send(deferred_messages_.front());
266 deferred_messages_.pop(); 343 deferred_messages_.pop();
267 } 344 }
268 345
269 if (dead_on_arrival_) { 346 if (dead_on_arrival_) {
270 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; 347 LOG(ERROR) << "Exiting GPU process due to errors during initialization";
271 base::MessageLoop::current()->QuitWhenIdle(); 348 base::MessageLoop::current()->QuitWhenIdle();
272 return; 349 return;
273 } 350 }
274 351
275 // We don't need to pipe log messages if we are running the GPU thread in 352 // We don't need to pipe log messages if we are running the GPU thread in
276 // the browser process. 353 // the browser process.
277 if (!in_browser_process_) 354 if (!in_browser_process_)
278 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); 355 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
279 356
280 // Defer creation of the render thread. This is to prevent it from handling 357 // 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 358 // IPC messages before the sandbox has been enabled and all other necessary
282 // initialization has succeeded. 359 // initialization has succeeded.
283 gpu_channel_manager_.reset( 360 gpu_channel_manager_.reset(new GpuChannelManager(
284 new GpuChannelManager(channel(), watchdog_thread_.get(), 361 this, watchdog_thread_.get(), base::ThreadTaskRunnerHandle::Get().get(),
285 base::ThreadTaskRunnerHandle::Get().get(), 362 ChildProcess::current()->io_task_runner(),
286 ChildProcess::current()->io_task_runner(), 363 ChildProcess::current()->GetShutDownEvent(), sync_point_manager_,
287 ChildProcess::current()->GetShutDownEvent(), 364 gpu_memory_buffer_factory_));
288 sync_point_manager_, gpu_memory_buffer_factory_));
289 365
290 #if defined(USE_OZONE) 366 #if defined(USE_OZONE)
291 ui::OzonePlatform::GetInstance() 367 ui::OzonePlatform::GetInstance()
292 ->GetGpuPlatformSupport() 368 ->GetGpuPlatformSupport()
293 ->OnChannelEstablished(this); 369 ->OnChannelEstablished(this);
294 #endif 370 #endif
295 } 371 }
296 372
297 void GpuChildThread::OnFinalize() { 373 void GpuChildThread::OnFinalize() {
298 // Quit the GPU process 374 // Quit the GPU process
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 GPUVideoMemoryUsageStats video_memory_usage_stats; 430 GPUVideoMemoryUsageStats video_memory_usage_stats;
355 if (gpu_channel_manager_) 431 if (gpu_channel_manager_)
356 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( 432 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats(
357 &video_memory_usage_stats); 433 &video_memory_usage_stats);
358 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats)); 434 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats));
359 } 435 }
360 436
361 void GpuChildThread::OnClean() { 437 void GpuChildThread::OnClean() {
362 DVLOG(1) << "GPU: Removing all contexts"; 438 DVLOG(1) << "GPU: Removing all contexts";
363 if (gpu_channel_manager_) 439 if (gpu_channel_manager_)
364 gpu_channel_manager_->LoseAllContexts(); 440 gpu_channel_manager_->DestroyAllChannels();
365 } 441 }
366 442
367 void GpuChildThread::OnCrash() { 443 void GpuChildThread::OnCrash() {
368 DVLOG(1) << "GPU: Simulating GPU crash"; 444 DVLOG(1) << "GPU: Simulating GPU crash";
369 // Good bye, cruel world. 445 // Good bye, cruel world.
370 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; 446 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; 447 *it_s_the_end_of_the_world_as_we_know_it = 0xdead;
372 } 448 }
373 449
374 void GpuChildThread::OnHang() { 450 void GpuChildThread::OnHang() {
(...skipping 15 matching lines...) Expand all
390 watchdog_thread_->Stop(); 466 watchdog_thread_->Stop();
391 } 467 }
392 } 468 }
393 469
394 void GpuChildThread::OnGpuSwitched() { 470 void GpuChildThread::OnGpuSwitched() {
395 DVLOG(1) << "GPU: GPU has switched"; 471 DVLOG(1) << "GPU: GPU has switched";
396 // Notify observers in the GPU process. 472 // Notify observers in the GPU process.
397 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); 473 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched();
398 } 474 }
399 475
476 #if defined(OS_MACOSX)
477 void GpuChildThread::OnBufferPresented(const IPC::Message& message) {
478 AcceleratedSurfaceMsg_BufferPresented::Param param;
479 if (!AcceleratedSurfaceMsg_BufferPresented::Read(&message, &param))
480 return;
481
482 if (gpu_channel_manager_)
483 gpu_channel_manager_->BufferPresented(message.routing_id(),
484 base::get<0>(param));
485 }
486 #endif
487
488 void GpuChildThread::OnEstablishChannel(const EstablishChannelParams& params) {
489 if (gpu_channel_manager_)
490 gpu_channel_manager_->EstablishChannel(params);
491 }
492
493 void GpuChildThread::OnCloseChannel(const IPC::ChannelHandle& channel_handle) {
494 if (gpu_channel_manager_)
495 gpu_channel_manager_->CloseChannel(channel_handle);
496 }
497
498 void GpuChildThread::OnLoadedShader(const std::string& shader) {
499 if (gpu_channel_manager_)
500 gpu_channel_manager_->PopulateShaderCache(shader);
501 }
502
503 void GpuChildThread::OnDestroyGpuMemoryBuffer(
504 gfx::GpuMemoryBufferId id,
505 int client_id,
506 const gpu::SyncToken& sync_token) {
507 if (gpu_channel_manager_)
508 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
509 }
510
511 void GpuChildThread::OnUpdateValueState(int client_id,
512 unsigned int target,
513 const gpu::ValueState& state) {
514 if (gpu_channel_manager_)
515 gpu_channel_manager_->UpdateValueState(client_id, target, state);
516 }
517
518 #if defined(OS_ANDROID)
519 void GpuChildThread::OnWakeUpGpu() {
520 if (gpu_channel_manager_)
521 gpu_channel_manager_->WakeUpGpu();
522 }
523 #endif
524
525 void GpuChildThread::OnLoseAllContexts() {
526 if (gpu_channel_manager_)
527 gpu_channel_manager_->DestroyAllChannels();
528 }
529
400 void GpuChildThread::BindProcessControlRequest( 530 void GpuChildThread::BindProcessControlRequest(
401 mojo::InterfaceRequest<ProcessControl> request) { 531 mojo::InterfaceRequest<ProcessControl> request) {
402 DVLOG(1) << "GPU: Binding ProcessControl request"; 532 DVLOG(1) << "GPU: Binding ProcessControl request";
403 DCHECK(process_control_); 533 DCHECK(process_control_);
404 process_control_bindings_.AddBinding(process_control_.get(), 534 process_control_bindings_.AddBinding(process_control_.get(),
405 std::move(request)); 535 std::move(request));
406 } 536 }
407 537
408 } // namespace content 538 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698