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