| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "content/browser/renderer_host/render_widget_host_impl.h" | 54 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 55 #include "content/common/host_shared_bitmap_manager.h" | 55 #include "content/common/host_shared_bitmap_manager.h" |
| 56 #include "content/public/browser/android/compositor.h" | 56 #include "content/public/browser/android/compositor.h" |
| 57 #include "content/public/browser/android/compositor_client.h" | 57 #include "content/public/browser/android/compositor_client.h" |
| 58 #include "content/public/common/content_switches.h" | 58 #include "content/public/common/content_switches.h" |
| 59 #include "gpu/command_buffer/client/context_support.h" | 59 #include "gpu/command_buffer/client/context_support.h" |
| 60 #include "gpu/command_buffer/client/gles2_interface.h" | 60 #include "gpu/command_buffer/client/gles2_interface.h" |
| 61 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 61 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 62 #include "gpu/ipc/client/gpu_channel_host.h" | 62 #include "gpu/ipc/client/gpu_channel_host.h" |
| 63 #include "gpu/ipc/common/gpu_surface_tracker.h" | 63 #include "gpu/ipc/common/gpu_surface_tracker.h" |
| 64 #include "gpu/vulkan/features.h" | |
| 65 #include "gpu/vulkan/vulkan_surface.h" | 64 #include "gpu/vulkan/vulkan_surface.h" |
| 66 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" | 65 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" |
| 67 #include "third_party/khronos/GLES2/gl2.h" | 66 #include "third_party/khronos/GLES2/gl2.h" |
| 68 #include "third_party/khronos/GLES2/gl2ext.h" | 67 #include "third_party/khronos/GLES2/gl2ext.h" |
| 69 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 68 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 70 #include "ui/android/window_android.h" | 69 #include "ui/android/window_android.h" |
| 71 #include "ui/display/display.h" | 70 #include "ui/display/display.h" |
| 72 #include "ui/display/screen.h" | 71 #include "ui/display/screen.h" |
| 73 #include "ui/gfx/swap_result.h" | 72 #include "ui/gfx/swap_result.h" |
| 74 | 73 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 ~SingleThreadTaskGraphRunner() override { Shutdown(); } | 92 ~SingleThreadTaskGraphRunner() override { Shutdown(); } |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 struct CompositorDependencies { | 95 struct CompositorDependencies { |
| 97 CompositorDependencies() : frame_sink_id_allocator(kDefaultClientId) {} | 96 CompositorDependencies() : frame_sink_id_allocator(kDefaultClientId) {} |
| 98 | 97 |
| 99 SingleThreadTaskGraphRunner task_graph_runner; | 98 SingleThreadTaskGraphRunner task_graph_runner; |
| 100 cc::SurfaceManager surface_manager; | 99 cc::SurfaceManager surface_manager; |
| 101 cc::FrameSinkIdAllocator frame_sink_id_allocator; | 100 cc::FrameSinkIdAllocator frame_sink_id_allocator; |
| 102 | 101 |
| 103 #if BUILDFLAG(ENABLE_VULKAN) | 102 #if defined(ENABLE_VULKAN) |
| 104 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider; | 103 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider; |
| 105 #endif | 104 #endif |
| 106 }; | 105 }; |
| 107 | 106 |
| 108 base::LazyInstance<CompositorDependencies>::DestructorAtExit | 107 base::LazyInstance<CompositorDependencies>::DestructorAtExit |
| 109 g_compositor_dependencies = LAZY_INSTANCE_INITIALIZER; | 108 g_compositor_dependencies = LAZY_INSTANCE_INITIALIZER; |
| 110 | 109 |
| 111 const unsigned int kMaxDisplaySwapBuffers = 1U; | 110 const unsigned int kMaxDisplaySwapBuffers = 1U; |
| 112 | 111 |
| 113 #if BUILDFLAG(ENABLE_VULKAN) | 112 #if defined(ENABLE_VULKAN) |
| 114 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() { | 113 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() { |
| 115 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 114 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 116 switches::kEnableVulkan)) { | 115 switches::kEnableVulkan)) { |
| 117 scoped_refptr<cc::VulkanContextProvider> context_provider = | 116 scoped_refptr<cc::VulkanContextProvider> context_provider = |
| 118 g_compositor_dependencies.Get().vulkan_context_provider; | 117 g_compositor_dependencies.Get().vulkan_context_provider; |
| 119 if (!*context_provider) | 118 if (!*context_provider) |
| 120 *context_provider = cc::VulkanInProcessContextProvider::Create(); | 119 *context_provider = cc::VulkanInProcessContextProvider::Create(); |
| 121 return *context_provider; | 120 return *context_provider; |
| 122 } | 121 } |
| 123 return nullptr; | 122 return nullptr; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 swap_buffers_callback_.Run(); | 297 swap_buffers_callback_.Run(); |
| 299 } | 298 } |
| 300 | 299 |
| 301 private: | 300 private: |
| 302 cc::OutputSurfaceClient* client_ = nullptr; | 301 cc::OutputSurfaceClient* client_ = nullptr; |
| 303 base::Closure swap_buffers_callback_; | 302 base::Closure swap_buffers_callback_; |
| 304 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 303 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
| 305 base::WeakPtrFactory<AndroidOutputSurface> weak_ptr_factory_; | 304 base::WeakPtrFactory<AndroidOutputSurface> weak_ptr_factory_; |
| 306 }; | 305 }; |
| 307 | 306 |
| 308 #if BUILDFLAG(ENABLE_VULKAN) | 307 #if defined(ENABLE_VULKAN) |
| 309 class VulkanOutputSurface : public cc::OutputSurface { | 308 class VulkanOutputSurface : public cc::OutputSurface { |
| 310 public: | 309 public: |
| 311 explicit VulkanOutputSurface( | 310 explicit VulkanOutputSurface( |
| 312 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 311 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 313 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 312 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 314 : OutputSurface(std::move(vulkan_context_provider)), | 313 : OutputSurface(std::move(vulkan_context_provider)), |
| 315 task_runner_(std::move(task_runner)), | 314 task_runner_(std::move(task_runner)), |
| 316 weak_ptr_factory_(this) {} | 315 weak_ptr_factory_(this) {} |
| 317 | 316 |
| 318 ~VulkanOutputSurface() override { Destroy(); } | 317 ~VulkanOutputSurface() override { Destroy(); } |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 NOTREACHED(); | 620 NOTREACHED(); |
| 622 } | 621 } |
| 623 | 622 |
| 624 void CompositorImpl::HandlePendingCompositorFrameSinkRequest() { | 623 void CompositorImpl::HandlePendingCompositorFrameSinkRequest() { |
| 625 DCHECK(compositor_frame_sink_request_pending_); | 624 DCHECK(compositor_frame_sink_request_pending_); |
| 626 | 625 |
| 627 // We might have been made invisible now. | 626 // We might have been made invisible now. |
| 628 if (!host_->IsVisible()) | 627 if (!host_->IsVisible()) |
| 629 return; | 628 return; |
| 630 | 629 |
| 631 #if BUILDFLAG(ENABLE_VULKAN) | 630 #if defined(ENABLE_VULKAN) |
| 632 CreateVulkanOutputSurface() | 631 CreateVulkanOutputSurface() |
| 633 if (display_) | 632 if (display_) |
| 634 return; | 633 return; |
| 635 #endif | 634 #endif |
| 636 | 635 |
| 637 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ | 636 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| 638 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) | 637 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) |
| 639 const int64_t kGpuChannelTimeoutInSeconds = 40; | 638 const int64_t kGpuChannelTimeoutInSeconds = 40; |
| 640 #else | 639 #else |
| 641 // The GPU watchdog timeout is 15 seconds (1.5x the kGpuTimeout value due to | 640 // The GPU watchdog timeout is 15 seconds (1.5x the kGpuTimeout value due to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 652 | 651 |
| 653 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); | 652 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); |
| 654 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(base::Bind( | 653 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(base::Bind( |
| 655 &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); | 654 &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); |
| 656 } | 655 } |
| 657 | 656 |
| 658 void CompositorImpl::OnGpuChannelTimeout() { | 657 void CompositorImpl::OnGpuChannelTimeout() { |
| 659 LOG(FATAL) << "Timed out waiting for GPU channel."; | 658 LOG(FATAL) << "Timed out waiting for GPU channel."; |
| 660 } | 659 } |
| 661 | 660 |
| 662 #if BUILDFLAG(ENABLE_VULKAN) | 661 #if defined(ENABLE_VULKAN) |
| 663 void CompositorImpl::CreateVulkanOutputSurface() { | 662 void CompositorImpl::CreateVulkanOutputSurface() { |
| 664 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 663 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 665 switches::kEnableVulkan)) | 664 switches::kEnableVulkan)) |
| 666 return; | 665 return; |
| 667 | 666 |
| 668 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = | 667 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 669 GetSharedVulkanContextProvider(); | 668 GetSharedVulkanContextProvider(); |
| 670 if (!vulkan_context_provider) | 669 if (!vulkan_context_provider) |
| 671 return; | 670 return; |
| 672 | 671 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 } | 854 } |
| 856 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_, | 855 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 857 frame_sink_id); | 856 frame_sink_id); |
| 858 } | 857 } |
| 859 | 858 |
| 860 bool CompositorImpl::HavePendingReadbacks() { | 859 bool CompositorImpl::HavePendingReadbacks() { |
| 861 return !readback_layer_tree_->children().empty(); | 860 return !readback_layer_tree_->children().empty(); |
| 862 } | 861 } |
| 863 | 862 |
| 864 } // namespace content | 863 } // namespace content |
| OLD | NEW |