| 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/referenced_surface_tracker.h" | 5 #include "cc/surfaces/referenced_surface_tracker.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 ReferencedSurfaceTracker::ReferencedSurfaceTracker( | 13 ReferencedSurfaceTracker::ReferencedSurfaceTracker( |
| 14 const FrameSinkId& frame_sink_id) | 14 const FrameSinkId& frame_sink_id) |
| 15 : current_surface_id_(frame_sink_id, LocalSurfaceId()) { | 15 : current_surface_id_(frame_sink_id, LocalSurfaceId()) { |
| 16 DCHECK(current_surface_id_.frame_sink_id().is_valid()); | 16 DCHECK(current_surface_id_.frame_sink_id().is_valid()); |
| 17 } | 17 } |
| 18 | 18 |
| 19 ReferencedSurfaceTracker::~ReferencedSurfaceTracker() {} | 19 ReferencedSurfaceTracker::~ReferencedSurfaceTracker() {} |
| 20 | 20 |
| 21 void ReferencedSurfaceTracker::UpdateReferences( | 21 void ReferencedSurfaceTracker::UpdateReferences( |
| 22 const LocalSurfaceId& local_surface_id, | 22 const LocalSurfaceId& local_surface_id, |
| 23 const std::vector<SurfaceId>* active_referenced_surfaces, | 23 const std::vector<SurfaceId>* active_referenced_surfaces) { |
| 24 const std::vector<SurfaceId>* pending_referenced_surfaces) { | |
| 25 DCHECK(local_surface_id.is_valid()); | 24 DCHECK(local_surface_id.is_valid()); |
| 26 | 25 |
| 27 // Clear references to add/remove from the last frame. | 26 // Clear references to add/remove from the last frame. |
| 28 references_to_remove_.clear(); | 27 references_to_remove_.clear(); |
| 29 references_to_add_.clear(); | 28 references_to_add_.clear(); |
| 30 | 29 |
| 31 // If |current_surface_id_| is changing then update |current_surface_id_|. | 30 // If |current_surface_id_| is changing then update |current_surface_id_|. |
| 32 // Also clear |referenced_surfaces_| because we haven't added any references | 31 // Also clear |referenced_surfaces_| because we haven't added any references |
| 33 // from the new SurfaceId yet. | 32 // from the new SurfaceId yet. |
| 34 if (current_surface_id_.local_surface_id() != local_surface_id) { | 33 if (current_surface_id_.local_surface_id() != local_surface_id) { |
| 35 current_surface_id_ = | 34 current_surface_id_ = |
| 36 SurfaceId(current_surface_id_.frame_sink_id(), local_surface_id); | 35 SurfaceId(current_surface_id_.frame_sink_id(), local_surface_id); |
| 37 referenced_surfaces_.clear(); | 36 referenced_surfaces_.clear(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 std::unordered_set<SurfaceId, SurfaceIdHash> referenced_surface_set; | 39 std::unordered_set<SurfaceId, SurfaceIdHash> referenced_surface_set; |
| 41 if (active_referenced_surfaces) { | 40 if (active_referenced_surfaces) { |
| 42 referenced_surface_set.insert(active_referenced_surfaces->begin(), | 41 referenced_surface_set.insert(active_referenced_surfaces->begin(), |
| 43 active_referenced_surfaces->end()); | 42 active_referenced_surfaces->end()); |
| 44 } | 43 } |
| 45 | 44 |
| 46 if (pending_referenced_surfaces) { | |
| 47 referenced_surface_set.insert(pending_referenced_surfaces->begin(), | |
| 48 pending_referenced_surfaces->end()); | |
| 49 } | |
| 50 | |
| 51 ProcessNewReferences(referenced_surface_set); | 45 ProcessNewReferences(referenced_surface_set); |
| 52 } | 46 } |
| 53 | 47 |
| 54 void ReferencedSurfaceTracker::ProcessNewReferences( | 48 void ReferencedSurfaceTracker::ProcessNewReferences( |
| 55 const std::unordered_set<SurfaceId, SurfaceIdHash>& | 49 const std::unordered_set<SurfaceId, SurfaceIdHash>& |
| 56 new_referenced_surfaces) { | 50 new_referenced_surfaces) { |
| 57 // Removed references for each SurfaceId in |referenced_surfaces_| if they | 51 // Removed references for each SurfaceId in |referenced_surfaces_| if they |
| 58 // aren't referenced anymore. Removing from a set invalidates iterators, so | 52 // aren't referenced anymore. Removing from a set invalidates iterators, so |
| 59 // create a new vector then remove everything in it. | 53 // create a new vector then remove everything in it. |
| 60 std::vector<SurfaceId> not_referenced; | 54 std::vector<SurfaceId> not_referenced; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 81 } | 75 } |
| 82 | 76 |
| 83 void ReferencedSurfaceTracker::RemoveSurfaceReference( | 77 void ReferencedSurfaceTracker::RemoveSurfaceReference( |
| 84 const SurfaceId& surface_id) { | 78 const SurfaceId& surface_id) { |
| 85 references_to_remove_.push_back( | 79 references_to_remove_.push_back( |
| 86 SurfaceReference(current_surface_id_, surface_id)); | 80 SurfaceReference(current_surface_id_, surface_id)); |
| 87 referenced_surfaces_.erase(surface_id); | 81 referenced_surfaces_.erase(surface_id); |
| 88 } | 82 } |
| 89 | 83 |
| 90 } // namespace cc | 84 } // namespace cc |
| OLD | NEW |