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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 | 708 |
709 #if defined(MOJO_SHELL_CLIENT) | 709 #if defined(MOJO_SHELL_CLIENT) |
710 if (MojoShellConnection::Get() && !use_software && | 710 if (MojoShellConnection::Get() && !use_software && |
711 command_line.HasSwitch(switches::kUseMusInRenderer)) { | 711 command_line.HasSwitch(switches::kUseMusInRenderer)) { |
712 RenderWidgetMusConnection* connection = | 712 RenderWidgetMusConnection* connection = |
713 RenderWidgetMusConnection::GetOrCreate(routing_id()); | 713 RenderWidgetMusConnection::GetOrCreate(routing_id()); |
714 return connection->CreateOutputSurface(); | 714 return connection->CreateOutputSurface(); |
715 } | 715 } |
716 #endif | 716 #endif |
717 | 717 |
| 718 uint32_t output_surface_id = next_output_surface_id_++; |
| 719 |
| 720 if (command_line.HasSwitch(switches::kEnableVulkan)) { |
| 721 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 722 cc::VulkanInProcessContextProvider::Create(); |
| 723 if (vulkan_context_provider) { |
| 724 return base::WrapUnique(new DelegatedCompositorOutputSurface( |
| 725 routing_id(), output_surface_id, nullptr, nullptr, |
| 726 vulkan_context_provider, frame_swap_message_queue_)); |
| 727 } |
| 728 } |
| 729 |
| 730 // Create a gpu process channel and verify we want to use GPU compositing |
| 731 // before creating any context providers. |
718 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; | 732 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host; |
719 if (!use_software) { | 733 if (!use_software) { |
720 CauseForGpuLaunch cause = | 734 gpu_channel_host = RenderThreadImpl::current()->EstablishGpuChannelSync( |
721 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE; | 735 CAUSE_FOR_GPU_LAUNCH_RENDERER_VERIFY_GPU_COMPOSITING); |
722 gpu_channel_host = | |
723 RenderThreadImpl::current()->EstablishGpuChannelSync(cause); | |
724 if (!gpu_channel_host) { | 736 if (!gpu_channel_host) { |
725 // Cause the compositor to wait and try again. | 737 // Cause the compositor to wait and try again. |
726 return nullptr; | 738 return nullptr; |
727 } | 739 } |
728 // We may get a valid channel, but with a software renderer. In that case, | 740 // We may get a valid channel, but with a software renderer. In that case, |
729 // disable GPU compositing. | 741 // disable GPU compositing. |
730 if (gpu_channel_host->gpu_info().software_rendering) | 742 if (gpu_channel_host->gpu_info().software_rendering) |
731 use_software = true; | 743 use_software = true; |
732 } | 744 } |
733 | 745 |
734 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider; | 746 if (use_software) { |
735 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 747 return base::WrapUnique(new CompositorOutputSurface( |
736 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider; | 748 routing_id(), output_surface_id, nullptr, nullptr, nullptr, |
737 if (!use_software) { | 749 base::WrapUnique(new cc::SoftwareOutputDevice), |
738 if (command_line.HasSwitch(switches::kEnableVulkan)) { | 750 frame_swap_message_queue_, true)); |
739 vulkan_context_provider = cc::VulkanInProcessContextProvider::Create(); | 751 } |
740 if (vulkan_context_provider) { | |
741 uint32_t output_surface_id = next_output_surface_id_++; | |
742 return base::WrapUnique(new DelegatedCompositorOutputSurface( | |
743 routing_id(), output_surface_id, context_provider, | |
744 worker_context_provider, vulkan_context_provider, | |
745 frame_swap_message_queue_)); | |
746 } | |
747 } | |
748 | 752 |
749 gpu::SharedMemoryLimits limits; | 753 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider = |
750 // The renderer compositor context doesn't do a lot of stuff, so we don't | 754 RenderThreadImpl::current()->SharedWorkerContextProvider(); |
751 // expect it to need a lot of space for commands or transfer. Raster and | 755 if (!worker_context_provider) { |
752 // uploads happen on the worker context instead. | 756 // Cause the compositor to wait and try again. |
753 limits.command_buffer_size = 64 * 1024; | 757 return nullptr; |
754 limits.start_transfer_buffer_size = 64 * 1024; | 758 } |
755 limits.min_transfer_buffer_size = 64 * 1024; | |
756 | 759 |
757 worker_context_provider = | 760 gpu::SharedMemoryLimits limits; |
758 RenderThreadImpl::current()->SharedWorkerContextProvider(); | 761 // The renderer compositor context doesn't do a lot of stuff, so we don't |
759 if (!worker_context_provider) { | 762 // expect it to need a lot of space for commands or transfer. Raster and |
760 // Cause the compositor to wait and try again. | 763 // uploads happen on the worker context instead. |
761 return nullptr; | 764 limits.command_buffer_size = 64 * 1024; |
762 } | 765 limits.start_transfer_buffer_size = 64 * 1024; |
| 766 limits.min_transfer_buffer_size = 64 * 1024; |
763 | 767 |
764 // This is for an offscreen context for the compositor. So the default | 768 // This is for an offscreen context for the compositor. So the default |
765 // framebuffer doesn't need alpha, depth, stencil, antialiasing. | 769 // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
766 gpu::gles2::ContextCreationAttribHelper attributes; | 770 gpu::gles2::ContextCreationAttribHelper attributes; |
767 attributes.alpha_size = -1; | 771 attributes.alpha_size = -1; |
768 attributes.depth_size = 0; | 772 attributes.depth_size = 0; |
769 attributes.stencil_size = 0; | 773 attributes.stencil_size = 0; |
770 attributes.samples = 0; | 774 attributes.samples = 0; |
771 attributes.sample_buffers = 0; | 775 attributes.sample_buffers = 0; |
772 attributes.bind_generates_resource = false; | 776 attributes.bind_generates_resource = false; |
773 attributes.lose_context_when_out_of_memory = true; | 777 attributes.lose_context_when_out_of_memory = true; |
774 | 778 |
775 bool automatic_flushes = false; | 779 constexpr bool automatic_flushes = false; |
776 | 780 |
777 // The compositor context shares resources with the worker context. | 781 // The compositor context shares resources with the worker context. |
778 context_provider = new ContextProviderCommandBuffer( | 782 scoped_refptr<ContextProviderCommandBuffer> context_provider( |
779 std::move(gpu_channel_host), gpu::kNullSurfaceHandle, | 783 new ContextProviderCommandBuffer( |
780 GetURLForGraphicsContext3D(), gfx::PreferIntegratedGpu, | 784 std::move(gpu_channel_host), gpu::kNullSurfaceHandle, |
781 automatic_flushes, limits, attributes, worker_context_provider.get(), | 785 GetURLForGraphicsContext3D(), gfx::PreferIntegratedGpu, |
782 command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT); | 786 automatic_flushes, limits, attributes, worker_context_provider.get(), |
| 787 command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT)); |
783 | 788 |
784 #if defined(OS_ANDROID) | 789 #if defined(OS_ANDROID) |
785 if (RenderThreadImpl::current() && | 790 if (RenderThreadImpl::current()->sync_compositor_message_filter()) { |
786 RenderThreadImpl::current()->sync_compositor_message_filter()) { | 791 return base::WrapUnique(new SynchronousCompositorOutputSurface( |
787 uint32_t output_surface_id = next_output_surface_id_++; | 792 context_provider, worker_context_provider, routing_id(), |
788 return base::WrapUnique(new SynchronousCompositorOutputSurface( | 793 output_surface_id, |
789 context_provider, worker_context_provider, routing_id(), | 794 RenderThreadImpl::current()->sync_compositor_message_filter(), |
790 output_surface_id, | 795 frame_swap_message_queue_)); |
791 RenderThreadImpl::current()->sync_compositor_message_filter(), | 796 } |
792 frame_swap_message_queue_)); | |
793 } | |
794 #endif | 797 #endif |
795 } | |
796 | 798 |
797 uint32_t output_surface_id = next_output_surface_id_++; | |
798 // Composite-to-mailbox is currently used for layout tests in order to cause | 799 // Composite-to-mailbox is currently used for layout tests in order to cause |
799 // them to draw inside in the renderer to do the readback there. This should | 800 // them to draw inside in the renderer to do the readback there. This should |
800 // no longer be the case when crbug.com/311404 is fixed. | 801 // no longer be the case when crbug.com/311404 is fixed. |
801 if (!RenderThreadImpl::current() || | 802 if (RenderThreadImpl::current()->layout_test_mode()) { |
802 !RenderThreadImpl::current()->layout_test_mode()) { | 803 return base::WrapUnique(new MailboxOutputSurface( |
803 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner()); | |
804 return base::WrapUnique(new DelegatedCompositorOutputSurface( | |
805 routing_id(), output_surface_id, std::move(context_provider), | 804 routing_id(), output_surface_id, std::move(context_provider), |
806 std::move(worker_context_provider), | 805 std::move(worker_context_provider), frame_swap_message_queue_, |
807 vulkan_context_provider, | 806 cc::RGBA_8888)); |
808 frame_swap_message_queue_)); | |
809 } | 807 } |
810 | 808 |
811 if (!context_provider) { | 809 return base::WrapUnique(new DelegatedCompositorOutputSurface( |
812 std::unique_ptr<cc::SoftwareOutputDevice> software_device( | |
813 new cc::SoftwareOutputDevice()); | |
814 | |
815 return base::WrapUnique(new CompositorOutputSurface( | |
816 routing_id(), output_surface_id, nullptr, nullptr, nullptr, | |
817 std::move(software_device), frame_swap_message_queue_, true)); | |
818 } | |
819 | |
820 return base::WrapUnique(new MailboxOutputSurface( | |
821 routing_id(), output_surface_id, std::move(context_provider), | 810 routing_id(), output_surface_id, std::move(context_provider), |
822 std::move(worker_context_provider), frame_swap_message_queue_, | 811 std::move(worker_context_provider), nullptr, frame_swap_message_queue_)); |
823 cc::RGBA_8888)); | |
824 } | 812 } |
825 | 813 |
826 std::unique_ptr<cc::BeginFrameSource> | 814 std::unique_ptr<cc::BeginFrameSource> |
827 RenderWidget::CreateExternalBeginFrameSource() { | 815 RenderWidget::CreateExternalBeginFrameSource() { |
828 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_); | 816 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_); |
829 } | 817 } |
830 | 818 |
831 void RenderWidget::DidCommitAndDrawCompositorFrame() { | 819 void RenderWidget::DidCommitAndDrawCompositorFrame() { |
832 // NOTE: Tests may break if this event is renamed or moved. See | 820 // NOTE: Tests may break if this event is renamed or moved. See |
833 // tab_capture_performancetest.cc. | 821 // tab_capture_performancetest.cc. |
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 } | 2081 } |
2094 | 2082 |
2095 float RenderWidget::GetOriginalDeviceScaleFactor() const { | 2083 float RenderWidget::GetOriginalDeviceScaleFactor() const { |
2096 return | 2084 return |
2097 screen_metrics_emulator_ ? | 2085 screen_metrics_emulator_ ? |
2098 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : | 2086 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : |
2099 device_scale_factor_; | 2087 device_scale_factor_; |
2100 } | 2088 } |
2101 | 2089 |
2102 } // namespace content | 2090 } // namespace content |
OLD | NEW |