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

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

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

Powered by Google App Engine
This is Rietveld 408576698