| 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 17 matching lines...) Expand all Loading... |
| 28 #include "base/threading/thread.h" | 28 #include "base/threading/thread.h" |
| 29 #include "base/threading/thread_checker.h" | 29 #include "base/threading/thread_checker.h" |
| 30 #include "base/threading/thread_task_runner_handle.h" | 30 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "cc/base/switches.h" | 31 #include "cc/base/switches.h" |
| 32 #include "cc/input/input_handler.h" | 32 #include "cc/input/input_handler.h" |
| 33 #include "cc/layers/layer.h" | 33 #include "cc/layers/layer.h" |
| 34 #include "cc/output/compositor_frame.h" | 34 #include "cc/output/compositor_frame.h" |
| 35 #include "cc/output/context_provider.h" | 35 #include "cc/output/context_provider.h" |
| 36 #include "cc/output/output_surface.h" | 36 #include "cc/output/output_surface.h" |
| 37 #include "cc/output/output_surface_client.h" | 37 #include "cc/output/output_surface_client.h" |
| 38 #include "cc/output/texture_mailbox_deleter.h" |
| 38 #include "cc/output/vulkan_in_process_context_provider.h" | 39 #include "cc/output/vulkan_in_process_context_provider.h" |
| 39 #include "cc/raster/single_thread_task_graph_runner.h" | 40 #include "cc/raster/single_thread_task_graph_runner.h" |
| 40 #include "cc/scheduler/begin_frame_source.h" | 41 #include "cc/scheduler/begin_frame_source.h" |
| 41 #include "cc/surfaces/display.h" | 42 #include "cc/surfaces/display.h" |
| 43 #include "cc/surfaces/display_scheduler.h" |
| 42 #include "cc/surfaces/surface_display_output_surface.h" | 44 #include "cc/surfaces/surface_display_output_surface.h" |
| 43 #include "cc/surfaces/surface_id_allocator.h" | 45 #include "cc/surfaces/surface_id_allocator.h" |
| 44 #include "cc/surfaces/surface_manager.h" | 46 #include "cc/surfaces/surface_manager.h" |
| 45 #include "cc/trees/layer_tree_host.h" | 47 #include "cc/trees/layer_tree_host.h" |
| 46 #include "cc/trees/layer_tree_settings.h" | 48 #include "cc/trees/layer_tree_settings.h" |
| 47 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" | 49 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" |
| 48 #include "components/display_compositor/gl_helper.h" | 50 #include "components/display_compositor/gl_helper.h" |
| 49 #include "content/browser/android/child_process_launcher_android.h" | 51 #include "content/browser/android/child_process_launcher_android.h" |
| 50 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 52 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 51 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 53 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 }; | 136 }; |
| 135 | 137 |
| 136 // Used to override capabilities_.adjust_deadline_for_parent to false | 138 // Used to override capabilities_.adjust_deadline_for_parent to false |
| 137 class OutputSurfaceWithoutParent : public cc::OutputSurface, | 139 class OutputSurfaceWithoutParent : public cc::OutputSurface, |
| 138 public CompositorImpl::VSyncObserver { | 140 public CompositorImpl::VSyncObserver { |
| 139 public: | 141 public: |
| 140 OutputSurfaceWithoutParent( | 142 OutputSurfaceWithoutParent( |
| 141 CompositorImpl* compositor, | 143 CompositorImpl* compositor, |
| 142 scoped_refptr<ContextProviderCommandBuffer> context_provider, | 144 scoped_refptr<ContextProviderCommandBuffer> context_provider, |
| 143 const base::Callback<void(gpu::Capabilities)>& | 145 const base::Callback<void(gpu::Capabilities)>& |
| 144 populate_gpu_capabilities_callback, | 146 populate_gpu_capabilities_callback) |
| 145 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source) | |
| 146 : cc::OutputSurface(std::move(context_provider), nullptr, nullptr), | 147 : cc::OutputSurface(std::move(context_provider), nullptr, nullptr), |
| 147 compositor_(compositor), | 148 compositor_(compositor), |
| 148 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback), | 149 populate_gpu_capabilities_callback_(populate_gpu_capabilities_callback), |
| 149 swap_buffers_completion_callback_( | 150 swap_buffers_completion_callback_( |
| 150 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, | 151 base::Bind(&OutputSurfaceWithoutParent::OnSwapBuffersCompleted, |
| 151 base::Unretained(this))), | 152 base::Unretained(this))), |
| 152 overlay_candidate_validator_( | 153 overlay_candidate_validator_( |
| 153 new display_compositor:: | 154 new display_compositor:: |
| 154 CompositorOverlayCandidateValidatorAndroid()), | 155 CompositorOverlayCandidateValidatorAndroid()) { |
| 155 begin_frame_source_(std::move(begin_frame_source)) { | |
| 156 capabilities_.adjust_deadline_for_parent = false; | 156 capabilities_.adjust_deadline_for_parent = false; |
| 157 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; | 157 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; |
| 158 } | 158 } |
| 159 | 159 |
| 160 ~OutputSurfaceWithoutParent() override { compositor_->RemoveObserver(this); } | 160 ~OutputSurfaceWithoutParent() override { compositor_->RemoveObserver(this); } |
| 161 | 161 |
| 162 void SwapBuffers(cc::CompositorFrame* frame) override { | 162 void SwapBuffers(cc::CompositorFrame* frame) override { |
| 163 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); | 163 GetCommandBufferProxy()->SetLatencyInfo(frame->metadata.latency_info); |
| 164 if (frame->gl_frame_data->sub_buffer_rect.IsEmpty()) { | 164 if (frame->gl_frame_data->sub_buffer_rect.IsEmpty()) { |
| 165 context_provider_->ContextSupport()->CommitOverlayPlanes(); | 165 context_provider_->ContextSupport()->CommitOverlayPlanes(); |
| 166 } else { | 166 } else { |
| 167 DCHECK(frame->gl_frame_data->sub_buffer_rect == | 167 DCHECK(frame->gl_frame_data->sub_buffer_rect == |
| 168 gfx::Rect(frame->gl_frame_data->size)); | 168 gfx::Rect(frame->gl_frame_data->size)); |
| 169 context_provider_->ContextSupport()->Swap(); | 169 context_provider_->ContextSupport()->Swap(); |
| 170 } | 170 } |
| 171 client_->DidSwapBuffers(); | 171 client_->DidSwapBuffers(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool BindToClient(cc::OutputSurfaceClient* client) override { | 174 bool BindToClient(cc::OutputSurfaceClient* client) override { |
| 175 if (!OutputSurface::BindToClient(client)) | 175 if (!OutputSurface::BindToClient(client)) |
| 176 return false; | 176 return false; |
| 177 | 177 |
| 178 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( | 178 GetCommandBufferProxy()->SetSwapBuffersCompletionCallback( |
| 179 swap_buffers_completion_callback_.callback()); | 179 swap_buffers_completion_callback_.callback()); |
| 180 | 180 |
| 181 populate_gpu_capabilities_callback_.Run( | 181 populate_gpu_capabilities_callback_.Run( |
| 182 context_provider_->ContextCapabilities()); | 182 context_provider_->ContextCapabilities()); |
| 183 compositor_->AddObserver(this); | 183 compositor_->AddObserver(this); |
| 184 | 184 |
| 185 client->SetBeginFrameSource(begin_frame_source_.get()); | |
| 186 | |
| 187 return true; | 185 return true; |
| 188 } | 186 } |
| 189 | 187 |
| 190 void DetachFromClient() override { | |
| 191 client_->SetBeginFrameSource(nullptr); | |
| 192 OutputSurface::DetachFromClient(); | |
| 193 } | |
| 194 | |
| 195 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override { | 188 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override { |
| 196 return overlay_candidate_validator_.get(); | 189 return overlay_candidate_validator_.get(); |
| 197 } | 190 } |
| 198 | 191 |
| 199 private: | 192 private: |
| 200 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { | 193 gpu::CommandBufferProxyImpl* GetCommandBufferProxy() { |
| 201 ContextProviderCommandBuffer* provider_command_buffer = | 194 ContextProviderCommandBuffer* provider_command_buffer = |
| 202 static_cast<content::ContextProviderCommandBuffer*>( | 195 static_cast<content::ContextProviderCommandBuffer*>( |
| 203 context_provider_.get()); | 196 context_provider_.get()); |
| 204 gpu::CommandBufferProxyImpl* command_buffer_proxy = | 197 gpu::CommandBufferProxyImpl* command_buffer_proxy = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 221 | 214 |
| 222 private: | 215 private: |
| 223 CompositorImpl* compositor_; | 216 CompositorImpl* compositor_; |
| 224 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; | 217 base::Callback<void(gpu::Capabilities)> populate_gpu_capabilities_callback_; |
| 225 base::CancelableCallback<void( | 218 base::CancelableCallback<void( |
| 226 const std::vector<ui::LatencyInfo>&, | 219 const std::vector<ui::LatencyInfo>&, |
| 227 gfx::SwapResult, | 220 gfx::SwapResult, |
| 228 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)> | 221 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)> |
| 229 swap_buffers_completion_callback_; | 222 swap_buffers_completion_callback_; |
| 230 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 223 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
| 231 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; | |
| 232 }; | 224 }; |
| 233 | 225 |
| 234 #if defined(ENABLE_VULKAN) | 226 #if defined(ENABLE_VULKAN) |
| 235 class VulkanOutputSurface : public cc::OutputSurface { | 227 class VulkanOutputSurface : public cc::OutputSurface { |
| 236 public: | 228 public: |
| 237 VulkanOutputSurface( | 229 VulkanOutputSurface( |
| 238 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, | 230 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider) |
| 239 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source) | |
| 240 : OutputSurface(nullptr, | 231 : OutputSurface(nullptr, |
| 241 nullptr, | 232 nullptr, |
| 242 std::move(vulkan_context_provider), | 233 std::move(vulkan_context_provider), |
| 243 nullptr), | 234 nullptr) {} |
| 244 begin_frame_source_(std::move(begin_frame_source)) {} | |
| 245 | 235 |
| 246 ~VulkanOutputSurface() override { Destroy(); } | 236 ~VulkanOutputSurface() override { Destroy(); } |
| 247 | 237 |
| 248 bool Initialize(gfx::AcceleratedWidget widget) { | 238 bool Initialize(gfx::AcceleratedWidget widget) { |
| 249 DCHECK(!surface_); | 239 DCHECK(!surface_); |
| 250 std::unique_ptr<gpu::VulkanSurface> surface( | 240 std::unique_ptr<gpu::VulkanSurface> surface( |
| 251 gpu::VulkanSurface::CreateViewSurface(widget)); | 241 gpu::VulkanSurface::CreateViewSurface(widget)); |
| 252 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), | 242 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), |
| 253 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { | 243 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { |
| 254 return false; | 244 return false; |
| 255 } | 245 } |
| 256 surface_ = std::move(surface); | 246 surface_ = std::move(surface); |
| 257 | 247 |
| 258 return true; | 248 return true; |
| 259 } | 249 } |
| 260 | 250 |
| 261 bool BindToClient(cc::OutputSurfaceClient* client) override { | 251 bool BindToClient(cc::OutputSurfaceClient* client) override { |
| 262 if (!OutputSurface::BindToClient(client)) | 252 if (!OutputSurface::BindToClient(client)) |
| 263 return false; | 253 return false; |
| 264 client->SetBeginFrameSource(begin_frame_source_.get()); | |
| 265 return true; | 254 return true; |
| 266 } | 255 } |
| 267 | 256 |
| 268 void SwapBuffers(cc::CompositorFrame* frame) override { | 257 void SwapBuffers(cc::CompositorFrame* frame) override { |
| 269 surface_->SwapBuffers(); | 258 surface_->SwapBuffers(); |
| 270 PostSwapBuffersComplete(); | 259 PostSwapBuffersComplete(); |
| 271 client_->DidSwapBuffers(); | 260 client_->DidSwapBuffers(); |
| 272 } | 261 } |
| 273 | 262 |
| 274 void Destroy() { | 263 void Destroy() { |
| 275 if (surface_) { | 264 if (surface_) { |
| 276 surface_->Destroy(); | 265 surface_->Destroy(); |
| 277 surface_.reset(); | 266 surface_.reset(); |
| 278 } | 267 } |
| 279 } | 268 } |
| 280 | 269 |
| 281 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | 270 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, |
| 282 gfx::SwapResult result) { | 271 gfx::SwapResult result) { |
| 283 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 272 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
| 284 OutputSurface::OnSwapBuffersComplete(); | 273 OutputSurface::OnSwapBuffersComplete(); |
| 285 } | 274 } |
| 286 | 275 |
| 287 private: | 276 private: |
| 288 std::unique_ptr<gpu::VulkanSurface> surface_; | 277 std::unique_ptr<gpu::VulkanSurface> surface_; |
| 289 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; | |
| 290 | 278 |
| 291 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); | 279 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); |
| 292 }; | 280 }; |
| 293 #endif | 281 #endif |
| 294 | 282 |
| 295 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>> | 283 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>> |
| 296 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER; | 284 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER; |
| 297 | 285 |
| 298 static bool g_initialized = false; | 286 static bool g_initialized = false; |
| 299 | 287 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 if (!output_surface_request_pending_ || !host_->visible()) | 583 if (!output_surface_request_pending_ || !host_->visible()) |
| 596 return; | 584 return; |
| 597 | 585 |
| 598 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 586 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 599 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = | 587 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
| 600 SharedVulkanContextProviderAndroid(); | 588 SharedVulkanContextProviderAndroid(); |
| 601 std::unique_ptr<cc::OutputSurface> display_output_surface; | 589 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 602 #if defined(ENABLE_VULKAN) | 590 #if defined(ENABLE_VULKAN) |
| 603 std::unique_ptr<VulkanOutputSurface> vulkan_surface; | 591 std::unique_ptr<VulkanOutputSurface> vulkan_surface; |
| 604 if (vulkan_context_provider) { | 592 if (vulkan_context_provider) { |
| 605 vulkan_surface.reset(new VulkanOutputSurface( | 593 vulkan_surface.reset( |
| 606 std::move(vulkan_context_provider), | 594 new VulkanOutputSurface(std::move(vulkan_context_provider))); |
| 607 base::WrapUnique(new ExternalBeginFrameSource(this)))); | |
| 608 if (!vulkan_surface->Initialize(window_)) { | 595 if (!vulkan_surface->Initialize(window_)) { |
| 609 vulkan_surface->Destroy(); | 596 vulkan_surface->Destroy(); |
| 610 vulkan_surface.reset(); | 597 vulkan_surface.reset(); |
| 611 } else { | 598 } else { |
| 612 display_output_surface = std::move(vulkan_surface); | 599 display_output_surface = std::move(vulkan_surface); |
| 613 } | 600 } |
| 614 } | 601 } |
| 615 #endif | 602 #endif |
| 616 | 603 |
| 617 if (!display_output_surface) { | 604 if (!display_output_surface) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, | 675 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, |
| 689 gpu::GpuStreamPriority::NORMAL, surface_handle_, url, | 676 gpu::GpuStreamPriority::NORMAL, surface_handle_, url, |
| 690 gl::PreferIntegratedGpu, automatic_flushes, support_locking, limits, | 677 gl::PreferIntegratedGpu, automatic_flushes, support_locking, limits, |
| 691 attributes, nullptr, | 678 attributes, nullptr, |
| 692 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | 679 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); |
| 693 DCHECK(context_provider.get()); | 680 DCHECK(context_provider.get()); |
| 694 | 681 |
| 695 display_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent( | 682 display_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent( |
| 696 this, context_provider, | 683 this, context_provider, |
| 697 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | 684 base::Bind(&CompositorImpl::PopulateGpuCapabilities, |
| 698 base::Unretained(this)), | 685 base::Unretained(this)))); |
| 699 base::WrapUnique(new ExternalBeginFrameSource(this)))); | |
| 700 } | 686 } |
| 701 | 687 |
| 702 cc::SurfaceManager* manager = GetSurfaceManager(); | 688 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 703 display_.reset(new cc::Display(manager, HostSharedBitmapManager::current(), | 689 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); |
| 704 BrowserGpuMemoryBufferManager::current(), | 690 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source( |
| 705 host_->settings().renderer_settings, | 691 new ExternalBeginFrameSource(this)); |
| 706 surface_id_allocator_->id_namespace(), | 692 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 707 base::ThreadTaskRunnerHandle::Get().get(), | 693 begin_frame_source.get(), task_runner, |
| 708 std::move(display_output_surface))); | 694 display_output_surface->capabilities().max_frames_pending)); |
| 695 |
| 696 display_.reset(new cc::Display( |
| 697 manager, HostSharedBitmapManager::current(), |
| 698 BrowserGpuMemoryBufferManager::current(), |
| 699 host_->settings().renderer_settings, |
| 700 surface_id_allocator_->id_namespace(), std::move(begin_frame_source), |
| 701 std::move(display_output_surface), std::move(scheduler), |
| 702 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); |
| 709 | 703 |
| 710 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( | 704 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( |
| 711 vulkan_context_provider | 705 vulkan_context_provider |
| 712 ? new cc::SurfaceDisplayOutputSurface( | 706 ? new cc::SurfaceDisplayOutputSurface( |
| 713 manager, surface_id_allocator_.get(), display_.get(), | 707 manager, surface_id_allocator_.get(), display_.get(), |
| 714 static_cast<scoped_refptr<cc::VulkanContextProvider>>( | 708 static_cast<scoped_refptr<cc::VulkanContextProvider>>( |
| 715 vulkan_context_provider)) | 709 vulkan_context_provider)) |
| 716 : new cc::SurfaceDisplayOutputSurface( | 710 : new cc::SurfaceDisplayOutputSurface( |
| 717 manager, surface_id_allocator_.get(), display_.get(), | 711 manager, surface_id_allocator_.get(), display_.get(), |
| 718 context_provider, nullptr)); | 712 context_provider, nullptr)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 void CompositorImpl::SetNeedsAnimate() { | 794 void CompositorImpl::SetNeedsAnimate() { |
| 801 needs_animate_ = true; | 795 needs_animate_ = true; |
| 802 if (!host_->visible()) | 796 if (!host_->visible()) |
| 803 return; | 797 return; |
| 804 | 798 |
| 805 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 799 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 806 host_->SetNeedsAnimate(); | 800 host_->SetNeedsAnimate(); |
| 807 } | 801 } |
| 808 | 802 |
| 809 } // namespace content | 803 } // namespace content |
| OLD | NEW |