| 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 bool submits_to_display_compositor) | 25 bool is_root, |
| 26 bool handles_frame_sink_id_invalidation, |
| 27 bool needs_sync_points) |
| 26 : client_(client), | 28 : client_(client), |
| 27 surface_manager_(surface_manager), | 29 surface_manager_(surface_manager), |
| 28 frame_sink_id_(frame_sink_id), | 30 frame_sink_id_(frame_sink_id), |
| 29 surface_factory_(frame_sink_id_, surface_manager_, this), | 31 surface_factory_(frame_sink_id_, surface_manager_, this), |
| 30 reference_tracker_(frame_sink_id), | 32 reference_tracker_(frame_sink_id), |
| 31 submits_to_display_compositor_(submits_to_display_compositor), | 33 is_root_(is_root), |
| 34 handles_frame_sink_id_invalidation_(handles_frame_sink_id_invalidation), |
| 32 weak_factory_(this) { | 35 weak_factory_(this) { |
| 33 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 36 surface_factory_.set_needs_sync_points(needs_sync_points); |
| 37 if (handles_frame_sink_id_invalidation_) |
| 38 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 34 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 39 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 35 } | 40 } |
| 36 | 41 |
| 37 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { | 42 CompositorFrameSinkSupport::~CompositorFrameSinkSupport() { |
| 43 // Unregister |this| as a BeginFrameObserver so that the BeginFrameSource does |
| 44 // not call into |this| after it's deleted. |
| 45 SetNeedsBeginFrame(false); |
| 46 |
| 38 // For display root surfaces, the surface is no longer going to be visible | 47 // For display root surfaces, the surface is no longer going to be visible |
| 39 // so make it unreachable from the top-level root. | 48 // so make it unreachable from the top-level root. |
| 40 if (surface_manager_->using_surface_references() && | 49 if (surface_manager_->using_surface_references() && is_root_ && |
| 41 submits_to_display_compositor_ && | |
| 42 reference_tracker_.current_surface_id().is_valid()) | 50 reference_tracker_.current_surface_id().is_valid()) |
| 43 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); | 51 RemoveTopLevelRootReference(reference_tracker_.current_surface_id()); |
| 44 | 52 |
| 45 for (auto& child_frame_sink_id : child_frame_sinks_) { | 53 for (auto& child_frame_sink_id : child_frame_sinks_) { |
| 46 DCHECK(child_frame_sink_id.is_valid()); | 54 DCHECK(child_frame_sink_id.is_valid()); |
| 47 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, | 55 surface_manager_->UnregisterFrameSinkHierarchy(frame_sink_id_, |
| 48 child_frame_sink_id); | 56 child_frame_sink_id); |
| 49 } | 57 } |
| 50 // SurfaceFactory's destructor will attempt to return resources which will | 58 // SurfaceFactory's destructor will attempt to return resources which will |
| 51 // call back into here and access |client_| so we should destroy | 59 // call back into here and access |client_| so we should destroy |
| 52 // |surface_factory_|'s resources early on. | 60 // |surface_factory_|'s resources early on. |
| 53 surface_factory_.EvictSurface(); | 61 surface_factory_.EvictSurface(); |
| 54 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 62 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 55 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 63 if (handles_frame_sink_id_invalidation_) |
| 64 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 56 } | 65 } |
| 57 | 66 |
| 58 void CompositorFrameSinkSupport::EvictFrame() { | 67 void CompositorFrameSinkSupport::EvictFrame() { |
| 59 surface_factory_.EvictSurface(); | 68 surface_factory_.EvictSurface(); |
| 60 } | 69 } |
| 61 | 70 |
| 62 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 71 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 63 needs_begin_frame_ = needs_begin_frame; | 72 needs_begin_frame_ = needs_begin_frame; |
| 64 UpdateNeedsBeginFramesInternal(); | 73 UpdateNeedsBeginFramesInternal(); |
| 65 } | 74 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 86 } | 95 } |
| 87 | 96 |
| 88 void CompositorFrameSinkSupport::UpdateSurfaceReferences( | 97 void CompositorFrameSinkSupport::UpdateSurfaceReferences( |
| 89 const SurfaceId& last_surface_id, | 98 const SurfaceId& last_surface_id, |
| 90 const LocalSurfaceId& local_surface_id) { | 99 const LocalSurfaceId& local_surface_id) { |
| 91 const bool surface_id_changed = | 100 const bool surface_id_changed = |
| 92 last_surface_id.local_surface_id() != local_surface_id; | 101 last_surface_id.local_surface_id() != local_surface_id; |
| 93 | 102 |
| 94 // If this is a display root surface and the SurfaceId is changing, make the | 103 // If this is a display root surface and the SurfaceId is changing, make the |
| 95 // new SurfaceId reachable from the top-level root. | 104 // new SurfaceId reachable from the top-level root. |
| 96 if (submits_to_display_compositor_ && surface_id_changed) | 105 if (is_root_ && surface_id_changed) |
| 97 AddTopLevelRootReference(reference_tracker_.current_surface_id()); | 106 AddTopLevelRootReference(reference_tracker_.current_surface_id()); |
| 98 | 107 |
| 99 // Add references based on CompositorFrame referenced surfaces. If the | 108 // Add references based on CompositorFrame referenced surfaces. If the |
| 100 // SurfaceId has changed all referenced surfaces will be in this list. | 109 // SurfaceId has changed all referenced surfaces will be in this list. |
| 101 if (!reference_tracker_.references_to_add().empty()) { | 110 if (!reference_tracker_.references_to_add().empty()) { |
| 102 surface_manager_->AddSurfaceReferences( | 111 surface_manager_->AddSurfaceReferences( |
| 103 reference_tracker_.references_to_add()); | 112 reference_tracker_.references_to_add()); |
| 104 } | 113 } |
| 105 | 114 |
| 106 // If this is a display root surface and the SurfaceId is changing, make the | 115 // If this is a display root surface and the SurfaceId is changing, make the |
| 107 // old SurfaceId unreachable from the top-level root. This needs to happen | 116 // old SurfaceId unreachable from the top-level root. This needs to happen |
| 108 // after adding all references for the new SurfaceId. | 117 // after adding all references for the new SurfaceId. |
| 109 if (submits_to_display_compositor_ && surface_id_changed && | 118 if (is_root_ && surface_id_changed && last_surface_id.is_valid()) |
| 110 last_surface_id.is_valid()) | |
| 111 RemoveTopLevelRootReference(last_surface_id); | 119 RemoveTopLevelRootReference(last_surface_id); |
| 112 | 120 |
| 113 // Remove references based on CompositorFrame referenced surfaces. If the | 121 // Remove references based on CompositorFrame referenced surfaces. If the |
| 114 // SurfaceId has changed this list will be empty. | 122 // SurfaceId has changed this list will be empty. |
| 115 if (!reference_tracker_.references_to_remove().empty()) { | 123 if (!reference_tracker_.references_to_remove().empty()) { |
| 116 DCHECK(!surface_id_changed); | 124 DCHECK(!surface_id_changed); |
| 117 surface_manager_->RemoveSurfaceReferences( | 125 surface_manager_->RemoveSurfaceReferences( |
| 118 reference_tracker_.references_to_remove()); | 126 reference_tracker_.references_to_remove()); |
| 119 } | 127 } |
| 120 } | 128 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return; | 241 return; |
| 234 | 242 |
| 235 added_frame_observer_ = needs_begin_frame_; | 243 added_frame_observer_ = needs_begin_frame_; |
| 236 if (needs_begin_frame_) | 244 if (needs_begin_frame_) |
| 237 begin_frame_source_->AddObserver(this); | 245 begin_frame_source_->AddObserver(this); |
| 238 else | 246 else |
| 239 begin_frame_source_->RemoveObserver(this); | 247 begin_frame_source_->RemoveObserver(this); |
| 240 } | 248 } |
| 241 | 249 |
| 242 } // namespace cc | 250 } // namespace cc |
| OLD | NEW |