| 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 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "cc/base/switches.h" | 32 #include "cc/base/switches.h" |
| 33 #include "cc/input/input_handler.h" | 33 #include "cc/input/input_handler.h" |
| 34 #include "cc/layers/layer.h" | 34 #include "cc/layers/layer.h" |
| 35 #include "cc/output/compositor_frame.h" | 35 #include "cc/output/compositor_frame.h" |
| 36 #include "cc/output/context_provider.h" | 36 #include "cc/output/context_provider.h" |
| 37 #include "cc/output/output_surface.h" | 37 #include "cc/output/output_surface.h" |
| 38 #include "cc/output/output_surface_client.h" | 38 #include "cc/output/output_surface_client.h" |
| 39 #include "cc/output/vulkan_in_process_context_provider.h" | 39 #include "cc/output/vulkan_in_process_context_provider.h" |
| 40 #include "cc/raster/single_thread_task_graph_runner.h" | 40 #include "cc/raster/single_thread_task_graph_runner.h" |
| 41 #include "cc/scheduler/begin_frame_source.h" | 41 #include "cc/scheduler/begin_frame_source.h" |
| 42 #include "cc/surfaces/onscreen_display_client.h" | 42 #include "cc/surfaces/display.h" |
| 43 #include "cc/surfaces/surface_display_output_surface.h" | 43 #include "cc/surfaces/surface_display_output_surface.h" |
| 44 #include "cc/surfaces/surface_id_allocator.h" | 44 #include "cc/surfaces/surface_id_allocator.h" |
| 45 #include "cc/surfaces/surface_manager.h" | 45 #include "cc/surfaces/surface_manager.h" |
| 46 #include "cc/trees/layer_tree_host.h" | 46 #include "cc/trees/layer_tree_host.h" |
| 47 #include "cc/trees/layer_tree_settings.h" | 47 #include "cc/trees/layer_tree_settings.h" |
| 48 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" | 48 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" |
| 49 #include "components/display_compositor/gl_helper.h" | 49 #include "components/display_compositor/gl_helper.h" |
| 50 #include "content/browser/android/child_process_launcher_android.h" | 50 #include "content/browser/android/child_process_launcher_android.h" |
| 51 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 51 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 52 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 52 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 | 486 |
| 487 void CompositorImpl::SetVisible(bool visible) { | 487 void CompositorImpl::SetVisible(bool visible) { |
| 488 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); | 488 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); |
| 489 if (!visible) { | 489 if (!visible) { |
| 490 DCHECK(host_->visible()); | 490 DCHECK(host_->visible()); |
| 491 host_->SetVisible(false); | 491 host_->SetVisible(false); |
| 492 if (!host_->output_surface_lost()) | 492 if (!host_->output_surface_lost()) |
| 493 host_->ReleaseOutputSurface(); | 493 host_->ReleaseOutputSurface(); |
| 494 pending_swapbuffers_ = 0; | 494 pending_swapbuffers_ = 0; |
| 495 establish_gpu_channel_timeout_.Stop(); | 495 establish_gpu_channel_timeout_.Stop(); |
| 496 display_client_.reset(); | 496 display_.reset(); |
| 497 } else { | 497 } else { |
| 498 host_->SetVisible(true); | 498 host_->SetVisible(true); |
| 499 if (output_surface_request_pending_) | 499 if (output_surface_request_pending_) |
| 500 RequestNewOutputSurface(); | 500 RequestNewOutputSurface(); |
| 501 } | 501 } |
| 502 } | 502 } |
| 503 | 503 |
| 504 void CompositorImpl::setDeviceScaleFactor(float factor) { | 504 void CompositorImpl::setDeviceScaleFactor(float factor) { |
| 505 device_scale_factor_ = factor; | 505 device_scale_factor_ = factor; |
| 506 if (host_) | 506 if (host_) |
| 507 host_->SetDeviceScaleFactor(factor); | 507 host_->SetDeviceScaleFactor(factor); |
| 508 } | 508 } |
| 509 | 509 |
| 510 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 510 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| 511 if (size_ == size) | 511 if (size_ == size) |
| 512 return; | 512 return; |
| 513 | 513 |
| 514 size_ = size; | 514 size_ = size; |
| 515 if (host_) | 515 if (host_) |
| 516 host_->SetViewportSize(size); | 516 host_->SetViewportSize(size); |
| 517 if (display_client_) | 517 if (display_) |
| 518 display_client_->display()->Resize(size); | 518 display_->Resize(size); |
| 519 root_layer_->SetBounds(size); | 519 root_layer_->SetBounds(size); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void CompositorImpl::SetHasTransparentBackground(bool flag) { | 522 void CompositorImpl::SetHasTransparentBackground(bool flag) { |
| 523 has_transparent_background_ = flag; | 523 has_transparent_background_ = flag; |
| 524 if (host_) | 524 if (host_) |
| 525 host_->set_has_transparent_background(flag); | 525 host_->set_has_transparent_background(flag); |
| 526 } | 526 } |
| 527 | 527 |
| 528 void CompositorImpl::SetNeedsComposite() { | 528 void CompositorImpl::SetNeedsComposite() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 void CompositorImpl::CreateOutputSurface() { | 590 void CompositorImpl::CreateOutputSurface() { |
| 591 // We might have had a request from a LayerTreeHost that was then | 591 // We might have had a request from a LayerTreeHost that was then |
| 592 // hidden (and hidden means we don't have a native surface). | 592 // hidden (and hidden means we don't have a native surface). |
| 593 // Also make sure we only handle this once. | 593 // Also make sure we only handle this once. |
| 594 if (!output_surface_request_pending_ || !host_->visible()) | 594 if (!output_surface_request_pending_ || !host_->visible()) |
| 595 return; | 595 return; |
| 596 | 596 |
| 597 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 597 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 598 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = | 598 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
| 599 SharedVulkanContextProviderAndroid(); | 599 SharedVulkanContextProviderAndroid(); |
| 600 std::unique_ptr<cc::OutputSurface> real_output_surface; | 600 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 601 #if defined(ENABLE_VULKAN) | 601 #if defined(ENABLE_VULKAN) |
| 602 std::unique_ptr<VulkanOutputSurface> vulkan_surface; | 602 std::unique_ptr<VulkanOutputSurface> vulkan_surface; |
| 603 if (vulkan_context_provider) { | 603 if (vulkan_context_provider) { |
| 604 vulkan_surface.reset(new VulkanOutputSurface( | 604 vulkan_surface.reset(new VulkanOutputSurface( |
| 605 std::move(vulkan_context_provider), | 605 std::move(vulkan_context_provider), |
| 606 base::WrapUnique(new ExternalBeginFrameSource(this)))); | 606 base::WrapUnique(new ExternalBeginFrameSource(this)))); |
| 607 if (!vulkan_surface->Initialize(window_)) { | 607 if (!vulkan_surface->Initialize(window_)) { |
| 608 vulkan_surface->Destroy(); | 608 vulkan_surface->Destroy(); |
| 609 vulkan_surface.reset(); | 609 vulkan_surface.reset(); |
| 610 } else { | 610 } else { |
| 611 real_output_surface = std::move(vulkan_surface); | 611 display_output_surface = std::move(vulkan_surface); |
| 612 } | 612 } |
| 613 } | 613 } |
| 614 #endif | 614 #endif |
| 615 | 615 |
| 616 if (!real_output_surface) { | 616 if (!display_output_surface) { |
| 617 // This is used for the browser compositor (offscreen) and for the display | 617 // This is used for the browser compositor (offscreen) and for the display |
| 618 // compositor (onscreen), so ask for capabilities needed by either one. | 618 // compositor (onscreen), so ask for capabilities needed by either one. |
| 619 // The default framebuffer for an offscreen context is not used, so it does | 619 // The default framebuffer for an offscreen context is not used, so it does |
| 620 // not need alpha, stencil, depth, antialiasing. The display compositor does | 620 // not need alpha, stencil, depth, antialiasing. The display compositor does |
| 621 // not use these things either, except for alpha when it has a transparent | 621 // not use these things either, except for alpha when it has a transparent |
| 622 // background. | 622 // background. |
| 623 gpu::gles2::ContextCreationAttribHelper attributes; | 623 gpu::gles2::ContextCreationAttribHelper attributes; |
| 624 attributes.alpha_size = -1; | 624 attributes.alpha_size = -1; |
| 625 attributes.stencil_size = 0; | 625 attributes.stencil_size = 0; |
| 626 attributes.depth_size = 0; | 626 attributes.depth_size = 0; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes; | 684 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes; |
| 685 | 685 |
| 686 context_provider = new ContextProviderCommandBuffer( | 686 context_provider = new ContextProviderCommandBuffer( |
| 687 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, | 687 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, |
| 688 gpu::GpuStreamPriority::NORMAL, surface_handle_, url, | 688 gpu::GpuStreamPriority::NORMAL, surface_handle_, url, |
| 689 gl::PreferIntegratedGpu, automatic_flushes, support_locking, limits, | 689 gl::PreferIntegratedGpu, automatic_flushes, support_locking, limits, |
| 690 attributes, nullptr, | 690 attributes, nullptr, |
| 691 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | 691 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
| 692 DCHECK(context_provider.get()); | 692 DCHECK(context_provider.get()); |
| 693 | 693 |
| 694 real_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent( | 694 display_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent( |
| 695 this, context_provider, | 695 this, context_provider, |
| 696 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | 696 base::Bind(&CompositorImpl::PopulateGpuCapabilities, |
| 697 base::Unretained(this)), | 697 base::Unretained(this)), |
| 698 base::WrapUnique(new ExternalBeginFrameSource(this)))); | 698 base::WrapUnique(new ExternalBeginFrameSource(this)))); |
| 699 } | 699 } |
| 700 | 700 |
| 701 cc::SurfaceManager* manager = GetSurfaceManager(); | 701 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 702 display_client_.reset(new cc::OnscreenDisplayClient( | 702 display_.reset(new cc::Display(manager, HostSharedBitmapManager::current(), |
| 703 std::move(real_output_surface), manager, | 703 BrowserGpuMemoryBufferManager::current(), |
| 704 HostSharedBitmapManager::current(), | 704 host_->settings().renderer_settings, |
| 705 BrowserGpuMemoryBufferManager::current(), | 705 surface_id_allocator_->id_namespace(), |
| 706 host_->settings().renderer_settings, base::ThreadTaskRunnerHandle::Get(), | 706 base::ThreadTaskRunnerHandle::Get().get(), |
| 707 surface_id_allocator_->id_namespace())); | 707 std::move(display_output_surface))); |
| 708 | 708 |
| 709 std::unique_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 709 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( |
| 710 vulkan_context_provider | 710 vulkan_context_provider |
| 711 ? new cc::SurfaceDisplayOutputSurface( | 711 ? new cc::SurfaceDisplayOutputSurface( |
| 712 manager, surface_id_allocator_.get(), | 712 manager, surface_id_allocator_.get(), display_.get(), |
| 713 static_cast<scoped_refptr<cc::VulkanContextProvider>>( | 713 static_cast<scoped_refptr<cc::VulkanContextProvider>>( |
| 714 vulkan_context_provider)) | 714 vulkan_context_provider)) |
| 715 : new cc::SurfaceDisplayOutputSurface(manager, | 715 : new cc::SurfaceDisplayOutputSurface( |
| 716 surface_id_allocator_.get(), | 716 manager, surface_id_allocator_.get(), display_.get(), |
| 717 context_provider, nullptr)); | 717 context_provider, nullptr)); |
| 718 | 718 |
| 719 display_client_->set_surface_output_surface(surface_output_surface.get()); | 719 display_->Resize(size_); |
| 720 surface_output_surface->set_display_client(display_client_.get()); | 720 host_->SetOutputSurface(std::move(delegated_output_surface)); |
| 721 display_client_->display()->Resize(size_); | |
| 722 host_->SetOutputSurface(std::move(surface_output_surface)); | |
| 723 } | 721 } |
| 724 | 722 |
| 725 void CompositorImpl::PopulateGpuCapabilities( | 723 void CompositorImpl::PopulateGpuCapabilities( |
| 726 gpu::Capabilities gpu_capabilities) { | 724 gpu::Capabilities gpu_capabilities) { |
| 727 gpu_capabilities_ = gpu_capabilities; | 725 gpu_capabilities_ = gpu_capabilities; |
| 728 } | 726 } |
| 729 | 727 |
| 730 void CompositorImpl::AddObserver(VSyncObserver* observer) { | 728 void CompositorImpl::AddObserver(VSyncObserver* observer) { |
| 731 observer_list_.AddObserver(observer); | 729 observer_list_.AddObserver(observer); |
| 732 } | 730 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 void CompositorImpl::SetNeedsAnimate() { | 799 void CompositorImpl::SetNeedsAnimate() { |
| 802 needs_animate_ = true; | 800 needs_animate_ = true; |
| 803 if (!host_->visible()) | 801 if (!host_->visible()) |
| 804 return; | 802 return; |
| 805 | 803 |
| 806 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 804 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 807 host_->SetNeedsAnimate(); | 805 host_->SetNeedsAnimate(); |
| 808 } | 806 } |
| 809 | 807 |
| 810 } // namespace content | 808 } // namespace content |
| OLD | NEW |