| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)> | 228 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)> |
| 229 swap_buffers_completion_callback_; | 229 swap_buffers_completion_callback_; |
| 230 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 230 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
| 231 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; | 231 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; |
| 232 }; | 232 }; |
| 233 | 233 |
| 234 #if defined(ENABLE_VULKAN) | 234 #if defined(ENABLE_VULKAN) |
| 235 class VulkanOutputSurface : public cc::OutputSurface { | 235 class VulkanOutputSurface : public cc::OutputSurface { |
| 236 public: | 236 public: |
| 237 VulkanOutputSurface( | 237 VulkanOutputSurface( |
| 238 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider) | 238 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 239 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source) |
| 239 : OutputSurface(nullptr, | 240 : OutputSurface(nullptr, |
| 240 nullptr, | 241 nullptr, |
| 241 std::move(vulkan_context_provider), | 242 std::move(vulkan_context_provider), |
| 242 nullptr) {} | 243 nullptr), |
| 244 begin_frame_source_(std::move(begin_frame_source)) {} |
| 243 | 245 |
| 244 ~VulkanOutputSurface() override { Destroy(); } | 246 ~VulkanOutputSurface() override { Destroy(); } |
| 245 | 247 |
| 246 bool Initialize(gfx::AcceleratedWidget widget) { | 248 bool Initialize(gfx::AcceleratedWidget widget) { |
| 247 DCHECK(!surface_); | 249 DCHECK(!surface_); |
| 248 std::unique_ptr<gpu::VulkanSurface> surface( | 250 std::unique_ptr<gpu::VulkanSurface> surface( |
| 249 gpu::VulkanSurface::CreateViewSurface(widget)); | 251 gpu::VulkanSurface::CreateViewSurface(widget)); |
| 250 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), | 252 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), |
| 251 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { | 253 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { |
| 252 return false; | 254 return false; |
| 253 } | 255 } |
| 254 surface_ = std::move(surface); | 256 surface_ = std::move(surface); |
| 255 | 257 |
| 256 return true; | 258 return true; |
| 257 } | 259 } |
| 258 | 260 |
| 261 bool BindToClient(cc::OutputSurfaceClient* client) override { |
| 262 if (!OutputSurface::BindToClient(client)) |
| 263 return false; |
| 264 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 265 return true; |
| 266 } |
| 267 |
| 259 void SwapBuffers(cc::CompositorFrame* frame) override { | 268 void SwapBuffers(cc::CompositorFrame* frame) override { |
| 260 surface_->SwapBuffers(); | 269 surface_->SwapBuffers(); |
| 261 PostSwapBuffersComplete(); | 270 PostSwapBuffersComplete(); |
| 262 client_->DidSwapBuffers(); | 271 client_->DidSwapBuffers(); |
| 263 } | 272 } |
| 264 | 273 |
| 265 void Destroy() { | 274 void Destroy() { |
| 266 if (surface_) { | 275 if (surface_) { |
| 267 surface_->Destroy(); | 276 surface_->Destroy(); |
| 268 surface_.reset(); | 277 surface_.reset(); |
| 269 } | 278 } |
| 270 } | 279 } |
| 271 | 280 |
| 272 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | 281 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, |
| 273 gfx::SwapResult result) { | 282 gfx::SwapResult result) { |
| 274 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 283 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); |
| 275 OutputSurface::OnSwapBuffersComplete(); | 284 OutputSurface::OnSwapBuffersComplete(); |
| 276 } | 285 } |
| 277 | 286 |
| 278 private: | 287 private: |
| 279 std::unique_ptr<gpu::VulkanSurface> surface_; | 288 std::unique_ptr<gpu::VulkanSurface> surface_; |
| 289 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source_; |
| 280 | 290 |
| 281 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); | 291 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); |
| 282 }; | 292 }; |
| 283 #endif | 293 #endif |
| 284 | 294 |
| 285 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>> | 295 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>> |
| 286 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER; | 296 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER; |
| 287 | 297 |
| 288 static bool g_initialized = false; | 298 static bool g_initialized = false; |
| 289 | 299 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 if (!output_surface_request_pending_ || !host_->visible()) | 595 if (!output_surface_request_pending_ || !host_->visible()) |
| 586 return; | 596 return; |
| 587 | 597 |
| 588 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 598 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 589 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = | 599 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
| 590 SharedVulkanContextProviderAndroid(); | 600 SharedVulkanContextProviderAndroid(); |
| 591 std::unique_ptr<cc::OutputSurface> real_output_surface; | 601 std::unique_ptr<cc::OutputSurface> real_output_surface; |
| 592 #if defined(ENABLE_VULKAN) | 602 #if defined(ENABLE_VULKAN) |
| 593 std::unique_ptr<VulkanOutputSurface> vulkan_surface; | 603 std::unique_ptr<VulkanOutputSurface> vulkan_surface; |
| 594 if (vulkan_context_provider) { | 604 if (vulkan_context_provider) { |
| 595 vulkan_surface.reset( | 605 vulkan_surface.reset(new VulkanOutputSurface( |
| 596 new VulkanOutputSurface(std::move(vulkan_context_provider))); | 606 std::move(vulkan_context_provider), |
| 607 base::WrapUnique(new ExternalBeginFrameSource(this)))); |
| 597 if (!vulkan_surface->Initialize(window_)) { | 608 if (!vulkan_surface->Initialize(window_)) { |
| 598 vulkan_surface->Destroy(); | 609 vulkan_surface->Destroy(); |
| 599 vulkan_surface.reset(); | 610 vulkan_surface.reset(); |
| 600 } else { | 611 } else { |
| 601 real_output_surface = std::move(vulkan_surface); | 612 real_output_surface = std::move(vulkan_surface); |
| 602 } | 613 } |
| 603 } | 614 } |
| 604 #endif | 615 #endif |
| 605 | 616 |
| 606 if (!real_output_surface) { | 617 if (!real_output_surface) { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 void CompositorImpl::SetNeedsAnimate() { | 798 void CompositorImpl::SetNeedsAnimate() { |
| 788 needs_animate_ = true; | 799 needs_animate_ = true; |
| 789 if (!host_->visible()) | 800 if (!host_->visible()) |
| 790 return; | 801 return; |
| 791 | 802 |
| 792 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 803 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 793 host_->SetNeedsAnimate(); | 804 host_->SetNeedsAnimate(); |
| 794 } | 805 } |
| 795 | 806 |
| 796 } // namespace content | 807 } // namespace content |
| OLD | NEW |