| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   75       background_color_(SK_ColorRED), |   75       background_color_(SK_ColorRED), | 
|   76       current_scale_factor_(1.f), |   76       current_scale_factor_(1.f), | 
|   77       can_lock_compositor_(YES_CAN_LOCK), |   77       can_lock_compositor_(YES_CAN_LOCK), | 
|   78       delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { |   78       delegated_frame_evictor_(new DelegatedFrameEvictor(this)) { | 
|   79   ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |   79   ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 
|   80   factory->GetContextFactory()->AddObserver(this); |   80   factory->GetContextFactory()->AddObserver(this); | 
|   81   id_allocator_.reset(new cc::SurfaceIdAllocator()); |   81   id_allocator_.reset(new cc::SurfaceIdAllocator()); | 
|   82   factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); |   82   factory->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); | 
|   83   factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, |   83   factory->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, | 
|   84                                                              this); |   84                                                              this); | 
 |   85   surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 
 |   86       frame_sink_id_, factory->GetSurfaceManager(), this); | 
|   85 } |   87 } | 
|   86  |   88  | 
|   87 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { |   89 void DelegatedFrameHost::WasShown(const ui::LatencyInfo& latency_info) { | 
|   88   delegated_frame_evictor_->SetVisible(true); |   90   delegated_frame_evictor_->SetVisible(true); | 
|   89  |   91  | 
|   90   if (local_frame_id_.is_null() && !released_front_lock_.get()) { |   92   if (local_frame_id_.is_null() && !released_front_lock_.get()) { | 
|   91     if (compositor_) |   93     if (compositor_) | 
|   92       released_front_lock_ = compositor_->GetCompositorLock(); |   94       released_front_lock_ = compositor_->GetCompositorLock(); | 
|   93   } |   95   } | 
|   94  |   96  | 
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  380   // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for |  382   // DelegatedFrameHost (e.g., a call to CopyFromCompositingSurface() for | 
|  381   // screenshots) since those copy requests do not specify |frame_subscriber()| |  383   // screenshots) since those copy requests do not specify |frame_subscriber()| | 
|  382   // as a source. |  384   // as a source. | 
|  383   request->set_source(frame_subscriber()); |  385   request->set_source(frame_subscriber()); | 
|  384   if (subscriber_texture.get()) { |  386   if (subscriber_texture.get()) { | 
|  385     request->SetTextureMailbox(cc::TextureMailbox( |  387     request->SetTextureMailbox(cc::TextureMailbox( | 
|  386         subscriber_texture->mailbox(), subscriber_texture->sync_token(), |  388         subscriber_texture->mailbox(), subscriber_texture->sync_token(), | 
|  387         subscriber_texture->target())); |  389         subscriber_texture->target())); | 
|  388   } |  390   } | 
|  389  |  391  | 
|  390   if (surface_factory_.get()) { |  392   if (!local_frame_id_.is_null()) { | 
|  391     // To avoid unnecessary composites, go directly to the Surface rather than |  393     // To avoid unnecessary composites, go directly to the Surface rather than | 
|  392     // through RequestCopyOfOutput (which goes through the browser |  394     // through RequestCopyOfOutput (which goes through the browser | 
|  393     // compositor). |  395     // compositor). | 
|  394     if (!request_copy_of_output_callback_for_testing_.is_null()) |  396     if (!request_copy_of_output_callback_for_testing_.is_null()) | 
|  395       request_copy_of_output_callback_for_testing_.Run(std::move(request)); |  397       request_copy_of_output_callback_for_testing_.Run(std::move(request)); | 
|  396     else |  398     else | 
|  397       surface_factory_->RequestCopyOfSurface(local_frame_id_, |  399       surface_factory_->RequestCopyOfSurface(local_frame_id_, | 
|  398                                              std::move(request)); |  400                                              std::move(request)); | 
|  399   } else { |  401   } else { | 
|  400     request->set_area(gfx::Rect(current_frame_size_in_dip_)); |  402     request->set_area(gfx::Rect(current_frame_size_in_dip_)); | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  449   if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { |  451   if (compositor_frame_sink_id != last_compositor_frame_sink_id_) { | 
|  450     // Resource ids are scoped by the output surface. |  452     // Resource ids are scoped by the output surface. | 
|  451     // If the originating output surface doesn't match the last one, it |  453     // If the originating output surface doesn't match the last one, it | 
|  452     // indicates the renderer's output surface may have been recreated, in which |  454     // indicates the renderer's output surface may have been recreated, in which | 
|  453     // case we should recreate the DelegatedRendererLayer, to avoid matching |  455     // case we should recreate the DelegatedRendererLayer, to avoid matching | 
|  454     // resources from the old one with resources from the new one which would |  456     // resources from the old one with resources from the new one which would | 
|  455     // have the same id. Changing the layer to showing painted content destroys |  457     // have the same id. Changing the layer to showing painted content destroys | 
|  456     // the DelegatedRendererLayer. |  458     // the DelegatedRendererLayer. | 
|  457     EvictDelegatedFrame(); |  459     EvictDelegatedFrame(); | 
|  458  |  460  | 
|  459     surface_factory_.reset(); |  461     surface_factory_->Reset(); | 
|  460     if (!surface_returned_resources_.empty()) { |  462     if (!surface_returned_resources_.empty()) { | 
|  461       SendReclaimCompositorResources(last_compositor_frame_sink_id_, |  463       SendReclaimCompositorResources(last_compositor_frame_sink_id_, | 
|  462                                      false /* is_swap_ack */); |  464                                      false /* is_swap_ack */); | 
|  463     } |  465     } | 
|  464     last_compositor_frame_sink_id_ = compositor_frame_sink_id; |  466     last_compositor_frame_sink_id_ = compositor_frame_sink_id; | 
|  465   } |  467   } | 
|  466   bool skip_frame = false; |  468   bool skip_frame = false; | 
|  467   pending_delegated_ack_count_++; |  469   pending_delegated_ack_count_++; | 
|  468  |  470  | 
|  469   background_color_ = frame.metadata.root_background_color; |  471   background_color_ = frame.metadata.root_background_color; | 
|  470  |  472  | 
|  471   if (frame_size.IsEmpty()) { |  473   if (frame_size.IsEmpty()) { | 
|  472     DCHECK(frame.resource_list.empty()); |  474     DCHECK(frame.resource_list.empty()); | 
|  473     EvictDelegatedFrame(); |  475     EvictDelegatedFrame(); | 
|  474   } else { |  476   } else { | 
|  475     ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |  477     ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 
|  476     cc::SurfaceManager* manager = factory->GetSurfaceManager(); |  478     cc::SurfaceManager* manager = factory->GetSurfaceManager(); | 
|  477     if (!surface_factory_) { |  | 
|  478       surface_factory_ = |  | 
|  479           base::MakeUnique<cc::SurfaceFactory>(frame_sink_id_, manager, this); |  | 
|  480     } |  | 
|  481     if (local_frame_id_.is_null() || frame_size != current_surface_size_ || |  479     if (local_frame_id_.is_null() || frame_size != current_surface_size_ || | 
|  482         frame_size_in_dip != current_frame_size_in_dip_) { |  480         frame_size_in_dip != current_frame_size_in_dip_) { | 
|  483       if (!local_frame_id_.is_null()) |  481       if (!local_frame_id_.is_null()) | 
|  484         surface_factory_->Destroy(local_frame_id_); |  482         surface_factory_->Destroy(local_frame_id_); | 
|  485       local_frame_id_ = id_allocator_->GenerateId(); |  483       local_frame_id_ = id_allocator_->GenerateId(); | 
|  486       surface_factory_->Create(local_frame_id_); |  484       surface_factory_->Create(local_frame_id_); | 
|  487       // manager must outlive compositors using it. |  485       // manager must outlive compositors using it. | 
|  488       client_->DelegatedFrameHostGetLayer()->SetShowSurface( |  486       client_->DelegatedFrameHostGetLayer()->SetShowSurface( | 
|  489           cc::SurfaceId(frame_sink_id_, local_frame_id_), |  487           cc::SurfaceId(frame_sink_id_, local_frame_id_), | 
|  490           base::Bind(&SatisfyCallback, base::Unretained(manager)), |  488           base::Bind(&SatisfyCallback, base::Unretained(manager)), | 
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  883         std::move(request)); |  881         std::move(request)); | 
|  884   } |  882   } | 
|  885 } |  883 } | 
|  886  |  884  | 
|  887 void DelegatedFrameHost::UnlockResources() { |  885 void DelegatedFrameHost::UnlockResources() { | 
|  888   DCHECK(!local_frame_id_.is_null()); |  886   DCHECK(!local_frame_id_.is_null()); | 
|  889   delegated_frame_evictor_->UnlockFrame(); |  887   delegated_frame_evictor_->UnlockFrame(); | 
|  890 } |  888 } | 
|  891  |  889  | 
|  892 }  // namespace content |  890 }  // namespace content | 
| OLD | NEW |