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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 gpu::GpuStreamPriority::NORMAL, handle, | 201 gpu::GpuStreamPriority::NORMAL, handle, |
202 GURL(std::string("chrome://gpu/Compositor::CreateContextProvider")), | 202 GURL(std::string("chrome://gpu/Compositor::CreateContextProvider")), |
203 automatic_flushes, support_locking, shared_memory_limits, attributes, | 203 automatic_flushes, support_locking, shared_memory_limits, attributes, |
204 nullptr /* shared_context */, | 204 nullptr /* shared_context */, |
205 ui::command_buffer_metrics::CONTEXT_TYPE_UNKNOWN); | 205 ui::command_buffer_metrics::CONTEXT_TYPE_UNKNOWN); |
206 callback.Run(std::move(context_provider)); | 206 callback.Run(std::move(context_provider)); |
207 } | 207 } |
208 | 208 |
209 class AndroidOutputSurface : public cc::OutputSurface { | 209 class AndroidOutputSurface : public cc::OutputSurface { |
210 public: | 210 public: |
211 explicit AndroidOutputSurface( | 211 AndroidOutputSurface( |
212 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider) | 212 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider, |
| 213 base::Closure swap_buffers_callback) |
213 : cc::OutputSurface(std::move(context_provider)), | 214 : cc::OutputSurface(std::move(context_provider)), |
| 215 swap_buffers_callback_(std::move(swap_buffers_callback)), |
214 overlay_candidate_validator_( | 216 overlay_candidate_validator_( |
215 new display_compositor:: | 217 new display_compositor:: |
216 CompositorOverlayCandidateValidatorAndroid()), | 218 CompositorOverlayCandidateValidatorAndroid()), |
217 weak_ptr_factory_(this) { | 219 weak_ptr_factory_(this) { |
218 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; | 220 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; |
219 } | 221 } |
220 | 222 |
221 ~AndroidOutputSurface() override = default; | 223 ~AndroidOutputSurface() override = default; |
222 | 224 |
223 void SwapBuffers(cc::OutputSurfaceFrame frame) override { | 225 void SwapBuffers(cc::OutputSurfaceFrame frame) override { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 DCHECK(command_buffer_proxy); | 287 DCHECK(command_buffer_proxy); |
286 return command_buffer_proxy; | 288 return command_buffer_proxy; |
287 } | 289 } |
288 | 290 |
289 void OnSwapBuffersCompleted( | 291 void OnSwapBuffersCompleted( |
290 const std::vector<ui::LatencyInfo>& latency_info, | 292 const std::vector<ui::LatencyInfo>& latency_info, |
291 gfx::SwapResult result, | 293 gfx::SwapResult result, |
292 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { | 294 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { |
293 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 295 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
294 client_->DidReceiveSwapBuffersAck(); | 296 client_->DidReceiveSwapBuffersAck(); |
| 297 swap_buffers_callback_.Run(); |
295 } | 298 } |
296 | 299 |
297 private: | 300 private: |
298 cc::OutputSurfaceClient* client_ = nullptr; | 301 cc::OutputSurfaceClient* client_ = nullptr; |
| 302 base::Closure swap_buffers_callback_; |
299 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 303 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
300 base::WeakPtrFactory<AndroidOutputSurface> weak_ptr_factory_; | 304 base::WeakPtrFactory<AndroidOutputSurface> weak_ptr_factory_; |
301 }; | 305 }; |
302 | 306 |
303 #if defined(ENABLE_VULKAN) | 307 #if defined(ENABLE_VULKAN) |
304 class VulkanOutputSurface : public cc::OutputSurface { | 308 class VulkanOutputSurface : public cc::OutputSurface { |
305 public: | 309 public: |
306 explicit VulkanOutputSurface( | 310 explicit VulkanOutputSurface( |
307 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 311 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
308 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 312 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 GetCompositorContextAttributes(has_transparent_background_), | 715 GetCompositorContextAttributes(has_transparent_background_), |
712 shared_context, | 716 shared_context, |
713 ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | 717 ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
714 if (!context_provider->BindToCurrentThread()) { | 718 if (!context_provider->BindToCurrentThread()) { |
715 LOG(ERROR) << "Failed to init ContextProvider for compositor."; | 719 LOG(ERROR) << "Failed to init ContextProvider for compositor."; |
716 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) | 720 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) |
717 << "Too many context creation failures. Giving up... "; | 721 << "Too many context creation failures. Giving up... "; |
718 HandlePendingCompositorFrameSinkRequest(); | 722 HandlePendingCompositorFrameSinkRequest(); |
719 } | 723 } |
720 | 724 |
721 auto display_output_surface = | 725 // Unretained is safe this owns cc::Display which owns OutputSurface. |
722 base::MakeUnique<AndroidOutputSurface>(context_provider); | 726 auto display_output_surface = base::MakeUnique<AndroidOutputSurface>( |
| 727 context_provider, |
| 728 base::Bind(&CompositorImpl::DidSwapBuffers, base::Unretained(this))); |
723 InitializeDisplay(std::move(display_output_surface), nullptr, | 729 InitializeDisplay(std::move(display_output_surface), nullptr, |
724 std::move(context_provider)); | 730 std::move(context_provider)); |
725 } | 731 } |
726 | 732 |
727 void CompositorImpl::InitializeDisplay( | 733 void CompositorImpl::InitializeDisplay( |
728 std::unique_ptr<cc::OutputSurface> display_output_surface, | 734 std::unique_ptr<cc::OutputSurface> display_output_surface, |
729 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 735 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
730 scoped_refptr<cc::ContextProvider> context_provider) { | 736 scoped_refptr<cc::ContextProvider> context_provider) { |
731 DCHECK(compositor_frame_sink_request_pending_); | 737 DCHECK(compositor_frame_sink_request_pending_); |
732 | 738 |
(...skipping 27 matching lines...) Expand all Loading... |
760 : base::MakeUnique<cc::DirectCompositorFrameSink>( | 766 : base::MakeUnique<cc::DirectCompositorFrameSink>( |
761 frame_sink_id_, manager, display_.get(), context_provider, | 767 frame_sink_id_, manager, display_.get(), context_provider, |
762 nullptr, BrowserGpuMemoryBufferManager::current(), | 768 nullptr, BrowserGpuMemoryBufferManager::current(), |
763 HostSharedBitmapManager::current()); | 769 HostSharedBitmapManager::current()); |
764 | 770 |
765 display_->SetVisible(true); | 771 display_->SetVisible(true); |
766 display_->Resize(size_); | 772 display_->Resize(size_); |
767 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 773 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
768 } | 774 } |
769 | 775 |
| 776 void CompositorImpl::DidSwapBuffers() { |
| 777 client_->DidSwapBuffers(); |
| 778 } |
| 779 |
770 cc::UIResourceId CompositorImpl::CreateUIResource( | 780 cc::UIResourceId CompositorImpl::CreateUIResource( |
771 cc::UIResourceClient* client) { | 781 cc::UIResourceClient* client) { |
772 TRACE_EVENT0("compositor", "CompositorImpl::CreateUIResource"); | 782 TRACE_EVENT0("compositor", "CompositorImpl::CreateUIResource"); |
773 return host_->GetUIResourceManager()->CreateUIResource(client); | 783 return host_->GetUIResourceManager()->CreateUIResource(client); |
774 } | 784 } |
775 | 785 |
776 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { | 786 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { |
777 TRACE_EVENT0("compositor", "CompositorImpl::DeleteUIResource"); | 787 TRACE_EVENT0("compositor", "CompositorImpl::DeleteUIResource"); |
778 host_->GetUIResourceManager()->DeleteUIResource(resource_id); | 788 host_->GetUIResourceManager()->DeleteUIResource(resource_id); |
779 } | 789 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 } | 854 } |
845 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_, | 855 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_, |
846 frame_sink_id); | 856 frame_sink_id); |
847 } | 857 } |
848 | 858 |
849 bool CompositorImpl::HavePendingReadbacks() { | 859 bool CompositorImpl::HavePendingReadbacks() { |
850 return !readback_layer_tree_->children().empty(); | 860 return !readback_layer_tree_->children().empty(); |
851 } | 861 } |
852 | 862 |
853 } // namespace content | 863 } // namespace content |
OLD | NEW |