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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 ->AllocateSurfaceClientId())), | 387 ->AllocateSurfaceClientId())), |
388 resource_manager_(root_window), | 388 resource_manager_(root_window), |
389 has_transparent_background_(false), | 389 has_transparent_background_(false), |
390 device_scale_factor_(1), | 390 device_scale_factor_(1), |
391 window_(NULL), | 391 window_(NULL), |
392 surface_handle_(gpu::kNullSurfaceHandle), | 392 surface_handle_(gpu::kNullSurfaceHandle), |
393 client_(client), | 393 client_(client), |
394 root_window_(root_window), | 394 root_window_(root_window), |
395 needs_animate_(false), | 395 needs_animate_(false), |
396 pending_swapbuffers_(0U), | 396 pending_swapbuffers_(0U), |
| 397 num_successive_gpu_process_initialization_failures_(0), |
397 num_successive_context_creation_failures_(0), | 398 num_successive_context_creation_failures_(0), |
398 output_surface_request_pending_(false), | 399 output_surface_request_pending_(false), |
399 needs_begin_frames_(false), | 400 needs_begin_frames_(false), |
400 weak_factory_(this) { | 401 weak_factory_(this) { |
401 ui::ContextProviderFactory::GetInstance() | 402 ui::ContextProviderFactory::GetInstance() |
402 ->GetSurfaceManager() | 403 ->GetSurfaceManager() |
403 ->RegisterSurfaceClientId(surface_id_allocator_->client_id()); | 404 ->RegisterSurfaceClientId(surface_id_allocator_->client_id()); |
404 DCHECK(client); | 405 DCHECK(client); |
405 DCHECK(root_window); | 406 DCHECK(root_window); |
406 DCHECK(root_window->GetLayer() == nullptr); | 407 DCHECK(root_window->GetLayer() == nullptr); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 | 643 |
643 if (!display_output_surface) | 644 if (!display_output_surface) |
644 return; | 645 return; |
645 | 646 |
646 InitializeDisplay(std::move(display_output_surface), | 647 InitializeDisplay(std::move(display_output_surface), |
647 std::move(vulkan_context_provider), nullptr); | 648 std::move(vulkan_context_provider), nullptr); |
648 } | 649 } |
649 #endif | 650 #endif |
650 | 651 |
651 void CompositorImpl::CreateCompositorOutputSurface( | 652 void CompositorImpl::CreateCompositorOutputSurface( |
652 const scoped_refptr<cc::ContextProvider>& context_provider) { | 653 const scoped_refptr<cc::ContextProvider>& context_provider, |
653 // This callback should run only if we have a pending output surface request, | 654 ui::ContextProviderFactory::ContextCreationResult 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_); | 655 DCHECK(output_surface_request_pending_); |
658 DCHECK(host_->visible()); | |
659 DCHECK(window_); | |
660 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); | |
661 DCHECK(context_provider); | |
662 | 656 |
663 scoped_refptr<ContextProviderCommandBuffer> context_provider_command_buffer = | 657 switch (result) { |
664 static_cast<ContextProviderCommandBuffer*>(context_provider.get()); | 658 // Don't retry if we are shutting down or if the Gpu Surface handle was |
665 std::unique_ptr<cc::OutputSurface> display_output_surface( | 659 // lost. The Gpu Surface handle loss should happen only if we are invisible |
666 new OutputSurfaceWithoutParent( | 660 // or this was from a previous request and the current surface has changed, |
667 context_provider_command_buffer, | 661 // in which case we would have made another request with the factory. |
668 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | 662 case ui::ContextProviderFactory::ContextCreationResult:: |
669 base::Unretained(this)))); | 663 FAILURE_FACTORY_SHUTDOWN: |
670 InitializeDisplay(std::move(display_output_surface), nullptr, | 664 case ui::ContextProviderFactory::ContextCreationResult:: |
671 std::move(context_provider)); | 665 FAILURE_GPU_SURFACE_HANDLE_LOST: |
| 666 break; |
| 667 case ui::ContextProviderFactory::ContextCreationResult:: |
| 668 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED: |
| 669 // Retry only if we are visible. |
| 670 if (host_->visible()) { |
| 671 LOG_IF(FATAL, |
| 672 ++num_successive_gpu_process_initialization_failures_ >= 2) |
| 673 << "Too many GPU Process initialization failures. Giving up... "; |
| 674 HandlePendingOutputSurfaceRequest(); |
| 675 } |
| 676 break; |
| 677 case ui::ContextProviderFactory::ContextCreationResult::SUCCESS: |
| 678 DCHECK(host_->visible()); |
| 679 DCHECK(window_); |
| 680 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); |
| 681 DCHECK(context_provider); |
| 682 |
| 683 num_successive_gpu_process_initialization_failures_ = 0; |
| 684 scoped_refptr<ContextProviderCommandBuffer> |
| 685 context_provider_command_buffer = |
| 686 static_cast<ContextProviderCommandBuffer*>( |
| 687 context_provider.get()); |
| 688 std::unique_ptr<cc::OutputSurface> display_output_surface( |
| 689 new OutputSurfaceWithoutParent( |
| 690 context_provider_command_buffer, |
| 691 base::Bind(&CompositorImpl::PopulateGpuCapabilities, |
| 692 base::Unretained(this)))); |
| 693 InitializeDisplay(std::move(display_output_surface), nullptr, |
| 694 std::move(context_provider)); |
| 695 break; |
| 696 } |
672 } | 697 } |
673 | 698 |
674 void CompositorImpl::InitializeDisplay( | 699 void CompositorImpl::InitializeDisplay( |
675 std::unique_ptr<cc::OutputSurface> display_output_surface, | 700 std::unique_ptr<cc::OutputSurface> display_output_surface, |
676 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 701 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
677 scoped_refptr<cc::ContextProvider> context_provider) { | 702 scoped_refptr<cc::ContextProvider> context_provider) { |
678 DCHECK(output_surface_request_pending_); | 703 DCHECK(output_surface_request_pending_); |
679 | 704 |
680 pending_swapbuffers_ = 0; | 705 pending_swapbuffers_ = 0; |
681 | 706 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 | 820 |
796 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 821 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
797 host_->SetNeedsAnimate(); | 822 host_->SetNeedsAnimate(); |
798 } | 823 } |
799 | 824 |
800 bool CompositorImpl::HavePendingReadbacks() { | 825 bool CompositorImpl::HavePendingReadbacks() { |
801 return !readback_layer_tree_->children().empty(); | 826 return !readback_layer_tree_->children().empty(); |
802 } | 827 } |
803 | 828 |
804 } // namespace content | 829 } // namespace content |
OLD | NEW |