| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 gfx::SwapResult, | 304 gfx::SwapResult, |
| 305 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)> | 305 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac)> |
| 306 swap_buffers_completion_callback_; | 306 swap_buffers_completion_callback_; |
| 307 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; | 307 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 #if defined(ENABLE_VULKAN) | 310 #if defined(ENABLE_VULKAN) |
| 311 class VulkanOutputSurface : public cc::OutputSurface { | 311 class VulkanOutputSurface : public cc::OutputSurface { |
| 312 public: | 312 public: |
| 313 explicit VulkanOutputSurface( | 313 explicit VulkanOutputSurface( |
| 314 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider) | 314 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 315 : OutputSurface(std::move(vulkan_context_provider)) {} | 315 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 316 : OutputSurface(std::move(vulkan_context_provider)), |
| 317 task_runner_(std::move(task_runner)), |
| 318 weak_ptr_factory_(this) {} |
| 316 | 319 |
| 317 ~VulkanOutputSurface() override { Destroy(); } | 320 ~VulkanOutputSurface() override { Destroy(); } |
| 318 | 321 |
| 319 bool Initialize(gfx::AcceleratedWidget widget) { | 322 bool Initialize(gfx::AcceleratedWidget widget) { |
| 320 DCHECK(!surface_); | 323 DCHECK(!surface_); |
| 321 std::unique_ptr<gpu::VulkanSurface> surface( | 324 std::unique_ptr<gpu::VulkanSurface> surface( |
| 322 gpu::VulkanSurface::CreateViewSurface(widget)); | 325 gpu::VulkanSurface::CreateViewSurface(widget)); |
| 323 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), | 326 if (!surface->Initialize(vulkan_context_provider()->GetDeviceQueue(), |
| 324 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { | 327 gpu::VulkanSurface::DEFAULT_SURFACE_FORMAT)) { |
| 325 return false; | 328 return false; |
| 326 } | 329 } |
| 327 surface_ = std::move(surface); | 330 surface_ = std::move(surface); |
| 328 | 331 |
| 329 return true; | 332 return true; |
| 330 } | 333 } |
| 331 | 334 |
| 332 bool BindToClient(cc::OutputSurfaceClient* client) override { | 335 bool BindToClient(cc::OutputSurfaceClient* client) override { |
| 333 if (!OutputSurface::BindToClient(client)) | 336 if (!OutputSurface::BindToClient(client)) |
| 334 return false; | 337 return false; |
| 335 return true; | 338 return true; |
| 336 } | 339 } |
| 337 | 340 |
| 338 void SwapBuffers(cc::CompositorFrame frame) override { | 341 void SwapBuffers(cc::CompositorFrame frame) override { |
| 339 surface_->SwapBuffers(); | 342 surface_->SwapBuffers(); |
| 340 PostSwapBuffersComplete(); | 343 task_runner_->PostTask(FROM_HERE, |
| 344 base::Bind(&VulkanOutputSurface::SwapBuffersCallback, |
| 345 weak_ptr_factory_.GetWeakPtr())); |
| 341 } | 346 } |
| 342 | 347 |
| 343 void Destroy() { | 348 void Destroy() { |
| 344 if (surface_) { | 349 if (surface_) { |
| 345 surface_->Destroy(); | 350 surface_->Destroy(); |
| 346 surface_.reset(); | 351 surface_.reset(); |
| 347 } | 352 } |
| 348 } | 353 } |
| 349 | 354 |
| 350 void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info, | 355 private: |
| 351 gfx::SwapResult result) { | 356 void OutputSurface::SwapBuffersCallback() { |
| 352 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); | 357 client_->DidSwapBuffersComplete(); |
| 353 OutputSurface::OnSwapBuffersComplete(); | |
| 354 } | 358 } |
| 355 | 359 |
| 356 private: | |
| 357 std::unique_ptr<gpu::VulkanSurface> surface_; | 360 std::unique_ptr<gpu::VulkanSurface> surface_; |
| 361 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 362 base::WeakPtrFactory<VulkanOutputSurface> weak_ptr_factory_; |
| 358 | 363 |
| 359 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); | 364 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); |
| 360 }; | 365 }; |
| 361 #endif | 366 #endif |
| 362 | 367 |
| 363 static bool g_initialized = false; | 368 static bool g_initialized = false; |
| 364 | 369 |
| 365 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { | 370 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { |
| 366 public: | 371 public: |
| 367 SingleThreadTaskGraphRunner() { | 372 SingleThreadTaskGraphRunner() { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 639 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 635 switches::kEnableVulkan)) | 640 switches::kEnableVulkan)) |
| 636 return; | 641 return; |
| 637 | 642 |
| 638 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = | 643 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 639 ui::ContextProviderFactory::GetInstance() | 644 ui::ContextProviderFactory::GetInstance() |
| 640 ->GetSharedVulkanContextProvider(); | 645 ->GetSharedVulkanContextProvider(); |
| 641 if (!vulkan_context_provider) | 646 if (!vulkan_context_provider) |
| 642 return; | 647 return; |
| 643 | 648 |
| 644 auto vulkan_surface = | 649 auto vulkan_surface = base::MakeUnique<VulkanOutputSurface>( |
| 645 base::MakeUnique<VulkanOutputSurface>(vulkan_context_provider); | 650 vulkan_context_provider, base::ThreadTaskRunnerHandle::Get()); |
| 646 if (!vulkan_surface->Initialize(window_)) | 651 if (!vulkan_surface->Initialize(window_)) |
| 647 return; | 652 return; |
| 648 | 653 |
| 649 InitializeDisplay(std::move(vulkan_surface), | 654 InitializeDisplay(std::move(vulkan_surface), |
| 650 std::move(vulkan_context_provider), nullptr); | 655 std::move(vulkan_context_provider), nullptr); |
| 651 } | 656 } |
| 652 #endif | 657 #endif |
| 653 | 658 |
| 654 void CompositorImpl::OnGpuChannelEstablished( | 659 void CompositorImpl::OnGpuChannelEstablished( |
| 655 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 660 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 | 831 |
| 827 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { | 832 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { |
| 828 return frame_sink_id_; | 833 return frame_sink_id_; |
| 829 } | 834 } |
| 830 | 835 |
| 831 bool CompositorImpl::HavePendingReadbacks() { | 836 bool CompositorImpl::HavePendingReadbacks() { |
| 832 return !readback_layer_tree_->children().empty(); | 837 return !readback_layer_tree_->children().empty(); |
| 833 } | 838 } |
| 834 | 839 |
| 835 } // namespace content | 840 } // namespace content |
| OLD | NEW |