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 | 9 |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/scheduler/begin_frame_source.h" | 11 #include "cc/scheduler/begin_frame_source.h" |
| 12 #include "cc/surfaces/compositor_frame_sink_support_client.h" | 12 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 13 #include "cc/surfaces/display.h" | 13 #include "cc/surfaces/display.h" |
| 14 #include "cc/surfaces/surface.h" | 14 #include "cc/surfaces/surface.h" |
| 15 #include "cc/surfaces/surface_info.h" | |
| 15 #include "cc/surfaces/surface_manager.h" | 16 #include "cc/surfaces/surface_manager.h" |
| 16 #include "cc/surfaces/surface_reference.h" | 17 #include "cc/surfaces/surface_reference.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 | 20 |
| 20 // static | 21 // static |
| 21 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create( | 22 std::unique_ptr<CompositorFrameSinkSupport> CompositorFrameSinkSupport::Create( |
| 22 CompositorFrameSinkSupportClient* client, | 23 CompositorFrameSinkSupportClient* client, |
| 23 SurfaceManager* surface_manager, | 24 SurfaceManager* surface_manager, |
| 24 const FrameSinkId& frame_sink_id, | 25 const FrameSinkId& frame_sink_id, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 36 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does | 37 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does |
| 37 // not call into |this| after it's deleted. | 38 // not call into |this| after it's deleted. |
| 38 SetNeedsBeginFrame(false); | 39 SetNeedsBeginFrame(false); |
| 39 | 40 |
| 40 // For display root surfaces, the surface is no longer going to be visible | 41 // For display root surfaces, the surface is no longer going to be visible |
| 41 // so make it unreachable from the top-level root. | 42 // so make it unreachable from the top-level root. |
| 42 if (surface_manager_->using_surface_references() && is_root_ && | 43 if (surface_manager_->using_surface_references() && is_root_ && |
| 43 reference_tracker_.current_surface_id().is_valid()) | 44 reference_tracker_.current_surface_id().is_valid()) |
| 44 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); | 45 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); |
| 45 | 46 |
| 46 // SurfaceFactory's destructor will attempt to return resources which will | 47 EvictFrame(); |
| 47 // call back into here and access |client_| so we should destroy | |
| 48 // |surface_factory_|'s resources early on. | |
| 49 surface_factory_->EvictSurface(); | |
| 50 surface_manager_->UnregisterFrameSinkManagerClient(frame_sink_id_); | 48 surface_manager_->UnregisterFrameSinkManagerClient(frame_sink_id_); |
| 51 if (handles_frame_sink_id_invalidation_) | 49 if (handles_frame_sink_id_invalidation_) |
| 52 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 50 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 53 } | 51 } |
| 54 | 52 |
| 55 void CompositorFrameSinkSupport::ReferencedSurfacesChanged( | |
| 56 const LocalSurfaceId& local_surface_id, | |
| 57 const std::vector<SurfaceId>* active_referenced_surfaces) { | |
| 58 if (!surface_manager_->using_surface_references()) | |
| 59 return; | |
| 60 | |
| 61 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); | |
| 62 | |
| 63 // Populate list of surface references to add and remove based on reference | |
| 64 // surfaces in current frame compared with the last frame. The list of | |
| 65 // surface references includes references from both the pending and active | |
| 66 // frame if any. | |
| 67 reference_tracker_.UpdateReferences(local_surface_id, | |
| 68 active_referenced_surfaces); | |
| 69 | |
| 70 UpdateSurfaceReferences(last_surface_id, local_surface_id); | |
| 71 } | |
| 72 | |
| 73 void CompositorFrameSinkSupport::ReturnResources( | 53 void CompositorFrameSinkSupport::ReturnResources( |
| 74 const ReturnedResourceArray& resources) { | 54 const ReturnedResourceArray& resources) { |
| 75 if (resources.empty()) | 55 if (resources.empty()) |
| 76 return; | 56 return; |
| 57 | |
|
Fady Samuel
2017/04/26 00:44:13
unnecessary change. Please delete.
Alex Z.
2017/04/27 22:10:01
Done.
| |
| 77 if (!ack_pending_count_ && client_) { | 58 if (!ack_pending_count_ && client_) { |
| 78 client_->ReclaimResources(resources); | 59 client_->ReclaimResources(resources); |
| 79 return; | 60 return; |
| 80 } | 61 } |
| 81 | 62 |
| 82 std::copy(resources.begin(), resources.end(), | 63 std::copy(resources.begin(), resources.end(), |
| 83 std::back_inserter(surface_returned_resources_)); | 64 std::back_inserter(surface_returned_resources_)); |
| 84 } | 65 } |
| 85 | 66 |
| 86 void CompositorFrameSinkSupport::SetBeginFrameSource( | 67 void CompositorFrameSinkSupport::SetBeginFrameSource( |
| 87 BeginFrameSource* begin_frame_source) { | 68 BeginFrameSource* begin_frame_source) { |
| 88 if (begin_frame_source_ && added_frame_observer_) { | 69 if (begin_frame_source_ && added_frame_observer_) { |
| 89 begin_frame_source_->RemoveObserver(this); | 70 begin_frame_source_->RemoveObserver(this); |
| 90 added_frame_observer_ = false; | 71 added_frame_observer_ = false; |
| 91 } | 72 } |
| 92 begin_frame_source_ = begin_frame_source; | 73 begin_frame_source_ = begin_frame_source; |
| 93 UpdateNeedsBeginFramesInternal(); | 74 UpdateNeedsBeginFramesInternal(); |
| 94 } | 75 } |
| 95 | 76 |
| 96 void CompositorFrameSinkSupport::EvictFrame() { | 77 void CompositorFrameSinkSupport::EvictFrame() { |
| 97 DCHECK(surface_factory_); | 78 if (!current_surface_) |
| 98 surface_factory_->EvictSurface(); | 79 return; |
| 80 DestroyCurrentSurface(); | |
| 99 } | 81 } |
| 100 | 82 |
| 101 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 83 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 102 needs_begin_frame_ = needs_begin_frame; | 84 needs_begin_frame_ = needs_begin_frame; |
| 103 UpdateNeedsBeginFramesInternal(); | 85 UpdateNeedsBeginFramesInternal(); |
| 104 } | 86 } |
| 105 | 87 |
| 106 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( | 88 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( |
| 107 const BeginFrameAck& ack) { | 89 const BeginFrameAck& ack) { |
| 108 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we | 90 // TODO(eseckler): While a pending CompositorFrame exists (see TODO below), we |
| 109 // should not acknowledge immediately. Instead, we should update the ack that | 91 // should not acknowledge immediately. Instead, we should update the ack that |
| 110 // will be sent to DisplayScheduler when the pending frame is activated. | 92 // will be sent to DisplayScheduler when the pending frame is activated. |
| 111 if (ack.sequence_number < BeginFrameArgs::kStartingFrameNumber) { | 93 if (ack.sequence_number < BeginFrameArgs::kStartingFrameNumber) { |
| 112 DLOG(ERROR) << "Received BeginFrameDidNotSwap with invalid BeginFrameAck."; | 94 DLOG(ERROR) << "Received BeginFrameDidNotSwap with invalid BeginFrameAck."; |
| 113 return; | 95 return; |
| 114 } | 96 } |
| 115 | 97 |
| 116 // |has_damage| is not transmitted, but false by default. | 98 // |has_damage| is not transmitted, but false by default. |
| 117 DCHECK(!ack.has_damage); | 99 DCHECK(!ack.has_damage); |
| 118 if (begin_frame_source_) | 100 if (begin_frame_source_) |
| 119 begin_frame_source_->DidFinishFrame(this, ack); | 101 begin_frame_source_->DidFinishFrame(this, ack); |
| 120 } | 102 } |
| 121 | 103 |
| 122 void CompositorFrameSinkSupport::SubmitCompositorFrame( | 104 void CompositorFrameSinkSupport::SubmitCompositorFrame( |
| 123 const LocalSurfaceId& local_surface_id, | 105 const LocalSurfaceId& local_surface_id, |
| 124 CompositorFrame frame) { | 106 CompositorFrame frame) { |
| 125 DCHECK(surface_factory_); | 107 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); |
| 108 DCHECK(local_surface_id.is_valid()); | |
| 109 TRACE_EVENT0("cc", "CompositorFrameSinkSupport::SubmitCompositorFrame"); | |
|
Fady Samuel
2017/04/26 00:44:13
Why is this trace event listed twice?
Alex Z.
2017/04/27 22:10:01
It must've got during rebase. It's removed now.
| |
| 126 ++ack_pending_count_; | 110 ++ack_pending_count_; |
| 127 | 111 |
| 128 if (frame.metadata.begin_frame_ack.sequence_number < | 112 if (frame.metadata.begin_frame_ack.sequence_number < |
| 129 BeginFrameArgs::kStartingFrameNumber) { | 113 BeginFrameArgs::kStartingFrameNumber) { |
| 130 DLOG(ERROR) << "Received CompositorFrame with invalid BeginFrameAck."; | 114 DLOG(ERROR) << "Received CompositorFrame with invalid BeginFrameAck."; |
| 131 frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId; | 115 frame.metadata.begin_frame_ack.source_id = BeginFrameArgs::kManualSourceId; |
| 132 frame.metadata.begin_frame_ack.sequence_number = | 116 frame.metadata.begin_frame_ack.sequence_number = |
| 133 BeginFrameArgs::kStartingFrameNumber; | 117 BeginFrameArgs::kStartingFrameNumber; |
| 134 } | 118 } |
| 135 // |has_damage| is not transmitted. | 119 // |has_damage| is not transmitted. |
| 136 frame.metadata.begin_frame_ack.has_damage = true; | 120 frame.metadata.begin_frame_ack.has_damage = true; |
| 137 | 121 |
| 138 BeginFrameAck ack = frame.metadata.begin_frame_ack; | 122 BeginFrameAck ack = frame.metadata.begin_frame_ack; |
| 139 surface_factory_->SubmitCompositorFrame( | 123 |
| 140 local_surface_id, std::move(frame), | 124 DCHECK(local_surface_id.is_valid()); |
| 125 | |
| 126 for (ui::LatencyInfo& latency : frame.metadata.latency_info) { | |
| 127 if (latency.latency_components().size() > 0) { | |
| 128 latency.AddLatencyNumber(ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, | |
| 129 0, 0); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 std::unique_ptr<Surface> surface; | |
| 134 bool create_new_surface = | |
| 135 (!current_surface_ || | |
| 136 local_surface_id != current_surface_->surface_id().local_surface_id()); | |
| 137 if (!create_new_surface) { | |
| 138 surface = std::move(current_surface_); | |
| 139 } else { | |
| 140 surface = CreateSurface(local_surface_id); | |
| 141 } | |
| 142 surface->QueueFrame( | |
| 143 std::move(frame), | |
| 141 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, | 144 base::Bind(&CompositorFrameSinkSupport::DidReceiveCompositorFrameAck, |
| 142 weak_factory_.GetWeakPtr()), | 145 weak_factory_.GetWeakPtr()), |
| 143 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, | 146 base::BindRepeating(&CompositorFrameSinkSupport::WillDrawSurface, |
| 144 weak_factory_.GetWeakPtr())); | 147 weak_factory_.GetWeakPtr())); |
| 145 | 148 |
| 149 if (current_surface_ && create_new_surface) { | |
| 150 surface->SetPreviousFrameSurface(current_surface_.get()); | |
| 151 DestroyCurrentSurface(); | |
| 152 } | |
| 153 current_surface_ = std::move(surface); | |
| 154 | |
| 146 // TODO(eseckler): The CompositorFrame submitted below might not be activated | 155 // TODO(eseckler): The CompositorFrame submitted below might not be activated |
| 147 // right away b/c of surface synchronization. We should only send the | 156 // right away b/c of surface synchronization. We should only send the |
| 148 // BeginFrameAck to DisplayScheduler when it is activated. This also means | 157 // BeginFrameAck to DisplayScheduler when it is activated. This also means |
| 149 // that we need to stay an active BFO while a CompositorFrame is pending. | 158 // that we need to stay an active BFO while a CompositorFrame is pending. |
| 150 // See https://crbug.com/703079. | 159 // See https://crbug.com/703079. |
| 151 if (begin_frame_source_) | 160 if (begin_frame_source_) |
| 152 begin_frame_source_->DidFinishFrame(this, ack); | 161 begin_frame_source_->DidFinishFrame(this, ack); |
| 153 } | 162 } |
| 154 | 163 |
| 155 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 164 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id); | 199 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id); |
| 191 surface_manager_->AddSurfaceReferences({reference}); | 200 surface_manager_->AddSurfaceReferences({reference}); |
| 192 } | 201 } |
| 193 | 202 |
| 194 void CompositorFrameSinkSupport::RemoveTopLevelRootReference( | 203 void CompositorFrameSinkSupport::RemoveTopLevelRootReference( |
| 195 const SurfaceId& surface_id) { | 204 const SurfaceId& surface_id) { |
| 196 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id); | 205 SurfaceReference reference(surface_manager_->GetRootSurfaceId(), surface_id); |
| 197 surface_manager_->RemoveSurfaceReferences({reference}); | 206 surface_manager_->RemoveSurfaceReferences({reference}); |
| 198 } | 207 } |
| 199 | 208 |
| 209 void CompositorFrameSinkSupport::ReferencedSurfacesChanged( | |
| 210 const LocalSurfaceId& local_surface_id, | |
| 211 const std::vector<SurfaceId>* active_referenced_surfaces) { | |
| 212 if (!surface_manager_->using_surface_references()) | |
| 213 return; | |
| 214 | |
| 215 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); | |
| 216 | |
| 217 // Populate list of surface references to add and remove based on reference | |
| 218 // surfaces in current frame compared with the last frame. The list of | |
| 219 // surface references includes references from both the pending and active | |
| 220 // frame if any. | |
| 221 reference_tracker_.UpdateReferences(local_surface_id, | |
| 222 active_referenced_surfaces); | |
| 223 | |
| 224 UpdateSurfaceReferences(last_surface_id, local_surface_id); | |
| 225 } | |
| 226 | |
| 200 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { | 227 void CompositorFrameSinkSupport::DidReceiveCompositorFrameAck() { |
| 201 DCHECK_GT(ack_pending_count_, 0); | 228 DCHECK_GT(ack_pending_count_, 0); |
| 202 ack_pending_count_--; | 229 ack_pending_count_--; |
| 203 if (!client_) | 230 if (!client_) |
| 204 return; | 231 return; |
| 232 | |
| 205 client_->DidReceiveCompositorFrameAck(surface_returned_resources_); | 233 client_->DidReceiveCompositorFrameAck(surface_returned_resources_); |
| 206 surface_returned_resources_.clear(); | 234 surface_returned_resources_.clear(); |
| 207 } | 235 } |
| 208 | 236 |
| 209 void CompositorFrameSinkSupport::WillDrawSurface( | 237 void CompositorFrameSinkSupport::WillDrawSurface( |
| 210 const LocalSurfaceId& local_surface_id, | 238 const LocalSurfaceId& local_surface_id, |
| 211 const gfx::Rect& damage_rect) { | 239 const gfx::Rect& damage_rect) { |
| 212 if (client_) | 240 if (client_) |
| 213 client_->WillDrawSurface(local_surface_id, damage_rect); | 241 client_->WillDrawSurface(local_surface_id, damage_rect); |
| 214 } | 242 } |
| 215 | 243 |
| 216 void CompositorFrameSinkSupport::ForceReclaimResources() { | 244 void CompositorFrameSinkSupport::ForceReclaimResources() { |
|
Fady Samuel
2017/04/26 00:44:13
This should be going away now.
Alex Z.
2017/04/27 22:10:01
Done.
| |
| 217 DCHECK(surface_factory_); | 245 if (!current_surface_) |
| 218 surface_factory_->ClearSurface(); | 246 return; |
| 247 current_surface_->EvictFrame(); | |
| 248 surface_manager_->SurfaceModified(current_surface_->surface_id()); | |
| 219 } | 249 } |
| 220 | 250 |
| 221 void CompositorFrameSinkSupport::ClaimTemporaryReference( | 251 void CompositorFrameSinkSupport::ClaimTemporaryReference( |
| 222 const SurfaceId& surface_id) { | 252 const SurfaceId& surface_id) { |
| 223 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); | 253 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); |
| 224 } | 254 } |
| 225 | 255 |
| 256 void CompositorFrameSinkSupport::ReceiveFromChild( | |
|
Fady Samuel
2017/04/26 00:44:13
It would be nice not having these public..
Alex Z.
2017/04/27 22:10:01
Done.
| |
| 257 const TransferableResourceArray& resources) { | |
| 258 surface_resource_holder_.ReceiveFromChild(resources); | |
| 259 } | |
| 260 | |
| 261 void CompositorFrameSinkSupport::RefResources( | |
| 262 const TransferableResourceArray& resources) { | |
| 263 surface_resource_holder_.RefResources(resources); | |
| 264 } | |
| 265 | |
| 266 void CompositorFrameSinkSupport::UnrefResources( | |
| 267 const ReturnedResourceArray& resources) { | |
| 268 surface_resource_holder_.UnrefResources(resources); | |
| 269 } | |
| 270 | |
| 271 void CompositorFrameSinkSupport::ForceAck() { | |
|
Fady Samuel
2017/04/26 00:44:13
What uses this? Delete it perhaps?
Alex Z.
2017/04/27 22:10:01
Done.
| |
| 272 ++ack_pending_count_; | |
| 273 DidReceiveCompositorFrameAck(); | |
| 274 } | |
| 275 | |
| 226 CompositorFrameSinkSupport::CompositorFrameSinkSupport( | 276 CompositorFrameSinkSupport::CompositorFrameSinkSupport( |
| 227 CompositorFrameSinkSupportClient* client, | 277 CompositorFrameSinkSupportClient* client, |
| 228 const FrameSinkId& frame_sink_id, | 278 const FrameSinkId& frame_sink_id, |
| 229 bool is_root, | 279 bool is_root, |
| 230 bool handles_frame_sink_id_invalidation) | 280 bool handles_frame_sink_id_invalidation) |
| 231 : client_(client), | 281 : client_(client), |
| 232 frame_sink_id_(frame_sink_id), | 282 frame_sink_id_(frame_sink_id), |
| 283 surface_resource_holder_(this), | |
| 233 reference_tracker_(frame_sink_id), | 284 reference_tracker_(frame_sink_id), |
| 234 is_root_(is_root), | 285 is_root_(is_root), |
| 235 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), | 286 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), |
| 236 weak_factory_(this) {} | 287 weak_factory_(this) {} |
| 237 | 288 |
| 238 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager, | 289 void CompositorFrameSinkSupport::Init(SurfaceManager* surface_manager, |
| 239 bool needs_sync_points) { | 290 bool needs_sync_points) { |
| 240 surface_manager_ = surface_manager; | 291 surface_manager_ = surface_manager; |
| 241 surface_factory_ = base::MakeUnique<SurfaceFactory>( | |
| 242 frame_sink_id_, surface_manager_, this, this); | |
| 243 if (handles_frame_sink_id_invalidation_) | 292 if (handles_frame_sink_id_invalidation_) |
| 244 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 293 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 245 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); | 294 surface_manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this); |
| 246 surface_factory_->set_needs_sync_points(needs_sync_points); | 295 needs_sync_points_ = needs_sync_points; |
| 247 } | 296 } |
| 248 | 297 |
| 249 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { | 298 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { |
| 250 UpdateNeedsBeginFramesInternal(); | 299 UpdateNeedsBeginFramesInternal(); |
| 251 last_begin_frame_args_ = args; | 300 last_begin_frame_args_ = args; |
| 252 if (client_) | 301 if (client_) |
| 253 client_->OnBeginFrame(args); | 302 client_->OnBeginFrame(args); |
| 254 } | 303 } |
| 255 | 304 |
| 256 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() | 305 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() |
| 257 const { | 306 const { |
| 258 return last_begin_frame_args_; | 307 return last_begin_frame_args_; |
| 259 } | 308 } |
| 260 | 309 |
| 261 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} | 310 void CompositorFrameSinkSupport::OnBeginFrameSourcePausedChanged(bool paused) {} |
| 262 | 311 |
| 312 void CompositorFrameSinkSupport::OnSurfaceActivated(Surface* surface) { | |
| 313 DCHECK(surface->HasActiveFrame()); | |
| 314 // TODO(staraz): Notify BeginFrameSource about the last activated sequence | |
| 315 // number. | |
| 316 if (!seen_first_frame_activation_) { | |
| 317 seen_first_frame_activation_ = true; | |
| 318 | |
| 319 const CompositorFrame& frame = surface->GetActiveFrame(); | |
| 320 // CompositorFrames might not be populated with a RenderPass in unit tests. | |
| 321 gfx::Size frame_size; | |
| 322 if (!frame.render_pass_list.empty()) | |
| 323 frame_size = frame.render_pass_list.back()->output_rect.size(); | |
| 324 | |
| 325 // SurfaceCreated only applies for the first Surface activation. Thus, | |
| 326 // SurfaceFactory stops observing new activations after the first one. | |
| 327 surface_manager_->SurfaceCreated(SurfaceInfo( | |
| 328 surface->surface_id(), frame.metadata.device_scale_factor, frame_size)); | |
| 329 } | |
| 330 // Fire SurfaceCreated first so that a temporary reference is added before it | |
| 331 // is potentially transformed into a real reference by the client. | |
| 332 ReferencedSurfacesChanged(surface->surface_id().local_surface_id(), | |
| 333 surface->active_referenced_surfaces()); | |
| 334 if (!surface_manager_->SurfaceModified(surface->surface_id())) { | |
| 335 TRACE_EVENT_INSTANT0("cc", "Damage not visible.", TRACE_EVENT_SCOPE_THREAD); | |
| 336 surface->RunDrawCallback(); | |
| 337 } | |
| 338 } | |
| 339 | |
| 340 void CompositorFrameSinkSupport::OnSurfaceDependenciesChanged( | |
| 341 Surface* surface, | |
| 342 const SurfaceDependencies& added_dependencies, | |
| 343 const SurfaceDependencies& removed_dependencies) {} | |
| 344 | |
| 345 void CompositorFrameSinkSupport::OnSurfaceDiscarded(Surface* surface) {} | |
| 346 | |
| 263 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { | 347 void CompositorFrameSinkSupport::UpdateNeedsBeginFramesInternal() { |
| 264 if (!begin_frame_source_) | 348 if (!begin_frame_source_) |
| 265 return; | 349 return; |
| 266 | 350 |
| 267 if (needs_begin_frame_ == added_frame_observer_) | 351 if (needs_begin_frame_ == added_frame_observer_) |
| 268 return; | 352 return; |
| 269 | 353 |
| 270 added_frame_observer_ = needs_begin_frame_; | 354 added_frame_observer_ = needs_begin_frame_; |
| 271 if (needs_begin_frame_) | 355 if (needs_begin_frame_) |
| 272 begin_frame_source_->AddObserver(this); | 356 begin_frame_source_->AddObserver(this); |
| 273 else | 357 else |
| 274 begin_frame_source_->RemoveObserver(this); | 358 begin_frame_source_->RemoveObserver(this); |
| 275 } | 359 } |
| 276 | 360 |
| 361 std::unique_ptr<Surface> CompositorFrameSinkSupport::CreateSurface( | |
| 362 const LocalSurfaceId& local_surface_id) { | |
| 363 seen_first_frame_activation_ = false; | |
| 364 std::unique_ptr<Surface> surface = surface_manager_->CreateSurface( | |
| 365 weak_factory_.GetWeakPtr(), local_surface_id); | |
| 366 surface->AddObserver(this); | |
| 367 return surface; | |
| 368 } | |
| 369 | |
| 370 void CompositorFrameSinkSupport::DestroyCurrentSurface() { | |
| 371 current_surface_->RemoveObserver(this); | |
| 372 surface_manager_->DestroySurface(std::move(current_surface_)); | |
| 373 } | |
| 374 | |
| 277 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 375 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
| 278 std::unique_ptr<CopyOutputRequest> request) { | 376 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 279 DCHECK(surface_factory_); | 377 if (!current_surface_) { |
| 280 surface_factory_->RequestCopyOfSurface(std::move(request)); | 378 copy_request->SendEmptyResult(); |
| 379 return; | |
| 380 } | |
| 381 DCHECK(current_surface_->compositor_frame_sink_support().get() == this); | |
| 382 current_surface_->RequestCopyOfOutput(std::move(copy_request)); | |
| 383 surface_manager_->SurfaceModified(current_surface_->surface_id()); | |
| 281 } | 384 } |
| 282 | 385 |
| 283 } // namespace cc | 386 } // namespace cc |
| OLD | NEW |