| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "cc/surfaces/display.h" | 43 #include "cc/surfaces/display.h" |
| 44 #include "cc/surfaces/display_scheduler.h" | 44 #include "cc/surfaces/display_scheduler.h" |
| 45 #include "cc/surfaces/surface_display_output_surface.h" | 45 #include "cc/surfaces/surface_display_output_surface.h" |
| 46 #include "cc/surfaces/surface_id_allocator.h" | 46 #include "cc/surfaces/surface_id_allocator.h" |
| 47 #include "cc/surfaces/surface_manager.h" | 47 #include "cc/surfaces/surface_manager.h" |
| 48 #include "cc/trees/layer_tree_host.h" | 48 #include "cc/trees/layer_tree_host.h" |
| 49 #include "cc/trees/layer_tree_settings.h" | 49 #include "cc/trees/layer_tree_settings.h" |
| 50 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" | 50 #include "components/display_compositor/compositor_overlay_candidate_validator_a
ndroid.h" |
| 51 #include "components/display_compositor/gl_helper.h" | 51 #include "components/display_compositor/gl_helper.h" |
| 52 #include "content/browser/android/child_process_launcher_android.h" | 52 #include "content/browser/android/child_process_launcher_android.h" |
| 53 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | |
| 54 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 53 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 55 #include "content/browser/gpu/compositor_util.h" | 54 #include "content/browser/gpu/compositor_util.h" |
| 56 #include "content/browser/gpu/gpu_surface_tracker.h" | 55 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 56 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" |
| 57 #include "content/browser/renderer_host/render_widget_host_impl.h" | 57 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 58 #include "content/common/gpu/client/context_provider_command_buffer.h" | 58 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 59 #include "content/common/gpu_process_launch_causes.h" | 59 #include "content/common/gpu_process_launch_causes.h" |
| 60 #include "content/common/host_shared_bitmap_manager.h" | 60 #include "content/common/host_shared_bitmap_manager.h" |
| 61 #include "content/public/browser/android/compositor.h" | 61 #include "content/public/browser/android/compositor.h" |
| 62 #include "content/public/browser/android/compositor_client.h" | 62 #include "content/public/browser/android/compositor_client.h" |
| 63 #include "content/public/common/content_switches.h" | 63 #include "content/public/common/content_switches.h" |
| 64 #include "gpu/command_buffer/client/context_support.h" | 64 #include "gpu/command_buffer/client/context_support.h" |
| 65 #include "gpu/command_buffer/client/gles2_interface.h" | 65 #include "gpu/command_buffer/client/gles2_interface.h" |
| 66 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 66 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 OutputSurface::OnSwapBuffersComplete(); | 281 OutputSurface::OnSwapBuffersComplete(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 private: | 284 private: |
| 285 std::unique_ptr<gpu::VulkanSurface> surface_; | 285 std::unique_ptr<gpu::VulkanSurface> surface_; |
| 286 | 286 |
| 287 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); | 287 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); |
| 288 }; | 288 }; |
| 289 #endif | 289 #endif |
| 290 | 290 |
| 291 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>> | |
| 292 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER; | |
| 293 | |
| 294 static bool g_initialized = false; | 291 static bool g_initialized = false; |
| 295 | 292 |
| 296 base::LazyInstance<cc::SurfaceManager> g_surface_manager = | 293 base::LazyInstance<cc::SurfaceManager> g_surface_manager = |
| 297 LAZY_INSTANCE_INITIALIZER; | 294 LAZY_INSTANCE_INITIALIZER; |
| 298 | 295 |
| 299 int g_surface_client_id = 0; | 296 int g_surface_client_id = 0; |
| 300 | 297 |
| 301 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { | 298 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { |
| 302 public: | 299 public: |
| 303 SingleThreadTaskGraphRunner() { | 300 SingleThreadTaskGraphRunner() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 334 // static | 331 // static |
| 335 cc::SurfaceManager* CompositorImpl::GetSurfaceManager() { | 332 cc::SurfaceManager* CompositorImpl::GetSurfaceManager() { |
| 336 return g_surface_manager.Pointer(); | 333 return g_surface_manager.Pointer(); |
| 337 } | 334 } |
| 338 | 335 |
| 339 // static | 336 // static |
| 340 uint32_t CompositorImpl::AllocateSurfaceClientId() { | 337 uint32_t CompositorImpl::AllocateSurfaceClientId() { |
| 341 return ++g_surface_client_id; | 338 return ++g_surface_client_id; |
| 342 } | 339 } |
| 343 | 340 |
| 344 // static | |
| 345 scoped_refptr<cc::VulkanInProcessContextProvider> | |
| 346 CompositorImpl::SharedVulkanContextProviderAndroid() { | |
| 347 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 348 switches::kEnableVulkan)) { | |
| 349 scoped_refptr<cc::VulkanInProcessContextProvider>* context_provider = | |
| 350 g_shared_vulkan_context_provider_android_.Pointer(); | |
| 351 if (!*context_provider) | |
| 352 *context_provider = cc::VulkanInProcessContextProvider::Create(); | |
| 353 return *context_provider; | |
| 354 } | |
| 355 return nullptr; | |
| 356 } | |
| 357 | |
| 358 CompositorImpl::CompositorImpl(CompositorClient* client, | 341 CompositorImpl::CompositorImpl(CompositorClient* client, |
| 359 gfx::NativeWindow root_window) | 342 gfx::NativeWindow root_window) |
| 360 : surface_id_allocator_( | 343 : surface_id_allocator_( |
| 361 new cc::SurfaceIdAllocator(AllocateSurfaceClientId())), | 344 new cc::SurfaceIdAllocator(AllocateSurfaceClientId())), |
| 362 resource_manager_(root_window), | 345 resource_manager_(root_window), |
| 363 has_transparent_background_(false), | 346 has_transparent_background_(false), |
| 364 device_scale_factor_(1), | 347 device_scale_factor_(1), |
| 365 window_(NULL), | 348 window_(NULL), |
| 366 surface_handle_(gpu::kNullSurfaceHandle), | 349 surface_handle_(gpu::kNullSurfaceHandle), |
| 367 client_(client), | 350 client_(client), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 467 } |
| 485 | 468 |
| 486 void CompositorImpl::SetVisible(bool visible) { | 469 void CompositorImpl::SetVisible(bool visible) { |
| 487 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); | 470 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); |
| 488 if (!visible) { | 471 if (!visible) { |
| 489 DCHECK(host_->visible()); | 472 DCHECK(host_->visible()); |
| 490 host_->SetVisible(false); | 473 host_->SetVisible(false); |
| 491 if (!host_->output_surface_lost()) | 474 if (!host_->output_surface_lost()) |
| 492 host_->ReleaseOutputSurface(); | 475 host_->ReleaseOutputSurface(); |
| 493 pending_swapbuffers_ = 0; | 476 pending_swapbuffers_ = 0; |
| 494 establish_gpu_channel_timeout_.Stop(); | |
| 495 display_.reset(); | 477 display_.reset(); |
| 496 } else { | 478 } else { |
| 497 host_->SetVisible(true); | 479 host_->SetVisible(true); |
| 498 if (output_surface_request_pending_) | 480 if (output_surface_request_pending_) |
| 499 RequestNewOutputSurface(); | 481 RequestNewOutputSurface(); |
| 500 } | 482 } |
| 501 } | 483 } |
| 502 | 484 |
| 503 void CompositorImpl::setDeviceScaleFactor(float factor) { | 485 void CompositorImpl::setDeviceScaleFactor(float factor) { |
| 504 device_scale_factor_ = factor; | 486 device_scale_factor_ = factor; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 532 } | 514 } |
| 533 | 515 |
| 534 void CompositorImpl::UpdateLayerTreeHost() { | 516 void CompositorImpl::UpdateLayerTreeHost() { |
| 535 client_->UpdateLayerTreeHost(); | 517 client_->UpdateLayerTreeHost(); |
| 536 if (needs_animate_) { | 518 if (needs_animate_) { |
| 537 needs_animate_ = false; | 519 needs_animate_ = false; |
| 538 root_window_->Animate(base::TimeTicks::Now()); | 520 root_window_->Animate(base::TimeTicks::Now()); |
| 539 } | 521 } |
| 540 } | 522 } |
| 541 | 523 |
| 542 void CompositorImpl::OnGpuChannelEstablished() { | 524 void CompositorImpl::OnGpuChannelEstablished( |
| 543 establish_gpu_channel_timeout_.Stop(); | 525 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 544 CreateOutputSurface(); | 526 CreateOutputSurface(std::move(gpu_channel_host)); |
| 545 } | |
| 546 | |
| 547 void CompositorImpl::OnGpuChannelTimeout() { | |
| 548 LOG(FATAL) << "Timed out waiting for GPU channel."; | |
| 549 } | 527 } |
| 550 | 528 |
| 551 void CompositorImpl::RequestNewOutputSurface() { | 529 void CompositorImpl::RequestNewOutputSurface() { |
| 552 output_surface_request_pending_ = true; | 530 output_surface_request_pending_ = true; |
| 553 | 531 CreateOutputSurface(nullptr); |
| 554 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \ | |
| 555 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION) | |
| 556 const int64_t kGpuChannelTimeoutInSeconds = 40; | |
| 557 #else | |
| 558 const int64_t kGpuChannelTimeoutInSeconds = 10; | |
| 559 #endif | |
| 560 | |
| 561 BrowserGpuChannelHostFactory* factory = | |
| 562 BrowserGpuChannelHostFactory::instance(); | |
| 563 if (!factory->GetGpuChannel()) { | |
| 564 factory->EstablishGpuChannel( | |
| 565 CAUSE_FOR_GPU_LAUNCH_DISPLAY_COMPOSITOR_CONTEXT, | |
| 566 base::Bind(&CompositorImpl::OnGpuChannelEstablished, | |
| 567 weak_factory_.GetWeakPtr())); | |
| 568 establish_gpu_channel_timeout_.Start( | |
| 569 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds), | |
| 570 this, &CompositorImpl::OnGpuChannelTimeout); | |
| 571 return; | |
| 572 } | |
| 573 | |
| 574 CreateOutputSurface(); | |
| 575 } | 532 } |
| 576 | 533 |
| 577 void CompositorImpl::DidInitializeOutputSurface() { | 534 void CompositorImpl::DidInitializeOutputSurface() { |
| 578 num_successive_context_creation_failures_ = 0; | 535 num_successive_context_creation_failures_ = 0; |
| 579 output_surface_request_pending_ = false; | 536 output_surface_request_pending_ = false; |
| 580 } | 537 } |
| 581 | 538 |
| 582 void CompositorImpl::DidFailToInitializeOutputSurface() { | 539 void CompositorImpl::DidFailToInitializeOutputSurface() { |
| 583 LOG(ERROR) << "Failed to init OutputSurface for compositor."; | 540 LOG(ERROR) << "Failed to init OutputSurface for compositor."; |
| 584 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) | 541 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) |
| 585 << "Too many context creation failures. Giving up... "; | 542 << "Too many context creation failures. Giving up... "; |
| 586 RequestNewOutputSurface(); | 543 RequestNewOutputSurface(); |
| 587 } | 544 } |
| 588 | 545 |
| 589 void CompositorImpl::CreateOutputSurface() { | 546 void CompositorImpl::CreateOutputSurface( |
| 547 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 590 // We might have had a request from a LayerTreeHost that was then | 548 // We might have had a request from a LayerTreeHost that was then |
| 591 // hidden (and hidden means we don't have a native surface). | 549 // hidden (and hidden means we don't have a native surface). |
| 592 // Also make sure we only handle this once. | 550 // Also make sure we only handle this once. |
| 593 if (!output_surface_request_pending_ || !host_->visible()) | 551 if (!output_surface_request_pending_ || !host_->visible()) |
| 594 return; | 552 return; |
| 595 | 553 |
| 596 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 554 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
| 597 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = | 555 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = |
| 598 SharedVulkanContextProviderAndroid(); | 556 ContextProviderFactoryImpl::GetInstance() |
| 557 ->GetSharedVulkanContextProviderAndroid(); |
| 599 std::unique_ptr<cc::OutputSurface> display_output_surface; | 558 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 600 #if defined(ENABLE_VULKAN) | 559 #if defined(ENABLE_VULKAN) |
| 601 std::unique_ptr<VulkanOutputSurface> vulkan_surface; | 560 std::unique_ptr<VulkanOutputSurface> vulkan_surface; |
| 602 if (vulkan_context_provider) { | 561 if (vulkan_context_provider) { |
| 603 vulkan_surface.reset( | 562 vulkan_surface.reset( |
| 604 new VulkanOutputSurface(std::move(vulkan_context_provider))); | 563 new VulkanOutputSurface(std::move(vulkan_context_provider))); |
| 605 if (!vulkan_surface->Initialize(window_)) { | 564 if (!vulkan_surface->Initialize(window_)) { |
| 606 vulkan_surface->Destroy(); | 565 vulkan_surface->Destroy(); |
| 607 vulkan_surface.reset(); | 566 vulkan_surface.reset(); |
| 608 } else { | 567 } else { |
| 609 display_output_surface = std::move(vulkan_surface); | 568 display_output_surface = std::move(vulkan_surface); |
| 610 } | 569 } |
| 611 } | 570 } |
| 612 #endif | 571 #endif |
| 613 | 572 |
| 573 if (!gpu_channel_host) { |
| 574 ContextProviderFactoryImpl::GetInstance()->RequestGpuChannel(base::Bind( |
| 575 &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); |
| 576 return; |
| 577 } |
| 578 |
| 614 if (!display_output_surface) { | 579 if (!display_output_surface) { |
| 615 // This is used for the browser compositor (offscreen) and for the display | 580 // This is used for the browser compositor (offscreen) and for the display |
| 616 // compositor (onscreen), so ask for capabilities needed by either one. | 581 // compositor (onscreen), so ask for capabilities needed by either one. |
| 617 // The default framebuffer for an offscreen context is not used, so it does | 582 // The default framebuffer for an offscreen context is not used, so it does |
| 618 // not need alpha, stencil, depth, antialiasing. The display compositor does | 583 // not need alpha, stencil, depth, antialiasing. The display compositor does |
| 619 // not use these things either, except for alpha when it has a transparent | 584 // not use these things either, except for alpha when it has a transparent |
| 620 // background. | 585 // background. |
| 621 gpu::gles2::ContextCreationAttribHelper attributes; | 586 gpu::gles2::ContextCreationAttribHelper attributes; |
| 622 attributes.alpha_size = -1; | 587 attributes.alpha_size = -1; |
| 623 attributes.stencil_size = 0; | 588 attributes.stencil_size = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 640 attributes.red_size = 5; | 605 attributes.red_size = 5; |
| 641 attributes.green_size = 6; | 606 attributes.green_size = 6; |
| 642 attributes.blue_size = 5; | 607 attributes.blue_size = 5; |
| 643 } | 608 } |
| 644 | 609 |
| 645 pending_swapbuffers_ = 0; | 610 pending_swapbuffers_ = 0; |
| 646 | 611 |
| 647 DCHECK(window_); | 612 DCHECK(window_); |
| 648 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); | 613 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); |
| 649 | 614 |
| 650 BrowserGpuChannelHostFactory* factory = | |
| 651 BrowserGpuChannelHostFactory::instance(); | |
| 652 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | |
| 653 factory->GetGpuChannel()); | |
| 654 // If the channel was already lost, we'll get null back here and need to | |
| 655 // try again. | |
| 656 if (!gpu_channel_host) { | |
| 657 RequestNewOutputSurface(); | |
| 658 return; | |
| 659 } | |
| 660 | |
| 661 GURL url("chrome://gpu/CompositorImpl::CreateOutputSurface"); | 615 GURL url("chrome://gpu/CompositorImpl::CreateOutputSurface"); |
| 662 constexpr bool automatic_flushes = false; | 616 constexpr bool automatic_flushes = false; |
| 663 constexpr bool support_locking = false; | 617 constexpr bool support_locking = false; |
| 664 | 618 |
| 665 constexpr size_t kBytesPerPixel = 4; | 619 constexpr size_t kBytesPerPixel = 4; |
| 666 const size_t full_screen_texture_size_in_bytes = | 620 const size_t full_screen_texture_size_in_bytes = |
| 667 gfx::DeviceDisplayInfo().GetDisplayHeight() * | 621 gfx::DeviceDisplayInfo().GetDisplayHeight() * |
| 668 gfx::DeviceDisplayInfo().GetDisplayWidth() * kBytesPerPixel; | 622 gfx::DeviceDisplayInfo().GetDisplayWidth() * kBytesPerPixel; |
| 669 | 623 |
| 670 gpu::SharedMemoryLimits limits; | 624 gpu::SharedMemoryLimits limits; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 void CompositorImpl::SetNeedsAnimate() { | 755 void CompositorImpl::SetNeedsAnimate() { |
| 802 needs_animate_ = true; | 756 needs_animate_ = true; |
| 803 if (!host_->visible()) | 757 if (!host_->visible()) |
| 804 return; | 758 return; |
| 805 | 759 |
| 806 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 760 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 807 host_->SetNeedsAnimate(); | 761 host_->SetNeedsAnimate(); |
| 808 } | 762 } |
| 809 | 763 |
| 810 } // namespace content | 764 } // namespace content |
| OLD | NEW |