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/renderer_host/delegated_frame_host.h" | 5 #include "content/browser/renderer_host/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> |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 subscriber_texture->target())); | 389 subscriber_texture->target())); |
390 } | 390 } |
391 | 391 |
392 if (local_frame_id_.is_valid()) { | 392 if (local_frame_id_.is_valid()) { |
393 // To avoid unnecessary composites, go directly to the Surface rather than | 393 // To avoid unnecessary composites, go directly to the Surface rather than |
394 // through RequestCopyOfOutput (which goes through the browser | 394 // through RequestCopyOfOutput (which goes through the browser |
395 // compositor). | 395 // compositor). |
396 if (!request_copy_of_output_callback_for_testing_.is_null()) | 396 if (!request_copy_of_output_callback_for_testing_.is_null()) |
397 request_copy_of_output_callback_for_testing_.Run(std::move(request)); | 397 request_copy_of_output_callback_for_testing_.Run(std::move(request)); |
398 else | 398 else |
399 surface_factory_->RequestCopyOfSurface(local_frame_id_, | 399 surface_factory_->RequestCopyOfSurface(std::move(request)); |
400 std::move(request)); | |
401 } else { | 400 } else { |
402 request->set_area(gfx::Rect(current_frame_size_in_dip_)); | 401 request->set_area(gfx::Rect(current_frame_size_in_dip_)); |
403 RequestCopyOfOutput(std::move(request)); | 402 RequestCopyOfOutput(std::move(request)); |
404 } | 403 } |
405 } | 404 } |
406 | 405 |
407 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, | 406 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, |
408 cc::CompositorFrame frame) { | 407 cc::CompositorFrame frame) { |
409 #if defined(OS_CHROMEOS) | 408 #if defined(OS_CHROMEOS) |
410 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); | 409 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 pending_delegated_ack_count_++; | 468 pending_delegated_ack_count_++; |
470 | 469 |
471 background_color_ = frame.metadata.root_background_color; | 470 background_color_ = frame.metadata.root_background_color; |
472 | 471 |
473 if (frame_size.IsEmpty()) { | 472 if (frame_size.IsEmpty()) { |
474 DCHECK(frame.resource_list.empty()); | 473 DCHECK(frame.resource_list.empty()); |
475 EvictDelegatedFrame(); | 474 EvictDelegatedFrame(); |
476 } else { | 475 } else { |
477 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 476 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
478 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 477 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
478 bool allocated_new_local_frame_id = false; | |
479 if (!local_frame_id_.is_valid() || frame_size != current_surface_size_ || | 479 if (!local_frame_id_.is_valid() || frame_size != current_surface_size_ || |
480 frame_size_in_dip != current_frame_size_in_dip_) { | 480 frame_size_in_dip != current_frame_size_in_dip_) { |
481 if (local_frame_id_.is_valid()) | |
482 surface_factory_->Destroy(local_frame_id_); | |
483 local_frame_id_ = id_allocator_->GenerateId(); | 481 local_frame_id_ = id_allocator_->GenerateId(); |
484 surface_factory_->Create(local_frame_id_); | 482 allocated_new_local_frame_id = true; |
485 // manager must outlive compositors using it. | |
486 client_->DelegatedFrameHostGetLayer()->SetShowSurface( | |
487 cc::SurfaceId(frame_sink_id_, local_frame_id_), | |
488 base::Bind(&SatisfyCallback, base::Unretained(manager)), | |
489 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size, | |
490 frame_device_scale_factor, frame_size_in_dip); | |
491 current_surface_size_ = frame_size; | |
492 current_scale_factor_ = frame_device_scale_factor; | |
493 } | 483 } |
494 | 484 |
495 gfx::Size desired_size = client_->DelegatedFrameHostDesiredSizeInDIP(); | 485 gfx::Size desired_size = client_->DelegatedFrameHostDesiredSizeInDIP(); |
496 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty()) { | 486 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty()) { |
497 skip_frame = true; | 487 skip_frame = true; |
498 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(), | 488 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(), |
499 frame.metadata.latency_info.begin(), | 489 frame.metadata.latency_info.begin(), |
500 frame.metadata.latency_info.end()); | 490 frame.metadata.latency_info.end()); |
501 frame.metadata.latency_info.clear(); | 491 frame.metadata.latency_info.clear(); |
502 } else { | 492 } else { |
503 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 493 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), |
504 skipped_latency_info_list_.begin(), | 494 skipped_latency_info_list_.begin(), |
505 skipped_latency_info_list_.end()); | 495 skipped_latency_info_list_.end()); |
506 skipped_latency_info_list_.clear(); | 496 skipped_latency_info_list_.clear(); |
507 } | 497 } |
508 | 498 |
509 cc::SurfaceFactory::DrawCallback ack_callback; | 499 cc::SurfaceFactory::DrawCallback ack_callback; |
510 if (compositor_ && !skip_frame) { | 500 if (compositor_ && !skip_frame) { |
511 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(), | 501 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(), |
512 compositor_frame_sink_id); | 502 compositor_frame_sink_id); |
513 } | 503 } |
514 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), | 504 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), |
515 ack_callback); | 505 ack_callback); |
506 if (allocated_new_local_frame_id) { | |
boliu
2016/11/11 23:50:45
same question
Fady Samuel
2016/11/11 23:57:33
Surfaces are now created lazily when CompositorFra
| |
507 // manager must outlive compositors using it. | |
508 client_->DelegatedFrameHostGetLayer()->SetShowSurface( | |
509 cc::SurfaceId(frame_sink_id_, local_frame_id_), | |
510 base::Bind(&SatisfyCallback, base::Unretained(manager)), | |
511 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size, | |
512 frame_device_scale_factor, frame_size_in_dip); | |
513 current_surface_size_ = frame_size; | |
514 current_scale_factor_ = frame_device_scale_factor; | |
515 } | |
516 } | 516 } |
517 released_front_lock_ = NULL; | 517 released_front_lock_ = NULL; |
518 current_frame_size_in_dip_ = frame_size_in_dip; | 518 current_frame_size_in_dip_ = frame_size_in_dip; |
519 CheckResizeLock(); | 519 CheckResizeLock(); |
520 | 520 |
521 UpdateGutters(); | 521 UpdateGutters(); |
522 | 522 |
523 if (!damage_rect_in_dip.IsEmpty()) { | 523 if (!damage_rect_in_dip.IsEmpty()) { |
524 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 524 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
525 damage_rect_in_dip); | 525 damage_rect_in_dip); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 } | 586 } |
587 | 587 |
588 void DelegatedFrameHost::SetBeginFrameSource( | 588 void DelegatedFrameHost::SetBeginFrameSource( |
589 cc::BeginFrameSource* begin_frame_source) { | 589 cc::BeginFrameSource* begin_frame_source) { |
590 client_->SetBeginFrameSource(begin_frame_source); | 590 client_->SetBeginFrameSource(begin_frame_source); |
591 } | 591 } |
592 | 592 |
593 void DelegatedFrameHost::EvictDelegatedFrame() { | 593 void DelegatedFrameHost::EvictDelegatedFrame() { |
594 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); | 594 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); |
595 if (local_frame_id_.is_valid()) { | 595 if (local_frame_id_.is_valid()) { |
596 surface_factory_->Destroy(local_frame_id_); | 596 surface_factory_->EvictFrame(); |
597 local_frame_id_ = cc::LocalFrameId(); | 597 local_frame_id_ = cc::LocalFrameId(); |
598 } | 598 } |
599 delegated_frame_evictor_->DiscardedFrame(); | 599 delegated_frame_evictor_->DiscardedFrame(); |
600 UpdateGutters(); | 600 UpdateGutters(); |
601 } | 601 } |
602 | 602 |
603 // static | 603 // static |
604 void DelegatedFrameHost::ReturnSubscriberTexture( | 604 void DelegatedFrameHost::ReturnSubscriberTexture( |
605 base::WeakPtr<DelegatedFrameHost> dfh, | 605 base::WeakPtr<DelegatedFrameHost> dfh, |
606 scoped_refptr<OwnedMailbox> subscriber_texture, | 606 scoped_refptr<OwnedMailbox> subscriber_texture, |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 yuv_readback_pipeline_.reset(); | 820 yuv_readback_pipeline_.reset(); |
821 } | 821 } |
822 | 822 |
823 //////////////////////////////////////////////////////////////////////////////// | 823 //////////////////////////////////////////////////////////////////////////////// |
824 // DelegatedFrameHost, private: | 824 // DelegatedFrameHost, private: |
825 | 825 |
826 DelegatedFrameHost::~DelegatedFrameHost() { | 826 DelegatedFrameHost::~DelegatedFrameHost() { |
827 DCHECK(!compositor_); | 827 DCHECK(!compositor_); |
828 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 828 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
829 factory->GetContextFactory()->RemoveObserver(this); | 829 factory->GetContextFactory()->RemoveObserver(this); |
830 | 830 surface_factory_->EvictFrame(); |
831 if (local_frame_id_.is_valid()) | |
832 surface_factory_->Destroy(local_frame_id_); | |
833 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); | 831 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); |
834 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 832 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
835 | 833 |
836 DCHECK(!vsync_manager_.get()); | 834 DCHECK(!vsync_manager_.get()); |
837 } | 835 } |
838 | 836 |
839 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { | 837 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { |
840 DCHECK(!compositor_); | 838 DCHECK(!compositor_); |
841 if (!compositor) | 839 if (!compositor) |
842 return; | 840 return; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 std::move(request)); | 879 std::move(request)); |
882 } | 880 } |
883 } | 881 } |
884 | 882 |
885 void DelegatedFrameHost::UnlockResources() { | 883 void DelegatedFrameHost::UnlockResources() { |
886 DCHECK(local_frame_id_.is_valid()); | 884 DCHECK(local_frame_id_.is_valid()); |
887 delegated_frame_evictor_->UnlockFrame(); | 885 delegated_frame_evictor_->UnlockFrame(); |
888 } | 886 } |
889 | 887 |
890 } // namespace content | 888 } // namespace content |
OLD | NEW |