| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 | 62 |
| 63 //////////////////////////////////////////////////////////////////////////////// | 63 //////////////////////////////////////////////////////////////////////////////// |
| 64 // DelegatedFrameHost | 64 // DelegatedFrameHost |
| 65 | 65 |
| 66 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) | 66 DelegatedFrameHost::DelegatedFrameHost(DelegatedFrameHostClient* client) |
| 67 : client_(client), | 67 : client_(client), |
| 68 compositor_(nullptr), | 68 compositor_(nullptr), |
| 69 tick_clock_(new base::DefaultTickClock()), | 69 tick_clock_(new base::DefaultTickClock()), |
| 70 last_output_surface_id_(0), | 70 last_compositor_frame_sink_id_(0), |
| 71 pending_delegated_ack_count_(0), | 71 pending_delegated_ack_count_(0), |
| 72 skipped_frames_(false), | 72 skipped_frames_(false), |
| 73 background_color_(SK_ColorRED), | 73 background_color_(SK_ColorRED), |
| 74 current_scale_factor_(1.f), | 74 current_scale_factor_(1.f), |
| 75 can_lock_compositor_(YES_CAN_LOCK), | 75 can_lock_compositor_(YES_CAN_LOCK), |
| 76 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 76 delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { |
| 77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 77 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 78 factory->GetContextFactory()->AddObserver(this); | 78 factory->GetContextFactory()->AddObserver(this); |
| 79 id_allocator_.reset(new cc::SurfaceIdAllocator( | 79 id_allocator_.reset(new cc::SurfaceIdAllocator( |
| 80 factory->GetContextFactory()->AllocateSurfaceClientId())); | 80 factory->GetContextFactory()->AllocateSurfaceClientId())); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 if (!request_copy_of_output_callback_for_testing_.is_null()) | 388 if (!request_copy_of_output_callback_for_testing_.is_null()) |
| 389 request_copy_of_output_callback_for_testing_.Run(std::move(request)); | 389 request_copy_of_output_callback_for_testing_.Run(std::move(request)); |
| 390 else | 390 else |
| 391 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | 391 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); |
| 392 } else { | 392 } else { |
| 393 request->set_area(gfx::Rect(current_frame_size_in_dip_)); | 393 request->set_area(gfx::Rect(current_frame_size_in_dip_)); |
| 394 RequestCopyOfOutput(std::move(request)); | 394 RequestCopyOfOutput(std::move(request)); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 | 397 |
| 398 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t output_surface_id, | 398 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, |
| 399 cc::CompositorFrame frame) { | 399 cc::CompositorFrame frame) { |
| 400 DCHECK(frame.delegated_frame_data.get()); | 400 DCHECK(frame.delegated_frame_data.get()); |
| 401 #if defined(OS_CHROMEOS) | 401 #if defined(OS_CHROMEOS) |
| 402 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); | 402 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); |
| 403 #endif | 403 #endif |
| 404 cc::DelegatedFrameData* frame_data = frame.delegated_frame_data.get(); | 404 cc::DelegatedFrameData* frame_data = frame.delegated_frame_data.get(); |
| 405 float frame_device_scale_factor = frame.metadata.device_scale_factor; | 405 float frame_device_scale_factor = frame.metadata.device_scale_factor; |
| 406 | 406 |
| 407 DCHECK(!frame_data->render_pass_list.empty()); | 407 DCHECK(!frame_data->render_pass_list.empty()); |
| 408 | 408 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 420 if (ShouldSkipFrame(frame_size_in_dip)) { | 420 if (ShouldSkipFrame(frame_size_in_dip)) { |
| 421 cc::ReturnedResourceArray resources; | 421 cc::ReturnedResourceArray resources; |
| 422 cc::TransferableResource::ReturnResources(frame_data->resource_list, | 422 cc::TransferableResource::ReturnResources(frame_data->resource_list, |
| 423 &resources); | 423 &resources); |
| 424 | 424 |
| 425 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(), | 425 skipped_latency_info_list_.insert(skipped_latency_info_list_.end(), |
| 426 frame.metadata.latency_info.begin(), | 426 frame.metadata.latency_info.begin(), |
| 427 frame.metadata.latency_info.end()); | 427 frame.metadata.latency_info.end()); |
| 428 | 428 |
| 429 client_->DelegatedFrameHostSendReclaimCompositorResources( | 429 client_->DelegatedFrameHostSendReclaimCompositorResources( |
| 430 output_surface_id, true /* is_swap_ack*/, resources); | 430 compositor_frame_sink_id, true /* is_swap_ack*/, resources); |
| 431 skipped_frames_ = true; | 431 skipped_frames_ = true; |
| 432 return; | 432 return; |
| 433 } | 433 } |
| 434 | 434 |
| 435 if (skipped_frames_) { | 435 if (skipped_frames_) { |
| 436 skipped_frames_ = false; | 436 skipped_frames_ = false; |
| 437 damage_rect = gfx::Rect(frame_size); | 437 damage_rect = gfx::Rect(frame_size); |
| 438 damage_rect_in_dip = gfx::Rect(frame_size_in_dip); | 438 damage_rect_in_dip = gfx::Rect(frame_size_in_dip); |
| 439 | 439 |
| 440 // Give the same damage rect to the compositor. | 440 // Give the same damage rect to the compositor. |
| 441 cc::RenderPass* root_pass = frame_data->render_pass_list.back().get(); | 441 cc::RenderPass* root_pass = frame_data->render_pass_list.back().get(); |
| 442 root_pass->damage_rect = damage_rect; | 442 root_pass->damage_rect = damage_rect; |
| 443 } | 443 } |
| 444 | 444 |
| 445 if (output_surface_id != last_output_surface_id_) { | 445 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { |
| 446 // Resource ids are scoped by the output surface. | 446 // Resource ids are scoped by the output surface. |
| 447 // If the originating output surface doesn't match the last one, it | 447 // If the originating output surface doesn't match the last one, it |
| 448 // indicates the renderer's output surface may have been recreated, in which | 448 // indicates the renderer's output surface may have been recreated, in which |
| 449 // case we should recreate the DelegatedRendererLayer, to avoid matching | 449 // case we should recreate the DelegatedRendererLayer, to avoid matching |
| 450 // resources from the old one with resources from the new one which would | 450 // resources from the old one with resources from the new one which would |
| 451 // have the same id. Changing the layer to showing painted content destroys | 451 // have the same id. Changing the layer to showing painted content destroys |
| 452 // the DelegatedRendererLayer. | 452 // the DelegatedRendererLayer. |
| 453 EvictDelegatedFrame(); | 453 EvictDelegatedFrame(); |
| 454 | 454 |
| 455 surface_factory_.reset(); | 455 surface_factory_.reset(); |
| 456 if (!surface_returned_resources_.empty()) { | 456 if (!surface_returned_resources_.empty()) { |
| 457 SendReclaimCompositorResources(last_output_surface_id_, | 457 SendReclaimCompositorResources(last_compositor_frame_sink_id_, |
| 458 false /* is_swap_ack */); | 458 false /* is_swap_ack */); |
| 459 } | 459 } |
| 460 last_output_surface_id_ = output_surface_id; | 460 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 461 } | 461 } |
| 462 bool skip_frame = false; | 462 bool skip_frame = false; |
| 463 pending_delegated_ack_count_++; | 463 pending_delegated_ack_count_++; |
| 464 | 464 |
| 465 background_color_ = frame.metadata.root_background_color; | 465 background_color_ = frame.metadata.root_background_color; |
| 466 | 466 |
| 467 if (frame_size.IsEmpty()) { | 467 if (frame_size.IsEmpty()) { |
| 468 DCHECK(frame_data->resource_list.empty()); | 468 DCHECK(frame_data->resource_list.empty()); |
| 469 EvictDelegatedFrame(); | 469 EvictDelegatedFrame(); |
| 470 } else { | 470 } else { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 498 } else { | 498 } else { |
| 499 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 499 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), |
| 500 skipped_latency_info_list_.begin(), | 500 skipped_latency_info_list_.begin(), |
| 501 skipped_latency_info_list_.end()); | 501 skipped_latency_info_list_.end()); |
| 502 skipped_latency_info_list_.clear(); | 502 skipped_latency_info_list_.clear(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 cc::SurfaceFactory::DrawCallback ack_callback; | 505 cc::SurfaceFactory::DrawCallback ack_callback; |
| 506 if (compositor_ && !skip_frame) { | 506 if (compositor_ && !skip_frame) { |
| 507 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(), | 507 ack_callback = base::Bind(&DelegatedFrameHost::SurfaceDrawn, AsWeakPtr(), |
| 508 output_surface_id); | 508 compositor_frame_sink_id); |
| 509 } | 509 } |
| 510 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 510 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 511 ack_callback); | 511 ack_callback); |
| 512 } | 512 } |
| 513 released_front_lock_ = NULL; | 513 released_front_lock_ = NULL; |
| 514 current_frame_size_in_dip_ = frame_size_in_dip; | 514 current_frame_size_in_dip_ = frame_size_in_dip; |
| 515 CheckResizeLock(); | 515 CheckResizeLock(); |
| 516 | 516 |
| 517 UpdateGutters(); | 517 UpdateGutters(); |
| 518 | 518 |
| 519 if (!damage_rect_in_dip.IsEmpty()) { | 519 if (!damage_rect_in_dip.IsEmpty()) { |
| 520 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 520 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 521 damage_rect_in_dip); | 521 damage_rect_in_dip); |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Note that |compositor_| may be reset by SetShowSurface or | 524 // Note that |compositor_| may be reset by SetShowSurface or |
| 525 // SetShowDelegatedContent above. | 525 // SetShowDelegatedContent above. |
| 526 if (!compositor_ || skip_frame) { | 526 if (!compositor_ || skip_frame) { |
| 527 SendReclaimCompositorResources(output_surface_id, true /* is_swap_ack */); | 527 SendReclaimCompositorResources(compositor_frame_sink_id, |
| 528 true /* is_swap_ack */); |
| 528 } else { | 529 } else { |
| 529 can_lock_compositor_ = NO_PENDING_COMMIT; | 530 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 530 } | 531 } |
| 531 if (!surface_id_.is_null()) { | 532 if (!surface_id_.is_null()) { |
| 532 delegated_frame_evictor_->SwappedFrame( | 533 delegated_frame_evictor_->SwappedFrame( |
| 533 client_->DelegatedFrameHostIsVisible()); | 534 client_->DelegatedFrameHostIsVisible()); |
| 534 } | 535 } |
| 535 // Note: the frame may have been evicted immediately. | 536 // Note: the frame may have been evicted immediately. |
| 536 } | 537 } |
| 537 | 538 |
| 538 void DelegatedFrameHost::ClearDelegatedFrame() { | 539 void DelegatedFrameHost::ClearDelegatedFrame() { |
| 539 if (!surface_id_.is_null()) | 540 if (!surface_id_.is_null()) |
| 540 EvictDelegatedFrame(); | 541 EvictDelegatedFrame(); |
| 541 } | 542 } |
| 542 | 543 |
| 543 void DelegatedFrameHost::SendReclaimCompositorResources( | 544 void DelegatedFrameHost::SendReclaimCompositorResources( |
| 544 uint32_t output_surface_id, | 545 uint32_t compositor_frame_sink_id, |
| 545 bool is_swap_ack) { | 546 bool is_swap_ack) { |
| 546 client_->DelegatedFrameHostSendReclaimCompositorResources( | 547 client_->DelegatedFrameHostSendReclaimCompositorResources( |
| 547 output_surface_id, is_swap_ack, surface_returned_resources_); | 548 compositor_frame_sink_id, is_swap_ack, surface_returned_resources_); |
| 548 surface_returned_resources_.clear(); | 549 surface_returned_resources_.clear(); |
| 549 if (is_swap_ack) { | 550 if (is_swap_ack) { |
| 550 DCHECK_GT(pending_delegated_ack_count_, 0); | 551 DCHECK_GT(pending_delegated_ack_count_, 0); |
| 551 pending_delegated_ack_count_--; | 552 pending_delegated_ack_count_--; |
| 552 } | 553 } |
| 553 } | 554 } |
| 554 | 555 |
| 555 void DelegatedFrameHost::SurfaceDrawn(uint32_t output_surface_id) { | 556 void DelegatedFrameHost::SurfaceDrawn(uint32_t compositor_frame_sink_id) { |
| 556 SendReclaimCompositorResources(output_surface_id, true /* is_swap_ack */); | 557 SendReclaimCompositorResources(compositor_frame_sink_id, |
| 558 true /* is_swap_ack */); |
| 557 } | 559 } |
| 558 | 560 |
| 559 void DelegatedFrameHost::ReturnResources( | 561 void DelegatedFrameHost::ReturnResources( |
| 560 const cc::ReturnedResourceArray& resources) { | 562 const cc::ReturnedResourceArray& resources) { |
| 561 if (resources.empty()) | 563 if (resources.empty()) |
| 562 return; | 564 return; |
| 563 std::copy(resources.begin(), resources.end(), | 565 std::copy(resources.begin(), resources.end(), |
| 564 std::back_inserter(surface_returned_resources_)); | 566 std::back_inserter(surface_returned_resources_)); |
| 565 if (!pending_delegated_ack_count_) { | 567 if (!pending_delegated_ack_count_) { |
| 566 SendReclaimCompositorResources(last_output_surface_id_, | 568 SendReclaimCompositorResources(last_compositor_frame_sink_id_, |
| 567 false /* is_swap_ack */); | 569 false /* is_swap_ack */); |
| 568 } | 570 } |
| 569 } | 571 } |
| 570 | 572 |
| 571 void DelegatedFrameHost::WillDrawSurface(const cc::SurfaceId& id, | 573 void DelegatedFrameHost::WillDrawSurface(const cc::SurfaceId& id, |
| 572 const gfx::Rect& damage_rect) { | 574 const gfx::Rect& damage_rect) { |
| 573 // Frame subscribers are only interested in changes to the target surface, so | 575 // Frame subscribers are only interested in changes to the target surface, so |
| 574 // do not attempt capture if |damage_rect| is empty. This prevents the draws | 576 // do not attempt capture if |damage_rect| is empty. This prevents the draws |
| 575 // of parent surfaces from triggering extra frame captures, which can affect | 577 // of parent surfaces from triggering extra frame captures, which can affect |
| 576 // smoothness. | 578 // smoothness. |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 902 cc::SurfaceManager* manager = factory->GetSurfaceManager(); |
| 901 new_layer->SetShowSurface( | 903 new_layer->SetShowSurface( |
| 902 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), | 904 surface_id_, base::Bind(&SatisfyCallback, base::Unretained(manager)), |
| 903 base::Bind(&RequireCallback, base::Unretained(manager)), | 905 base::Bind(&RequireCallback, base::Unretained(manager)), |
| 904 current_surface_size_, current_scale_factor_, | 906 current_surface_size_, current_scale_factor_, |
| 905 current_frame_size_in_dip_); | 907 current_frame_size_in_dip_); |
| 906 } | 908 } |
| 907 } | 909 } |
| 908 | 910 |
| 909 } // namespace content | 911 } // namespace content |
| OLD | NEW |