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

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

Issue 2485473003: Remove SurfaceFactory::Create and SurfaceFactory::Destroy (Closed)
Patch Set: up Created 4 years 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
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/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
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 SendReclaimCompositorResources(last_compositor_frame_sink_id_, 462 SendReclaimCompositorResources(last_compositor_frame_sink_id_,
464 false /* is_swap_ack */); 463 false /* is_swap_ack */);
465 } 464 }
466 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 465 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
467 } 466 }
468 bool skip_frame = false; 467 bool skip_frame = false;
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
472 bool did_send_ack_callback = false;
473 if (frame_size.IsEmpty()) { 473 if (frame_size.IsEmpty()) {
474 DCHECK(frame.resource_list.empty()); 474 DCHECK(frame.resource_list.empty());
475 EvictDelegatedFrame(); 475 EvictDelegatedFrame();
476 } else { 476 } else {
477 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 477 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
478 cc::SurfaceManager* manager = factory->GetSurfaceManager(); 478 cc::SurfaceManager* manager = factory->GetSurfaceManager();
479 bool allocated_new_local_frame_id = false;
479 if (!local_frame_id_.is_valid() || frame_size != current_surface_size_ || 480 if (!local_frame_id_.is_valid() || frame_size != current_surface_size_ ||
480 frame_size_in_dip != current_frame_size_in_dip_) { 481 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(); 482 local_frame_id_ = id_allocator_->GenerateId();
484 surface_factory_->Create(local_frame_id_); 483 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 } 484 }
494 485
495 gfx::Size desired_size = client_->DelegatedFrameHostDesiredSizeInDIP(); 486 gfx::Size desired_size = client_->DelegatedFrameHostDesiredSizeInDIP();
496 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty()) { 487 if (desired_size != frame_size_in_dip && !desired_size.IsEmpty()) {
497 skip_frame = true; 488 skip_frame = true;
498 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(), 489 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(),
499 frame.metadata.latency_info.begin(), 490 frame.metadata.latency_info.begin(),
500 frame.metadata.latency_info.end()); 491 frame.metadata.latency_info.end());
501 frame.metadata.latency_info.clear(); 492 frame.metadata.latency_info.clear();
502 } else { 493 } else {
503 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), 494 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(),
504 skipped_latency_info_list_.begin(), 495 skipped_latency_info_list_.begin(),
505 skipped_latency_info_list_.end()); 496 skipped_latency_info_list_.end());
506 skipped_latency_info_list_.clear(); 497 skipped_latency_info_list_.clear();
507 } 498 }
508 499
509 cc::SurfaceFactory::DrawCallback ack_callback; 500 cc::SurfaceFactory::DrawCallback ack_callback;
510 if (compositor_ && !skip_frame) { 501 if (compositor_ && !skip_frame) {
511 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(), 502 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(),
512 compositor_frame_sink_id); 503 compositor_frame_sink_id);
504 did_send_ack_callback = true;
513 } 505 }
514 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 506 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
515 ack_callback); 507 ack_callback);
508 if (allocated_new_local_frame_id) {
509 // manager must outlive compositors using it.
510 client_->DelegatedFrameHostGetLayer()->SetShowSurface(
511 cc::SurfaceId(frame_sink_id_, local_frame_id_),
512 base::Bind(&SatisfyCallback, base::Unretained(manager)),
513 base::Bind(&RequireCallback, base::Unretained(manager)), frame_size,
514 frame_device_scale_factor, frame_size_in_dip);
515 current_surface_size_ = frame_size;
516 current_scale_factor_ = frame_device_scale_factor;
517 }
516 } 518 }
517 released_front_lock_ = NULL; 519 released_front_lock_ = NULL;
518 current_frame_size_in_dip_ = frame_size_in_dip; 520 current_frame_size_in_dip_ = frame_size_in_dip;
519 CheckResizeLock(); 521 CheckResizeLock();
520 522
521 UpdateGutters(); 523 UpdateGutters();
522 524
523 if (!damage_rect_in_dip.IsEmpty()) { 525 if (!damage_rect_in_dip.IsEmpty()) {
524 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( 526 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage(
525 damage_rect_in_dip); 527 damage_rect_in_dip);
526 } 528 }
527 529
528 // Note that |compositor_| may be reset by SetShowSurface or 530 // Note that |compositor_| may be reset by SetShowSurface or
529 // SetShowDelegatedContent above. 531 // SetShowDelegatedContent above.
530 if (!compositor_ || skip_frame) { 532 if (!compositor_ || skip_frame) {
531 SendReclaimCompositorResources(compositor_frame_sink_id, 533 SendReclaimCompositorResources(compositor_frame_sink_id,
532 true /* is_swap_ack */); 534 !did_send_ack_callback /* is_swap_ack */);
533 } else { 535 } else {
534 can_lock_compositor_ = NO_PENDING_COMMIT; 536 can_lock_compositor_ = NO_PENDING_COMMIT;
535 } 537 }
536 if (local_frame_id_.is_valid()) { 538 if (local_frame_id_.is_valid()) {
537 delegated_frame_evictor_->SwappedFrame( 539 delegated_frame_evictor_->SwappedFrame(
538 client_->DelegatedFrameHostIsVisible()); 540 client_->DelegatedFrameHostIsVisible());
539 } 541 }
540 // Note: the frame may have been evicted immediately. 542 // Note: the frame may have been evicted immediately.
541 } 543 }
542 544
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 588 }
587 589
588 void DelegatedFrameHost::SetBeginFrameSource( 590 void DelegatedFrameHost::SetBeginFrameSource(
589 cc::BeginFrameSource* begin_frame_source) { 591 cc::BeginFrameSource* begin_frame_source) {
590 client_->SetBeginFrameSource(begin_frame_source); 592 client_->SetBeginFrameSource(begin_frame_source);
591 } 593 }
592 594
593 void DelegatedFrameHost::EvictDelegatedFrame() { 595 void DelegatedFrameHost::EvictDelegatedFrame() {
594 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); 596 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent();
595 if (local_frame_id_.is_valid()) { 597 if (local_frame_id_.is_valid()) {
596 surface_factory_->Destroy(local_frame_id_); 598 surface_factory_->EvictSurface();
597 local_frame_id_ = cc::LocalFrameId(); 599 local_frame_id_ = cc::LocalFrameId();
598 } 600 }
599 delegated_frame_evictor_->DiscardedFrame(); 601 delegated_frame_evictor_->DiscardedFrame();
600 UpdateGutters(); 602 UpdateGutters();
601 } 603 }
602 604
603 // static 605 // static
604 void DelegatedFrameHost::ReturnSubscriberTexture( 606 void DelegatedFrameHost::ReturnSubscriberTexture(
605 base::WeakPtr<DelegatedFrameHost> dfh, 607 base::WeakPtr<DelegatedFrameHost> dfh,
606 scoped_refptr<OwnedMailbox> subscriber_texture, 608 scoped_refptr<OwnedMailbox> subscriber_texture,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 yuv_readback_pipeline_.reset(); 822 yuv_readback_pipeline_.reset();
821 } 823 }
822 824
823 //////////////////////////////////////////////////////////////////////////////// 825 ////////////////////////////////////////////////////////////////////////////////
824 // DelegatedFrameHost, private: 826 // DelegatedFrameHost, private:
825 827
826 DelegatedFrameHost::~DelegatedFrameHost() { 828 DelegatedFrameHost::~DelegatedFrameHost() {
827 DCHECK(!compositor_); 829 DCHECK(!compositor_);
828 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 830 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
829 factory->GetContextFactory()->RemoveObserver(this); 831 factory->GetContextFactory()->RemoveObserver(this);
830 832 surface_factory_->EvictSurface();
831 if (local_frame_id_.is_valid())
832 surface_factory_->Destroy(local_frame_id_);
833 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_); 833 factory->GetSurfaceManager()->UnregisterSurfaceFactoryClient(frame_sink_id_);
834 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); 834 factory->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
835 835
836 DCHECK(!vsync_manager_.get()); 836 DCHECK(!vsync_manager_.get());
837 } 837 }
838 838
839 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) { 839 void DelegatedFrameHost::SetCompositor(ui::Compositor* compositor) {
840 DCHECK(!compositor_); 840 DCHECK(!compositor_);
841 if (!compositor) 841 if (!compositor)
842 return; 842 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 std::move(request)); 881 std::move(request));
882 } 882 }
883 } 883 }
884 884
885 void DelegatedFrameHost::UnlockResources() { 885 void DelegatedFrameHost::UnlockResources() {
886 DCHECK(local_frame_id_.is_valid()); 886 DCHECK(local_frame_id_.is_valid());
887 delegated_frame_evictor_->UnlockFrame(); 887 delegated_frame_evictor_->UnlockFrame();
888 } 888 }
889 889
890 } // namespace content 890 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698