| 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/delegated_frame_host.h" | 5 #include "content/browser/compositor/delegated_frame_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/time/default_tick_clock.h" | 14 #include "base/time/default_tick_clock.h" |
| 15 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
| 16 #include "cc/output/compositor_frame_ack.h" | 16 #include "cc/output/compositor_frame_ack.h" |
| 17 #include "cc/output/copy_output_request.h" | 17 #include "cc/output/copy_output_request.h" |
| 18 #include "cc/resources/single_release_callback.h" | 18 #include "cc/resources/single_release_callback.h" |
| 19 #include "cc/resources/texture_mailbox.h" | 19 #include "cc/resources/texture_mailbox.h" |
| 20 #include "cc/surfaces/surface.h" | 20 #include "cc/surfaces/surface.h" |
| 21 #include "cc/surfaces/surface_factory.h" | 21 #include "cc/surfaces/surface_factory.h" |
| 22 #include "cc/surfaces/surface_hittest.h" | 22 #include "cc/surfaces/surface_hittest.h" |
| 23 #include "cc/surfaces/surface_manager.h" | 23 #include "cc/surfaces/surface_manager.h" |
| 24 #include "content/browser/compositor/resize_lock.h" | 24 #include "content/browser/compositor/resize_lock.h" |
| 25 #include "content/browser/compositor/surface_utils.h" | 25 #include "content/browser/compositor/surface_utils.h" |
| 26 #include "content/browser/gpu/compositor_util.h" | 26 #include "content/browser/gpu/compositor_util.h" |
| 27 #include "content/common/gpu/client/gl_helper.h" | 27 #include "content/common/gpu/client/gl_helper.h" |
| 28 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 28 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 29 #include "content/public/browser/surface_utils.h" |
| 29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 30 #include "media/base/video_frame.h" | 31 #include "media/base/video_frame.h" |
| 31 #include "media/base/video_util.h" | 32 #include "media/base/video_util.h" |
| 32 #include "skia/ext/image_operations.h" | 33 #include "skia/ext/image_operations.h" |
| 33 #include "third_party/skia/include/core/SkCanvas.h" | 34 #include "third_party/skia/include/core/SkCanvas.h" |
| 34 #include "third_party/skia/include/core/SkPaint.h" | 35 #include "third_party/skia/include/core/SkPaint.h" |
| 35 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 36 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
| 36 #include "ui/gfx/geometry/dip_util.h" | 37 #include "ui/gfx/geometry/dip_util.h" |
| 37 | 38 |
| 38 namespace content { | 39 namespace content { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 pending_delegated_ack_count_(0), | 71 pending_delegated_ack_count_(0), |
| 71 skipped_frames_(false), | 72 skipped_frames_(false), |
| 72 background_color_(SK_ColorRED), | 73 background_color_(SK_ColorRED), |
| 73 current_scale_factor_(1.f), | 74 current_scale_factor_(1.f), |
| 74 can_lock_compositor_(YES_CAN_LOCK), | 75 can_lock_compositor_(YES_CAN_LOCK), |
| 75 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), | 76 delegated_frame_evictor_(new DelegatedFrameEvictor(this)), |
| 76 begin_frame_source_(nullptr) { | 77 begin_frame_source_(nullptr) { |
| 77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 78 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 78 factory->AddObserver(this); | 79 factory->AddObserver(this); |
| 79 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); | 80 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator(); |
| 80 factory->GetSurfaceManager()->RegisterSurfaceFactoryClient( | 81 GetSurfaceManager()->RegisterSurfaceFactoryClient( |
| 81 id_allocator_->id_namespace(), this); | 82 id_allocator_->id_namespace(), this); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 85 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 85 delegated_frame_evictor_->SetVisible(true); | 86 delegated_frame_evictor_->SetVisible(true); |
| 86 | 87 |
| 87 if (surface_id_.is_null() && | 88 if (surface_id_.is_null() && |
| 88 !released_front_lock_.get()) { | 89 !released_front_lock_.get()) { |
| 89 if (compositor_) | 90 if (compositor_) |
| 90 released_front_lock_ = compositor_->GetCompositorLock(); | 91 released_front_lock_ = compositor_->GetCompositorLock(); |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } | 443 } |
| 443 bool skip_frame = false; | 444 bool skip_frame = false; |
| 444 pending_delegated_ack_count_++; | 445 pending_delegated_ack_count_++; |
| 445 | 446 |
| 446 background_color_ = frame->metadata.root_background_color; | 447 background_color_ = frame->metadata.root_background_color; |
| 447 | 448 |
| 448 if (frame_size.IsEmpty()) { | 449 if (frame_size.IsEmpty()) { |
| 449 DCHECK(frame_data->resource_list.empty()); | 450 DCHECK(frame_data->resource_list.empty()); |
| 450 EvictDelegatedFrame(); | 451 EvictDelegatedFrame(); |
| 451 } else { | 452 } else { |
| 452 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 453 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 453 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | |
| 454 if (!surface_factory_) { | 454 if (!surface_factory_) { |
| 455 surface_factory_ = | 455 surface_factory_ = |
| 456 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | 456 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
| 457 } | 457 } |
| 458 if (surface_id_.is_null() || frame_size != current_surface_size_ || | 458 if (surface_id_.is_null() || frame_size != current_surface_size_ || |
| 459 frame_size_in_dip != current_frame_size_in_dip_) { | 459 frame_size_in_dip != current_frame_size_in_dip_) { |
| 460 if (!surface_id_.is_null()) | 460 if (!surface_id_.is_null()) |
| 461 surface_factory_->Destroy(surface_id_); | 461 surface_factory_->Destroy(surface_id_); |
| 462 surface_id_ = id_allocator_->GenerateId(); | 462 surface_id_ = id_allocator_->GenerateId(); |
| 463 surface_factory_->Create(surface_id_); | 463 surface_factory_->Create(surface_id_); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 //////////////////////////////////////////////////////////////////////////////// | 808 //////////////////////////////////////////////////////////////////////////////// |
| 809 // DelegatedFrameHost, private: | 809 // DelegatedFrameHost, private: |
| 810 | 810 |
| 811 DelegatedFrameHost::~DelegatedFrameHost() { | 811 DelegatedFrameHost::~DelegatedFrameHost() { |
| 812 DCHECK(!compositor_); | 812 DCHECK(!compositor_); |
| 813 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 813 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 814 factory->RemoveObserver(this); | 814 factory->RemoveObserver(this); |
| 815 | 815 |
| 816 if (!surface_id_.is_null()) | 816 if (!surface_id_.is_null()) |
| 817 surface_factory_->Destroy(surface_id_); | 817 surface_factory_->Destroy(surface_id_); |
| 818 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient( | 818 GetSurfaceManager()->UnregisterSurfaceFactoryClient( |
| 819 id_allocator_->id_namespace()); | 819 id_allocator_->id_namespace()); |
| 820 | 820 |
| 821 DCHECK(!vsync_manager_.get()); | 821 DCHECK(!vsync_manager_.get()); |
| 822 } | 822 } |
| 823 | 823 |
| 824 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { | 824 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { |
| 825 DCHECK(!compositor_); | 825 DCHECK(!compositor_); |
| 826 if (!compositor) | 826 if (!compositor) |
| 827 return; | 827 return; |
| 828 compositor_ = compositor; | 828 compositor_ = compositor; |
| 829 compositor_->AddObserver(this); | 829 compositor_->AddObserver(this); |
| 830 DCHECK(!vsync_manager_.get()); | 830 DCHECK(!vsync_manager_.get()); |
| 831 vsync_manager_ = compositor_->vsync_manager(); | 831 vsync_manager_ = compositor_->vsync_manager(); |
| 832 vsync_manager_->AddObserver(this); | 832 vsync_manager_->AddObserver(this); |
| 833 | 833 |
| 834 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
| 835 uint32_t parent = compositor->surface_id_allocator()->id_namespace(); | 834 uint32_t parent = compositor->surface_id_allocator()->id_namespace(); |
| 836 factory->GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( | 835 GetSurfaceManager()->RegisterSurfaceNamespaceHierarchy( |
| 837 parent, id_allocator_->id_namespace()); | 836 parent, id_allocator_->id_namespace()); |
| 838 } | 837 } |
| 839 | 838 |
| 840 void DelegatedFrameHost::ResetCompositor() { | 839 void DelegatedFrameHost::ResetCompositor() { |
| 841 if (!compositor_) | 840 if (!compositor_) |
| 842 return; | 841 return; |
| 843 if (resize_lock_) { | 842 if (resize_lock_) { |
| 844 resize_lock_.reset(); | 843 resize_lock_.reset(); |
| 845 client_->DelegatedFrameHostResizeLockWasReleased(); | 844 client_->DelegatedFrameHostResizeLockWasReleased(); |
| 846 } | 845 } |
| 847 if (compositor_->HasObserver(this)) | 846 if (compositor_->HasObserver(this)) |
| 848 compositor_->RemoveObserver(this); | 847 compositor_->RemoveObserver(this); |
| 849 if (vsync_manager_.get()) { | 848 if (vsync_manager_.get()) { |
| 850 vsync_manager_->RemoveObserver(this); | 849 vsync_manager_->RemoveObserver(this); |
| 851 vsync_manager_ = NULL; | 850 vsync_manager_ = NULL; |
| 852 } | 851 } |
| 853 | 852 |
| 854 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
| 855 uint32_t parent = compositor_->surface_id_allocator()->id_namespace(); | 853 uint32_t parent = compositor_->surface_id_allocator()->id_namespace(); |
| 856 factory->GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( | 854 GetSurfaceManager()->UnregisterSurfaceNamespaceHierarchy( |
| 857 parent, id_allocator_->id_namespace()); | 855 parent, id_allocator_->id_namespace()); |
| 858 | 856 |
| 859 compositor_ = nullptr; | 857 compositor_ = nullptr; |
| 860 } | 858 } |
| 861 | 859 |
| 862 void DelegatedFrameHost::SetVSyncParameters(const base::TimeTicks& timebase, | 860 void DelegatedFrameHost::SetVSyncParameters(const base::TimeTicks& timebase, |
| 863 const base::TimeDelta& interval) { | 861 const base::TimeDelta& interval) { |
| 864 vsync_timebase_ = timebase; | 862 vsync_timebase_ = timebase; |
| 865 vsync_interval_ = interval; | 863 vsync_interval_ = interval; |
| 866 } | 864 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 896 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 899 new_layer->SetShowSurface( | 897 new_layer->SetShowSurface( |
| 900 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 898 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 901 base::Bind(&RequireCallback, base::Unretained(manager)), | 899 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 902 current_surface_size_, current_scale_factor_, | 900 current_surface_size_, current_scale_factor_, |
| 903 current_frame_size_in_dip_); | 901 current_frame_size_in_dip_); |
| 904 } | 902 } |
| 905 } | 903 } |
| 906 | 904 |
| 907 } // namespace content | 905 } // namespace content |
| OLD | NEW |