| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compositor/gpu_process_transport_factory.h" | 5 #include "content/browser/compositor/gpu_process_transport_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 ::RemoveProp(compositor->widget(), kForceSoftwareCompositor)) | 275 ::RemoveProp(compositor->widget(), kForceSoftwareCompositor)) |
| 276 return false; | 276 return false; |
| 277 #endif | 277 #endif |
| 278 | 278 |
| 279 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor(); | 279 return GpuDataManagerImpl::GetInstance()->CanUseGpuBrowserCompositor(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void GpuProcessTransportFactory::CreateOutputSurface( | 282 void GpuProcessTransportFactory::CreateOutputSurface( |
| 283 base::WeakPtr<ui::Compositor> compositor) { | 283 base::WeakPtr<ui::Compositor> compositor) { |
| 284 DCHECK(!!compositor); | 284 DCHECK(!!compositor); |
| 285 PerCompositorData* data = per_compositor_data_[compositor.get()]; | 285 PerCompositorData* data = per_compositor_data_[compositor.get()].get(); |
| 286 if (!data) { | 286 if (!data) { |
| 287 data = CreatePerCompositorData(compositor.get()); | 287 data = CreatePerCompositorData(compositor.get()); |
| 288 } else { | 288 } else { |
| 289 // TODO(danakj): We can destroy the |data->display| here when the compositor | 289 // TODO(danakj): We can destroy the |data->display| here when the compositor |
| 290 // destroys its OutputSurface before calling back here. | 290 // destroys its OutputSurface before calling back here. |
| 291 data->display_output_surface = nullptr; | 291 data->display_output_surface = nullptr; |
| 292 data->begin_frame_source = nullptr; | 292 data->begin_frame_source = nullptr; |
| 293 } | 293 } |
| 294 | 294 |
| 295 #if defined(OS_WIN) | 295 #if defined(OS_WIN) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 319 scoped_refptr<gpu::GpuChannelHost> established_channel_host) { | 319 scoped_refptr<gpu::GpuChannelHost> established_channel_host) { |
| 320 if (!compositor) | 320 if (!compositor) |
| 321 return; | 321 return; |
| 322 | 322 |
| 323 // The widget might have been released in the meantime. | 323 // The widget might have been released in the meantime. |
| 324 PerCompositorDataMap::iterator it = | 324 PerCompositorDataMap::iterator it = |
| 325 per_compositor_data_.find(compositor.get()); | 325 per_compositor_data_.find(compositor.get()); |
| 326 if (it == per_compositor_data_.end()) | 326 if (it == per_compositor_data_.end()) |
| 327 return; | 327 return; |
| 328 | 328 |
| 329 PerCompositorData* data = it->second; | 329 PerCompositorData* data = it->second.get(); |
| 330 DCHECK(data); | 330 DCHECK(data); |
| 331 | 331 |
| 332 if (num_attempts > kNumRetriesBeforeSoftwareFallback) { | 332 if (num_attempts > kNumRetriesBeforeSoftwareFallback) { |
| 333 bool fatal = IsUsingMus(); | 333 bool fatal = IsUsingMus(); |
| 334 #if defined(OS_CHROMEOS) | 334 #if defined(OS_CHROMEOS) |
| 335 fatal = true; | 335 fatal = true; |
| 336 #endif | 336 #endif |
| 337 LOG_IF(FATAL, fatal) << "Unable to create a UI graphics context, and " | 337 LOG_IF(FATAL, fatal) << "Unable to create a UI graphics context, and " |
| 338 << "cannot use software compositing on ChromeOS."; | 338 << "cannot use software compositing on ChromeOS."; |
| 339 create_gpu_output_surface = false; | 339 create_gpu_output_surface = false; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 shared_worker_context_provider_)); | 566 shared_worker_context_provider_)); |
| 567 data->display->Resize(compositor->size()); | 567 data->display->Resize(compositor->size()); |
| 568 data->display->SetOutputIsSecure(data->output_is_secure); | 568 data->display->SetOutputIsSecure(data->output_is_secure); |
| 569 data->display->SetColorSpace(data->color_space); | 569 data->display->SetColorSpace(data->color_space); |
| 570 compositor->SetOutputSurface(std::move(delegated_output_surface)); | 570 compositor->SetOutputSurface(std::move(delegated_output_surface)); |
| 571 } | 571 } |
| 572 | 572 |
| 573 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( | 573 std::unique_ptr<ui::Reflector> GpuProcessTransportFactory::CreateReflector( |
| 574 ui::Compositor* source_compositor, | 574 ui::Compositor* source_compositor, |
| 575 ui::Layer* target_layer) { | 575 ui::Layer* target_layer) { |
| 576 PerCompositorData* source_data = per_compositor_data_[source_compositor]; | 576 PerCompositorData* source_data = |
| 577 per_compositor_data_[source_compositor].get(); |
| 577 DCHECK(source_data); | 578 DCHECK(source_data); |
| 578 | 579 |
| 579 std::unique_ptr<ReflectorImpl> reflector( | 580 std::unique_ptr<ReflectorImpl> reflector( |
| 580 new ReflectorImpl(source_compositor, target_layer)); | 581 new ReflectorImpl(source_compositor, target_layer)); |
| 581 source_data->reflector = reflector.get(); | 582 source_data->reflector = reflector.get(); |
| 582 if (auto* source_surface = source_data->display_output_surface) | 583 if (auto* source_surface = source_data->display_output_surface) |
| 583 reflector->OnSourceSurfaceReady(source_surface); | 584 reflector->OnSourceSurfaceReady(source_surface); |
| 584 return std::move(reflector); | 585 return std::move(reflector); |
| 585 } | 586 } |
| 586 | 587 |
| 587 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) { | 588 void GpuProcessTransportFactory::RemoveReflector(ui::Reflector* reflector) { |
| 588 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector); | 589 ReflectorImpl* reflector_impl = static_cast<ReflectorImpl*>(reflector); |
| 589 PerCompositorData* data = | 590 PerCompositorData* data = |
| 590 per_compositor_data_[reflector_impl->mirrored_compositor()]; | 591 per_compositor_data_[reflector_impl->mirrored_compositor()].get(); |
| 591 DCHECK(data); | 592 DCHECK(data); |
| 592 data->reflector->Shutdown(); | 593 data->reflector->Shutdown(); |
| 593 data->reflector = nullptr; | 594 data->reflector = nullptr; |
| 594 } | 595 } |
| 595 | 596 |
| 596 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { | 597 void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 597 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 598 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 598 if (it == per_compositor_data_.end()) | 599 if (it == per_compositor_data_.end()) |
| 599 return; | 600 return; |
| 600 PerCompositorData* data = it->second; | 601 PerCompositorData* data = it->second.get(); |
| 601 DCHECK(data); | 602 DCHECK(data); |
| 602 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 603 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 603 if (data->surface_handle) | 604 if (data->surface_handle) |
| 604 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 605 GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
| 605 #endif | 606 #endif |
| 606 delete data; | |
| 607 per_compositor_data_.erase(it); | 607 per_compositor_data_.erase(it); |
| 608 if (per_compositor_data_.empty()) { | 608 if (per_compositor_data_.empty()) { |
| 609 // Destroying the GLHelper may cause some async actions to be cancelled, | 609 // Destroying the GLHelper may cause some async actions to be cancelled, |
| 610 // causing things to request a new GLHelper. Due to crbug.com/176091 the | 610 // causing things to request a new GLHelper. Due to crbug.com/176091 the |
| 611 // GLHelper created in this case would be lost/leaked if we just reset() | 611 // GLHelper created in this case would be lost/leaked if we just reset() |
| 612 // on the |gl_helper_| variable directly. So instead we call reset() on a | 612 // on the |gl_helper_| variable directly. So instead we call reset() on a |
| 613 // local std::unique_ptr. | 613 // local std::unique_ptr. |
| 614 std::unique_ptr<display_compositor::GLHelper> helper = | 614 std::unique_ptr<display_compositor::GLHelper> helper = |
| 615 std::move(gl_helper_); | 615 std::move(gl_helper_); |
| 616 | 616 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 | 656 |
| 657 uint32_t GpuProcessTransportFactory::AllocateSurfaceClientId() { | 657 uint32_t GpuProcessTransportFactory::AllocateSurfaceClientId() { |
| 658 return next_surface_client_id_++; | 658 return next_surface_client_id_++; |
| 659 } | 659 } |
| 660 | 660 |
| 661 void GpuProcessTransportFactory::SetDisplayVisible(ui::Compositor* compositor, | 661 void GpuProcessTransportFactory::SetDisplayVisible(ui::Compositor* compositor, |
| 662 bool visible) { | 662 bool visible) { |
| 663 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 663 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 664 if (it == per_compositor_data_.end()) | 664 if (it == per_compositor_data_.end()) |
| 665 return; | 665 return; |
| 666 PerCompositorData* data = it->second; | 666 PerCompositorData* data = it->second.get(); |
| 667 DCHECK(data); | 667 DCHECK(data); |
| 668 // The compositor will always SetVisible on the Display once it is set up, so | 668 // The compositor will always SetVisible on the Display once it is set up, so |
| 669 // do nothing if |display| is null. | 669 // do nothing if |display| is null. |
| 670 if (data->display) | 670 if (data->display) |
| 671 data->display->SetVisible(visible); | 671 data->display->SetVisible(visible); |
| 672 } | 672 } |
| 673 | 673 |
| 674 void GpuProcessTransportFactory::ResizeDisplay(ui::Compositor* compositor, | 674 void GpuProcessTransportFactory::ResizeDisplay(ui::Compositor* compositor, |
| 675 const gfx::Size& size) { | 675 const gfx::Size& size) { |
| 676 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 676 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 677 if (it == per_compositor_data_.end()) | 677 if (it == per_compositor_data_.end()) |
| 678 return; | 678 return; |
| 679 PerCompositorData* data = it->second; | 679 PerCompositorData* data = it->second.get(); |
| 680 DCHECK(data); | 680 DCHECK(data); |
| 681 if (data->display) | 681 if (data->display) |
| 682 data->display->Resize(size); | 682 data->display->Resize(size); |
| 683 } | 683 } |
| 684 | 684 |
| 685 void GpuProcessTransportFactory::SetDisplayColorSpace( | 685 void GpuProcessTransportFactory::SetDisplayColorSpace( |
| 686 ui::Compositor* compositor, | 686 ui::Compositor* compositor, |
| 687 const gfx::ColorSpace& color_space) { | 687 const gfx::ColorSpace& color_space) { |
| 688 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 688 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 689 if (it == per_compositor_data_.end()) | 689 if (it == per_compositor_data_.end()) |
| 690 return; | 690 return; |
| 691 PerCompositorData* data = it->second; | 691 PerCompositorData* data = it->second.get(); |
| 692 DCHECK(data); | 692 DCHECK(data); |
| 693 data->color_space = color_space; | 693 data->color_space = color_space; |
| 694 if (data->display) | 694 if (data->display) |
| 695 data->display->SetColorSpace(data->color_space); | 695 data->display->SetColorSpace(data->color_space); |
| 696 } | 696 } |
| 697 | 697 |
| 698 void GpuProcessTransportFactory::SetAuthoritativeVSyncInterval( | 698 void GpuProcessTransportFactory::SetAuthoritativeVSyncInterval( |
| 699 ui::Compositor* compositor, | 699 ui::Compositor* compositor, |
| 700 base::TimeDelta interval) { | 700 base::TimeDelta interval) { |
| 701 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 701 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 702 if (it == per_compositor_data_.end()) | 702 if (it == per_compositor_data_.end()) |
| 703 return; | 703 return; |
| 704 PerCompositorData* data = it->second; | 704 PerCompositorData* data = it->second.get(); |
| 705 DCHECK(data); | 705 DCHECK(data); |
| 706 if (data->begin_frame_source) | 706 if (data->begin_frame_source) |
| 707 data->begin_frame_source->SetAuthoritativeVSyncInterval(interval); | 707 data->begin_frame_source->SetAuthoritativeVSyncInterval(interval); |
| 708 } | 708 } |
| 709 | 709 |
| 710 void GpuProcessTransportFactory::SetDisplayVSyncParameters( | 710 void GpuProcessTransportFactory::SetDisplayVSyncParameters( |
| 711 ui::Compositor* compositor, | 711 ui::Compositor* compositor, |
| 712 base::TimeTicks timebase, | 712 base::TimeTicks timebase, |
| 713 base::TimeDelta interval) { | 713 base::TimeDelta interval) { |
| 714 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 714 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 715 if (it == per_compositor_data_.end()) | 715 if (it == per_compositor_data_.end()) |
| 716 return; | 716 return; |
| 717 PerCompositorData* data = it->second; | 717 PerCompositorData* data = it->second.get(); |
| 718 DCHECK(data); | 718 DCHECK(data); |
| 719 if (data->begin_frame_source) | 719 if (data->begin_frame_source) |
| 720 data->begin_frame_source->OnUpdateVSyncParameters(timebase, interval); | 720 data->begin_frame_source->OnUpdateVSyncParameters(timebase, interval); |
| 721 } | 721 } |
| 722 | 722 |
| 723 void GpuProcessTransportFactory::SetOutputIsSecure(ui::Compositor* compositor, | 723 void GpuProcessTransportFactory::SetOutputIsSecure(ui::Compositor* compositor, |
| 724 bool secure) { | 724 bool secure) { |
| 725 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 725 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 726 if (it == per_compositor_data_.end()) | 726 if (it == per_compositor_data_.end()) |
| 727 return; | 727 return; |
| 728 PerCompositorData* data = it->second; | 728 PerCompositorData* data = it->second.get(); |
| 729 DCHECK(data); | 729 DCHECK(data); |
| 730 data->output_is_secure = secure; | 730 data->output_is_secure = secure; |
| 731 if (data->display) | 731 if (data->display) |
| 732 data->display->SetOutputIsSecure(secure); | 732 data->display->SetOutputIsSecure(secure); |
| 733 } | 733 } |
| 734 | 734 |
| 735 void GpuProcessTransportFactory::AddObserver( | 735 void GpuProcessTransportFactory::AddObserver( |
| 736 ui::ContextFactoryObserver* observer) { | 736 ui::ContextFactoryObserver* observer) { |
| 737 observer_list_.AddObserver(observer); | 737 observer_list_.AddObserver(observer); |
| 738 } | 738 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 763 gpu_channel_factory_ = factory; | 763 gpu_channel_factory_ = factory; |
| 764 } | 764 } |
| 765 | 765 |
| 766 #if defined(OS_MACOSX) | 766 #if defined(OS_MACOSX) |
| 767 void GpuProcessTransportFactory::SetCompositorSuspendedForRecycle( | 767 void GpuProcessTransportFactory::SetCompositorSuspendedForRecycle( |
| 768 ui::Compositor* compositor, | 768 ui::Compositor* compositor, |
| 769 bool suspended) { | 769 bool suspended) { |
| 770 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); | 770 PerCompositorDataMap::iterator it = per_compositor_data_.find(compositor); |
| 771 if (it == per_compositor_data_.end()) | 771 if (it == per_compositor_data_.end()) |
| 772 return; | 772 return; |
| 773 PerCompositorData* data = it->second; | 773 PerCompositorData* data = it->second.get(); |
| 774 DCHECK(data); | 774 DCHECK(data); |
| 775 if (data->display_output_surface) | 775 if (data->display_output_surface) |
| 776 data->display_output_surface->SetSurfaceSuspendedForRecycle(suspended); | 776 data->display_output_surface->SetSurfaceSuspendedForRecycle(suspended); |
| 777 } | 777 } |
| 778 #endif | 778 #endif |
| 779 | 779 |
| 780 scoped_refptr<cc::ContextProvider> | 780 scoped_refptr<cc::ContextProvider> |
| 781 GpuProcessTransportFactory::SharedMainThreadContextProvider() { | 781 GpuProcessTransportFactory::SharedMainThreadContextProvider() { |
| 782 if (shared_main_thread_contexts_) | 782 if (shared_main_thread_contexts_) |
| 783 return shared_main_thread_contexts_; | 783 return shared_main_thread_contexts_; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 813 return shared_main_thread_contexts_; | 813 return shared_main_thread_contexts_; |
| 814 } | 814 } |
| 815 | 815 |
| 816 GpuProcessTransportFactory::PerCompositorData* | 816 GpuProcessTransportFactory::PerCompositorData* |
| 817 GpuProcessTransportFactory::CreatePerCompositorData( | 817 GpuProcessTransportFactory::CreatePerCompositorData( |
| 818 ui::Compositor* compositor) { | 818 ui::Compositor* compositor) { |
| 819 DCHECK(!per_compositor_data_[compositor]); | 819 DCHECK(!per_compositor_data_[compositor]); |
| 820 | 820 |
| 821 gfx::AcceleratedWidget widget = compositor->widget(); | 821 gfx::AcceleratedWidget widget = compositor->widget(); |
| 822 | 822 |
| 823 PerCompositorData* data = new PerCompositorData; | 823 auto data = base::MakeUnique<PerCompositorData>(); |
| 824 if (widget == gfx::kNullAcceleratedWidget) { | 824 if (widget == gfx::kNullAcceleratedWidget) { |
| 825 data->surface_handle = gpu::kNullSurfaceHandle; | 825 data->surface_handle = gpu::kNullSurfaceHandle; |
| 826 } else { | 826 } else { |
| 827 #if defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 827 #if defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 828 data->surface_handle = widget; | 828 data->surface_handle = widget; |
| 829 #else | 829 #else |
| 830 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); | 830 GpuSurfaceTracker* tracker = GpuSurfaceTracker::Get(); |
| 831 data->surface_handle = tracker->AddSurfaceForNativeWidget(widget); | 831 data->surface_handle = tracker->AddSurfaceForNativeWidget(widget); |
| 832 #endif | 832 #endif |
| 833 } | 833 } |
| 834 | 834 |
| 835 per_compositor_data_[compositor] = data; | 835 PerCompositorData* return_ptr = data.get(); |
| 836 | 836 per_compositor_data_[compositor] = std::move(data); |
| 837 return data; | 837 return return_ptr; |
| 838 } | 838 } |
| 839 | 839 |
| 840 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() { | 840 void GpuProcessTransportFactory::OnLostMainThreadSharedContextInsideCallback() { |
| 841 base::ThreadTaskRunnerHandle::Get()->PostTask( | 841 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 842 FROM_HERE, | 842 FROM_HERE, |
| 843 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, | 843 base::Bind(&GpuProcessTransportFactory::OnLostMainThreadSharedContext, |
| 844 callback_factory_.GetWeakPtr())); | 844 callback_factory_.GetWeakPtr())); |
| 845 } | 845 } |
| 846 | 846 |
| 847 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() { | 847 void GpuProcessTransportFactory::OnLostMainThreadSharedContext() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 874 shared_vulkan_context_provider_ = | 874 shared_vulkan_context_provider_ = |
| 875 cc::VulkanInProcessContextProvider::Create(); | 875 cc::VulkanInProcessContextProvider::Create(); |
| 876 } | 876 } |
| 877 | 877 |
| 878 shared_vulkan_context_provider_initialized_ = true; | 878 shared_vulkan_context_provider_initialized_ = true; |
| 879 } | 879 } |
| 880 return shared_vulkan_context_provider_; | 880 return shared_vulkan_context_provider_; |
| 881 } | 881 } |
| 882 | 882 |
| 883 } // namespace content | 883 } // namespace content |
| OLD | NEW |