| 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/renderer_host/compositor_impl_android.h" | 5 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 if (!host_->visible()) | 603 if (!host_->visible()) |
| 604 return; | 604 return; |
| 605 | 605 |
| 606 #if defined(ENABLE_VULKAN) | 606 #if defined(ENABLE_VULKAN) |
| 607 CreateVulkanOutputSurface() | 607 CreateVulkanOutputSurface() |
| 608 if (display_) | 608 if (display_) |
| 609 return; | 609 return; |
| 610 #endif | 610 #endif |
| 611 | 611 |
| 612 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); | 612 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); |
| 613 | 613 ContextProviderFactoryImpl::GetInstance()->RequestGpuChannelHost(base::Bind( |
| 614 ContextProviderFactoryImpl::GetInstance()->CreateDisplayContextProvider( | 614 &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); |
| 615 surface_handle_, GetCompositorContextSharedMemoryLimits(), | |
| 616 GetCompositorContextAttributes(has_transparent_background_), | |
| 617 false /*support_locking*/, false /*automatic_flushes*/, | |
| 618 base::Bind(&CompositorImpl::CreateCompositorOutputSurface, | |
| 619 weak_factory_.GetWeakPtr())); | |
| 620 } | 615 } |
| 621 | 616 |
| 622 #if defined(ENABLE_VULKAN) | 617 #if defined(ENABLE_VULKAN) |
| 623 void CompositorImpl::CreateVulkanOutputSurface() { | 618 void CompositorImpl::CreateVulkanOutputSurface() { |
| 624 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 619 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 625 switches::kEnableVulkan)) | 620 switches::kEnableVulkan)) |
| 626 return; | 621 return; |
| 627 | 622 |
| 628 std::unique_ptr<cc::OutputSurface> display_output_surface; | 623 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 629 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = | 624 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 641 } | 636 } |
| 642 | 637 |
| 643 if (!display_output_surface) | 638 if (!display_output_surface) |
| 644 return; | 639 return; |
| 645 | 640 |
| 646 InitializeDisplay(std::move(display_output_surface), | 641 InitializeDisplay(std::move(display_output_surface), |
| 647 std::move(vulkan_context_provider), nullptr); | 642 std::move(vulkan_context_provider), nullptr); |
| 648 } | 643 } |
| 649 #endif | 644 #endif |
| 650 | 645 |
| 651 void CompositorImpl::CreateCompositorOutputSurface( | 646 void CompositorImpl::OnGpuChannelEstablished( |
| 652 const scoped_refptr<cc::ContextProvider>& context_provider) { | 647 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| 653 // This callback should run only if we have a pending output surface request, | 648 ui::ContextProviderFactory::GpuChannelHostResult result) { |
| 654 // since that is when we should have queued a context request. | |
| 655 // In case the surface was invalidated after the context request was queued, | |
| 656 // the request should have been dropped by the ContextProviderFactory. | |
| 657 DCHECK(output_surface_request_pending_); | 649 DCHECK(output_surface_request_pending_); |
| 658 DCHECK(host_->visible()); | |
| 659 DCHECK(window_); | |
| 660 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); | |
| 661 DCHECK(context_provider); | |
| 662 | 650 |
| 663 scoped_refptr<ContextProviderCommandBuffer> context_provider_command_buffer = | 651 switch (result) { |
| 664 static_cast<ContextProviderCommandBuffer*>(context_provider.get()); | 652 // Don't retry if we are shutting down. |
| 665 std::unique_ptr<cc::OutputSurface> display_output_surface( | 653 case ui::ContextProviderFactory::GpuChannelHostResult:: |
| 666 new OutputSurfaceWithoutParent( | 654 FAILURE_FACTORY_SHUTDOWN: |
| 667 context_provider_command_buffer, | 655 break; |
| 668 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | 656 case ui::ContextProviderFactory::GpuChannelHostResult:: |
| 669 base::Unretained(this)))); | 657 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED: |
| 670 InitializeDisplay(std::move(display_output_surface), nullptr, | 658 // TODO(khushalsagar): Retry or have a fallback path after |
| 671 std::move(context_provider)); | 659 // crbug.com/643282 is resolved. |
| 660 break; |
| 661 case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS: |
| 662 // We don't need the context anymore if we are invisible. |
| 663 if (!host_->visible()) |
| 664 return; |
| 665 |
| 666 DCHECK(window_); |
| 667 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); |
| 668 scoped_refptr<cc::ContextProvider> context_provider = |
| 669 ContextProviderFactoryImpl::GetInstance() |
| 670 ->CreateDisplayContextProvider( |
| 671 surface_handle_, GetCompositorContextSharedMemoryLimits(), |
| 672 GetCompositorContextAttributes(has_transparent_background_), |
| 673 false /*support_locking*/, false /*automatic_flushes*/, |
| 674 std::move(gpu_channel_host)); |
| 675 |
| 676 scoped_refptr<ContextProviderCommandBuffer> |
| 677 context_provider_command_buffer = |
| 678 static_cast<ContextProviderCommandBuffer*>( |
| 679 context_provider.get()); |
| 680 std::unique_ptr<cc::OutputSurface> display_output_surface( |
| 681 new OutputSurfaceWithoutParent( |
| 682 context_provider_command_buffer, |
| 683 base::Bind(&CompositorImpl::PopulateGpuCapabilities, |
| 684 base::Unretained(this)))); |
| 685 InitializeDisplay(std::move(display_output_surface), nullptr, |
| 686 std::move(context_provider)); |
| 687 break; |
| 688 } |
| 672 } | 689 } |
| 673 | 690 |
| 674 void CompositorImpl::InitializeDisplay( | 691 void CompositorImpl::InitializeDisplay( |
| 675 std::unique_ptr<cc::OutputSurface> display_output_surface, | 692 std::unique_ptr<cc::OutputSurface> display_output_surface, |
| 676 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 693 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 677 scoped_refptr<cc::ContextProvider> context_provider) { | 694 scoped_refptr<cc::ContextProvider> context_provider) { |
| 678 DCHECK(output_surface_request_pending_); | 695 DCHECK(output_surface_request_pending_); |
| 679 | 696 |
| 680 pending_swapbuffers_ = 0; | 697 pending_swapbuffers_ = 0; |
| 681 | 698 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 812 |
| 796 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 813 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 797 host_->SetNeedsAnimate(); | 814 host_->SetNeedsAnimate(); |
| 798 } | 815 } |
| 799 | 816 |
| 800 bool CompositorImpl::HavePendingReadbacks() { | 817 bool CompositorImpl::HavePendingReadbacks() { |
| 801 return !readback_layer_tree_->children().empty(); | 818 return !readback_layer_tree_->children().empty(); |
| 802 } | 819 } |
| 803 | 820 |
| 804 } // namespace content | 821 } // namespace content |
| OLD | NEW |