| 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 | 496 |
| 497 cc::LayerTreeHost::InitParams params; | 497 cc::LayerTreeHost::InitParams params; |
| 498 params.client = this; | 498 params.client = this; |
| 499 params.shared_bitmap_manager = HostSharedBitmapManager::current(); | 499 params.shared_bitmap_manager = HostSharedBitmapManager::current(); |
| 500 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); | 500 params.gpu_memory_buffer_manager = BrowserGpuMemoryBufferManager::current(); |
| 501 params.task_graph_runner = g_task_graph_runner.Pointer(); | 501 params.task_graph_runner = g_task_graph_runner.Pointer(); |
| 502 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 502 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 503 params.settings = &settings; | 503 params.settings = &settings; |
| 504 params.animation_host = cc::AnimationHost::CreateMainInstance(); | 504 params.animation_host = cc::AnimationHost::CreateMainInstance(); |
| 505 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); | 505 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, ¶ms); |
| 506 DCHECK(!host_->visible()); | 506 DCHECK(!host_->IsVisible()); |
| 507 host_->GetLayerTree()->SetRootLayer(root_window_->GetLayer()); | 507 host_->GetLayerTree()->SetRootLayer(root_window_->GetLayer()); |
| 508 host_->set_surface_client_id(surface_id_allocator_->client_id()); | 508 host_->SetSurfaceClientId(surface_id_allocator_->client_id()); |
| 509 host_->GetLayerTree()->SetViewportSize(size_); | 509 host_->GetLayerTree()->SetViewportSize(size_); |
| 510 host_->GetLayerTree()->set_has_transparent_background( | 510 host_->GetLayerTree()->set_has_transparent_background( |
| 511 has_transparent_background_); | 511 has_transparent_background_); |
| 512 host_->GetLayerTree()->SetDeviceScaleFactor(device_scale_factor_); | 512 host_->GetLayerTree()->SetDeviceScaleFactor(device_scale_factor_); |
| 513 | 513 |
| 514 if (needs_animate_) | 514 if (needs_animate_) |
| 515 host_->SetNeedsAnimate(); | 515 host_->SetNeedsAnimate(); |
| 516 } | 516 } |
| 517 | 517 |
| 518 void CompositorImpl::SetVisible(bool visible) { | 518 void CompositorImpl::SetVisible(bool visible) { |
| 519 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); | 519 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); |
| 520 if (!visible) { | 520 if (!visible) { |
| 521 DCHECK(host_->visible()); | 521 DCHECK(host_->IsVisible()); |
| 522 | 522 |
| 523 // Make a best effort to try to complete pending readbacks. | 523 // Make a best effort to try to complete pending readbacks. |
| 524 // TODO(crbug.com/637035): Consider doing this in a better way, | 524 // TODO(crbug.com/637035): Consider doing this in a better way, |
| 525 // ideally with the guarantee of readbacks completing. | 525 // ideally with the guarantee of readbacks completing. |
| 526 if (display_.get() && HavePendingReadbacks()) | 526 if (display_.get() && HavePendingReadbacks()) |
| 527 display_->ForceImmediateDrawAndSwapIfPossible(); | 527 display_->ForceImmediateDrawAndSwapIfPossible(); |
| 528 | 528 |
| 529 host_->SetVisible(false); | 529 host_->SetVisible(false); |
| 530 host_->ReleaseOutputSurface(); | 530 host_->ReleaseOutputSurface(); |
| 531 pending_swapbuffers_ = 0; | 531 pending_swapbuffers_ = 0; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 555 root_window_->GetLayer()->SetBounds(size); | 555 root_window_->GetLayer()->SetBounds(size); |
| 556 } | 556 } |
| 557 | 557 |
| 558 void CompositorImpl::SetHasTransparentBackground(bool flag) { | 558 void CompositorImpl::SetHasTransparentBackground(bool flag) { |
| 559 has_transparent_background_ = flag; | 559 has_transparent_background_ = flag; |
| 560 if (host_) | 560 if (host_) |
| 561 host_->GetLayerTree()->set_has_transparent_background(flag); | 561 host_->GetLayerTree()->set_has_transparent_background(flag); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void CompositorImpl::SetNeedsComposite() { | 564 void CompositorImpl::SetNeedsComposite() { |
| 565 if (!host_->visible()) | 565 if (!host_->IsVisible()) |
| 566 return; | 566 return; |
| 567 TRACE_EVENT0("compositor", "Compositor::SetNeedsComposite"); | 567 TRACE_EVENT0("compositor", "Compositor::SetNeedsComposite"); |
| 568 host_->SetNeedsAnimate(); | 568 host_->SetNeedsAnimate(); |
| 569 } | 569 } |
| 570 | 570 |
| 571 void CompositorImpl::UpdateLayerTreeHost() { | 571 void CompositorImpl::UpdateLayerTreeHost() { |
| 572 client_->UpdateLayerTreeHost(); | 572 client_->UpdateLayerTreeHost(); |
| 573 if (needs_animate_) { | 573 if (needs_animate_) { |
| 574 needs_animate_ = false; | 574 needs_animate_ = false; |
| 575 root_window_->Animate(base::TimeTicks::Now()); | 575 root_window_->Animate(base::TimeTicks::Now()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 593 LOG(ERROR) << "Failed to init OutputSurface for compositor."; | 593 LOG(ERROR) << "Failed to init OutputSurface for compositor."; |
| 594 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) | 594 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) |
| 595 << "Too many context creation failures. Giving up... "; | 595 << "Too many context creation failures. Giving up... "; |
| 596 HandlePendingOutputSurfaceRequest(); | 596 HandlePendingOutputSurfaceRequest(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void CompositorImpl::HandlePendingOutputSurfaceRequest() { | 599 void CompositorImpl::HandlePendingOutputSurfaceRequest() { |
| 600 DCHECK(output_surface_request_pending_); | 600 DCHECK(output_surface_request_pending_); |
| 601 | 601 |
| 602 // We might have been made invisible now. | 602 // We might have been made invisible now. |
| 603 if (!host_->visible()) | 603 if (!host_->IsVisible()) |
| 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 ContextProviderFactoryImpl::GetInstance()->RequestGpuChannelHost(base::Bind( | 613 ContextProviderFactoryImpl::GetInstance()->RequestGpuChannelHost(base::Bind( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 case ui::ContextProviderFactory::GpuChannelHostResult:: | 657 case ui::ContextProviderFactory::GpuChannelHostResult:: |
| 658 FAILURE_FACTORY_SHUTDOWN: | 658 FAILURE_FACTORY_SHUTDOWN: |
| 659 break; | 659 break; |
| 660 case ui::ContextProviderFactory::GpuChannelHostResult:: | 660 case ui::ContextProviderFactory::GpuChannelHostResult:: |
| 661 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED: | 661 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED: |
| 662 // TODO(khushalsagar): Retry or have a fallback path after | 662 // TODO(khushalsagar): Retry or have a fallback path after |
| 663 // crbug.com/643282 is resolved. | 663 // crbug.com/643282 is resolved. |
| 664 break; | 664 break; |
| 665 case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS: | 665 case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS: |
| 666 // We don't need the context anymore if we are invisible. | 666 // We don't need the context anymore if we are invisible. |
| 667 if (!host_->visible()) | 667 if (!host_->IsVisible()) |
| 668 return; | 668 return; |
| 669 | 669 |
| 670 DCHECK(window_); | 670 DCHECK(window_); |
| 671 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); | 671 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); |
| 672 scoped_refptr<cc::ContextProvider> context_provider = | 672 scoped_refptr<cc::ContextProvider> context_provider = |
| 673 ContextProviderFactoryImpl::GetInstance() | 673 ContextProviderFactoryImpl::GetInstance() |
| 674 ->CreateDisplayContextProvider( | 674 ->CreateDisplayContextProvider( |
| 675 surface_handle_, GetCompositorContextSharedMemoryLimits(), | 675 surface_handle_, GetCompositorContextSharedMemoryLimits(), |
| 676 GetCompositorContextAttributes(has_transparent_background_), | 676 GetCompositorContextAttributes(has_transparent_background_), |
| 677 false /*support_locking*/, false /*automatic_flushes*/, | 677 false /*support_locking*/, false /*automatic_flushes*/, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 705 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); | 705 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); |
| 706 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source( | 706 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source( |
| 707 new ExternalBeginFrameSource(this)); | 707 new ExternalBeginFrameSource(this)); |
| 708 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 708 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 709 begin_frame_source.get(), task_runner, | 709 begin_frame_source.get(), task_runner, |
| 710 display_output_surface->capabilities().max_frames_pending)); | 710 display_output_surface->capabilities().max_frames_pending)); |
| 711 | 711 |
| 712 display_.reset(new cc::Display( | 712 display_.reset(new cc::Display( |
| 713 HostSharedBitmapManager::current(), | 713 HostSharedBitmapManager::current(), |
| 714 BrowserGpuMemoryBufferManager::current(), | 714 BrowserGpuMemoryBufferManager::current(), |
| 715 host_->settings().renderer_settings, std::move(begin_frame_source), | 715 host_->GetSettings().renderer_settings, std::move(begin_frame_source), |
| 716 std::move(display_output_surface), std::move(scheduler), | 716 std::move(display_output_surface), std::move(scheduler), |
| 717 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); | 717 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); |
| 718 | 718 |
| 719 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( | 719 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( |
| 720 vulkan_context_provider ? new cc::SurfaceDisplayOutputSurface( | 720 vulkan_context_provider ? new cc::SurfaceDisplayOutputSurface( |
| 721 manager, surface_id_allocator_.get(), | 721 manager, surface_id_allocator_.get(), |
| 722 display_.get(), vulkan_context_provider) | 722 display_.get(), vulkan_context_provider) |
| 723 : new cc::SurfaceDisplayOutputSurface( | 723 : new cc::SurfaceDisplayOutputSurface( |
| 724 manager, surface_id_allocator_.get(), | 724 manager, surface_id_allocator_.get(), |
| 725 display_.get(), context_provider, nullptr)); | 725 display_.get(), context_provider, nullptr)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 DCHECK_GT(pending_swapbuffers_, 0U); | 767 DCHECK_GT(pending_swapbuffers_, 0U); |
| 768 pending_swapbuffers_--; | 768 pending_swapbuffers_--; |
| 769 client_->OnSwapBuffersCompleted(pending_swapbuffers_); | 769 client_->OnSwapBuffersCompleted(pending_swapbuffers_); |
| 770 } | 770 } |
| 771 | 771 |
| 772 void CompositorImpl::DidAbortSwapBuffers() { | 772 void CompositorImpl::DidAbortSwapBuffers() { |
| 773 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); | 773 TRACE_EVENT0("compositor", "CompositorImpl::DidAbortSwapBuffers"); |
| 774 // This really gets called only once from | 774 // This really gets called only once from |
| 775 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the | 775 // SingleThreadProxy::DidLoseOutputSurfaceOnImplThread() when the |
| 776 // context was lost. | 776 // context was lost. |
| 777 if (host_->visible()) | 777 if (host_->IsVisible()) |
| 778 host_->SetNeedsCommit(); | 778 host_->SetNeedsCommit(); |
| 779 client_->OnSwapBuffersCompleted(0); | 779 client_->OnSwapBuffersCompleted(0); |
| 780 } | 780 } |
| 781 | 781 |
| 782 void CompositorImpl::DidCommit() { | 782 void CompositorImpl::DidCommit() { |
| 783 root_window_->OnCompositingDidCommit(); | 783 root_window_->OnCompositingDidCommit(); |
| 784 } | 784 } |
| 785 | 785 |
| 786 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { | 786 void CompositorImpl::AttachLayerForReadback(scoped_refptr<cc::Layer> layer) { |
| 787 readback_layer_tree_->AddChild(layer); | 787 readback_layer_tree_->AddChild(layer); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 804 if (needs_begin_frames_ == needs_begin_frames) | 804 if (needs_begin_frames_ == needs_begin_frames) |
| 805 return; | 805 return; |
| 806 | 806 |
| 807 needs_begin_frames_ = needs_begin_frames; | 807 needs_begin_frames_ = needs_begin_frames; |
| 808 if (needs_begin_frames_) | 808 if (needs_begin_frames_) |
| 809 root_window_->RequestVSyncUpdate(); | 809 root_window_->RequestVSyncUpdate(); |
| 810 } | 810 } |
| 811 | 811 |
| 812 void CompositorImpl::SetNeedsAnimate() { | 812 void CompositorImpl::SetNeedsAnimate() { |
| 813 needs_animate_ = true; | 813 needs_animate_ = true; |
| 814 if (!host_->visible()) | 814 if (!host_->IsVisible()) |
| 815 return; | 815 return; |
| 816 | 816 |
| 817 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 817 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 818 host_->SetNeedsAnimate(); | 818 host_->SetNeedsAnimate(); |
| 819 } | 819 } |
| 820 | 820 |
| 821 bool CompositorImpl::HavePendingReadbacks() { | 821 bool CompositorImpl::HavePendingReadbacks() { |
| 822 return !readback_layer_tree_->children().empty(); | 822 return !readback_layer_tree_->children().empty(); |
| 823 } | 823 } |
| 824 | 824 |
| 825 } // namespace content | 825 } // namespace content |
| OLD | NEW |