| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/display_compositor/gpu_compositor_frame_sink.h" | 5 #include "components/display_compositor/gpu_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include "cc/surfaces/surface_reference.h" | 7 #include "cc/surfaces/surface_reference.h" |
| 8 | 8 |
| 9 namespace display_compositor { | 9 namespace display_compositor { |
| 10 | 10 |
| 11 GpuCompositorFrameSink::GpuCompositorFrameSink( | 11 GpuCompositorFrameSink::GpuCompositorFrameSink( |
| 12 GpuCompositorFrameSinkDelegate* delegate, | 12 GpuCompositorFrameSinkDelegate* delegate, |
| 13 cc::SurfaceManager* surface_manager, | 13 cc::SurfaceManager* surface_manager, |
| 14 const cc::FrameSinkId& frame_sink_id, | 14 const cc::FrameSinkId& frame_sink_id, |
| 15 std::unique_ptr<cc::Display> display, | 15 std::unique_ptr<cc::Display> display, |
| 16 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, | 16 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, |
| 17 cc::mojom::MojoCompositorFrameSinkPrivateRequest | 17 cc::mojom::MojoCompositorFrameSinkPrivateRequest |
| 18 compositor_frame_sink_private_request, | 18 compositor_frame_sink_private_request, |
| 19 cc::mojom::MojoCompositorFrameSinkClientPtr client) | 19 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
| 20 : delegate_(delegate), | 20 : delegate_(delegate), |
| 21 support_(this, | 21 support_(this, |
| 22 surface_manager, | 22 surface_manager, |
| 23 frame_sink_id, | 23 frame_sink_id, |
| 24 std::move(display), | 24 std::move(display), |
| 25 std::move(begin_frame_source)), | 25 std::move(begin_frame_source)), |
| 26 surface_manager_(surface_manager), | 26 surface_manager_(surface_manager), |
| 27 surface_tracker_(frame_sink_id), | |
| 28 client_(std::move(client)), | 27 client_(std::move(client)), |
| 29 compositor_frame_sink_private_binding_( | 28 compositor_frame_sink_private_binding_( |
| 30 this, | 29 this, |
| 31 std::move(compositor_frame_sink_private_request)) { | 30 std::move(compositor_frame_sink_private_request)) { |
| 32 compositor_frame_sink_private_binding_.set_connection_error_handler( | 31 compositor_frame_sink_private_binding_.set_connection_error_handler( |
| 33 base::Bind(&GpuCompositorFrameSink::OnPrivateConnectionLost, | 32 base::Bind(&GpuCompositorFrameSink::OnPrivateConnectionLost, |
| 34 base::Unretained(this))); | 33 base::Unretained(this))); |
| 35 } | 34 } |
| 36 | 35 |
| 37 GpuCompositorFrameSink::~GpuCompositorFrameSink() { | 36 GpuCompositorFrameSink::~GpuCompositorFrameSink() {} |
| 38 // For display root surfaces, remove the reference from top level root to | |
| 39 // indicate the display root surface is no longer visible. | |
| 40 if (support_.display() && surface_tracker_.current_surface_id().is_valid()) { | |
| 41 const cc::SurfaceId top_level_root_surface_id = | |
| 42 surface_manager_->GetRootSurfaceId(); | |
| 43 std::vector<cc::SurfaceReference> references_to_remove{cc::SurfaceReference( | |
| 44 top_level_root_surface_id, surface_tracker_.current_surface_id())}; | |
| 45 surface_manager_->RemoveSurfaceReferences(references_to_remove); | |
| 46 } | |
| 47 } | |
| 48 | 37 |
| 49 void GpuCompositorFrameSink::EvictFrame() { | 38 void GpuCompositorFrameSink::EvictFrame() { |
| 50 support_.EvictFrame(); | 39 support_.EvictFrame(); |
| 51 } | 40 } |
| 52 | 41 |
| 53 void GpuCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { | 42 void GpuCompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 54 support_.SetNeedsBeginFrame(needs_begin_frame); | 43 support_.SetNeedsBeginFrame(needs_begin_frame); |
| 55 } | 44 } |
| 56 | 45 |
| 57 void GpuCompositorFrameSink::SubmitCompositorFrame( | 46 void GpuCompositorFrameSink::SubmitCompositorFrame( |
| 58 const cc::LocalSurfaceId& local_surface_id, | 47 const cc::LocalSurfaceId& local_surface_id, |
| 59 cc::CompositorFrame frame) { | 48 cc::CompositorFrame frame) { |
| 60 cc::SurfaceId start_surface_id = surface_tracker_.current_surface_id(); | |
| 61 surface_tracker_.UpdateReferences(local_surface_id, | |
| 62 frame.metadata.referenced_surfaces); | |
| 63 // TODO(kylechar): Move adding top-level root references to | |
| 64 // GpuDisplayCompositorFrameSink. | |
| 65 | |
| 66 support_.SubmitCompositorFrame(local_surface_id, std::move(frame)); | 49 support_.SubmitCompositorFrame(local_surface_id, std::move(frame)); |
| 67 | |
| 68 // Get the list of surfaces to add/remove from |surface_tracker_| so we can | |
| 69 // append to them before adding/removing. | |
| 70 std::vector<cc::SurfaceReference>& references_to_add = | |
| 71 surface_tracker_.references_to_add(); | |
| 72 std::vector<cc::SurfaceReference>& references_to_remove = | |
| 73 surface_tracker_.references_to_remove(); | |
| 74 | |
| 75 // Append TLR references for the display root surfaces when display root | |
| 76 // surface changes. | |
| 77 if (support_.display() && | |
| 78 start_surface_id != surface_tracker_.current_surface_id()) { | |
| 79 const cc::SurfaceId top_level_root_surface_id = | |
| 80 surface_manager_->GetRootSurfaceId(); | |
| 81 | |
| 82 // The first frame will not have a valid |start_surface_id| and there will | |
| 83 // be no surface to remove. | |
| 84 if (start_surface_id.local_surface_id().is_valid()) { | |
| 85 references_to_remove.push_back( | |
| 86 cc::SurfaceReference(top_level_root_surface_id, start_surface_id)); | |
| 87 } | |
| 88 | |
| 89 references_to_add.push_back(cc::SurfaceReference( | |
| 90 top_level_root_surface_id, surface_tracker_.current_surface_id())); | |
| 91 } | |
| 92 | |
| 93 if (!references_to_add.empty()) | |
| 94 surface_manager_->AddSurfaceReferences(references_to_add); | |
| 95 if (!references_to_remove.empty()) | |
| 96 surface_manager_->RemoveSurfaceReferences(references_to_remove); | |
| 97 } | 50 } |
| 98 | 51 |
| 99 void GpuCompositorFrameSink::Require(const cc::LocalSurfaceId& local_surface_id, | 52 void GpuCompositorFrameSink::Require(const cc::LocalSurfaceId& local_surface_id, |
| 100 const cc::SurfaceSequence& sequence) { | 53 const cc::SurfaceSequence& sequence) { |
| 101 support_.Require(local_surface_id, sequence); | 54 support_.Require(local_surface_id, sequence); |
| 102 } | 55 } |
| 103 | 56 |
| 104 void GpuCompositorFrameSink::Satisfy(const cc::SurfaceSequence& sequence) { | 57 void GpuCompositorFrameSink::Satisfy(const cc::SurfaceSequence& sequence) { |
| 105 support_.Satisfy(sequence); | 58 support_.Satisfy(sequence); |
| 106 } | 59 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 97 } |
| 145 | 98 |
| 146 void GpuCompositorFrameSink::OnPrivateConnectionLost() { | 99 void GpuCompositorFrameSink::OnPrivateConnectionLost() { |
| 147 private_connection_lost_ = true; | 100 private_connection_lost_ = true; |
| 148 // Request destruction of |this| only if both connections are lost. | 101 // Request destruction of |this| only if both connections are lost. |
| 149 delegate_->OnPrivateConnectionLost(support_.frame_sink_id(), | 102 delegate_->OnPrivateConnectionLost(support_.frame_sink_id(), |
| 150 client_connection_lost_); | 103 client_connection_lost_); |
| 151 } | 104 } |
| 152 | 105 |
| 153 } // namespace display_compositor | 106 } // namespace display_compositor |
| OLD | NEW |