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 "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/compositor_frame_ack.h" | 10 #include "cc/output/compositor_frame_ack.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 if (resource_collection_.get()) { | 336 if (resource_collection_.get()) { |
337 resource_collection_->SetClient(NULL); | 337 resource_collection_->SetClient(NULL); |
338 | 338 |
339 if (resource_collection_->LoseAllResources()) | 339 if (resource_collection_->LoseAllResources()) |
340 SendReturnedDelegatedResources(last_output_surface_id_); | 340 SendReturnedDelegatedResources(last_output_surface_id_); |
341 | 341 |
342 resource_collection_ = NULL; | 342 resource_collection_ = NULL; |
343 } | 343 } |
344 last_output_surface_id_ = output_surface_id; | 344 last_output_surface_id_ = output_surface_id; |
345 } | 345 } |
| 346 bool modified_layers = false; |
346 if (frame_size.IsEmpty()) { | 347 if (frame_size.IsEmpty()) { |
347 DCHECK(frame_data->resource_list.empty()); | 348 DCHECK(frame_data->resource_list.empty()); |
348 EvictDelegatedFrame(); | 349 EvictDelegatedFrame(); |
| 350 modified_layers = true; |
349 } else { | 351 } else { |
350 if (use_surfaces_) { | 352 if (use_surfaces_) { |
351 if (!surface_factory_) { | 353 if (!surface_factory_) { |
352 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 354 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
353 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 355 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
354 id_allocator_ = factory->CreateSurfaceIdAllocator(); | 356 id_allocator_ = factory->CreateSurfaceIdAllocator(); |
355 surface_factory_ = | 357 surface_factory_ = |
356 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); | 358 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); |
357 } | 359 } |
358 if (surface_id_.is_null() || frame_size != current_surface_size_ || | 360 if (surface_id_.is_null() || frame_size != current_surface_size_ || |
359 frame_size_in_dip != current_frame_size_in_dip_) { | 361 frame_size_in_dip != current_frame_size_in_dip_) { |
360 if (!surface_id_.is_null()) | 362 if (!surface_id_.is_null()) |
361 surface_factory_->Destroy(surface_id_); | 363 surfaces_to_destroy_after_commit_.push_back(surface_id_); |
362 surface_id_ = id_allocator_->GenerateId(); | 364 surface_id_ = id_allocator_->GenerateId(); |
363 surface_factory_->Create(surface_id_, frame_size); | 365 surface_factory_->Create(surface_id_, frame_size); |
364 client_->GetLayer()->SetShowSurface(surface_id_, frame_size_in_dip); | 366 client_->GetLayer()->SetShowSurface(surface_id_, frame_size_in_dip); |
365 current_surface_size_ = frame_size; | 367 current_surface_size_ = frame_size; |
| 368 modified_layers = true; |
366 } | 369 } |
367 scoped_ptr<cc::CompositorFrame> compositor_frame = | 370 scoped_ptr<cc::CompositorFrame> compositor_frame = |
368 make_scoped_ptr(new cc::CompositorFrame()); | 371 make_scoped_ptr(new cc::CompositorFrame()); |
369 compositor_frame->delegated_frame_data = frame_data.Pass(); | 372 compositor_frame->delegated_frame_data = frame_data.Pass(); |
370 surface_factory_->SubmitFrame(surface_id_, compositor_frame.Pass()); | 373 surface_factory_->SubmitFrame(surface_id_, compositor_frame.Pass()); |
371 } else { | 374 } else { |
372 if (!resource_collection_) { | 375 if (!resource_collection_) { |
373 resource_collection_ = new cc::DelegatedFrameResourceCollection; | 376 resource_collection_ = new cc::DelegatedFrameResourceCollection; |
374 resource_collection_->SetClient(this); | 377 resource_collection_->SetClient(this); |
375 } | 378 } |
376 // If the physical frame size changes, we need a new |frame_provider_|. If | 379 // If the physical frame size changes, we need a new |frame_provider_|. If |
377 // the physical frame size is the same, but the size in DIP changed, we | 380 // the physical frame size is the same, but the size in DIP changed, we |
378 // need to adjust the scale at which the frames will be drawn, and we do | 381 // need to adjust the scale at which the frames will be drawn, and we do |
379 // this by making a new |frame_provider_| also to ensure the scale change | 382 // this by making a new |frame_provider_| also to ensure the scale change |
380 // is presented in sync with the new frame content. | 383 // is presented in sync with the new frame content. |
381 if (!frame_provider_.get() || | 384 if (!frame_provider_.get() || |
382 frame_size != frame_provider_->frame_size() || | 385 frame_size != frame_provider_->frame_size() || |
383 frame_size_in_dip != current_frame_size_in_dip_) { | 386 frame_size_in_dip != current_frame_size_in_dip_) { |
384 frame_provider_ = new cc::DelegatedFrameProvider( | 387 frame_provider_ = new cc::DelegatedFrameProvider( |
385 resource_collection_.get(), frame_data.Pass()); | 388 resource_collection_.get(), frame_data.Pass()); |
386 client_->GetLayer()->SetShowDelegatedContent(frame_provider_.get(), | 389 client_->GetLayer()->SetShowDelegatedContent(frame_provider_.get(), |
387 frame_size_in_dip); | 390 frame_size_in_dip); |
388 } else { | 391 } else { |
389 frame_provider_->SetFrameData(frame_data.Pass()); | 392 frame_provider_->SetFrameData(frame_data.Pass()); |
390 } | 393 } |
| 394 modified_layers = true; |
391 } | 395 } |
392 } | 396 } |
393 released_front_lock_ = NULL; | 397 released_front_lock_ = NULL; |
394 current_frame_size_in_dip_ = frame_size_in_dip; | 398 current_frame_size_in_dip_ = frame_size_in_dip; |
395 CheckResizeLock(); | 399 CheckResizeLock(); |
396 | 400 |
397 client_->SchedulePaintInRect(damage_rect_in_dip); | 401 if (modified_layers) { |
| 402 // TODO(jbauman): Need to always tell the window observer about the |
| 403 // damage. |
| 404 client_->SchedulePaintInRect(damage_rect_in_dip); |
| 405 } |
398 | 406 |
399 pending_delegated_ack_count_++; | 407 pending_delegated_ack_count_++; |
400 | 408 |
401 ui::Compositor* compositor = client_->GetCompositor(); | 409 ui::Compositor* compositor = client_->GetCompositor(); |
402 if (!compositor) { | 410 if (!compositor || !modified_layers) { |
403 SendDelegatedFrameAck(output_surface_id); | 411 SendDelegatedFrameAck(output_surface_id); |
404 } else { | 412 } else { |
405 std::vector<ui::LatencyInfo>::const_iterator it; | 413 std::vector<ui::LatencyInfo>::const_iterator it; |
406 for (it = latency_info.begin(); it != latency_info.end(); ++it) | 414 for (it = latency_info.begin(); it != latency_info.end(); ++it) |
407 compositor->SetLatencyInfo(*it); | 415 compositor->SetLatencyInfo(*it); |
408 // If we've previously skipped any latency infos add them. | 416 // If we've previously skipped any latency infos add them. |
409 for (it = skipped_latency_info_list_.begin(); | 417 for (it = skipped_latency_info_list_.begin(); |
410 it != skipped_latency_info_list_.end(); | 418 it != skipped_latency_info_list_.end(); |
411 ++it) | 419 ++it) |
412 compositor->SetLatencyInfo(*it); | 420 compositor->SetLatencyInfo(*it); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 resources.end(), | 480 resources.end(), |
473 std::back_inserter(surface_returned_resources_)); | 481 std::back_inserter(surface_returned_resources_)); |
474 if (!pending_delegated_ack_count_) | 482 if (!pending_delegated_ack_count_) |
475 SendReturnedDelegatedResources(last_output_surface_id_); | 483 SendReturnedDelegatedResources(last_output_surface_id_); |
476 } | 484 } |
477 | 485 |
478 void DelegatedFrameHost::EvictDelegatedFrame() { | 486 void DelegatedFrameHost::EvictDelegatedFrame() { |
479 client_->GetLayer()->SetShowPaintedContent(); | 487 client_->GetLayer()->SetShowPaintedContent(); |
480 frame_provider_ = NULL; | 488 frame_provider_ = NULL; |
481 if (!surface_id_.is_null()) { | 489 if (!surface_id_.is_null()) { |
482 surface_factory_->Destroy(surface_id_); | 490 surfaces_to_destroy_after_commit_.push_back(surface_id_); |
483 surface_id_ = cc::SurfaceId(); | 491 surface_id_ = cc::SurfaceId(); |
484 } | 492 } |
485 delegated_frame_evictor_->DiscardedFrame(); | 493 delegated_frame_evictor_->DiscardedFrame(); |
486 } | 494 } |
487 | 495 |
488 // static | 496 // static |
489 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( | 497 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( |
490 const gfx::Size& dst_size_in_pixel, | 498 const gfx::Size& dst_size_in_pixel, |
491 const SkColorType color_type, | 499 const SkColorType color_type, |
492 const base::Callback<void(bool, const SkBitmap&)>& callback, | 500 const base::Callback<void(bool, const SkBitmap&)>& callback, |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 texture_mailbox.sync_point(), | 768 texture_mailbox.sync_point(), |
761 video_frame.get(), | 769 video_frame.get(), |
762 finished_callback); | 770 finished_callback); |
763 } | 771 } |
764 | 772 |
765 //////////////////////////////////////////////////////////////////////////////// | 773 //////////////////////////////////////////////////////////////////////////////// |
766 // DelegatedFrameHost, ui::CompositorObserver implementation: | 774 // DelegatedFrameHost, ui::CompositorObserver implementation: |
767 | 775 |
768 void DelegatedFrameHost::OnCompositingDidCommit( | 776 void DelegatedFrameHost::OnCompositingDidCommit( |
769 ui::Compositor* compositor) { | 777 ui::Compositor* compositor) { |
| 778 std::copy(surfaces_to_destroy_after_commit_.begin(), |
| 779 surfaces_to_destroy_after_commit_.end(), |
| 780 std::back_inserter(surfaces_to_destroy_after_swap_)); |
| 781 surfaces_to_destroy_after_commit_.clear(); |
770 RenderWidgetHostImpl* host = client_->GetHost(); | 782 RenderWidgetHostImpl* host = client_->GetHost(); |
771 if (can_lock_compositor_ == NO_PENDING_COMMIT) { | 783 if (can_lock_compositor_ == NO_PENDING_COMMIT) { |
772 can_lock_compositor_ = YES_CAN_LOCK; | 784 can_lock_compositor_ = YES_CAN_LOCK; |
773 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) | 785 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) |
774 can_lock_compositor_ = YES_DID_LOCK; | 786 can_lock_compositor_ = YES_DID_LOCK; |
775 } | 787 } |
776 RunOnCommitCallbacks(); | 788 RunOnCommitCallbacks(); |
777 if (resize_lock_ && | 789 if (resize_lock_ && |
778 resize_lock_->expected_size() == current_frame_size_in_dip_) { | 790 resize_lock_->expected_size() == current_frame_size_in_dip_) { |
779 resize_lock_.reset(); | 791 resize_lock_.reset(); |
780 host->WasResized(); | 792 host->WasResized(); |
781 // We may have had a resize while we had the lock (e.g. if the lock expired, | 793 // We may have had a resize while we had the lock (e.g. if the lock expired, |
782 // or if the UI still gave us some resizes), so make sure we grab a new lock | 794 // or if the UI still gave us some resizes), so make sure we grab a new lock |
783 // if necessary. | 795 // if necessary. |
784 MaybeCreateResizeLock(); | 796 MaybeCreateResizeLock(); |
785 } | 797 } |
786 } | 798 } |
787 | 799 |
788 void DelegatedFrameHost::OnCompositingStarted( | 800 void DelegatedFrameHost::OnCompositingStarted( |
789 ui::Compositor* compositor, base::TimeTicks start_time) { | 801 ui::Compositor* compositor, base::TimeTicks start_time) { |
790 last_draw_ended_ = start_time; | 802 last_draw_ended_ = start_time; |
791 } | 803 } |
792 | 804 |
793 void DelegatedFrameHost::OnCompositingEnded( | 805 void DelegatedFrameHost::OnCompositingEnded( |
794 ui::Compositor* compositor) { | 806 ui::Compositor* compositor) { |
| 807 for (std::vector<cc::SurfaceId>::iterator it = |
| 808 surfaces_to_destroy_after_swap_.begin(); |
| 809 it != surfaces_to_destroy_after_swap_.end(); |
| 810 ++it) { |
| 811 surface_factory_->Destroy(*it); |
| 812 } |
| 813 surfaces_to_destroy_after_swap_.clear(); |
795 } | 814 } |
796 | 815 |
797 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) { | 816 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) { |
798 } | 817 } |
799 | 818 |
800 void DelegatedFrameHost::OnCompositingLockStateChanged( | 819 void DelegatedFrameHost::OnCompositingLockStateChanged( |
801 ui::Compositor* compositor) { | 820 ui::Compositor* compositor) { |
802 // A compositor lock that is part of a resize lock timed out. We | 821 // A compositor lock that is part of a resize lock timed out. We |
803 // should display a renderer frame. | 822 // should display a renderer frame. |
804 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { | 823 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { |
(...skipping 25 matching lines...) Expand all Loading... |
830 } | 849 } |
831 | 850 |
832 //////////////////////////////////////////////////////////////////////////////// | 851 //////////////////////////////////////////////////////////////////////////////// |
833 // DelegatedFrameHost, private: | 852 // DelegatedFrameHost, private: |
834 | 853 |
835 DelegatedFrameHost::~DelegatedFrameHost() { | 854 DelegatedFrameHost::~DelegatedFrameHost() { |
836 ImageTransportFactory::GetInstance()->RemoveObserver(this); | 855 ImageTransportFactory::GetInstance()->RemoveObserver(this); |
837 | 856 |
838 if (!surface_id_.is_null()) | 857 if (!surface_id_.is_null()) |
839 surface_factory_->Destroy(surface_id_); | 858 surface_factory_->Destroy(surface_id_); |
| 859 for (std::vector<cc::SurfaceId>::iterator it = |
| 860 surfaces_to_destroy_after_commit_.begin(); |
| 861 it != surfaces_to_destroy_after_commit_.end(); |
| 862 ++it) { |
| 863 surface_factory_->Destroy(*it); |
| 864 } |
| 865 surfaces_to_destroy_after_commit_.clear(); |
| 866 for (std::vector<cc::SurfaceId>::iterator it = |
| 867 surfaces_to_destroy_after_swap_.begin(); |
| 868 it != surfaces_to_destroy_after_swap_.end(); |
| 869 ++it) { |
| 870 surface_factory_->Destroy(*it); |
| 871 } |
| 872 surfaces_to_destroy_after_swap_.clear(); |
840 if (resource_collection_.get()) | 873 if (resource_collection_.get()) |
841 resource_collection_->SetClient(NULL); | 874 resource_collection_->SetClient(NULL); |
842 | 875 |
843 DCHECK(!vsync_manager_); | 876 DCHECK(!vsync_manager_); |
844 } | 877 } |
845 | 878 |
846 void DelegatedFrameHost::RunOnCommitCallbacks() { | 879 void DelegatedFrameHost::RunOnCommitCallbacks() { |
847 for (std::vector<base::Closure>::const_iterator | 880 for (std::vector<base::Closure>::const_iterator |
848 it = on_compositing_did_commit_callbacks_.begin(); | 881 it = on_compositing_did_commit_callbacks_.begin(); |
849 it != on_compositing_did_commit_callbacks_.end(); ++it) { | 882 it != on_compositing_did_commit_callbacks_.end(); ++it) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 if (frame_provider_.get()) { | 941 if (frame_provider_.get()) { |
909 new_layer->SetShowDelegatedContent(frame_provider_.get(), | 942 new_layer->SetShowDelegatedContent(frame_provider_.get(), |
910 current_frame_size_in_dip_); | 943 current_frame_size_in_dip_); |
911 } | 944 } |
912 if (!surface_id_.is_null()) { | 945 if (!surface_id_.is_null()) { |
913 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); | 946 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); |
914 } | 947 } |
915 } | 948 } |
916 | 949 |
917 } // namespace content | 950 } // namespace content |
OLD | NEW |