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) { |
danakj
2016/05/04 01:16:01
This branch didn't exist before, we'd skip down to
| |
735 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 747 return base::WrapUnique(new DelegatedCompositorOutputSurface( |
736 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider; | 748 routing_id(), output_surface_id, nullptr, nullptr, nullptr, |
737 if (!use_software) { | 749 frame_swap_message_queue_)); |
738 if (command_line.HasSwitch(switches::kEnableVulkan)) { | 750 } |
739 vulkan_context_provider = cc::VulkanInProcessContextProvider::Create(); | |
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 | 751 |
749 gpu::SharedMemoryLimits limits; | 752 scoped_refptr<ContextProviderCommandBuffer> worker_context_provider = |
750 // The renderer compositor context doesn't do a lot of stuff, so we don't | 753 RenderThreadImpl::current()->SharedWorkerContextProvider(); |
751 // expect it to need a lot of space for commands or transfer. Raster and | 754 if (!worker_context_provider) { |
752 // uploads happen on the worker context instead. | 755 // Cause the compositor to wait and try again. |
753 limits.command_buffer_size = 64 * 1024; | 756 return nullptr; |
754 limits.start_transfer_buffer_size = 64 * 1024; | 757 } |
755 limits.min_transfer_buffer_size = 64 * 1024; | |
756 | 758 |
757 worker_context_provider = | 759 gpu::SharedMemoryLimits limits; |
758 RenderThreadImpl::current()->SharedWorkerContextProvider(); | 760 // The renderer compositor context doesn't do a lot of stuff, so we don't |
759 if (!worker_context_provider) { | 761 // expect it to need a lot of space for commands or transfer. Raster and |
760 // Cause the compositor to wait and try again. | 762 // uploads happen on the worker context instead. |
761 return nullptr; | 763 limits.command_buffer_size = 64 * 1024; |
762 } | 764 limits.start_transfer_buffer_size = 64 * 1024; |
765 limits.min_transfer_buffer_size = 64 * 1024; | |
763 | 766 |
764 // This is for an offscreen context for the compositor. So the default | 767 // This is for an offscreen context for the compositor. So the default |
765 // framebuffer doesn't need alpha, depth, stencil, antialiasing. | 768 // framebuffer doesn't need alpha, depth, stencil, antialiasing. |
766 gpu::gles2::ContextCreationAttribHelper attributes; | 769 gpu::gles2::ContextCreationAttribHelper attributes; |
767 attributes.alpha_size = -1; | 770 attributes.alpha_size = -1; |
768 attributes.depth_size = 0; | 771 attributes.depth_size = 0; |
769 attributes.stencil_size = 0; | 772 attributes.stencil_size = 0; |
770 attributes.samples = 0; | 773 attributes.samples = 0; |
771 attributes.sample_buffers = 0; | 774 attributes.sample_buffers = 0; |
772 attributes.bind_generates_resource = false; | 775 attributes.bind_generates_resource = false; |
773 attributes.lose_context_when_out_of_memory = true; | 776 attributes.lose_context_when_out_of_memory = true; |
774 | 777 |
775 bool automatic_flushes = false; | 778 constexpr bool automatic_flushes = false; |
776 | 779 |
777 // The compositor context shares resources with the worker context. | 780 // The compositor context shares resources with the worker context. |
778 context_provider = new ContextProviderCommandBuffer( | 781 scoped_refptr<ContextProviderCommandBuffer> context_provider( |
779 std::move(gpu_channel_host), gpu::kNullSurfaceHandle, | 782 new ContextProviderCommandBuffer( |
780 GetURLForGraphicsContext3D(), gfx::PreferIntegratedGpu, | 783 std::move(gpu_channel_host), gpu::kNullSurfaceHandle, |
781 automatic_flushes, limits, attributes, worker_context_provider.get(), | 784 GetURLForGraphicsContext3D(), gfx::PreferIntegratedGpu, |
782 command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT); | 785 automatic_flushes, limits, attributes, worker_context_provider.get(), |
786 command_buffer_metrics::RENDER_COMPOSITOR_CONTEXT)); | |
783 | 787 |
784 #if defined(OS_ANDROID) | 788 #if defined(OS_ANDROID) |
785 if (RenderThreadImpl::current() && | 789 if (RenderThreadImpl::current()->sync_compositor_message_filter()) { |
786 RenderThreadImpl::current()->sync_compositor_message_filter()) { | 790 return base::WrapUnique(new SynchronousCompositorOutputSurface( |
787 uint32_t output_surface_id = next_output_surface_id_++; | 791 context_provider, worker_context_provider, routing_id(), |
788 return base::WrapUnique(new SynchronousCompositorOutputSurface( | 792 output_surface_id, |
789 context_provider, worker_context_provider, routing_id(), | 793 RenderThreadImpl::current()->sync_compositor_message_filter(), |
790 output_surface_id, | 794 frame_swap_message_queue_)); |
791 RenderThreadImpl::current()->sync_compositor_message_filter(), | 795 } |
792 frame_swap_message_queue_)); | |
793 } | |
794 #endif | 796 #endif |
795 } | |
796 | 797 |
797 uint32_t output_surface_id = next_output_surface_id_++; | |
798 // Composite-to-mailbox is currently used for layout tests in order to cause | 798 // 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 | 799 // 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. | 800 // no longer be the case when crbug.com/311404 is fixed. |
801 if (!RenderThreadImpl::current() || | 801 if (RenderThreadImpl::current()->layout_test_mode()) { |
802 !RenderThreadImpl::current()->layout_test_mode()) { | 802 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), | 803 routing_id(), output_surface_id, std::move(context_provider), |
806 std::move(worker_context_provider), | 804 std::move(worker_context_provider), frame_swap_message_queue_, |
807 vulkan_context_provider, | 805 cc::RGBA_8888)); |
808 frame_swap_message_queue_)); | |
809 } | 806 } |
810 | 807 |
811 if (!context_provider) { | 808 return base::WrapUnique(new DelegatedCompositorOutputSurface( |
danakj
2016/05/04 01:16:01
Turns out this branch is only for layout tests in
| |
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), | 809 routing_id(), output_surface_id, std::move(context_provider), |
822 std::move(worker_context_provider), frame_swap_message_queue_, | 810 std::move(worker_context_provider), nullptr, frame_swap_message_queue_)); |
823 cc::RGBA_8888)); | |
824 } | 811 } |
825 | 812 |
826 std::unique_ptr<cc::BeginFrameSource> | 813 std::unique_ptr<cc::BeginFrameSource> |
827 RenderWidget::CreateExternalBeginFrameSource() { | 814 RenderWidget::CreateExternalBeginFrameSource() { |
828 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_); | 815 return compositor_deps_->CreateExternalBeginFrameSource(routing_id_); |
829 } | 816 } |
830 | 817 |
831 void RenderWidget::DidCommitAndDrawCompositorFrame() { | 818 void RenderWidget::DidCommitAndDrawCompositorFrame() { |
832 // NOTE: Tests may break if this event is renamed or moved. See | 819 // NOTE: Tests may break if this event is renamed or moved. See |
833 // tab_capture_performancetest.cc. | 820 // tab_capture_performancetest.cc. |
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2093 } | 2080 } |
2094 | 2081 |
2095 float RenderWidget::GetOriginalDeviceScaleFactor() const { | 2082 float RenderWidget::GetOriginalDeviceScaleFactor() const { |
2096 return | 2083 return |
2097 screen_metrics_emulator_ ? | 2084 screen_metrics_emulator_ ? |
2098 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : | 2085 screen_metrics_emulator_->original_screen_info().deviceScaleFactor : |
2099 device_scale_factor_; | 2086 device_scale_factor_; |
2100 } | 2087 } |
2101 | 2088 |
2102 } // namespace content | 2089 } // namespace content |
OLD | NEW |