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

Side by Side Diff: content/browser/compositor/delegated_frame_host.cc

Issue 432093003: Enqueuing new frames in a Surface should cause Displays to reaggregate it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (resource_collection_.get()) { 325 if (resource_collection_.get()) {
326 resource_collection_->SetClient(NULL); 326 resource_collection_->SetClient(NULL);
327 327
328 if (resource_collection_->LoseAllResources()) 328 if (resource_collection_->LoseAllResources())
329 SendReturnedDelegatedResources(last_output_surface_id_); 329 SendReturnedDelegatedResources(last_output_surface_id_);
330 330
331 resource_collection_ = NULL; 331 resource_collection_ = NULL;
332 } 332 }
333 last_output_surface_id_ = output_surface_id; 333 last_output_surface_id_ = output_surface_id;
334 } 334 }
335 bool modified_layers = false;
335 if (frame_size.IsEmpty()) { 336 if (frame_size.IsEmpty()) {
336 DCHECK(frame_data->resource_list.empty()); 337 DCHECK(frame_data->resource_list.empty());
337 EvictDelegatedFrame(); 338 EvictDelegatedFrame();
339 modified_layers = true;
338 } else { 340 } else {
339 if (use_surfaces_) { 341 if (use_surfaces_) {
340 if (!surface_factory_) { 342 if (!surface_factory_) {
341 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 343 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
342 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 344 cc::SurfaceManager* manager = factory->GetSurfaceManager();
343 id_allocator_ = factory->CreateSurfaceIdAllocator(); 345 id_allocator_ = factory->CreateSurfaceIdAllocator();
344 surface_factory_ = 346 surface_factory_ =
345 make_scoped_ptr(new cc::SurfaceFactory(manager, this)); 347 make_scoped_ptr(new cc::SurfaceFactory(manager, this));
346 } 348 }
347 if (surface_id_.is_null() || frame_size != current_surface_size_ || 349 if (surface_id_.is_null() || frame_size != current_surface_size_ ||
348 frame_size_in_dip != current_frame_size_in_dip_) { 350 frame_size_in_dip != current_frame_size_in_dip_) {
349 if (!surface_id_.is_null()) 351 if (!surface_id_.is_null())
350 surface_factory_->Destroy(surface_id_); 352 surfaces_to_destroy_after_commit_.push_back(surface_id_);
351 surface_id_ = id_allocator_->GenerateId(); 353 surface_id_ = id_allocator_->GenerateId();
352 surface_factory_->Create(surface_id_, frame_size); 354 surface_factory_->Create(surface_id_, frame_size);
353 client_->GetLayer()->SetShowSurface(surface_id_, frame_size_in_dip); 355 client_->GetLayer()->SetShowSurface(surface_id_, frame_size_in_dip);
354 current_surface_size_ = frame_size; 356 current_surface_size_ = frame_size;
357 modified_layers = true;
355 } 358 }
356 scoped_ptr<cc::CompositorFrame> compositor_frame = 359 scoped_ptr<cc::CompositorFrame> compositor_frame =
357 make_scoped_ptr(new cc::CompositorFrame()); 360 make_scoped_ptr(new cc::CompositorFrame());
358 compositor_frame->delegated_frame_data = frame_data.Pass(); 361 compositor_frame->delegated_frame_data = frame_data.Pass();
359 surface_factory_->SubmitFrame(surface_id_, compositor_frame.Pass()); 362 surface_factory_->SubmitFrame(surface_id_, compositor_frame.Pass());
360 } else { 363 } else {
361 if (!resource_collection_) { 364 if (!resource_collection_) {
362 resource_collection_ = new cc::DelegatedFrameResourceCollection; 365 resource_collection_ = new cc::DelegatedFrameResourceCollection;
363 resource_collection_->SetClient(this); 366 resource_collection_->SetClient(this);
364 } 367 }
365 // If the physical frame size changes, we need a new |frame_provider_|. If 368 // If the physical frame size changes, we need a new |frame_provider_|. If
366 // the physical frame size is the same, but the size in DIP changed, we 369 // the physical frame size is the same, but the size in DIP changed, we
367 // need to adjust the scale at which the frames will be drawn, and we do 370 // need to adjust the scale at which the frames will be drawn, and we do
368 // this by making a new |frame_provider_| also to ensure the scale change 371 // this by making a new |frame_provider_| also to ensure the scale change
369 // is presented in sync with the new frame content. 372 // is presented in sync with the new frame content.
370 if (!frame_provider_.get() || 373 if (!frame_provider_.get() ||
371 frame_size != frame_provider_->frame_size() || 374 frame_size != frame_provider_->frame_size() ||
372 frame_size_in_dip != current_frame_size_in_dip_) { 375 frame_size_in_dip != current_frame_size_in_dip_) {
373 frame_provider_ = new cc::DelegatedFrameProvider( 376 frame_provider_ = new cc::DelegatedFrameProvider(
374 resource_collection_.get(), frame_data.Pass()); 377 resource_collection_.get(), frame_data.Pass());
375 client_->GetLayer()->SetShowDelegatedContent(frame_provider_.get(), 378 client_->GetLayer()->SetShowDelegatedContent(frame_provider_.get(),
376 frame_size_in_dip); 379 frame_size_in_dip);
377 } else { 380 } else {
378 frame_provider_->SetFrameData(frame_data.Pass()); 381 frame_provider_->SetFrameData(frame_data.Pass());
379 } 382 }
383 modified_layers = true;
380 } 384 }
381 } 385 }
382 released_front_lock_ = NULL; 386 released_front_lock_ = NULL;
383 current_frame_size_in_dip_ = frame_size_in_dip; 387 current_frame_size_in_dip_ = frame_size_in_dip;
384 CheckResizeLock(); 388 CheckResizeLock();
385 389
386 client_->SchedulePaintInRect(damage_rect_in_dip); 390 if (modified_layers) {
391 // TODO(jbauman): Need to always tell the window observer about the
392 // damage.
393 client_->SchedulePaintInRect(damage_rect_in_dip);
394 }
387 395
388 pending_delegated_ack_count_++; 396 pending_delegated_ack_count_++;
389 397
390 ui::Compositor* compositor = client_->GetCompositor(); 398 ui::Compositor* compositor = client_->GetCompositor();
391 if (!compositor) { 399 if (!compositor || !modified_layers) {
392 SendDelegatedFrameAck(output_surface_id); 400 SendDelegatedFrameAck(output_surface_id);
393 } else { 401 } else {
394 std::vector<ui::LatencyInfo>::const_iterator it; 402 std::vector<ui::LatencyInfo>::const_iterator it;
395 for (it = latency_info.begin(); it != latency_info.end(); ++it) 403 for (it = latency_info.begin(); it != latency_info.end(); ++it)
396 compositor->SetLatencyInfo(*it); 404 compositor->SetLatencyInfo(*it);
397 // If we've previously skipped any latency infos add them. 405 // If we've previously skipped any latency infos add them.
398 for (it = skipped_latency_info_list_.begin(); 406 for (it = skipped_latency_info_list_.begin();
399 it != skipped_latency_info_list_.end(); 407 it != skipped_latency_info_list_.end();
400 ++it) 408 ++it)
401 compositor->SetLatencyInfo(*it); 409 compositor->SetLatencyInfo(*it);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 resources.end(), 469 resources.end(),
462 std::back_inserter(surface_returned_resources_)); 470 std::back_inserter(surface_returned_resources_));
463 if (!pending_delegated_ack_count_) 471 if (!pending_delegated_ack_count_)
464 SendReturnedDelegatedResources(last_output_surface_id_); 472 SendReturnedDelegatedResources(last_output_surface_id_);
465 } 473 }
466 474
467 void DelegatedFrameHost::EvictDelegatedFrame() { 475 void DelegatedFrameHost::EvictDelegatedFrame() {
468 client_->GetLayer()->SetShowPaintedContent(); 476 client_->GetLayer()->SetShowPaintedContent();
469 frame_provider_ = NULL; 477 frame_provider_ = NULL;
470 if (!surface_id_.is_null()) { 478 if (!surface_id_.is_null()) {
471 surface_factory_->Destroy(surface_id_); 479 surfaces_to_destroy_after_commit_.push_back(surface_id_);
472 surface_id_ = cc::SurfaceId(); 480 surface_id_ = cc::SurfaceId();
473 } 481 }
474 delegated_frame_evictor_->DiscardedFrame(); 482 delegated_frame_evictor_->DiscardedFrame();
475 } 483 }
476 484
477 // static 485 // static
478 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult( 486 void DelegatedFrameHost::CopyFromCompositingSurfaceHasResult(
479 const gfx::Size& dst_size_in_pixel, 487 const gfx::Size& dst_size_in_pixel,
480 const SkColorType color_type, 488 const SkColorType color_type,
481 const base::Callback<void(bool, const SkBitmap&)>& callback, 489 const base::Callback<void(bool, const SkBitmap&)>& callback,
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 texture_mailbox.sync_point(), 757 texture_mailbox.sync_point(),
750 video_frame.get(), 758 video_frame.get(),
751 finished_callback); 759 finished_callback);
752 } 760 }
753 761
754 //////////////////////////////////////////////////////////////////////////////// 762 ////////////////////////////////////////////////////////////////////////////////
755 // DelegatedFrameHost, ui::CompositorObserver implementation: 763 // DelegatedFrameHost, ui::CompositorObserver implementation:
756 764
757 void DelegatedFrameHost::OnCompositingDidCommit( 765 void DelegatedFrameHost::OnCompositingDidCommit(
758 ui::Compositor* compositor) { 766 ui::Compositor* compositor) {
767 std::copy(surfaces_to_destroy_after_commit_.begin(),
768 surfaces_to_destroy_after_commit_.end(),
769 std::back_inserter(surfaces_to_destroy_after_swap_));
770 surfaces_to_destroy_after_commit_.clear();
759 RenderWidgetHostImpl* host = client_->GetHost(); 771 RenderWidgetHostImpl* host = client_->GetHost();
760 if (can_lock_compositor_ == NO_PENDING_COMMIT) { 772 if (can_lock_compositor_ == NO_PENDING_COMMIT) {
761 can_lock_compositor_ = YES_CAN_LOCK; 773 can_lock_compositor_ = YES_CAN_LOCK;
762 if (resize_lock_.get() && resize_lock_->GrabDeferredLock()) 774 if (resize_lock_.get() && resize_lock_->GrabDeferredLock())
763 can_lock_compositor_ = YES_DID_LOCK; 775 can_lock_compositor_ = YES_DID_LOCK;
764 } 776 }
765 RunOnCommitCallbacks(); 777 RunOnCommitCallbacks();
766 if (resize_lock_ && 778 if (resize_lock_ &&
767 resize_lock_->expected_size() == current_frame_size_in_dip_) { 779 resize_lock_->expected_size() == current_frame_size_in_dip_) {
768 resize_lock_.reset(); 780 resize_lock_.reset();
769 host->WasResized(); 781 host->WasResized();
770 // We may have had a resize while we had the lock (e.g. if the lock expired, 782 // We may have had a resize while we had the lock (e.g. if the lock expired,
771 // or if the UI still gave us some resizes), so make sure we grab a new lock 783 // or if the UI still gave us some resizes), so make sure we grab a new lock
772 // if necessary. 784 // if necessary.
773 MaybeCreateResizeLock(); 785 MaybeCreateResizeLock();
774 } 786 }
775 } 787 }
776 788
777 void DelegatedFrameHost::OnCompositingStarted( 789 void DelegatedFrameHost::OnCompositingStarted(
778 ui::Compositor* compositor, base::TimeTicks start_time) { 790 ui::Compositor* compositor, base::TimeTicks start_time) {
779 last_draw_ended_ = start_time; 791 last_draw_ended_ = start_time;
780 } 792 }
781 793
782 void DelegatedFrameHost::OnCompositingEnded( 794 void DelegatedFrameHost::OnCompositingEnded(
783 ui::Compositor* compositor) { 795 ui::Compositor* compositor) {
796 for (std::vector<cc::SurfaceId>::iterator it =
797 surfaces_to_destroy_after_swap_.begin();
798 it != surfaces_to_destroy_after_swap_.end();
799 ++it) {
800 surface_factory_->Destroy(*it);
801 }
802 surfaces_to_destroy_after_swap_.clear();
784 } 803 }
785 804
786 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) { 805 void DelegatedFrameHost::OnCompositingAborted(ui::Compositor* compositor) {
787 } 806 }
788 807
789 void DelegatedFrameHost::OnCompositingLockStateChanged( 808 void DelegatedFrameHost::OnCompositingLockStateChanged(
790 ui::Compositor* compositor) { 809 ui::Compositor* compositor) {
791 // A compositor lock that is part of a resize lock timed out. We 810 // A compositor lock that is part of a resize lock timed out. We
792 // should display a renderer frame. 811 // should display a renderer frame.
793 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) { 812 if (!compositor->IsLocked() && can_lock_compositor_ == YES_DID_LOCK) {
(...skipping 23 matching lines...) Expand all
817 } 836 }
818 837
819 //////////////////////////////////////////////////////////////////////////////// 838 ////////////////////////////////////////////////////////////////////////////////
820 // DelegatedFrameHost, private: 839 // DelegatedFrameHost, private:
821 840
822 DelegatedFrameHost::~DelegatedFrameHost() { 841 DelegatedFrameHost::~DelegatedFrameHost() {
823 ImageTransportFactory::GetInstance()->RemoveObserver(this); 842 ImageTransportFactory::GetInstance()->RemoveObserver(this);
824 843
825 if (!surface_id_.is_null()) 844 if (!surface_id_.is_null())
826 surface_factory_->Destroy(surface_id_); 845 surface_factory_->Destroy(surface_id_);
846 for (std::vector<cc::SurfaceId>::iterator it =
847 surfaces_to_destroy_after_commit_.begin();
848 it != surfaces_to_destroy_after_commit_.end();
849 ++it) {
850 surface_factory_->Destroy(*it);
851 }
852 surfaces_to_destroy_after_commit_.clear();
853 for (std::vector<cc::SurfaceId>::iterator it =
854 surfaces_to_destroy_after_swap_.begin();
855 it != surfaces_to_destroy_after_swap_.end();
856 ++it) {
857 surface_factory_->Destroy(*it);
858 }
859 surfaces_to_destroy_after_swap_.clear();
827 if (resource_collection_.get()) 860 if (resource_collection_.get())
828 resource_collection_->SetClient(NULL); 861 resource_collection_->SetClient(NULL);
829 862
830 DCHECK(!vsync_manager_); 863 DCHECK(!vsync_manager_);
831 } 864 }
832 865
833 void DelegatedFrameHost::RunOnCommitCallbacks() { 866 void DelegatedFrameHost::RunOnCommitCallbacks() {
834 for (std::vector<base::Closure>::const_iterator 867 for (std::vector<base::Closure>::const_iterator
835 it = on_compositing_did_commit_callbacks_.begin(); 868 it = on_compositing_did_commit_callbacks_.begin();
836 it != on_compositing_did_commit_callbacks_.end(); ++it) { 869 it != on_compositing_did_commit_callbacks_.end(); ++it) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 new_layer->SetShowDelegatedContent(frame_provider_.get(), 929 new_layer->SetShowDelegatedContent(frame_provider_.get(),
897 current_frame_size_in_dip_); 930 current_frame_size_in_dip_);
898 } 931 }
899 if (!surface_id_.is_null()) { 932 if (!surface_id_.is_null()) {
900 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_); 933 new_layer->SetShowSurface(surface_id_, current_frame_size_in_dip_);
901 } 934 }
902 } 935 }
903 936
904 } // namespace content 937 } // namespace content
905 938
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698