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

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

Powered by Google App Engine
This is Rietveld 408576698