Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser/gpu/gpu_process_host.h" | 5 #include "content/browser/gpu/gpu_process_host.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 while (!queued_messages_.empty()) { | 422 while (!queued_messages_.empty()) { |
| 423 delete queued_messages_.front(); | 423 delete queued_messages_.front(); |
| 424 queued_messages_.pop(); | 424 queued_messages_.pop(); |
| 425 } | 425 } |
| 426 | 426 |
| 427 // This is only called on the IO thread so no race against the constructor | 427 // This is only called on the IO thread so no race against the constructor |
| 428 // for another GpuProcessHost. | 428 // for another GpuProcessHost. |
| 429 if (g_gpu_process_hosts[kind_] == this) | 429 if (g_gpu_process_hosts[kind_] == this) |
| 430 g_gpu_process_hosts[kind_] = NULL; | 430 g_gpu_process_hosts[kind_] = NULL; |
| 431 | 431 |
| 432 // If there are any remaining offscreen contexts at the point the | |
| 433 // GPU process exits, assume something went wrong, and block their | |
| 434 // URLs from accessing client 3D APIs without prompting. | |
| 435 BlockLiveOffscreenContexts(); | |
|
Ken Russell (switch to Gerrit)
2012/12/04 21:16:10
This is the change to the GpuProcessHost destructo
apatrick_chromium
2012/12/04 21:24:23
Okay I'm blind then.
| |
| 436 | |
| 432 BrowserThread::PostTask(BrowserThread::UI, | 437 BrowserThread::PostTask(BrowserThread::UI, |
| 433 FROM_HERE, | 438 FROM_HERE, |
| 434 base::Bind(&GpuProcessHostUIShim::Destroy, host_id_)); | 439 base::Bind(&GpuProcessHostUIShim::Destroy, host_id_)); |
| 435 } | 440 } |
| 436 | 441 |
| 437 bool GpuProcessHost::Init() { | 442 bool GpuProcessHost::Init() { |
| 438 init_start_time_ = base::TimeTicks::Now(); | 443 init_start_time_ = base::TimeTicks::Now(); |
| 439 | 444 |
| 440 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess"); | 445 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess"); |
| 441 | 446 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 } | 505 } |
| 501 | 506 |
| 502 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 507 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 503 DCHECK(CalledOnValidThread()); | 508 DCHECK(CalledOnValidThread()); |
| 504 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 509 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
| 505 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) | 510 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) |
| 506 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) | 511 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
| 507 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) | 512 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) |
| 508 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) | 513 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) |
| 509 IPC_MESSAGE_HANDLER(GpuHostMsg_ImageCreated, OnImageCreated) | 514 IPC_MESSAGE_HANDLER(GpuHostMsg_ImageCreated, OnImageCreated) |
| 515 IPC_MESSAGE_HANDLER(GpuHostMsg_DidCreateOffscreenContext, | |
| 516 OnDidCreateOffscreenContext) | |
| 517 IPC_MESSAGE_HANDLER(GpuHostMsg_DidLoseContext, OnDidLoseContext) | |
| 518 IPC_MESSAGE_HANDLER(GpuHostMsg_DidDestroyOffscreenContext, | |
| 519 OnDidDestroyOffscreenContext) | |
| 510 #if defined(OS_MACOSX) | 520 #if defined(OS_MACOSX) |
| 511 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 521 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 512 OnAcceleratedSurfaceBuffersSwapped) | 522 OnAcceleratedSurfaceBuffersSwapped) |
| 513 #endif | 523 #endif |
| 514 #if defined(OS_WIN) | 524 #if defined(OS_WIN) |
| 515 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, | 525 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, |
| 516 OnAcceleratedSurfaceBuffersSwapped) | 526 OnAcceleratedSurfaceBuffersSwapped) |
| 517 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfacePostSubBuffer, | 527 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfacePostSubBuffer, |
| 518 OnAcceleratedSurfacePostSubBuffer) | 528 OnAcceleratedSurfacePostSubBuffer) |
| 519 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSuspend, | 529 IPC_MESSAGE_HANDLER(GpuHostMsg_AcceleratedSurfaceSuspend, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 void GpuProcessHost::OnImageCreated(const gfx::Size size) { | 689 void GpuProcessHost::OnImageCreated(const gfx::Size size) { |
| 680 TRACE_EVENT0("gpu", "GpuProcessHost::OnImageCreated"); | 690 TRACE_EVENT0("gpu", "GpuProcessHost::OnImageCreated"); |
| 681 | 691 |
| 682 if (!create_image_requests_.empty()) { | 692 if (!create_image_requests_.empty()) { |
| 683 CreateImageCallback callback = create_image_requests_.front(); | 693 CreateImageCallback callback = create_image_requests_.front(); |
| 684 create_image_requests_.pop(); | 694 create_image_requests_.pop(); |
| 685 callback.Run(size); | 695 callback.Run(size); |
| 686 } | 696 } |
| 687 } | 697 } |
| 688 | 698 |
| 699 void GpuProcessHost::OnDidCreateOffscreenContext( | |
| 700 const GURL& url) { | |
| 701 urls_with_live_offscreen_contexts_.insert(url); | |
| 702 } | |
| 703 | |
| 704 void GpuProcessHost::OnDidLoseContext(bool offscreen, | |
| 705 gpu::error::ContextLostReason reason, | |
| 706 const GURL& url) { | |
| 707 // TODO(kbr): would be nice to see the "offscreen" flag too. | |
| 708 TRACE_EVENT2("gpu", "GpuProcessHost::OnDidLoseContext", | |
| 709 "reason", reason, | |
| 710 "url", | |
| 711 url.possibly_invalid_spec()); | |
| 712 | |
| 713 if (!offscreen || url.is_empty()) { | |
| 714 // Assume that the loss of the compositor's or accelerated canvas' | |
| 715 // context is a serious event and blame the loss on all live | |
| 716 // offscreen contexts. This more robustly handles situations where | |
| 717 // the GPU process may not actually detect the context loss in the | |
| 718 // offscreen context. | |
| 719 BlockLiveOffscreenContexts(); | |
| 720 return; | |
| 721 } | |
| 722 | |
| 723 GpuDataManagerImpl::DomainGuilt guilt; | |
| 724 | |
| 725 switch (reason) { | |
| 726 case gpu::error::kGuilty: | |
| 727 guilt = GpuDataManagerImpl::DOMAIN_GUILT_KNOWN; | |
| 728 break; | |
| 729 case gpu::error::kUnknown: | |
| 730 guilt = GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN; | |
| 731 break; | |
| 732 case gpu::error::kInnocent: | |
| 733 return; | |
| 734 } | |
| 735 | |
| 736 GpuDataManagerImpl::GetInstance()->BlockDomainFrom3DAPIs( | |
| 737 url, guilt); | |
| 738 } | |
| 739 | |
| 740 void GpuProcessHost::OnDidDestroyOffscreenContext( | |
| 741 const GURL& url) { | |
| 742 urls_with_live_offscreen_contexts_.erase(url); | |
| 743 } | |
| 744 | |
| 689 #if defined(OS_MACOSX) | 745 #if defined(OS_MACOSX) |
| 690 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( | 746 void GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped( |
| 691 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | 747 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { |
| 692 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); | 748 TRACE_EVENT0("gpu", "GpuProcessHost::OnAcceleratedSurfaceBuffersSwapped"); |
| 693 | 749 |
| 694 gfx::PluginWindowHandle handle = | 750 gfx::PluginWindowHandle handle = |
| 695 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); | 751 GpuSurfaceTracker::Get()->GetSurfaceWindowHandle(params.surface_id); |
| 696 // Compositor window is always gfx::kNullPluginWindow. | 752 // Compositor window is always gfx::kNullPluginWindow. |
| 697 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no | 753 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no |
| 698 // plugin windows. | 754 // plugin windows. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 981 void GpuProcessHost::CreateCommandBufferError( | 1037 void GpuProcessHost::CreateCommandBufferError( |
| 982 const CreateCommandBufferCallback& callback, int32 route_id) { | 1038 const CreateCommandBufferCallback& callback, int32 route_id) { |
| 983 callback.Run(route_id); | 1039 callback.Run(route_id); |
| 984 } | 1040 } |
| 985 | 1041 |
| 986 void GpuProcessHost::CreateImageError( | 1042 void GpuProcessHost::CreateImageError( |
| 987 const CreateImageCallback& callback, const gfx::Size size) { | 1043 const CreateImageCallback& callback, const gfx::Size size) { |
| 988 callback.Run(size); | 1044 callback.Run(size); |
| 989 } | 1045 } |
| 990 | 1046 |
| 1047 void GpuProcessHost::BlockLiveOffscreenContexts() { | |
| 1048 for (std::multiset<GURL>::iterator iter = | |
| 1049 urls_with_live_offscreen_contexts_.begin(); | |
| 1050 iter != urls_with_live_offscreen_contexts_.end(); ++iter) { | |
| 1051 GpuDataManagerImpl::GetInstance()->BlockDomainFrom3DAPIs( | |
| 1052 *iter, GpuDataManagerImpl::DOMAIN_GUILT_UNKNOWN); | |
| 1053 } | |
| 1054 } | |
| 1055 | |
| 991 } // namespace content | 1056 } // namespace content |
| OLD | NEW |