Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 2686243002: content/ui[Android]: Remove ContextProviderFactory. (Closed)
Patch Set: more rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
36 #include "cc/output/output_surface.h" 36 #include "cc/output/output_surface.h"
37 #include "cc/output/output_surface_client.h" 37 #include "cc/output/output_surface_client.h"
38 #include "cc/output/output_surface_frame.h" 38 #include "cc/output/output_surface_frame.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/resources/ui_resource_manager.h" 42 #include "cc/resources/ui_resource_manager.h"
43 #include "cc/surfaces/direct_compositor_frame_sink.h" 43 #include "cc/surfaces/direct_compositor_frame_sink.h"
44 #include "cc/surfaces/display.h" 44 #include "cc/surfaces/display.h"
45 #include "cc/surfaces/display_scheduler.h" 45 #include "cc/surfaces/display_scheduler.h"
46 #include "cc/surfaces/frame_sink_id_allocator.h"
46 #include "cc/trees/layer_tree_host.h" 47 #include "cc/trees/layer_tree_host.h"
47 #include "cc/trees/layer_tree_settings.h" 48 #include "cc/trees/layer_tree_settings.h"
48 #include "components/display_compositor/compositor_overlay_candidate_validator_a ndroid.h" 49 #include "components/display_compositor/compositor_overlay_candidate_validator_a ndroid.h"
49 #include "components/display_compositor/gl_helper.h" 50 #include "components/display_compositor/gl_helper.h"
51 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
50 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 52 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
51 #include "content/browser/gpu/compositor_util.h" 53 #include "content/browser/gpu/compositor_util.h"
52 #include "content/browser/renderer_host/context_provider_factory_impl_android.h"
53 #include "content/browser/renderer_host/render_widget_host_impl.h" 54 #include "content/browser/renderer_host/render_widget_host_impl.h"
54 #include "content/common/host_shared_bitmap_manager.h" 55 #include "content/common/host_shared_bitmap_manager.h"
55 #include "content/public/browser/android/compositor.h" 56 #include "content/public/browser/android/compositor.h"
56 #include "content/public/browser/android/compositor_client.h" 57 #include "content/public/browser/android/compositor_client.h"
57 #include "content/public/common/content_switches.h" 58 #include "content/public/common/content_switches.h"
58 #include "gpu/command_buffer/client/context_support.h" 59 #include "gpu/command_buffer/client/context_support.h"
59 #include "gpu/command_buffer/client/gles2_interface.h" 60 #include "gpu/command_buffer/client/gles2_interface.h"
60 #include "gpu/ipc/client/command_buffer_proxy_impl.h" 61 #include "gpu/ipc/client/command_buffer_proxy_impl.h"
61 #include "gpu/ipc/client/gpu_channel_host.h" 62 #include "gpu/ipc/client/gpu_channel_host.h"
62 #include "gpu/ipc/common/gpu_surface_tracker.h" 63 #include "gpu/ipc/common/gpu_surface_tracker.h"
63 #include "gpu/vulkan/vulkan_surface.h" 64 #include "gpu/vulkan/vulkan_surface.h"
64 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" 65 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
65 #include "third_party/khronos/GLES2/gl2.h" 66 #include "third_party/khronos/GLES2/gl2.h"
66 #include "third_party/khronos/GLES2/gl2ext.h" 67 #include "third_party/khronos/GLES2/gl2ext.h"
67 #include "third_party/skia/include/core/SkMallocPixelRef.h" 68 #include "third_party/skia/include/core/SkMallocPixelRef.h"
68 #include "ui/android/window_android.h" 69 #include "ui/android/window_android.h"
69 #include "ui/display/display.h" 70 #include "ui/display/display.h"
70 #include "ui/display/screen.h" 71 #include "ui/display/screen.h"
71 #include "ui/gfx/swap_result.h" 72 #include "ui/gfx/swap_result.h"
72 73
73 namespace gpu { 74 namespace gpu {
74 struct GpuProcessHostedCALayerTreeParamsMac; 75 struct GpuProcessHostedCALayerTreeParamsMac;
75 } 76 }
76 77
77 namespace content { 78 namespace content {
78 79
79 namespace { 80 namespace {
80 81
82 // The client_id used here should not conflict with the client_id generated
83 // from RenderWidgetHostImpl.
84 constexpr uint32_t kDefaultClientId = 0u;
85
86 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
87 public:
88 SingleThreadTaskGraphRunner() {
89 Start("CompositorTileWorker1", base::SimpleThread::Options());
90 }
91
92 ~SingleThreadTaskGraphRunner() override { Shutdown(); }
93 };
94
95 struct CompositorDependencies {
96 CompositorDependencies() : frame_sink_id_allocator(kDefaultClientId) {}
97
98 SingleThreadTaskGraphRunner task_graph_runner;
99 cc::SurfaceManager surface_manager;
100 cc::FrameSinkIdAllocator frame_sink_id_allocator;
101
102 #if defined(ENABLE_VULKAN)
103 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider;
104 #endif
105 };
106
107 base::LazyInstance<CompositorDependencies> g_compositor_dependencies =
108 LAZY_INSTANCE_INITIALIZER;
109
81 const unsigned int kMaxDisplaySwapBuffers = 1U; 110 const unsigned int kMaxDisplaySwapBuffers = 1U;
82 111
112 #if defined(ENABLE_VULKAN)
113 scoped_refptr<cc::VulkanContextProvider> GetSharedVulkanContextProvider() {
114 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
115 switches::kEnableVulkan)) {
116 scoped_refptr<cc::VulkanContextProvider> context_provider =
117 g_compositor_dependencies.Get().vulkan_context_provider;
118 if (!*context_provider)
119 *context_provider = cc::VulkanInProcessContextProvider::Create();
120 return *context_provider;
121 }
122 return nullptr;
123 }
124 #endif
125
83 gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits( 126 gpu::SharedMemoryLimits GetCompositorContextSharedMemoryLimits(
84 gfx::NativeWindow window) { 127 gfx::NativeWindow window) {
85 constexpr size_t kBytesPerPixel = 4; 128 constexpr size_t kBytesPerPixel = 4;
86 const gfx::Size size = display::Screen::GetScreen() 129 const gfx::Size size = display::Screen::GetScreen()
87 ->GetDisplayNearestWindow(window) 130 ->GetDisplayNearestWindow(window)
88 .GetSizeInPixel(); 131 .GetSizeInPixel();
89 const size_t full_screen_texture_size_in_bytes = 132 const size_t full_screen_texture_size_in_bytes =
90 size.width() * size.height() * kBytesPerPixel; 133 size.width() * size.height() * kBytesPerPixel;
91 134
92 gpu::SharedMemoryLimits limits; 135 gpu::SharedMemoryLimits limits;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 std::unique_ptr<gpu::VulkanSurface> surface_; 327 std::unique_ptr<gpu::VulkanSurface> surface_;
285 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 328 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
286 base::WeakPtrFactory<VulkanOutputSurface> weak_ptr_factory_; 329 base::WeakPtrFactory<VulkanOutputSurface> weak_ptr_factory_;
287 330
288 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface); 331 DISALLOW_COPY_AND_ASSIGN(VulkanOutputSurface);
289 }; 332 };
290 #endif 333 #endif
291 334
292 static bool g_initialized = false; 335 static bool g_initialized = false;
293 336
294 class SingleThreadTaskGraphRunner : public cc::SingleThreadTaskGraphRunner {
295 public:
296 SingleThreadTaskGraphRunner() {
297 Start("CompositorTileWorker1", base::SimpleThread::Options());
298 }
299
300 ~SingleThreadTaskGraphRunner() override {
301 Shutdown();
302 }
303 };
304
305 base::LazyInstance<SingleThreadTaskGraphRunner> g_task_graph_runner =
306 LAZY_INSTANCE_INITIALIZER;
307
308 } // anonymous namespace 337 } // anonymous namespace
309 338
310 // static 339 // static
311 Compositor* Compositor::Create(CompositorClient* client, 340 Compositor* Compositor::Create(CompositorClient* client,
312 gfx::NativeWindow root_window) { 341 gfx::NativeWindow root_window) {
313 return client ? new CompositorImpl(client, root_window) : NULL; 342 return client ? new CompositorImpl(client, root_window) : NULL;
314 } 343 }
315 344
316 // static 345 // static
317 void Compositor::Initialize() { 346 void Compositor::Initialize() {
318 DCHECK(!CompositorImpl::IsInitialized()); 347 DCHECK(!CompositorImpl::IsInitialized());
319 g_initialized = true; 348 g_initialized = true;
320 } 349 }
321 350
322 // static 351 // static
352 cc::SurfaceManager* CompositorImpl::GetSurfaceManager() {
353 return &g_compositor_dependencies.Get().surface_manager;
354 }
355
356 // static
357 cc::FrameSinkId CompositorImpl::AllocateFrameSinkId() {
358 return g_compositor_dependencies.Get()
359 .frame_sink_id_allocator.NextFrameSinkId();
360 }
361
362 // static
323 bool CompositorImpl::IsInitialized() { 363 bool CompositorImpl::IsInitialized() {
324 return g_initialized; 364 return g_initialized;
325 } 365 }
326 366
327 CompositorImpl::CompositorImpl(CompositorClient* client, 367 CompositorImpl::CompositorImpl(CompositorClient* client,
328 gfx::NativeWindow root_window) 368 gfx::NativeWindow root_window)
329 : frame_sink_id_( 369 : frame_sink_id_(AllocateFrameSinkId()),
330 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()),
331 resource_manager_(root_window), 370 resource_manager_(root_window),
332 window_(NULL), 371 window_(NULL),
333 surface_handle_(gpu::kNullSurfaceHandle), 372 surface_handle_(gpu::kNullSurfaceHandle),
334 client_(client), 373 client_(client),
335 root_window_(root_window), 374 root_window_(root_window),
336 needs_animate_(false), 375 needs_animate_(false),
337 pending_frames_(0U), 376 pending_frames_(0U),
338 num_successive_context_creation_failures_(0), 377 num_successive_context_creation_failures_(0),
339 compositor_frame_sink_request_pending_(false), 378 compositor_frame_sink_request_pending_(false),
340 weak_factory_(this) { 379 weak_factory_(this) {
341 ui::ContextProviderFactory::GetInstance() 380 GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
342 ->GetSurfaceManager()
343 ->RegisterFrameSinkId(frame_sink_id_);
344 DCHECK(client); 381 DCHECK(client);
345 DCHECK(root_window); 382 DCHECK(root_window);
346 DCHECK(root_window->GetLayer() == nullptr); 383 DCHECK(root_window->GetLayer() == nullptr);
347 root_window->SetLayer(cc::Layer::Create()); 384 root_window->SetLayer(cc::Layer::Create());
348 readback_layer_tree_ = cc::Layer::Create(); 385 readback_layer_tree_ = cc::Layer::Create();
349 readback_layer_tree_->SetHideLayerAndSubtree(true); 386 readback_layer_tree_->SetHideLayerAndSubtree(true);
350 root_window->GetLayer()->AddChild(readback_layer_tree_); 387 root_window->GetLayer()->AddChild(readback_layer_tree_);
351 root_window->AttachCompositor(this); 388 root_window->AttachCompositor(this);
352 CreateLayerTreeHost(); 389 CreateLayerTreeHost();
353 resource_manager_.Init(host_->GetUIResourceManager()); 390 resource_manager_.Init(host_->GetUIResourceManager());
354 } 391 }
355 392
356 CompositorImpl::~CompositorImpl() { 393 CompositorImpl::~CompositorImpl() {
357 root_window_->DetachCompositor(); 394 root_window_->DetachCompositor();
358 root_window_->SetLayer(nullptr); 395 root_window_->SetLayer(nullptr);
359 // Clean-up any surface references. 396 // Clean-up any surface references.
360 SetSurface(NULL); 397 SetSurface(NULL);
361 ui::ContextProviderFactory::GetInstance() 398 GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
362 ->GetSurfaceManager()
363 ->InvalidateFrameSinkId(frame_sink_id_);
364 } 399 }
365 400
366 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() { 401 ui::UIResourceProvider& CompositorImpl::GetUIResourceProvider() {
367 return *this; 402 return *this;
368 } 403 }
369 404
370 ui::ResourceManager& CompositorImpl::GetResourceManager() { 405 ui::ResourceManager& CompositorImpl::GetResourceManager() {
371 return resource_manager_; 406 return resource_manager_;
372 } 407 }
373 408
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 settings.initial_debug_state.SetRecordRenderingStats( 465 settings.initial_debug_state.SetRecordRenderingStats(
431 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking)); 466 command_line->HasSwitch(cc::switches::kEnableGpuBenchmarking));
432 settings.initial_debug_state.show_fps_counter = 467 settings.initial_debug_state.show_fps_counter =
433 command_line->HasSwitch(cc::switches::kUIShowFPSCounter); 468 command_line->HasSwitch(cc::switches::kUIShowFPSCounter);
434 settings.single_thread_proxy_scheduler = true; 469 settings.single_thread_proxy_scheduler = true;
435 470
436 animation_host_ = cc::AnimationHost::CreateMainInstance(); 471 animation_host_ = cc::AnimationHost::CreateMainInstance();
437 472
438 cc::LayerTreeHost::InitParams params; 473 cc::LayerTreeHost::InitParams params;
439 params.client = this; 474 params.client = this;
440 params.task_graph_runner = g_task_graph_runner.Pointer(); 475 params.task_graph_runner = &g_compositor_dependencies.Get().task_graph_runner;
441 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); 476 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
442 params.settings = &settings; 477 params.settings = &settings;
443 params.mutator_host = animation_host_.get(); 478 params.mutator_host = animation_host_.get();
444 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params); 479 host_ = cc::LayerTreeHost::CreateSingleThreaded(this, &params);
445 DCHECK(!host_->IsVisible()); 480 DCHECK(!host_->IsVisible());
446 host_->SetRootLayer(root_window_->GetLayer()); 481 host_->SetRootLayer(root_window_->GetLayer());
447 host_->SetFrameSinkId(frame_sink_id_); 482 host_->SetFrameSinkId(frame_sink_id_);
448 host_->SetViewportSize(size_); 483 host_->SetViewportSize(size_);
449 SetHasTransparentBackground(false); 484 SetHasTransparentBackground(false);
450 host_->SetDeviceScaleFactor(1); 485 host_->SetDeviceScaleFactor(1);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 // We might have been made invisible now. 587 // We might have been made invisible now.
553 if (!host_->IsVisible()) 588 if (!host_->IsVisible())
554 return; 589 return;
555 590
556 #if defined(ENABLE_VULKAN) 591 #if defined(ENABLE_VULKAN)
557 CreateVulkanOutputSurface() 592 CreateVulkanOutputSurface()
558 if (display_) 593 if (display_)
559 return; 594 return;
560 #endif 595 #endif
561 596
597 #if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || \
598 defined(SYZYASAN) || defined(CYGPROFILE_INSTRUMENTATION)
599 const int64_t kGpuChannelTimeoutInSeconds = 40;
600 #else
601 // The GPU watchdog timeout is 15 seconds (1.5x the kGpuTimeout value due to
602 // logic in GpuWatchdogThread). Make this slightly longer to give the GPU a
603 // chance to crash itself before crashing the browser.
604 const int64_t kGpuChannelTimeoutInSeconds = 20;
605 #endif
606
607 // Start the timer first, if the result comes synchronously, we want it to
608 // stop in the callback.
609 establish_gpu_channel_timeout_.Start(
610 FROM_HERE, base::TimeDelta::FromSeconds(kGpuChannelTimeoutInSeconds),
611 this, &CompositorImpl::OnGpuChannelTimeout);
612
562 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle); 613 DCHECK(surface_handle_ != gpu::kNullSurfaceHandle);
563 ContextProviderFactoryImpl::GetInstance()->RequestGpuChannelHost(base::Bind( 614 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(base::Bind(
564 &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr())); 615 &CompositorImpl::OnGpuChannelEstablished, weak_factory_.GetWeakPtr()));
565 } 616 }
566 617
618 void CompositorImpl::OnGpuChannelTimeout() {
619 LOG(FATAL) << "Timed out waiting for GPU channel.";
620 }
621
567 #if defined(ENABLE_VULKAN) 622 #if defined(ENABLE_VULKAN)
568 void CompositorImpl::CreateVulkanOutputSurface() { 623 void CompositorImpl::CreateVulkanOutputSurface() {
569 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 624 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
570 switches::kEnableVulkan)) 625 switches::kEnableVulkan))
571 return; 626 return;
572 627
573 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider = 628 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider =
574 ui::ContextProviderFactory::GetInstance() 629 GetSharedVulkanContextProvider();
575 ->GetSharedVulkanContextProvider();
576 if (!vulkan_context_provider) 630 if (!vulkan_context_provider)
577 return; 631 return;
578 632
579 auto vulkan_surface = base::MakeUnique<VulkanOutputSurface>( 633 auto vulkan_surface = base::MakeUnique<VulkanOutputSurface>(
580 vulkan_context_provider, base::ThreadTaskRunnerHandle::Get()); 634 vulkan_context_provider, base::ThreadTaskRunnerHandle::Get());
581 if (!vulkan_surface->Initialize(window_)) 635 if (!vulkan_surface->Initialize(window_))
582 return; 636 return;
583 637
584 InitializeDisplay(std::move(vulkan_surface), 638 InitializeDisplay(std::move(vulkan_surface),
585 std::move(vulkan_context_provider), nullptr); 639 std::move(vulkan_context_provider), nullptr);
586 } 640 }
587 #endif 641 #endif
588 642
589 void CompositorImpl::OnGpuChannelEstablished( 643 void CompositorImpl::OnGpuChannelEstablished(
590 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, 644 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
591 ui::ContextProviderFactory::GpuChannelHostResult result) { 645 establish_gpu_channel_timeout_.Stop();
646
592 // We might end up queing multiple GpuChannel requests for the same 647 // We might end up queing multiple GpuChannel requests for the same
593 // CompositorFrameSink request as the visibility of the compositor changes, so 648 // CompositorFrameSink request as the visibility of the compositor changes, so
594 // the CompositorFrameSink request could have been handled already. 649 // the CompositorFrameSink request could have been handled already.
595 if (!compositor_frame_sink_request_pending_) 650 if (!compositor_frame_sink_request_pending_)
596 return; 651 return;
597 652
598 switch (result) { 653 if (!gpu_channel_host) {
599 // Don't retry if we are shutting down. 654 HandlePendingCompositorFrameSinkRequest();
600 case ui::ContextProviderFactory::GpuChannelHostResult:: 655 return;
601 FAILURE_FACTORY_SHUTDOWN: 656 }
602 break;
603 case ui::ContextProviderFactory::GpuChannelHostResult::
604 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED:
605 HandlePendingCompositorFrameSinkRequest();
606 break;
607 case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS:
608 // We don't need the context anymore if we are invisible.
609 if (!host_->IsVisible())
610 return;
611 657
612 DCHECK(window_); 658 // We don't need the context anymore if we are invisible.
613 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle); 659 if (!host_->IsVisible())
614 scoped_refptr<cc::ContextProvider> context_provider = 660 return;
615 ContextProviderFactoryImpl::GetInstance()
616 ->CreateDisplayContextProvider(
617 surface_handle_,
618 GetCompositorContextSharedMemoryLimits(root_window_),
619 GetCompositorContextAttributes(has_transparent_background_),
620 false /*support_locking*/, false /*automatic_flushes*/,
621 std::move(gpu_channel_host));
622 if (!context_provider->BindToCurrentThread()) {
623 LOG(ERROR) << "Failed to init ContextProvider for compositor.";
624 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2)
625 << "Too many context creation failures. Giving up... ";
626 HandlePendingCompositorFrameSinkRequest();
627 break;
628 }
629 661
630 scoped_refptr<ui::ContextProviderCommandBuffer> 662 DCHECK(window_);
631 context_provider_command_buffer = 663 DCHECK_NE(surface_handle_, gpu::kNullSurfaceHandle);
632 static_cast<ui::ContextProviderCommandBuffer*>( 664 constexpr bool support_locking = false;
633 context_provider.get()); 665 constexpr bool automatic_flushes = false;
634 auto display_output_surface = base::MakeUnique<AndroidOutputSurface>( 666 ui::ContextProviderCommandBuffer* shared_context = nullptr;
635 std::move(context_provider_command_buffer)); 667 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider =
636 InitializeDisplay(std::move(display_output_surface), nullptr, 668 new ui::ContextProviderCommandBuffer(
637 std::move(context_provider)); 669 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT,
638 break; 670 gpu::GpuStreamPriority::NORMAL, surface_handle_,
671 GURL(std::string("chrome://gpu/CompositorImpl::") +
672 std::string("CompositorContextProvider")),
673 automatic_flushes, support_locking,
674 GetCompositorContextSharedMemoryLimits(root_window_),
675 GetCompositorContextAttributes(has_transparent_background_),
676 shared_context,
677 ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
678 if (!context_provider->BindToCurrentThread()) {
679 LOG(ERROR) << "Failed to init ContextProvider for compositor.";
680 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2)
681 << "Too many context creation failures. Giving up... ";
682 HandlePendingCompositorFrameSinkRequest();
639 } 683 }
684
685 auto display_output_surface =
686 base::MakeUnique<AndroidOutputSurface>(context_provider);
687 InitializeDisplay(std::move(display_output_surface), nullptr,
688 std::move(context_provider));
640 } 689 }
641 690
642 void CompositorImpl::InitializeDisplay( 691 void CompositorImpl::InitializeDisplay(
643 std::unique_ptr<cc::OutputSurface> display_output_surface, 692 std::unique_ptr<cc::OutputSurface> display_output_surface,
644 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, 693 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider,
645 scoped_refptr<cc::ContextProvider> context_provider) { 694 scoped_refptr<cc::ContextProvider> context_provider) {
646 DCHECK(compositor_frame_sink_request_pending_); 695 DCHECK(compositor_frame_sink_request_pending_);
647 696
648 pending_frames_ = 0; 697 pending_frames_ = 0;
649 num_successive_context_creation_failures_ = 0; 698 num_successive_context_creation_failures_ = 0;
650 699
651 if (context_provider) { 700 if (context_provider) {
652 gpu_capabilities_ = context_provider->ContextCapabilities(); 701 gpu_capabilities_ = context_provider->ContextCapabilities();
653 } else { 702 } else {
654 // TODO(danakj): Populate gpu_capabilities_ for VulkanContextProvider. 703 // TODO(danakj): Populate gpu_capabilities_ for VulkanContextProvider.
655 } 704 }
656 705
657 cc::SurfaceManager* manager = 706 cc::SurfaceManager* manager = GetSurfaceManager();
658 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
659 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get(); 707 auto* task_runner = base::ThreadTaskRunnerHandle::Get().get();
660 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( 708 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler(
661 task_runner, display_output_surface->capabilities().max_frames_pending)); 709 task_runner, display_output_surface->capabilities().max_frames_pending));
662 710
663 display_.reset(new cc::Display( 711 display_.reset(new cc::Display(
664 HostSharedBitmapManager::current(), 712 HostSharedBitmapManager::current(),
665 BrowserGpuMemoryBufferManager::current(), 713 BrowserGpuMemoryBufferManager::current(),
666 host_->GetSettings().renderer_settings, frame_sink_id_, 714 host_->GetSettings().renderer_settings, frame_sink_id_,
667 root_window_->GetBeginFrameSource(), std::move(display_output_surface), 715 root_window_->GetBeginFrameSource(), std::move(display_output_surface),
668 std::move(scheduler), 716 std::move(scheduler),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate"); 785 TRACE_EVENT0("compositor", "Compositor::SetNeedsAnimate");
738 host_->SetNeedsAnimate(); 786 host_->SetNeedsAnimate();
739 } 787 }
740 788
741 cc::FrameSinkId CompositorImpl::GetFrameSinkId() { 789 cc::FrameSinkId CompositorImpl::GetFrameSinkId() {
742 return frame_sink_id_; 790 return frame_sink_id_;
743 } 791 }
744 792
745 void CompositorImpl::AddChildFrameSink(const cc::FrameSinkId& frame_sink_id) { 793 void CompositorImpl::AddChildFrameSink(const cc::FrameSinkId& frame_sink_id) {
746 if (has_compositor_frame_sink_) { 794 if (has_compositor_frame_sink_) {
747 ui::ContextProviderFactory::GetInstance() 795 GetSurfaceManager()->RegisterFrameSinkHierarchy(frame_sink_id_,
748 ->GetSurfaceManager() 796 frame_sink_id);
749 ->RegisterFrameSinkHierarchy(frame_sink_id_, frame_sink_id);
750 } else { 797 } else {
751 pending_child_frame_sink_ids_.insert(frame_sink_id); 798 pending_child_frame_sink_ids_.insert(frame_sink_id);
752 } 799 }
753 } 800 }
754 801
755 void CompositorImpl::RemoveChildFrameSink( 802 void CompositorImpl::RemoveChildFrameSink(
756 const cc::FrameSinkId& frame_sink_id) { 803 const cc::FrameSinkId& frame_sink_id) {
757 auto it = pending_child_frame_sink_ids_.find(frame_sink_id); 804 auto it = pending_child_frame_sink_ids_.find(frame_sink_id);
758 if (it != pending_child_frame_sink_ids_.end()) { 805 if (it != pending_child_frame_sink_ids_.end()) {
759 pending_child_frame_sink_ids_.erase(it); 806 pending_child_frame_sink_ids_.erase(it);
760 return; 807 return;
761 } 808 }
762 ui::ContextProviderFactory::GetInstance() 809 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_,
763 ->GetSurfaceManager() 810 frame_sink_id);
764 ->UnregisterFrameSinkHierarchy(frame_sink_id_, frame_sink_id);
765 } 811 }
766 812
767 bool CompositorImpl::HavePendingReadbacks() { 813 bool CompositorImpl::HavePendingReadbacks() {
768 return !readback_layer_tree_->children().empty(); 814 return !readback_layer_tree_->children().empty();
769 } 815 }
770 816
771 } // namespace content 817 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698