Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 #include "cc/output/output_surface.h" | 37 #include "cc/output/output_surface.h" |
| 38 #include "cc/output/output_surface_client.h" | 38 #include "cc/output/output_surface_client.h" |
| 39 #include "cc/output/texture_mailbox_deleter.h" | 39 #include "cc/output/texture_mailbox_deleter.h" |
| 40 #include "cc/output/vulkan_in_process_context_provider.h" | 40 #include "cc/output/vulkan_in_process_context_provider.h" |
| 41 #include "cc/raster/single_thread_task_graph_runner.h" | 41 #include "cc/raster/single_thread_task_graph_runner.h" |
| 42 #include "cc/scheduler/begin_frame_source.h" | 42 #include "cc/scheduler/begin_frame_source.h" |
| 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" | |
| 48 #include "cc/trees/layer_tree_host.h" | 47 #include "cc/trees/layer_tree_host.h" |
| 49 #include "cc/trees/layer_tree_settings.h" | 48 #include "cc/trees/layer_tree_settings.h" |
| 50 #include "components/display_compositor/compositor_overlay_candidate_validator_a ndroid.h" | 49 #include "components/display_compositor/compositor_overlay_candidate_validator_a ndroid.h" |
| 51 #include "components/display_compositor/gl_helper.h" | 50 #include "components/display_compositor/gl_helper.h" |
| 52 #include "content/browser/android/child_process_launcher_android.h" | 51 #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" | 52 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 55 #include "content/browser/gpu/compositor_util.h" | 53 #include "content/browser/gpu/compositor_util.h" |
| 56 #include "content/browser/gpu/gpu_surface_tracker.h" | 54 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 55 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" | |
| 57 #include "content/browser/renderer_host/render_widget_host_impl.h" | 56 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 58 #include "content/common/gpu/client/context_provider_command_buffer.h" | 57 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 59 #include "content/common/gpu_process_launch_causes.h" | 58 #include "content/common/gpu_process_launch_causes.h" |
| 60 #include "content/common/host_shared_bitmap_manager.h" | 59 #include "content/common/host_shared_bitmap_manager.h" |
| 61 #include "content/public/browser/android/compositor.h" | 60 #include "content/public/browser/android/compositor.h" |
| 62 #include "content/public/browser/android/compositor_client.h" | 61 #include "content/public/browser/android/compositor_client.h" |
| 63 #include "content/public/common/content_switches.h" | 62 #include "content/public/common/content_switches.h" |
| 64 #include "gpu/command_buffer/client/context_support.h" | 63 #include "gpu/command_buffer/client/context_support.h" |
| 65 #include "gpu/command_buffer/client/gles2_interface.h" | 64 #include "gpu/command_buffer/client/gles2_interface.h" |
| 66 #include "gpu/ipc/client/command_buffer_proxy_impl.h" | 65 #include "gpu/ipc/client/command_buffer_proxy_impl.h" |
| 67 #include "gpu/ipc/client/gpu_channel_host.h" | 66 #include "gpu/ipc/client/gpu_channel_host.h" |
| 68 #include "gpu/vulkan/vulkan_surface.h" | 67 #include "gpu/vulkan/vulkan_surface.h" |
| 69 #include "third_party/khronos/GLES2/gl2.h" | 68 #include "third_party/khronos/GLES2/gl2.h" |
| 70 #include "third_party/khronos/GLES2/gl2ext.h" | 69 #include "third_party/khronos/GLES2/gl2ext.h" |
| 71 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 70 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 72 #include "ui/android/window_android.h" | 71 #include "ui/android/window_android.h" |
| 73 #include "ui/gfx/android/device_display_info.h" | 72 #include "ui/gfx/android/device_display_info.h" |
| 74 #include "ui/gfx/swap_result.h" | 73 #include "ui/gfx/swap_result.h" |
| 75 | 74 |
| 76 namespace gpu { | 75 namespace gpu { |
| 77 struct GpuProcessHostedCALayerTreeParamsMac; | 76 struct GpuProcessHostedCALayerTreeParamsMac; |
| 78 } | 77 } |
| 79 | 78 |
| 80 namespace content { | 79 namespace content { |
| 81 | 80 |
| 82 namespace { | 81 namespace { |
| 83 | 82 |
| 84 const unsigned int kMaxDisplaySwapBuffers = 1U; | 83 const unsigned int kMaxDisplaySwapBuffers = 1U; |
| 85 | 84 |
| 85 gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits() { | |
| 86 constexpr size_t kBytesPerPixel = 4; | |
| 87 const size_t full_screen_texture_size_in_bytes = | |
| 88 gfx::DeviceDisplayInfo().GetDisplayHeight() * | |
| 89 gfx::DeviceDisplayInfo().GetDisplayWidth() * kBytesPerPixel; | |
| 90 | |
| 91 gpu::SharedMemoryLimits limits; | |
| 92 // This limit is meant to hold the contents of the display compositor | |
| 93 // drawing the scene. See discussion here: | |
| 94 // https://codereview.chromium.org/1900993002/diff/90001/content/browser/rende rer_host/compositor_impl_android.cc?context=3&column_width=80&tab_spaces=8 | |
| 95 limits.command_buffer_size = 64 * 1024; | |
| 96 // These limits are meant to hold the uploads for the browser UI without | |
| 97 // any excess space. | |
| 98 limits.start_transfer_buffer_size = 64 * 1024; | |
| 99 limits.min_transfer_buffer_size = 64 * 1024; | |
| 100 limits.max_transfer_buffer_size = full_screen_texture_size_in_bytes; | |
| 101 // Texture uploads may use mapped memory so give a reasonable limit for | |
| 102 // them. | |
| 103 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes; | |
| 104 | |
| 105 return limits; | |
| 106 } | |
| 107 | |
| 108 gpu::gles2::ContextCreationAttribHelper GetCompositorContextAttributes( | |
| 109 bool has_transparent_background) { | |
| 110 // This is used for the browser compositor (offscreen) and for the display | |
| 111 // compositor (onscreen), so ask for capabilities needed by either one. | |
| 112 // The default framebuffer for an offscreen context is not used, so it does | |
| 113 // not need alpha, stencil, depth, antialiasing. The display compositor does | |
| 114 // not use these things either, except for alpha when it has a transparent | |
| 115 // background. | |
| 116 gpu::gles2::ContextCreationAttribHelper attributes; | |
| 117 attributes.alpha_size = -1; | |
| 118 attributes.stencil_size = 0; | |
| 119 attributes.depth_size = 0; | |
| 120 attributes.samples = 0; | |
| 121 attributes.sample_buffers = 0; | |
| 122 attributes.bind_generates_resource = false; | |
| 123 | |
| 124 if (has_transparent_background) { | |
| 125 attributes.alpha_size = 8; | |
| 126 } else if (base::SysInfo::IsLowEndDevice()) { | |
| 127 // In this case we prefer to use RGB565 format instead of RGBA8888 if | |
| 128 // possible. | |
| 129 // TODO(danakj): GpuCommandBufferStub constructor checks for alpha == 0 in | |
| 130 // order to enable 565, but it should avoid using 565 when -1s are | |
| 131 // specified | |
| 132 // (IOW check that a <= 0 && rgb > 0 && rgb <= 565) then alpha should be | |
| 133 // -1. | |
| 134 attributes.alpha_size = 0; | |
| 135 attributes.red_size = 5; | |
| 136 attributes.green_size = 6; | |
| 137 attributes.blue_size = 5; | |
| 138 } | |
| 139 | |
| 140 return attributes; | |
| 141 } | |
| 142 | |
| 86 class ExternalBeginFrameSource : public cc::BeginFrameSource, | 143 class ExternalBeginFrameSource : public cc::BeginFrameSource, |
| 87 public CompositorImpl::VSyncObserver { | 144 public CompositorImpl::VSyncObserver { |
| 88 public: | 145 public: |
| 89 explicit ExternalBeginFrameSource(CompositorImpl* compositor) | 146 explicit ExternalBeginFrameSource(CompositorImpl* compositor) |
| 90 : compositor_(compositor) { | 147 : compositor_(compositor) { |
| 91 compositor_->AddObserver(this); | 148 compositor_->AddObserver(this); |
| 92 } | 149 } |
| 93 ~ExternalBeginFrameSource() override { compositor_->RemoveObserver(this); } | 150 ~ExternalBeginFrameSource() override { compositor_->RemoveObserver(this); } |
| 94 | 151 |
| 95 // cc::BeginFrameSource implementation. | 152 // cc::BeginFrameSource implementation. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 OutputSurface::OnSwapBuffersComplete(); | 338 OutputSurface::OnSwapBuffersComplete(); |
| 282 } | 339 } |
| 283 | 340 |
| 284 private: | 341 private: |
| 285 std::unique_ptr<gpu::VulkanSurface> surface_; | 342 std::unique_ptr<gpu::VulkanSurface> surface_; |
| 286 | 343 |
| 287 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); | 344 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); |
| 288 }; | 345 }; |
| 289 #endif | 346 #endif |
| 290 | 347 |
| 291 base::LazyInstance<scoped_refptr<cc::VulkanInProcessContextProvider>> | |
| 292 g_shared_vulkan_context_provider_android_ = LAZY_INSTANCE_INITIALIZER; | |
| 293 | |
| 294 static bool g_initialized = false; | 348 static bool g_initialized = false; |
| 295 | 349 |
| 296 base::LazyInstance<cc::SurfaceManager> g_surface_manager = | |
| 297 LAZY_INSTANCE_INITIALIZER; | |
| 298 | |
| 299 int g_surface_client_id = 0; | |
| 300 | |
| 301 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { | 350 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner { |
| 302 public: | 351 public: |
| 303 SingleThreadTaskGraphRunner() { | 352 SingleThreadTaskGraphRunner() { |
| 304 Start("CompositorTileWorker1", base::SimpleThread::Options()); | 353 Start("CompositorTileWorker1", base::SimpleThread::Options()); |
| 305 } | 354 } |
| 306 | 355 |
| 307 ~SingleThreadTaskGraphRunner() override { | 356 ~SingleThreadTaskGraphRunner() override { |
| 308 Shutdown(); | 357 Shutdown(); |
| 309 } | 358 } |
| 310 }; | 359 }; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 324 void Compositor::Initialize() { | 373 void Compositor::Initialize() { |
| 325 DCHECK(!CompositorImpl::IsInitialized()); | 374 DCHECK(!CompositorImpl::IsInitialized()); |
| 326 g_initialized = true; | 375 g_initialized = true; |
| 327 } | 376 } |
| 328 | 377 |
| 329 // static | 378 // static |
| 330 bool CompositorImpl::IsInitialized() { | 379 bool CompositorImpl::IsInitialized() { |
| 331 return g_initialized; | 380 return g_initialized; |
| 332 } | 381 } |
| 333 | 382 |
| 334 // static | |
| 335 cc::SurfaceManager* CompositorImpl::GetSurfaceManager() { | |
| 336 return g_surface_manager.Pointer(); | |
| 337 } | |
| 338 | |
| 339 // static | |
| 340 uint32_t CompositorImpl::AllocateSurfaceClientId() { | |
| 341 return ++g_surface_client_id; | |
| 342 } | |
| 343 | |
| 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, | 383 CompositorImpl::CompositorImpl(CompositorClient* client, |
| 359 gfx::NativeWindow root_window) | 384 gfx::NativeWindow root_window) |
| 360 : surface_id_allocator_( | 385 : surface_id_allocator_( |
| 361 new cc::SurfaceIdAllocator(AllocateSurfaceClientId())), | 386 new cc::SurfaceIdAllocator(ui::ContextProviderFactory::GetInstance() |
| 387 ->AllocateSurfaceClientId())), | |
| 362 resource_manager_(root_window), | 388 resource_manager_(root_window), |
| 363 has_transparent_background_(false), | 389 has_transparent_background_(false), |
| 364 device_scale_factor_(1), | 390 device_scale_factor_(1), |
| 365 window_(NULL), | 391 window_(NULL), |
| 366 surface_handle_(gpu::kNullSurfaceHandle), | 392 surface_handle_(gpu::kNullSurfaceHandle), |
| 367 client_(client), | 393 client_(client), |
| 368 root_window_(root_window), | 394 root_window_(root_window), |
| 369 needs_animate_(false), | 395 needs_animate_(false), |
| 370 pending_swapbuffers_(0U), | 396 pending_swapbuffers_(0U), |
| 371 num_successive_context_creation_failures_(0), | 397 num_successive_context_creation_failures_(0), |
| 372 output_surface_request_pending_(false), | 398 output_surface_request_pending_(false), |
| 373 needs_begin_frames_(false), | 399 needs_begin_frames_(false), |
| 374 weak_factory_(this) { | 400 weak_factory_(this) { |
| 375 GetSurfaceManager()->RegisterSurfaceClientId( | 401 ui::ContextProviderFactory::GetInstance() |
| 376 surface_id_allocator_->client_id()); | 402 ->GetSurfaceManager() |
| 403 ->RegisterSurfaceClientId(surface_id_allocator_->client_id()); | |
| 377 DCHECK(client); | 404 DCHECK(client); |
| 378 DCHECK(root_window); | 405 DCHECK(root_window); |
| 379 DCHECK(root_window->GetLayer() == nullptr); | 406 DCHECK(root_window->GetLayer() == nullptr); |
| 380 root_window->SetLayer(cc::Layer::Create()); | 407 root_window->SetLayer(cc::Layer::Create()); |
| 381 root_window->AttachCompositor(this); | 408 root_window->AttachCompositor(this); |
| 382 CreateLayerTreeHost(); | 409 CreateLayerTreeHost(); |
| 383 resource_manager_.Init(host_.get()); | 410 resource_manager_.Init(host_.get()); |
| 384 } | 411 } |
| 385 | 412 |
| 386 CompositorImpl::~CompositorImpl() { | 413 CompositorImpl::~CompositorImpl() { |
| 387 root_window_->DetachCompositor(); | 414 root_window_->DetachCompositor(); |
| 388 root_window_->SetLayer(nullptr); | 415 root_window_->SetLayer(nullptr); |
| 389 // Clean-up any surface references. | 416 // Clean-up any surface references. |
| 390 SetSurface(NULL); | 417 SetSurface(NULL); |
| 391 GetSurfaceManager()->InvalidateSurfaceClientId( | 418 ui::ContextProviderFactory::GetInstance() |
| 392 surface_id_allocator_->client_id()); | 419 ->GetSurfaceManager() |
| 420 ->InvalidateSurfaceClientId(surface_id_allocator_->client_id()); | |
| 393 } | 421 } |
| 394 | 422 |
| 395 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { | 423 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { |
| 396 return *this; | 424 return *this; |
| 397 } | 425 } |
| 398 | 426 |
| 399 ui::ResourceManager& CompositorImpl::GetResourceManager() { | 427 ui::ResourceManager& CompositorImpl::GetResourceManager() { |
| 400 return resource_manager_; | 428 return resource_manager_; |
| 401 } | 429 } |
| 402 | 430 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 } | 512 } |
| 485 | 513 |
| 486 void CompositorImpl::SetVisible(bool visible) { | 514 void CompositorImpl::SetVisible(bool visible) { |
| 487 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); | 515 TRACE_EVENT1("cc", "CompositorImpl::SetVisible", "visible", visible); |
| 488 if (!visible) { | 516 if (!visible) { |
| 489 DCHECK(host_->visible()); | 517 DCHECK(host_->visible()); |
| 490 host_->SetVisible(false); | 518 host_->SetVisible(false); |
| 491 if (!host_->output_surface_lost()) | 519 if (!host_->output_surface_lost()) |
| 492 host_->ReleaseOutputSurface(); | 520 host_->ReleaseOutputSurface(); |
| 493 pending_swapbuffers_ = 0; | 521 pending_swapbuffers_ = 0; |
| 494 establish_gpu_channel_timeout_.Stop(); | |
| 495 display_.reset(); | 522 display_.reset(); |
| 496 } else { | 523 } else { |
| 497 host_->SetVisible(true); | 524 host_->SetVisible(true); |
| 498 if (output_surface_request_pending_) | 525 if (output_surface_request_pending_) |
| 499 RequestNewOutputSurface(); | 526 HandlePendingOutputSurfaceRequest(); |
| 500 } | 527 } |
| 501 } | 528 } |
| 502 | 529 |
| 503 void CompositorImpl::setDeviceScaleFactor(float factor) { | 530 void CompositorImpl::setDeviceScaleFactor(float factor) { |
| 504 device_scale_factor_ = factor; | 531 device_scale_factor_ = factor; |
| 505 if (host_) | 532 if (host_) |
| 506 host_->SetDeviceScaleFactor(factor); | 533 host_->SetDeviceScaleFactor(factor); |
| 507 } | 534 } |
| 508 | 535 |
| 509 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { | 536 void CompositorImpl::SetWindowBounds(const gfx::Size& size) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 532 } | 559 } |
| 533 | 560 |
| 534 void CompositorImpl::UpdateLayerTreeHost() { | 561 void CompositorImpl::UpdateLayerTreeHost() { |
| 535 client_->UpdateLayerTreeHost(); | 562 client_->UpdateLayerTreeHost(); |
| 536 if (needs_animate_) { | 563 if (needs_animate_) { |
| 537 needs_animate_ = false; | 564 needs_animate_ = false; |
| 538 root_window_->Animate(base::TimeTicks::Now()); | 565 root_window_->Animate(base::TimeTicks::Now()); |
| 539 } | 566 } |
| 540 } | 567 } |
| 541 | 568 |
| 542 void CompositorImpl::OnGpuChannelEstablished() { | 569 void CompositorImpl::RequestNewOutputSurface() { |
| 543 establish_gpu_channel_timeout_.Stop(); | 570 DCHECK(!output_surface_request_pending_) |
| 544 CreateOutputSurface(); | 571 << "Output Surface Request is already pending?"; |
| 545 } | |
| 546 | 572 |
| 547 void CompositorImpl::OnGpuChannelTimeout() { | |
| 548 LOG(FATAL) << "Timed out waiting for GPU channel."; | |
| 549 } | |
| 550 | |
| 551 void CompositorImpl::RequestNewOutputSurface() { | |
| 552 output_surface_request_pending_ = true; | 573 output_surface_request_pending_ = true; |
| 553 | 574 HandlePendingOutputSurfaceRequest(); |
| 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 } | 575 } |
| 576 | 576 |
| 577 void CompositorImpl::DidInitializeOutputSurface() { | 577 void CompositorImpl::DidInitializeOutputSurface() { |
| 578 num_successive_context_creation_failures_ = 0; | 578 num_successive_context_creation_failures_ = 0; |
| 579 output_surface_request_pending_ = false; | 579 output_surface_request_pending_ = false; |
| 580 } | 580 } |
| 581 | 581 |
| 582 void CompositorImpl::DidFailToInitializeOutputSurface() { | 582 void CompositorImpl::DidFailToInitializeOutputSurface() { |
| 583 LOG(ERROR) << "Failed to init OutputSurface for compositor."; | 583 LOG(ERROR) << "Failed to init OutputSurface for compositor."; |
| 584 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) | 584 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) |
| 585 << "Too many context creation failures. Giving up... "; | 585 << "Too many context creation failures. Giving up... "; |
| 586 RequestNewOutputSurface(); | 586 HandlePendingOutputSurfaceRequest(); |
| 587 } | 587 } |
| 588 | 588 |
| 589 void CompositorImpl::CreateOutputSurface() { | 589 void CompositorImpl::HandlePendingOutputSurfaceRequest() { |
| 590 // We might have had a request from a LayerTreeHost that was then | 590 DCHECK(output_surface_request_pending_); |
| 591 // hidden (and hidden means we don't have a native surface). | 591 |
| 592 // Also make sure we only handle this once. | 592 // We might have been made invisible now. |
| 593 if (!output_surface_request_pending_ || !host_->visible()) | 593 if (!host_->visible()) |
| 594 return; | 594 return; |
| 595 | 595 |
| 596 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 596 #if defined(ENABLE_VULKAN) |
| 597 scoped_refptr<cc::VulkanInProcessContextProvider> vulkan_context_provider = | 597 CreateVulkanOutputSurface() |
| 598 SharedVulkanContextProviderAndroid(); | 598 if (display_) |
| 599 return; | |
| 600 #endif | |
| 601 | |
| 602 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); | |
| 603 | |
| 604 ui::ContextProviderFactory::GetInstance()->CreateContextProviders( | |
| 605 window_, GetCompositorContextSharedMemoryLimits(), | |
| 606 GetCompositorContextAttributes(has_transparent_background_), | |
| 607 false /*support_locking*/, false /*automatic_flushes*/, | |
| 608 base::Bind(&CompositorImpl::CreateCompositorOutputSurface, | |
| 609 weak_factory_.GetWeakPtr())); | |
| 610 } | |
| 611 | |
| 612 #if defined(ENABLE_VULKAN) | |
| 613 bool CompositorImpl::CreateVulkanOutputSurface() { | |
|
no sievers
2016/08/02 22:47:36
s/bool/void
Khushal
2016/08/02 23:31:53
Done.
| |
| 614 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 615 switches::kEnableVulkan)) | |
|
no sievers
2016/08/02 22:47:36
!kEnableVulkan
Khushal
2016/08/02 23:31:53
Umm, sorry. Done.
| |
| 616 return; | |
| 617 | |
| 599 std::unique_ptr<cc::OutputSurface> display_output_surface; | 618 std::unique_ptr<cc::OutputSurface> display_output_surface; |
| 600 #if defined(ENABLE_VULKAN) | 619 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = |
| 601 std::unique_ptr<VulkanOutputSurface> vulkan_surface; | 620 ui::ContextProviderFactory::GetInstance() |
| 621 ->GetSharedVulkanContextProvider(); | |
| 602 if (vulkan_context_provider) { | 622 if (vulkan_context_provider) { |
| 603 vulkan_surface.reset( | 623 std::unique_ptr<VulkanOutputSurface> vulkan_surface( |
| 604 new VulkanOutputSurface(std::move(vulkan_context_provider))); | 624 new VulkanOutputSurface(std::move(vulkan_context_provider))); |
| 605 if (!vulkan_surface->Initialize(window_)) { | 625 if (!vulkan_surface->Initialize(window_)) { |
| 606 vulkan_surface->Destroy(); | 626 vulkan_surface->Destroy(); |
| 607 vulkan_surface.reset(); | 627 vulkan_surface.reset(); |
| 608 } else { | 628 } else { |
| 609 display_output_surface = std::move(vulkan_surface); | 629 display_output_surface = std::move(vulkan_surface); |
| 610 } | 630 } |
| 611 } | 631 } |
| 632 | |
| 633 if (!display_output_surface) | |
| 634 return; | |
| 635 | |
| 636 InitializeDisplay(std::move(display_output_surface), | |
| 637 std::move(vulkan_context_provider), nullptr); | |
| 638 } | |
| 612 #endif | 639 #endif |
| 613 | 640 |
| 614 if (!display_output_surface) { | 641 void CompositorImpl::CreateCompositorOutputSurface( |
| 615 // This is used for the browser compositor (offscreen) and for the display | 642 const ui::ContextProviderFactory::ContextProviders& context_providers) { |
| 616 // compositor (onscreen), so ask for capabilities needed by either one. | 643 DCHECK(output_surface_request_pending_); |
| 617 // The default framebuffer for an offscreen context is not used, so it does | |
| 618 // not need alpha, stencil, depth, antialiasing. The display compositor does | |
| 619 // not use these things either, except for alpha when it has a transparent | |
| 620 // background. | |
| 621 gpu::gles2::ContextCreationAttribHelper attributes; | |
| 622 attributes.alpha_size = -1; | |
| 623 attributes.stencil_size = 0; | |
| 624 attributes.depth_size = 0; | |
| 625 attributes.samples = 0; | |
| 626 attributes.sample_buffers = 0; | |
| 627 attributes.bind_generates_resource = false; | |
| 628 | 644 |
| 629 if (has_transparent_background_) { | 645 // We might be invisible now. |
| 630 attributes.alpha_size = 8; | 646 if (!host_->visible()) |
|
no sievers
2016/08/02 22:47:36
If we became invisible then we also shouldn't have
Khushal
2016/08/02 23:31:53
Done. Added the worker context provider check at t
| |
| 631 } else if (base::SysInfo::IsLowEndDevice()) { | 647 return; |
| 632 // In this case we prefer to use RGB565 format instead of RGBA8888 if | |
| 633 // possible. | |
| 634 // TODO(danakj): GpuCommandBufferStub constructor checks for alpha == 0 in | |
| 635 // order to enable 565, but it should avoid using 565 when -1s are | |
| 636 // specified | |
| 637 // (IOW check that a <= 0 && rgb > 0 && rgb <= 565) then alpha should be | |
| 638 // -1. | |
| 639 attributes.alpha_size = 0; | |
| 640 attributes.red_size = 5; | |
| 641 attributes.green_size = 6; | |
| 642 attributes.blue_size = 5; | |
| 643 } | |
| 644 | 648 |
| 645 pending_swapbuffers_ = 0; | 649 DCHECK(window_); |
| 650 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); | |
| 651 // If the context request failed while we still have a valid surface, we need | |
| 652 // to try again. | |
| 653 if (!context_providers.compositor_context_provider) | |
| 654 HandlePendingOutputSurfaceRequest(); | |
| 646 | 655 |
| 647 DCHECK(window_); | 656 pending_swapbuffers_ = 0; |
| 648 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); | 657 scoped_refptr<ContextProviderCommandBuffer> context_provider_command_buffer = |
| 658 static_cast<ContextProviderCommandBuffer*>( | |
| 659 context_providers.compositor_context_provider.get()); | |
| 660 std::unique_ptr<cc::OutputSurface> display_output_surface( | |
| 661 new OutputSurfaceWithoutParent( | |
| 662 context_provider_command_buffer, | |
| 663 base::Bind(&CompositorImpl::PopulateGpuCapabilities, | |
| 664 base::Unretained(this)))); | |
| 665 InitializeDisplay(std::move(display_output_surface), nullptr, | |
| 666 std::move(context_providers.compositor_context_provider)); | |
| 667 } | |
| 649 | 668 |
| 650 BrowserGpuChannelHostFactory* factory = | 669 void CompositorImpl::InitializeDisplay( |
| 651 BrowserGpuChannelHostFactory::instance(); | 670 std::unique_ptr<cc::OutputSurface> display_output_surface, |
| 652 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 671 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, |
| 653 factory->GetGpuChannel()); | 672 scoped_refptr<cc::ContextProvider> context_provider) { |
| 654 // If the channel was already lost, we'll get null back here and need to | 673 DCHECK(output_surface_request_pending_); |
| 655 // try again. | 674 DCHECK(!display_); |
| 656 if (!gpu_channel_host) { | |
| 657 RequestNewOutputSurface(); | |
| 658 return; | |
| 659 } | |
| 660 | 675 |
| 661 GURL url("chrome://gpu/CompositorImpl::CreateOutputSurface"); | 676 cc::SurfaceManager* manager = |
| 662 constexpr bool automatic_flushes = false; | 677 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); |
| 663 constexpr bool support_locking = false; | |
| 664 | |
| 665 constexpr size_t kBytesPerPixel = 4; | |
| 666 const size_t full_screen_texture_size_in_bytes = | |
| 667 gfx::DeviceDisplayInfo().GetDisplayHeight() * | |
| 668 gfx::DeviceDisplayInfo().GetDisplayWidth() * kBytesPerPixel; | |
| 669 | |
| 670 gpu::SharedMemoryLimits limits; | |
| 671 // This limit is meant to hold the contents of the display compositor | |
| 672 // drawing the scene. See discussion here: | |
| 673 // https://codereview.chromium.org/1900993002/diff/90001/content/browser/ren derer_host/compositor_impl_android.cc?context=3&column_width=80&tab_spaces=8 | |
| 674 limits.command_buffer_size = 64 * 1024; | |
| 675 // These limits are meant to hold the uploads for the browser UI without | |
| 676 // any excess space. | |
| 677 limits.start_transfer_buffer_size = 64 * 1024; | |
| 678 limits.min_transfer_buffer_size = 64 * 1024; | |
| 679 limits.max_transfer_buffer_size = full_screen_texture_size_in_bytes; | |
| 680 // Texture uploads may use mapped memory so give a reasonable limit for | |
| 681 // them. | |
| 682 limits.mapped_memory_reclaim_limit = full_screen_texture_size_in_bytes; | |
| 683 | |
| 684 context_provider = new ContextProviderCommandBuffer( | |
| 685 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, | |
| 686 gpu::GpuStreamPriority::NORMAL, surface_handle_, url, automatic_flushes, | |
| 687 support_locking, limits, attributes, nullptr, | |
| 688 command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); | |
| 689 DCHECK(context_provider.get()); | |
| 690 | |
| 691 display_output_surface = base::WrapUnique(new OutputSurfaceWithoutParent( | |
| 692 context_provider, base::Bind(&CompositorImpl::PopulateGpuCapabilities, | |
| 693 base::Unretained(this)))); | |
| 694 } | |
| 695 | |
| 696 cc::SurfaceManager* manager = GetSurfaceManager(); | |
| 697 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); | 678 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); |
| 698 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source( | 679 std::unique_ptr<ExternalBeginFrameSource> begin_frame_source( |
| 699 new ExternalBeginFrameSource(this)); | 680 new ExternalBeginFrameSource(this)); |
| 700 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 681 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 701 begin_frame_source.get(), task_runner, | 682 begin_frame_source.get(), task_runner, |
| 702 display_output_surface->capabilities().max_frames_pending)); | 683 display_output_surface->capabilities().max_frames_pending)); |
| 703 | 684 |
| 704 display_.reset(new cc::Display( | 685 display_.reset(new cc::Display( |
| 705 HostSharedBitmapManager::current(), | 686 HostSharedBitmapManager::current(), |
| 706 BrowserGpuMemoryBufferManager::current(), | 687 BrowserGpuMemoryBufferManager::current(), |
| 707 host_->settings().renderer_settings, std::move(begin_frame_source), | 688 host_->settings().renderer_settings, std::move(begin_frame_source), |
| 708 std::move(display_output_surface), std::move(scheduler), | 689 std::move(display_output_surface), std::move(scheduler), |
| 709 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); | 690 base::MakeUnique<cc::TextureMailboxDeleter>(task_runner))); |
| 710 | 691 |
| 711 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( | 692 std::unique_ptr<cc::SurfaceDisplayOutputSurface> delegated_output_surface( |
| 712 vulkan_context_provider | 693 vulkan_context_provider ? new cc::SurfaceDisplayOutputSurface( |
| 713 ? new cc::SurfaceDisplayOutputSurface( | 694 manager, surface_id_allocator_.get(), |
| 714 manager, surface_id_allocator_.get(), display_.get(), | 695 display_.get(), vulkan_context_provider) |
| 715 static_cast<scoped_refptr<cc::VulkanContextProvider>>( | 696 : new cc::SurfaceDisplayOutputSurface( |
| 716 vulkan_context_provider)) | 697 manager, surface_id_allocator_.get(), |
| 717 : new cc::SurfaceDisplayOutputSurface( | 698 display_.get(), context_provider, nullptr)); |
| 718 manager, surface_id_allocator_.get(), display_.get(), | |
| 719 context_provider, nullptr)); | |
| 720 | 699 |
| 721 display_->Resize(size_); | 700 display_->Resize(size_); |
| 722 host_->SetOutputSurface(std::move(delegated_output_surface)); | 701 host_->SetOutputSurface(std::move(delegated_output_surface)); |
| 723 } | 702 } |
| 724 | 703 |
| 725 void CompositorImpl::PopulateGpuCapabilities( | 704 void CompositorImpl::PopulateGpuCapabilities( |
| 726 gpu::Capabilities gpu_capabilities) { | 705 gpu::Capabilities gpu_capabilities) { |
| 727 gpu_capabilities_ = gpu_capabilities; | 706 gpu_capabilities_ = gpu_capabilities; |
| 728 } | 707 } |
| 729 | 708 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 void CompositorImpl::SetNeedsAnimate() { | 780 void CompositorImpl::SetNeedsAnimate() { |
| 802 needs_animate_ = true; | 781 needs_animate_ = true; |
| 803 if (!host_->visible()) | 782 if (!host_->visible()) |
| 804 return; | 783 return; |
| 805 | 784 |
| 806 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); | 785 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); |
| 807 host_->SetNeedsAnimate(); | 786 host_->SetNeedsAnimate(); |
| 808 } | 787 } |
| 809 | 788 |
| 810 } // namespace content | 789 } // namespace content |
| OLD | NEW |