Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "cc/surfaces/compositor_frame_sink_support.h" | 5 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "cc/output/compositor_frame.h" | 11 #include "cc/output/compositor_frame.h" |
| 12 #include "cc/scheduler/begin_frame_source.h" | 12 #include "cc/scheduler/begin_frame_source.h" |
| 13 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 13 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 14 #include "cc/surfaces/display.h" | 14 #include "cc/surfaces/display.h" |
| 15 #include "cc/surfaces/surface.h" | 15 #include "cc/surfaces/surface.h" |
| 16 #include "cc/surfaces/surface_manager.h" | 16 #include "cc/surfaces/surface_manager.h" |
| 17 #include "cc/surfaces/surface_reference.h" | 17 #include "cc/surfaces/surface_reference.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 CompositorFrameSinkSupport::CompositorFrameSinkSupport( | 21 CompositorFrameSinkSupport::CompositorFrameSinkSupport( |
| 22 CompositorFrameSinkSupportClient* client, | 22 CompositorFrameSinkSupportClient* client, |
| 23 SurfaceManager* surface_manager, | 23 SurfaceManager* surface_manager, |
| 24 const FrameSinkId& frame_sink_id, | 24 const FrameSinkId& frame_sink_id, |
| 25 Display* display, | |
| 26 bool handles_frame_sink_id_invalidation, | 25 bool handles_frame_sink_id_invalidation, |
| 27 bool needs_sync_points) | 26 bool needs_sync_points, |
| 27 bool has_display) | |
|
danakj
2017/02/08 19:23:38
it seems a bit unmeaningful to call this has_displ
Alex Z.
2017/02/08 21:26:47
Done.
| |
| 28 : client_(client), | 28 : client_(client), |
| 29 surface_manager_(surface_manager), | 29 surface_manager_(surface_manager), |
| 30 frame_sink_id_(frame_sink_id), | 30 frame_sink_id_(frame_sink_id), |
| 31 display_(display), | |
| 32 surface_factory_(frame_sink_id_, surface_manager_, this), | 31 surface_factory_(frame_sink_id_, surface_manager_, this), |
| 33 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), | 32 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), |
| 34 reference_tracker_(frame_sink_id), | 33 reference_tracker_(frame_sink_id), |
| 34 has_display_(has_display), | |
| 35 weak_factory_(this) { | 35 weak_factory_(this) { |
| 36 if (handles_frame_sink_id_invalidation_) | 36 if (handles_frame_sink_id_invalidation_) |
| 37 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 37 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 38 | 38 |
| 39 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 39 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 40 surface_factory_.set_needs_sync_points(needs_sync_points); | 40 surface_factory_.set_needs_sync_points(needs_sync_points); |
| 41 | |
| 42 if (display_) | |
| 43 display_->Initialize(this, surface_manager_); | |
| 44 } | 41 } |
| 45 | 42 |
| 46 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { | 43 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { |
| 47 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does | 44 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does |
| 48 // not call into |this| after it's deleted. | 45 // not call into |this| after it's deleted. |
| 49 SetNeedsBeginFrame(false); | 46 SetNeedsBeginFrame(false); |
| 50 | 47 |
| 51 // For display root surfaces, the surface is no longer going to be visible | 48 // For display root surfaces, the surface is no longer going to be visible |
| 52 // so make it unreachable from the top-level root. | 49 // so make it unreachable from the top-level root. |
| 53 if (surface_manager_->using_surface_references() && display_ && | 50 if (surface_manager_->using_surface_references() && has_display_ && |
| 54 reference_tracker_.current_surface_id().is_valid()) | 51 reference_tracker_.current_surface_id().is_valid()) |
| 55 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); | 52 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); |
| 56 | 53 |
| 57 for (auto& child_frame_sink_id : child_frame_sinks_) { | 54 for (auto& child_frame_sink_id : child_frame_sinks_) { |
| 58 DCHECK(child_frame_sink_id.is_valid()); | 55 DCHECK(child_frame_sink_id.is_valid()); |
| 59 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 56 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 60 child_frame_sink_id); | 57 child_frame_sink_id); |
| 61 } | 58 } |
| 62 // SurfaceFactory's destructor will attempt to return resources which will | 59 // SurfaceFactory's destructor will attempt to return resources which will |
| 63 // call back into here and access |client_| so we should destroy | 60 // call back into here and access |client_| so we should destroy |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 74 | 71 |
| 75 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 72 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 76 needs_begin_frame_ = needs_begin_frame; | 73 needs_begin_frame_ = needs_begin_frame; |
| 77 UpdateNeedsBeginFramesInternal(); | 74 UpdateNeedsBeginFramesInternal(); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void CompositorFrameSinkSupport::SubmitCompositorFrame( | 77 void CompositorFrameSinkSupport::SubmitCompositorFrame( |
| 81 const LocalSurfaceId& local_surface_id, | 78 const LocalSurfaceId& local_surface_id, |
| 82 CompositorFrame frame) { | 79 CompositorFrame frame) { |
| 83 ++ack_pending_count_; | 80 ++ack_pending_count_; |
| 84 if (display_) { | |
| 85 display_->SetLocalSurfaceId(local_surface_id, | |
| 86 frame.metadata.device_scale_factor); | |
| 87 } | |
| 88 | |
| 89 if (surface_manager_->using_surface_references()) { | 81 if (surface_manager_->using_surface_references()) { |
| 90 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); | 82 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); |
| 91 | 83 |
| 92 // Populate surface references to add/remove based on reference surfaces in | 84 // Populate surface references to add/remove based on reference surfaces in |
| 93 // current frame compared with the last frame. | 85 // current frame compared with the last frame. |
| 94 reference_tracker_.UpdateReferences(local_surface_id, | 86 reference_tracker_.UpdateReferences(local_surface_id, |
| 95 frame.metadata.referenced_surfaces); | 87 frame.metadata.referenced_surfaces); |
| 96 | 88 |
| 97 surface_factory_.SubmitCompositorFrame( | 89 surface_factory_.SubmitCompositorFrame( |
| 98 local_surface_id, std::move(frame), | 90 local_surface_id, std::move(frame), |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 117 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { | 109 void CompositorFrameSinkSupport::Satisfy(const SurfaceSequence& sequence) { |
| 118 surface_manager_->SatisfySequence(sequence); | 110 surface_manager_->SatisfySequence(sequence); |
| 119 } | 111 } |
| 120 | 112 |
| 121 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 113 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
| 122 const SurfaceId& last_surface_id, | 114 const SurfaceId& last_surface_id, |
| 123 const LocalSurfaceId& local_surface_id) { | 115 const LocalSurfaceId& local_surface_id) { |
| 124 const bool surface_id_changed = | 116 const bool surface_id_changed = |
| 125 last_surface_id.local_surface_id() != local_surface_id; | 117 last_surface_id.local_surface_id() != local_surface_id; |
| 126 | 118 |
| 127 // If this is a display root surface and the SurfaceId is changing, make the | 119 // If this is a display root surface and the SurfaceId is changing, make the |
|
xlai (Olivia)
2017/02/08 20:11:34
Not sure if this comment about "display root surfa
Alex Z.
2017/02/08 21:26:47
Yes, it's still relevant. Checking display_ is not
| |
| 128 // new SurfaceId reachable from the top-level root. | 120 // new SurfaceId reachable from the top-level root. |
| 129 if (display_ && surface_id_changed) | 121 if (has_display_ && surface_id_changed) |
| 130 AddTopLevelRootReference(reference_tracker_.current_surface_id()); | 122 AddTopLevelRootReference(reference_tracker_.current_surface_id()); |
| 131 | 123 |
| 132 // Add references based on CompositorFrame referenced surfaces. If the | 124 // Add references based on CompositorFrame referenced surfaces. If the |
| 133 // SurfaceId has changed all referenced surfaces will be in this list. | 125 // SurfaceId has changed all referenced surfaces will be in this list. |
| 134 if (!reference_tracker_.references_to_add().empty()) { | 126 if (!reference_tracker_.references_to_add().empty()) { |
| 135 surface_manager_->AddSurfaceReferences( | 127 surface_manager_->AddSurfaceReferences( |
| 136 reference_tracker_.references_to_add()); | 128 reference_tracker_.references_to_add()); |
| 137 } | 129 } |
| 138 | 130 |
| 139 // If this is a display root surface and the SurfaceId is changing, make the | 131 // If this is a display root surface and the SurfaceId is changing, make the |
| 140 // old SurfaceId unreachable from the top-level root. This needs to happen | 132 // old SurfaceId unreachable from the top-level root. This needs to happen |
| 141 // after adding all references for the new SurfaceId. | 133 // after adding all references for the new SurfaceId. |
| 142 if (display_ && surface_id_changed && last_surface_id.is_valid()) | 134 if (has_display_ && surface_id_changed && last_surface_id.is_valid()) |
| 143 RemoveTopLevelRootReference(last_surface_id); | 135 RemoveTopLevelRootReference(last_surface_id); |
| 144 | 136 |
| 145 // Remove references based on CompositorFrame referenced surfaces. If the | 137 // Remove references based on CompositorFrame referenced surfaces. If the |
| 146 // SurfaceId has changed this list will be empty. | 138 // SurfaceId has changed this list will be empty. |
| 147 if (!reference_tracker_.references_to_remove().empty()) { | 139 if (!reference_tracker_.references_to_remove().empty()) { |
| 148 DCHECK(!surface_id_changed); | 140 DCHECK(!surface_id_changed); |
| 149 surface_manager_->RemoveSurfaceReferences( | 141 surface_manager_->RemoveSurfaceReferences( |
| 150 reference_tracker_.references_to_remove()); | 142 reference_tracker_.references_to_remove()); |
| 151 } | 143 } |
| 152 } | 144 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 DCHECK(it->is_valid()); | 182 DCHECK(it->is_valid()); |
| 191 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 183 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 192 child_frame_sink_id); | 184 child_frame_sink_id); |
| 193 child_frame_sinks_.erase(it); | 185 child_frame_sinks_.erase(it); |
| 194 } | 186 } |
| 195 | 187 |
| 196 void CompositorFrameSinkSupport::ForceReclaimResources() { | 188 void CompositorFrameSinkSupport::ForceReclaimResources() { |
| 197 surface_factory_.ClearSurface(); | 189 surface_factory_.ClearSurface(); |
| 198 } | 190 } |
| 199 | 191 |
| 200 void CompositorFrameSinkSupport::DisplayOutputSurfaceLost() {} | |
| 201 | |
| 202 void CompositorFrameSinkSupport::DisplayWillDrawAndSwap( | |
| 203 bool will_draw_and_swap, | |
| 204 const RenderPassList& render_passes) {} | |
| 205 | |
| 206 void CompositorFrameSinkSupport::DisplayDidDrawAndSwap() {} | |
| 207 | |
| 208 void CompositorFrameSinkSupport::ReturnResources( | 192 void CompositorFrameSinkSupport::ReturnResources( |
| 209 const ReturnedResourceArray& resources) { | 193 const ReturnedResourceArray& resources) { |
| 210 if (resources.empty()) | 194 if (resources.empty()) |
| 211 return; | 195 return; |
| 212 | 196 |
| 213 if (!ack_pending_count_ && client_) { | 197 if (!ack_pending_count_ && client_) { |
| 214 client_->ReclaimResources(resources); | 198 client_->ReclaimResources(resources); |
| 215 return; | 199 return; |
| 216 } | 200 } |
| 217 | 201 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 return; | 242 return; |
| 259 | 243 |
| 260 added_frame_observer_ = needs_begin_frame_; | 244 added_frame_observer_ = needs_begin_frame_; |
| 261 if (needs_begin_frame_) | 245 if (needs_begin_frame_) |
| 262 begin_frame_source_->AddObserver(this); | 246 begin_frame_source_->AddObserver(this); |
| 263 else | 247 else |
| 264 begin_frame_source_->RemoveObserver(this); | 248 begin_frame_source_->RemoveObserver(this); |
| 265 } | 249 } |
| 266 | 250 |
| 267 } // namespace cc | 251 } // namespace cc |
| OLD | NEW |