| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( | 61 factory->GetContextFactoryPrivate()->GetSurfaceManager()->RegisterFrameSinkId( |
| 62 frame_sink_id_); | 62 frame_sink_id_); |
| 63 CreateCompositorFrameSinkSupport(); | 63 CreateCompositorFrameSinkSupport(); |
| 64 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); | 64 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 65 client_->SetBeginFrameSource(begin_frame_source_.get()); | 65 client_->SetBeginFrameSource(begin_frame_source_.get()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 68 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |
| 69 delegated_frame_evictor_->SetVisible(true); | 69 delegated_frame_evictor_->SetVisible(true); |
| 70 | 70 |
| 71 if (!local_surface_id_.is_valid() && !released_front_lock_.get()) { | 71 if (!has_frame_ && !released_front_lock_.get()) { |
| 72 if (compositor_) | 72 if (compositor_) |
| 73 released_front_lock_ = compositor_->GetCompositorLock(); | 73 released_front_lock_ = compositor_->GetCompositorLock(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (compositor_) { | 76 if (compositor_) { |
| 77 compositor_->SetLatencyInfo(latency_info); | 77 compositor_->SetLatencyInfo(latency_info); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool DelegatedFrameHost::HasSavedFrame() { | 81 bool DelegatedFrameHost::HasSavedFrame() { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 | 218 |
| 219 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager()); | 219 cc::SurfaceHittest hittest(nullptr, GetSurfaceManager()); |
| 220 return hittest.TransformPointToTargetSurface(original_surface, surface_id, | 220 return hittest.TransformPointToTargetSurface(original_surface, surface_id, |
| 221 transformed_point); | 221 transformed_point); |
| 222 } | 222 } |
| 223 | 223 |
| 224 bool DelegatedFrameHost::TransformPointToCoordSpaceForView( | 224 bool DelegatedFrameHost::TransformPointToCoordSpaceForView( |
| 225 const gfx::Point& point, | 225 const gfx::Point& point, |
| 226 RenderWidgetHostViewBase* target_view, | 226 RenderWidgetHostViewBase* target_view, |
| 227 gfx::Point* transformed_point) { | 227 gfx::Point* transformed_point) { |
| 228 if (!local_surface_id_.is_valid()) | 228 if (!has_frame_) |
| 229 return false; | 229 return false; |
| 230 | 230 |
| 231 return target_view->TransformPointToLocalCoordSpace( | 231 return target_view->TransformPointToLocalCoordSpace( |
| 232 point, cc::SurfaceId(frame_sink_id_, local_surface_id_), | 232 point, cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 233 transformed_point); | 233 transformed_point); |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const { | 236 bool DelegatedFrameHost::ShouldSkipFrame(gfx::Size size_in_dip) const { |
| 237 // Should skip a frame only when another frame from the renderer is guaranteed | 237 // Should skip a frame only when another frame from the renderer is guaranteed |
| 238 // to replace it. Otherwise may cause hangs when the renderer is waiting for | 238 // to replace it. Otherwise may cause hangs when the renderer is waiting for |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 } | 254 } |
| 255 | 255 |
| 256 SkColor DelegatedFrameHost::GetGutterColor() const { | 256 SkColor DelegatedFrameHost::GetGutterColor() const { |
| 257 // In fullscreen mode resizing is uncommon, so it makes more sense to | 257 // In fullscreen mode resizing is uncommon, so it makes more sense to |
| 258 // make the initial switch to fullscreen mode look better by using black as | 258 // make the initial switch to fullscreen mode look better by using black as |
| 259 // the gutter color. | 259 // the gutter color. |
| 260 return client_->DelegatedFrameHostGetGutterColor(background_color_); | 260 return client_->DelegatedFrameHostGetGutterColor(background_color_); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void DelegatedFrameHost::UpdateGutters() { | 263 void DelegatedFrameHost::UpdateGutters() { |
| 264 if (!local_surface_id_.is_valid()) { | 264 if (!has_frame_) { |
| 265 right_gutter_.reset(); | 265 right_gutter_.reset(); |
| 266 bottom_gutter_.reset(); | 266 bottom_gutter_.reset(); |
| 267 return; | 267 return; |
| 268 } | 268 } |
| 269 | 269 |
| 270 if (current_frame_size_in_dip_.width() < | 270 if (current_frame_size_in_dip_.width() < |
| 271 client_->DelegatedFrameHostDesiredSizeInDIP().width()) { | 271 client_->DelegatedFrameHostDesiredSizeInDIP().width()) { |
| 272 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 272 right_gutter_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 273 right_gutter_->SetColor(GetGutterColor()); | 273 right_gutter_->SetColor(GetGutterColor()); |
| 274 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() - | 274 int width = client_->DelegatedFrameHostDesiredSizeInDIP().width() - |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // as a source. | 359 // as a source. |
| 360 request->set_source(frame_subscriber()->GetSourceIdForCopyRequest()); | 360 request->set_source(frame_subscriber()->GetSourceIdForCopyRequest()); |
| 361 if (subscriber_texture.get()) { | 361 if (subscriber_texture.get()) { |
| 362 request->SetTextureMailbox(cc::TextureMailbox( | 362 request->SetTextureMailbox(cc::TextureMailbox( |
| 363 subscriber_texture->mailbox(), subscriber_texture->sync_token(), | 363 subscriber_texture->mailbox(), subscriber_texture->sync_token(), |
| 364 subscriber_texture->target())); | 364 subscriber_texture->target())); |
| 365 } | 365 } |
| 366 | 366 |
| 367 // To avoid unnecessary browser composites, try to go directly to the Surface | 367 // To avoid unnecessary browser composites, try to go directly to the Surface |
| 368 // rather than through the Layer (which goes through the browser compositor). | 368 // rather than through the Layer (which goes through the browser compositor). |
| 369 if (local_surface_id_.is_valid() && | 369 if (has_frame_ && request_copy_of_output_callback_for_testing_.is_null()) { |
| 370 request_copy_of_output_callback_for_testing_.is_null()) { | |
| 371 support_->RequestCopyOfSurface(std::move(request)); | 370 support_->RequestCopyOfSurface(std::move(request)); |
| 372 } else { | 371 } else { |
| 373 RequestCopyOfOutput(std::move(request)); | 372 RequestCopyOfOutput(std::move(request)); |
| 374 } | 373 } |
| 375 } | 374 } |
| 376 | 375 |
| 377 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, | 376 void DelegatedFrameHost::SwapDelegatedFrame(uint32_t compositor_frame_sink_id, |
| 378 cc::CompositorFrame frame) { | 377 cc::CompositorFrame frame) { |
| 379 #if defined(OS_CHROMEOS) | 378 #if defined(OS_CHROMEOS) |
| 380 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); | 379 DCHECK(!resize_lock_ || !client_->IsAutoResizeEnabled()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 } | 418 } |
| 420 | 419 |
| 421 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { | 420 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { |
| 422 // Resource ids are scoped by the output surface. | 421 // Resource ids are scoped by the output surface. |
| 423 // If the originating output surface doesn't match the last one, it | 422 // If the originating output surface doesn't match the last one, it |
| 424 // indicates the renderer's output surface may have been recreated, in which | 423 // indicates the renderer's output surface may have been recreated, in which |
| 425 // case we should recreate the DelegatedRendererLayer, to avoid matching | 424 // case we should recreate the DelegatedRendererLayer, to avoid matching |
| 426 // resources from the old one with resources from the new one which would | 425 // resources from the old one with resources from the new one which would |
| 427 // have the same id. Changing the layer to showing painted content destroys | 426 // have the same id. Changing the layer to showing painted content destroys |
| 428 // the DelegatedRendererLayer. | 427 // the DelegatedRendererLayer. |
| 429 EvictDelegatedFrame(); | 428 local_surface_id_ = cc::LocalSurfaceId(); |
| 430 ResetCompositorFrameSinkSupport(); | 429 ResetCompositorFrameSinkSupport(); |
| 431 CreateCompositorFrameSinkSupport(); | 430 CreateCompositorFrameSinkSupport(); |
| 432 last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 431 last_compositor_frame_sink_id_ = compositor_frame_sink_id; |
| 433 } | 432 } |
| 434 | 433 |
| 435 background_color_ = frame.metadata.root_background_color; | 434 background_color_ = frame.metadata.root_background_color; |
| 436 | 435 |
| 437 if (frame_size.IsEmpty()) { | 436 if (frame_size.IsEmpty()) { |
| 438 DCHECK(frame.resource_list.empty()); | 437 DCHECK(frame.resource_list.empty()); |
| 439 EvictDelegatedFrame(); | 438 EvictDelegatedFrame(); |
| 440 } else { | 439 } else { |
| 441 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 440 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 442 cc::SurfaceManager* manager = | 441 cc::SurfaceManager* manager = |
| 443 factory->GetContextFactoryPrivate()->GetSurfaceManager(); | 442 factory->GetContextFactoryPrivate()->GetSurfaceManager(); |
| 444 bool allocated_new_local_surface_id = false; | 443 bool allocated_new_local_surface_id = false; |
| 445 if (!local_surface_id_.is_valid() || frame_size != current_surface_size_ || | 444 if (!local_surface_id_.is_valid() || frame_size != current_surface_size_ || |
| 446 frame_size_in_dip != current_frame_size_in_dip_) { | 445 frame_size_in_dip != current_frame_size_in_dip_) { |
| 447 local_surface_id_ = id_allocator_->GenerateId(); | 446 local_surface_id_ = id_allocator_->GenerateId(); |
| 448 allocated_new_local_surface_id = true; | 447 allocated_new_local_surface_id = true; |
| 449 } | 448 } |
| 450 | 449 |
| 451 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), | 450 frame.metadata.latency_info.insert(frame.metadata.latency_info.end(), |
| 452 skipped_latency_info_list_.begin(), | 451 skipped_latency_info_list_.begin(), |
| 453 skipped_latency_info_list_.end()); | 452 skipped_latency_info_list_.end()); |
| 454 skipped_latency_info_list_.clear(); | 453 skipped_latency_info_list_.clear(); |
| 455 | 454 |
| 456 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); | 455 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 457 | 456 |
| 458 if (allocated_new_local_surface_id) { | 457 if (allocated_new_local_surface_id || !has_frame_) { |
| 459 // manager must outlive compositors using it. | 458 // manager must outlive compositors using it. |
| 460 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); | 459 cc::SurfaceId surface_id(frame_sink_id_, local_surface_id_); |
| 461 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, | 460 cc::SurfaceInfo surface_info(surface_id, frame_device_scale_factor, |
| 462 frame_size); | 461 frame_size); |
| 463 client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( | 462 client_->DelegatedFrameHostGetLayer()->SetShowPrimarySurface( |
| 464 surface_info, manager->reference_factory()); | 463 surface_info, manager->reference_factory()); |
| 465 current_surface_size_ = frame_size; | 464 current_surface_size_ = frame_size; |
| 466 current_scale_factor_ = frame_device_scale_factor; | 465 current_scale_factor_ = frame_device_scale_factor; |
| 467 } | 466 } |
| 467 |
| 468 has_frame_ = true; |
| 468 } | 469 } |
| 469 released_front_lock_ = NULL; | 470 released_front_lock_ = NULL; |
| 470 current_frame_size_in_dip_ = frame_size_in_dip; | 471 current_frame_size_in_dip_ = frame_size_in_dip; |
| 471 CheckResizeLock(); | 472 CheckResizeLock(); |
| 472 | 473 |
| 473 UpdateGutters(); | 474 UpdateGutters(); |
| 474 | 475 |
| 475 if (!damage_rect_in_dip.IsEmpty()) { | 476 if (!damage_rect_in_dip.IsEmpty()) { |
| 476 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( | 477 client_->DelegatedFrameHostGetLayer()->OnDelegatedFrameDamage( |
| 477 damage_rect_in_dip); | 478 damage_rect_in_dip); |
| 478 } | 479 } |
| 479 | 480 |
| 480 if (compositor_) | 481 if (compositor_) |
| 481 can_lock_compositor_ = NO_PENDING_COMMIT; | 482 can_lock_compositor_ = NO_PENDING_COMMIT; |
| 482 | 483 |
| 483 if (local_surface_id_.is_valid()) { | 484 if (has_frame_) { |
| 484 delegated_frame_evictor_->SwappedFrame( | 485 delegated_frame_evictor_->SwappedFrame( |
| 485 client_->DelegatedFrameHostIsVisible()); | 486 client_->DelegatedFrameHostIsVisible()); |
| 486 } | 487 } |
| 487 // Note: the frame may have been evicted immediately. | 488 // Note: the frame may have been evicted immediately. |
| 488 } | 489 } |
| 489 | 490 |
| 490 void DelegatedFrameHost::ClearDelegatedFrame() { | 491 void DelegatedFrameHost::ClearDelegatedFrame() { |
| 491 if (local_surface_id_.is_valid()) | 492 EvictDelegatedFrame(); |
| 492 EvictDelegatedFrame(); | |
| 493 } | 493 } |
| 494 | 494 |
| 495 void DelegatedFrameHost::DidReceiveCompositorFrameAck() { | 495 void DelegatedFrameHost::DidReceiveCompositorFrameAck() { |
| 496 client_->DelegatedFrameHostSendReclaimCompositorResources( | 496 client_->DelegatedFrameHostSendReclaimCompositorResources( |
| 497 last_compositor_frame_sink_id_, true /* is_swap_ack */, | 497 last_compositor_frame_sink_id_, true /* is_swap_ack */, |
| 498 cc::ReturnedResourceArray()); | 498 cc::ReturnedResourceArray()); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void DelegatedFrameHost::ReclaimResources( | 501 void DelegatedFrameHost::ReclaimResources( |
| 502 const cc::ReturnedResourceArray& resources) { | 502 const cc::ReturnedResourceArray& resources) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 513 if (id != local_surface_id_ || damage_rect.IsEmpty()) | 513 if (id != local_surface_id_ || damage_rect.IsEmpty()) |
| 514 return; | 514 return; |
| 515 AttemptFrameSubscriberCapture(damage_rect); | 515 AttemptFrameSubscriberCapture(damage_rect); |
| 516 } | 516 } |
| 517 | 517 |
| 518 void DelegatedFrameHost::OnBeginFrame(const cc::BeginFrameArgs& args) { | 518 void DelegatedFrameHost::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 519 begin_frame_source_->OnBeginFrame(args); | 519 begin_frame_source_->OnBeginFrame(args); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void DelegatedFrameHost::EvictDelegatedFrame() { | 522 void DelegatedFrameHost::EvictDelegatedFrame() { |
| 523 if (!has_frame_) |
| 524 return; |
| 523 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); | 525 client_->DelegatedFrameHostGetLayer()->SetShowSolidColorContent(); |
| 524 if (local_surface_id_.is_valid()) { | 526 support_->EvictFrame(); |
| 525 support_->EvictFrame(); | 527 has_frame_ = false; |
| 526 local_surface_id_ = cc::LocalSurfaceId(); | |
| 527 } | |
| 528 delegated_frame_evictor_->DiscardedFrame(); | 528 delegated_frame_evictor_->DiscardedFrame(); |
| 529 UpdateGutters(); | 529 UpdateGutters(); |
| 530 } | 530 } |
| 531 | 531 |
| 532 // static | 532 // static |
| 533 void DelegatedFrameHost::ReturnSubscriberTexture( | 533 void DelegatedFrameHost::ReturnSubscriberTexture( |
| 534 base::WeakPtr<DelegatedFrameHost> dfh, | 534 base::WeakPtr<DelegatedFrameHost> dfh, |
| 535 scoped_refptr<OwnedMailbox> subscriber_texture, | 535 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 536 const gpu::SyncToken& sync_token) { | 536 const gpu::SyncToken& sync_token) { |
| 537 if (!subscriber_texture.get()) | 537 if (!subscriber_texture.get()) |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase, | 740 void DelegatedFrameHost::OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 741 base::TimeDelta interval) { | 741 base::TimeDelta interval) { |
| 742 vsync_timebase_ = timebase; | 742 vsync_timebase_ = timebase; |
| 743 vsync_interval_ = interval; | 743 vsync_interval_ = interval; |
| 744 } | 744 } |
| 745 | 745 |
| 746 //////////////////////////////////////////////////////////////////////////////// | 746 //////////////////////////////////////////////////////////////////////////////// |
| 747 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: | 747 // DelegatedFrameHost, ImageTransportFactoryObserver implementation: |
| 748 | 748 |
| 749 void DelegatedFrameHost::OnLostResources() { | 749 void DelegatedFrameHost::OnLostResources() { |
| 750 if (local_surface_id_.is_valid()) | 750 EvictDelegatedFrame(); |
| 751 EvictDelegatedFrame(); | |
| 752 idle_frame_subscriber_textures_.clear(); | 751 idle_frame_subscriber_textures_.clear(); |
| 753 yuv_readback_pipeline_.reset(); | 752 yuv_readback_pipeline_.reset(); |
| 754 } | 753 } |
| 755 | 754 |
| 756 //////////////////////////////////////////////////////////////////////////////// | 755 //////////////////////////////////////////////////////////////////////////////// |
| 757 // DelegatedFrameHost, private: | 756 // DelegatedFrameHost, private: |
| 758 | 757 |
| 759 DelegatedFrameHost::~DelegatedFrameHost() { | 758 DelegatedFrameHost::~DelegatedFrameHost() { |
| 760 DCHECK(!compositor_); | 759 DCHECK(!compositor_); |
| 761 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 760 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 849 |
| 851 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() { | 850 void DelegatedFrameHost::ResetCompositorFrameSinkSupport() { |
| 852 if (!support_) | 851 if (!support_) |
| 853 return; | 852 return; |
| 854 if (compositor_) | 853 if (compositor_) |
| 855 compositor_->RemoveFrameSink(frame_sink_id_); | 854 compositor_->RemoveFrameSink(frame_sink_id_); |
| 856 support_.reset(); | 855 support_.reset(); |
| 857 } | 856 } |
| 858 | 857 |
| 859 } // namespace content | 858 } // namespace content |
| OLD | NEW |