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

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: Removed dependencies on gpu_browser_messages in content/common/gpu 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 "gpu/config/gpu_info_collector.h" 24 #include "gpu/config/gpu_info_collector.h"
24 #include "ipc/ipc_channel_handle.h" 25 #include "ipc/ipc_channel_handle.h"
25 #include "ipc/ipc_sync_message_filter.h" 26 #include "ipc/ipc_sync_message_filter.h"
26 #include "ui/gl/gl_implementation.h" 27 #include "ui/gl/gl_implementation.h"
27 #include "ui/gl/gpu_switching_manager.h" 28 #include "ui/gl/gpu_switching_manager.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 return true; 242 return true;
242 #endif 243 #endif
243 244
244 return false; 245 return false;
245 } 246 }
246 247
247 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) { 248 bool GpuChildThread::OnMessageReceived(const IPC::Message& msg) {
248 if (ChildThreadImpl::OnMessageReceived(msg)) 249 if (ChildThreadImpl::OnMessageReceived(msg))
249 return true; 250 return true;
250 251
252 bool handled = true;
253 IPC_BEGIN_MESSAGE_MAP(GpuChildThread, msg)
254 IPC_MESSAGE_HANDLER(GpuMsg_EstablishChannel, OnEstablishChannel)
255 IPC_MESSAGE_HANDLER(GpuMsg_CloseChannel, OnCloseChannel)
256 IPC_MESSAGE_HANDLER(GpuMsg_DestroyGpuMemoryBuffer, OnDestroyGpuMemoryBuffer)
257 IPC_MESSAGE_HANDLER(GpuMsg_LoadedShader, OnLoadedShader)
258 IPC_MESSAGE_HANDLER(GpuMsg_UpdateValueState, OnUpdateValueState)
259 #if defined(OS_ANDROID)
260 IPC_MESSAGE_HANDLER(GpuMsg_WakeUpGpu, OnWakeUpGpu);
261 #endif
262 IPC_MESSAGE_UNHANDLED(handled = false)
263 IPC_END_MESSAGE_MAP()
264 if (handled)
265 return true;
266
251 return gpu_channel_manager_.get() && 267 return gpu_channel_manager_.get() &&
252 gpu_channel_manager_->OnMessageReceived(msg); 268 gpu_channel_manager_->OnMessageReceived(msg);
253 } 269 }
254 270
271 void GpuChildThread::AddSubscription(int32_t client_id, unsigned int target) {}
272
273 void GpuChildThread::CacheShader(int32_t client_id,
274 const std::string& key,
275 const std::string& shader) {}
276
277 void GpuChildThread::ChannelEstablished(
278 const IPC::ChannelHandle& channel_handle) {
279 Send(new GpuHostMsg_ChannelEstablished(channel_handle));
280 }
281
282 void GpuChildThread::DestroyChannel(int client_id) {
283 Send(new GpuHostMsg_DestroyChannel(client_id));
284 }
285
286 void GpuChildThread::DidCreateOffscreenContext(const GURL& active_url) {
287 Send(new GpuHostMsg_DidCreateOffscreenContext(active_url));
288 }
289
290 void GpuChildThread::DidDestroyOffscreenContext(const GURL& active_url) {
291 Send(new GpuHostMsg_DidDestroyOffscreenContext(active_url));
292 }
293
294 void GpuChildThread::DidLoseContext(bool offscreen,
295 gpu::error::ContextLostReason reason,
296 const GURL& active_url) {
297 Send(new GpuHostMsg_DidLoseContext(offscreen, reason, active_url));
298 }
299
300 void GpuChildThread::GpuMemoryUmaStats(const GPUMemoryUmaStats& params) {
301 Send(new GpuHostMsg_GpuMemoryUmaStats(params));
302 }
303
304 void GpuChildThread::RemoveSubscription(int32_t client_id,
305 unsigned int target) {
306 Send(new GpuHostMsg_RemoveSubscription(client_id, target));
307 }
308
255 void GpuChildThread::OnInitialize() { 309 void GpuChildThread::OnInitialize() {
256 // Record initialization only after collecting the GPU info because that can 310 // Record initialization only after collecting the GPU info because that can
257 // take a significant amount of time. 311 // take a significant amount of time.
258 gpu_info_.initialization_time = base::Time::Now() - process_start_time_; 312 gpu_info_.initialization_time = base::Time::Now() - process_start_time_;
259 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_)); 313 Send(new GpuHostMsg_Initialized(!dead_on_arrival_, gpu_info_));
260 while (!deferred_messages_.empty()) { 314 while (!deferred_messages_.empty()) {
261 Send(deferred_messages_.front()); 315 Send(deferred_messages_.front());
262 deferred_messages_.pop(); 316 deferred_messages_.pop();
263 } 317 }
264 318
265 if (dead_on_arrival_) { 319 if (dead_on_arrival_) {
266 LOG(ERROR) << "Exiting GPU process due to errors during initialization"; 320 LOG(ERROR) << "Exiting GPU process due to errors during initialization";
267 base::MessageLoop::current()->QuitWhenIdle(); 321 base::MessageLoop::current()->QuitWhenIdle();
268 return; 322 return;
269 } 323 }
270 324
271 // We don't need to pipe log messages if we are running the GPU thread in 325 // We don't need to pipe log messages if we are running the GPU thread in
272 // the browser process. 326 // the browser process.
273 if (!in_browser_process_) 327 if (!in_browser_process_)
274 logging::SetLogMessageHandler(GpuProcessLogMessageHandler); 328 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
275 329
276 // Defer creation of the render thread. This is to prevent it from handling 330 // Defer creation of the render thread. This is to prevent it from handling
277 // IPC messages before the sandbox has been enabled and all other necessary 331 // IPC messages before the sandbox has been enabled and all other necessary
278 // initialization has succeeded. 332 // initialization has succeeded.
279 gpu_channel_manager_.reset( 333 gpu_channel_manager_.reset(
280 new GpuChannelManager(channel(), watchdog_thread_.get(), 334 new GpuChannelManager(this, channel(), watchdog_thread_.get(),
281 base::ThreadTaskRunnerHandle::Get().get(), 335 base::ThreadTaskRunnerHandle::Get().get(),
282 ChildProcess::current()->io_task_runner(), 336 ChildProcess::current()->io_task_runner(),
283 ChildProcess::current()->GetShutDownEvent(), 337 ChildProcess::current()->GetShutDownEvent(),
284 sync_point_manager_, gpu_memory_buffer_factory_)); 338 sync_point_manager_, gpu_memory_buffer_factory_));
285 339
286 #if defined(USE_OZONE) 340 #if defined(USE_OZONE)
287 ui::OzonePlatform::GetInstance() 341 ui::OzonePlatform::GetInstance()
288 ->GetGpuPlatformSupport() 342 ->GetGpuPlatformSupport()
289 ->OnChannelEstablished(this); 343 ->OnChannelEstablished(this);
290 #endif 344 #endif
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 GPUVideoMemoryUsageStats video_memory_usage_stats; 404 GPUVideoMemoryUsageStats video_memory_usage_stats;
351 if (gpu_channel_manager_) 405 if (gpu_channel_manager_)
352 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats( 406 gpu_channel_manager_->gpu_memory_manager()->GetVideoMemoryUsageStats(
353 &video_memory_usage_stats); 407 &video_memory_usage_stats);
354 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats)); 408 Send(new GpuHostMsg_VideoMemoryUsageStats(video_memory_usage_stats));
355 } 409 }
356 410
357 void GpuChildThread::OnClean() { 411 void GpuChildThread::OnClean() {
358 DVLOG(1) << "GPU: Removing all contexts"; 412 DVLOG(1) << "GPU: Removing all contexts";
359 if (gpu_channel_manager_) 413 if (gpu_channel_manager_)
360 gpu_channel_manager_->LoseAllContexts(); 414 gpu_channel_manager_->ClearAllChannels();
361 } 415 }
362 416
363 void GpuChildThread::OnCrash() { 417 void GpuChildThread::OnCrash() {
364 DVLOG(1) << "GPU: Simulating GPU crash"; 418 DVLOG(1) << "GPU: Simulating GPU crash";
365 // Good bye, cruel world. 419 // Good bye, cruel world.
366 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL; 420 volatile int* it_s_the_end_of_the_world_as_we_know_it = NULL;
367 *it_s_the_end_of_the_world_as_we_know_it = 0xdead; 421 *it_s_the_end_of_the_world_as_we_know_it = 0xdead;
368 } 422 }
369 423
370 void GpuChildThread::OnHang() { 424 void GpuChildThread::OnHang() {
(...skipping 15 matching lines...) Expand all
386 watchdog_thread_->Stop(); 440 watchdog_thread_->Stop();
387 } 441 }
388 } 442 }
389 443
390 void GpuChildThread::OnGpuSwitched() { 444 void GpuChildThread::OnGpuSwitched() {
391 DVLOG(1) << "GPU: GPU has switched"; 445 DVLOG(1) << "GPU: GPU has switched";
392 // Notify observers in the GPU process. 446 // Notify observers in the GPU process.
393 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched(); 447 ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched();
394 } 448 }
395 449
450 void GpuChildThread::OnEstablishChannel(const EstablishChannelParams& params) {
451 if (gpu_channel_manager_)
452 gpu_channel_manager_->EstablishChannel(params);
453 }
454
455 void GpuChildThread::OnCloseChannel(const IPC::ChannelHandle& channel_handle) {
456 if (gpu_channel_manager_)
457 gpu_channel_manager_->CloseChannel(channel_handle);
458 }
459
460 void GpuChildThread::OnLoadedShader(const std::string& shader) {
461 if (gpu_channel_manager_)
462 gpu_channel_manager_->LoadedShader(shader);
463 }
464
465 void GpuChildThread::OnDestroyGpuMemoryBuffer(
466 gfx::GpuMemoryBufferId id,
467 int client_id,
468 const gpu::SyncToken& sync_token) {
469 if (gpu_channel_manager_)
470 gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token);
471 }
472
473 void GpuChildThread::OnUpdateValueState(int client_id,
474 unsigned int target,
475 const gpu::ValueState& state) {
476 if (gpu_channel_manager_)
477 gpu_channel_manager_->UpdateValueState(client_id, target, state);
478 }
479
480 #if defined(OS_ANDROID)
481 void GpuChildThread::OnWakeUpGpu() {
482 if (gpu_channel_manager_)
483 gpu_channel_manager_->WakeUpGpu();
484 }
485 #endif
486
487 void GpuChildThread::OnLoseAllContexts() {
488 if (gpu_channel_manager_)
489 gpu_channel_manager_->ClearAllChannels();
490 }
491
396 void GpuChildThread::BindProcessControlRequest( 492 void GpuChildThread::BindProcessControlRequest(
397 mojo::InterfaceRequest<ProcessControl> request) { 493 mojo::InterfaceRequest<ProcessControl> request) {
398 DVLOG(1) << "GPU: Binding ProcessControl request"; 494 DVLOG(1) << "GPU: Binding ProcessControl request";
399 DCHECK(process_control_); 495 DCHECK(process_control_);
400 process_control_bindings_.AddBinding(process_control_.get(), 496 process_control_bindings_.AddBinding(process_control_.get(),
401 std::move(request)); 497 std::move(request));
402 } 498 }
403 499
404 } // namespace content 500 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698