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/base64.h" | 7 #include "base/base64.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/sha1.h" | 16 #include "base/sha1.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "components/tracing/tracing_switches.h" | 19 #include "components/tracing/tracing_switches.h" |
20 #include "content/browser/browser_child_process_host_impl.h" | 20 #include "content/browser/browser_child_process_host_impl.h" |
21 #include "content/browser/gpu/compositor_util.h" | 21 #include "content/browser/gpu/compositor_util.h" |
22 #include "content/browser/gpu/gpu_data_manager_impl.h" | 22 #include "content/browser/gpu/gpu_data_manager_impl.h" |
23 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 23 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 24 #include "content/browser/gpu/gpu_surface_tracker.h" |
24 #include "content/browser/gpu/shader_disk_cache.h" | 25 #include "content/browser/gpu/shader_disk_cache.h" |
25 #include "content/browser/renderer_host/render_widget_host_impl.h" | 26 #include "content/browser/renderer_host/render_widget_host_impl.h" |
26 #include "content/common/child_process_host_impl.h" | 27 #include "content/common/child_process_host_impl.h" |
27 #include "content/common/gpu/gpu_messages.h" | 28 #include "content/common/gpu/gpu_messages.h" |
28 #include "content/common/in_process_child_thread_params.h" | 29 #include "content/common/in_process_child_thread_params.h" |
29 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
32 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 DCHECK(CalledOnValidThread()); | 603 DCHECK(CalledOnValidThread()); |
603 process_->GetHost()->AddFilter(filter); | 604 process_->GetHost()->AddFilter(filter); |
604 } | 605 } |
605 | 606 |
606 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { | 607 bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
607 DCHECK(CalledOnValidThread()); | 608 DCHECK(CalledOnValidThread()); |
608 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) | 609 IPC_BEGIN_MESSAGE_MAP(GpuProcessHost, message) |
609 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) | 610 IPC_MESSAGE_HANDLER(GpuHostMsg_Initialized, OnInitialized) |
610 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) | 611 IPC_MESSAGE_HANDLER(GpuHostMsg_ChannelEstablished, OnChannelEstablished) |
611 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) | 612 IPC_MESSAGE_HANDLER(GpuHostMsg_CommandBufferCreated, OnCommandBufferCreated) |
612 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyCommandBuffer, OnDestroyCommandBuffer) | |
613 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, | 613 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryBufferCreated, |
614 OnGpuMemoryBufferCreated) | 614 OnGpuMemoryBufferCreated) |
615 IPC_MESSAGE_HANDLER(GpuHostMsg_DidCreateOffscreenContext, | 615 IPC_MESSAGE_HANDLER(GpuHostMsg_DidCreateOffscreenContext, |
616 OnDidCreateOffscreenContext) | 616 OnDidCreateOffscreenContext) |
617 IPC_MESSAGE_HANDLER(GpuHostMsg_DidLoseContext, OnDidLoseContext) | 617 IPC_MESSAGE_HANDLER(GpuHostMsg_DidLoseContext, OnDidLoseContext) |
618 IPC_MESSAGE_HANDLER(GpuHostMsg_DidDestroyOffscreenContext, | 618 IPC_MESSAGE_HANDLER(GpuHostMsg_DidDestroyOffscreenContext, |
619 OnDidDestroyOffscreenContext) | 619 OnDidDestroyOffscreenContext) |
620 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, | 620 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, |
621 OnGpuMemoryUmaStatsReceived) | 621 OnGpuMemoryUmaStatsReceived) |
622 #if defined(OS_MACOSX) | 622 #if defined(OS_MACOSX) |
(...skipping 16 matching lines...) Expand all Loading... |
639 | 639 |
640 while (!queued_messages_.empty()) { | 640 while (!queued_messages_.empty()) { |
641 Send(queued_messages_.front()); | 641 Send(queued_messages_.front()); |
642 queued_messages_.pop(); | 642 queued_messages_.pop(); |
643 } | 643 } |
644 } | 644 } |
645 | 645 |
646 void GpuProcessHost::EstablishGpuChannel( | 646 void GpuProcessHost::EstablishGpuChannel( |
647 int client_id, | 647 int client_id, |
648 uint64_t client_tracing_id, | 648 uint64_t client_tracing_id, |
649 bool share_context, | 649 bool preempts, |
| 650 bool preempted, |
650 bool allow_future_sync_points, | 651 bool allow_future_sync_points, |
651 bool allow_real_time_streams, | 652 bool allow_real_time_streams, |
652 const EstablishChannelCallback& callback) { | 653 const EstablishChannelCallback& callback) { |
653 DCHECK(CalledOnValidThread()); | 654 DCHECK(CalledOnValidThread()); |
654 TRACE_EVENT0("gpu", "GpuProcessHost::EstablishGpuChannel"); | 655 TRACE_EVENT0("gpu", "GpuProcessHost::EstablishGpuChannel"); |
655 | 656 |
656 // If GPU features are already blacklisted, no need to establish the channel. | 657 // If GPU features are already blacklisted, no need to establish the channel. |
657 if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { | 658 if (!GpuDataManagerImpl::GetInstance()->GpuAccessAllowed(NULL)) { |
658 DVLOG(1) << "GPU blacklisted, refusing to open a GPU channel."; | 659 DVLOG(1) << "GPU blacklisted, refusing to open a GPU channel."; |
659 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 660 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
660 return; | 661 return; |
661 } | 662 } |
662 | 663 |
663 if (Send(new GpuMsg_EstablishChannel(client_id, client_tracing_id, | 664 GpuMsg_EstablishChannel_Params params; |
664 share_context, allow_future_sync_points, | 665 params.client_id = client_id; |
665 allow_real_time_streams))) { | 666 params.client_tracing_id = client_tracing_id; |
| 667 params.preempts = preempts; |
| 668 params.preempted = preempted; |
| 669 params.allow_future_sync_points = allow_future_sync_points; |
| 670 params.allow_real_time_streams = allow_real_time_streams; |
| 671 if (Send(new GpuMsg_EstablishChannel(params))) { |
666 channel_requests_.push(callback); | 672 channel_requests_.push(callback); |
667 } else { | 673 } else { |
668 DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; | 674 DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; |
669 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 675 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
670 } | 676 } |
671 | 677 |
672 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 678 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
673 switches::kDisableGpuShaderDiskCache)) { | 679 switches::kDisableGpuShaderDiskCache)) { |
674 CreateChannelCache(client_id); | 680 CreateChannelCache(client_id); |
675 } | 681 } |
676 } | 682 } |
677 | 683 |
678 void GpuProcessHost::CreateViewCommandBuffer( | 684 void GpuProcessHost::CreateViewCommandBuffer( |
679 const gfx::GLSurfaceHandle& compositing_surface, | 685 const gfx::GLSurfaceHandle& compositing_surface, |
680 int surface_id, | |
681 int client_id, | 686 int client_id, |
682 const GPUCreateCommandBufferConfig& init_params, | 687 const GPUCreateCommandBufferConfig& init_params, |
683 int route_id, | 688 int route_id, |
684 const CreateCommandBufferCallback& callback) { | 689 const CreateCommandBufferCallback& callback) { |
685 TRACE_EVENT0("gpu", "GpuProcessHost::CreateViewCommandBuffer"); | 690 TRACE_EVENT0("gpu", "GpuProcessHost::CreateViewCommandBuffer"); |
686 | 691 |
687 DCHECK(CalledOnValidThread()); | 692 DCHECK(CalledOnValidThread()); |
688 | 693 |
689 if (!compositing_surface.is_null() && | 694 if (!compositing_surface.is_null() && |
690 Send(new GpuMsg_CreateViewCommandBuffer( | 695 Send(new GpuMsg_CreateViewCommandBuffer(compositing_surface, client_id, |
691 compositing_surface, surface_id, client_id, init_params, route_id))) { | 696 init_params, route_id))) { |
692 create_command_buffer_requests_.push(callback); | 697 create_command_buffer_requests_.push(callback); |
693 surface_refs_.insert(std::make_pair(surface_id, | |
694 GpuSurfaceTracker::GetInstance()->GetSurfaceRefForSurface(surface_id))); | |
695 } else { | 698 } else { |
696 // Could distinguish here between compositing_surface being NULL | 699 // Could distinguish here between compositing_surface being NULL |
697 // and Send failing, if desired. | 700 // and Send failing, if desired. |
698 callback.Run(CREATE_COMMAND_BUFFER_FAILED_AND_CHANNEL_LOST); | 701 callback.Run(CREATE_COMMAND_BUFFER_FAILED_AND_CHANNEL_LOST); |
699 } | 702 } |
700 } | 703 } |
701 | 704 |
702 void GpuProcessHost::CreateGpuMemoryBuffer( | 705 void GpuProcessHost::CreateGpuMemoryBuffer( |
703 gfx::GpuMemoryBufferId id, | 706 gfx::GpuMemoryBufferId id, |
704 const gfx::Size& size, | 707 const gfx::Size& size, |
705 gfx::BufferFormat format, | 708 gfx::BufferFormat format, |
706 gfx::BufferUsage usage, | 709 gfx::BufferUsage usage, |
707 int client_id, | 710 int client_id, |
708 int32 surface_id, | 711 int32 surface_id, |
709 const CreateGpuMemoryBufferCallback& callback) { | 712 const CreateGpuMemoryBufferCallback& callback) { |
710 TRACE_EVENT0("gpu", "GpuProcessHost::CreateGpuMemoryBuffer"); | 713 TRACE_EVENT0("gpu", "GpuProcessHost::CreateGpuMemoryBuffer"); |
711 | 714 |
712 DCHECK(CalledOnValidThread()); | 715 DCHECK(CalledOnValidThread()); |
713 | 716 |
714 GpuMsg_CreateGpuMemoryBuffer_Params params; | 717 GpuMsg_CreateGpuMemoryBuffer_Params params; |
715 params.id = id; | 718 params.id = id; |
716 params.size = size; | 719 params.size = size; |
717 params.format = format; | 720 params.format = format; |
718 params.usage = usage; | 721 params.usage = usage; |
719 params.client_id = client_id; | 722 params.client_id = client_id; |
720 params.surface_handle = | 723 params.surface_handle = |
721 GpuSurfaceTracker::GetInstance()->GetSurfaceHandle(surface_id).handle; | 724 GpuSurfaceTracker::GetInstance()->GetSurfaceHandle(surface_id).handle; |
722 if (Send(new GpuMsg_CreateGpuMemoryBuffer(params))) { | 725 if (Send(new GpuMsg_CreateGpuMemoryBuffer(params))) { |
723 create_gpu_memory_buffer_requests_.push(callback); | 726 create_gpu_memory_buffer_requests_.push(callback); |
724 create_gpu_memory_buffer_surface_refs_.push(surface_id); | |
725 if (surface_id) { | |
726 surface_refs_.insert(std::make_pair( | |
727 surface_id, GpuSurfaceTracker::GetInstance()->GetSurfaceRefForSurface( | |
728 surface_id))); | |
729 } | |
730 } else { | 727 } else { |
731 callback.Run(gfx::GpuMemoryBufferHandle()); | 728 callback.Run(gfx::GpuMemoryBufferHandle()); |
732 } | 729 } |
733 } | 730 } |
734 | 731 |
735 void GpuProcessHost::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, | 732 void GpuProcessHost::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
736 int client_id, | 733 int client_id, |
737 int sync_point) { | 734 int sync_point) { |
738 TRACE_EVENT0("gpu", "GpuProcessHost::DestroyGpuMemoryBuffer"); | 735 TRACE_EVENT0("gpu", "GpuProcessHost::DestroyGpuMemoryBuffer"); |
739 | 736 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 | 786 |
790 if (create_command_buffer_requests_.empty()) | 787 if (create_command_buffer_requests_.empty()) |
791 return; | 788 return; |
792 | 789 |
793 CreateCommandBufferCallback callback = | 790 CreateCommandBufferCallback callback = |
794 create_command_buffer_requests_.front(); | 791 create_command_buffer_requests_.front(); |
795 create_command_buffer_requests_.pop(); | 792 create_command_buffer_requests_.pop(); |
796 callback.Run(result); | 793 callback.Run(result); |
797 } | 794 } |
798 | 795 |
799 void GpuProcessHost::OnDestroyCommandBuffer(int32 surface_id) { | |
800 TRACE_EVENT0("gpu", "GpuProcessHost::OnDestroyCommandBuffer"); | |
801 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); | |
802 if (it != surface_refs_.end()) { | |
803 surface_refs_.erase(it); | |
804 } | |
805 } | |
806 | |
807 void GpuProcessHost::OnGpuMemoryBufferCreated( | 796 void GpuProcessHost::OnGpuMemoryBufferCreated( |
808 const gfx::GpuMemoryBufferHandle& handle) { | 797 const gfx::GpuMemoryBufferHandle& handle) { |
809 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); | 798 TRACE_EVENT0("gpu", "GpuProcessHost::OnGpuMemoryBufferCreated"); |
810 | 799 |
811 if (create_gpu_memory_buffer_requests_.empty()) | 800 if (create_gpu_memory_buffer_requests_.empty()) |
812 return; | 801 return; |
813 | 802 |
814 CreateGpuMemoryBufferCallback callback = | 803 CreateGpuMemoryBufferCallback callback = |
815 create_gpu_memory_buffer_requests_.front(); | 804 create_gpu_memory_buffer_requests_.front(); |
816 create_gpu_memory_buffer_requests_.pop(); | 805 create_gpu_memory_buffer_requests_.pop(); |
817 callback.Run(handle); | 806 callback.Run(handle); |
818 | |
819 int32 surface_id = create_gpu_memory_buffer_surface_refs_.front(); | |
820 create_gpu_memory_buffer_surface_refs_.pop(); | |
821 SurfaceRefMap::iterator it = surface_refs_.find(surface_id); | |
822 if (it != surface_refs_.end()) { | |
823 surface_refs_.erase(it); | |
824 } | |
825 } | 807 } |
826 | 808 |
827 void GpuProcessHost::OnDidCreateOffscreenContext(const GURL& url) { | 809 void GpuProcessHost::OnDidCreateOffscreenContext(const GURL& url) { |
828 urls_with_live_offscreen_contexts_.insert(url); | 810 urls_with_live_offscreen_contexts_.insert(url); |
829 } | 811 } |
830 | 812 |
831 void GpuProcessHost::OnDidLoseContext(bool offscreen, | 813 void GpuProcessHost::OnDidLoseContext(bool offscreen, |
832 gpu::error::ContextLostReason reason, | 814 gpu::error::ContextLostReason reason, |
833 const GURL& url) { | 815 const GURL& url) { |
834 // TODO(kbr): would be nice to see the "offscreen" flag too. | 816 // TODO(kbr): would be nice to see the "offscreen" flag too. |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1126 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
1145 ClientIdToShaderCacheMap::iterator iter = | 1127 ClientIdToShaderCacheMap::iterator iter = |
1146 client_id_to_shader_cache_.find(client_id); | 1128 client_id_to_shader_cache_.find(client_id); |
1147 // If the cache doesn't exist then this is an off the record profile. | 1129 // If the cache doesn't exist then this is an off the record profile. |
1148 if (iter == client_id_to_shader_cache_.end()) | 1130 if (iter == client_id_to_shader_cache_.end()) |
1149 return; | 1131 return; |
1150 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1132 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
1151 } | 1133 } |
1152 | 1134 |
1153 } // namespace content | 1135 } // namespace content |
OLD | NEW |