| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/surfaces/referenced_surface_tracker.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace cc { |
| 12 |
| 13 ReferencedSurfaceTracker::ReferencedSurfaceTracker( |
| 14 const FrameSinkId& frame_sink_id) |
| 15 : current_surface_id_(frame_sink_id, LocalFrameId()) { |
| 16 DCHECK(current_surface_id_.frame_sink_id().is_valid()); |
| 17 } |
| 18 |
| 19 ReferencedSurfaceTracker::~ReferencedSurfaceTracker() {} |
| 20 |
| 21 void ReferencedSurfaceTracker::UpdateReferences( |
| 22 const LocalFrameId& local_frame_id, |
| 23 const std::vector<SurfaceId>& referenced_surfaces) { |
| 24 DCHECK(local_frame_id.is_valid()); |
| 25 |
| 26 // Clear references to add/remove from the last frame. |
| 27 references_to_remove_.clear(); |
| 28 references_to_add_.clear(); |
| 29 |
| 30 // If |current_surface_id_| is changing then update |current_surface_id_|. |
| 31 // Also clear |referenced_surfaces_| because we haven't added any references |
| 32 // from the new SurfaceId yet. |
| 33 if (current_surface_id_.local_frame_id() != local_frame_id) { |
| 34 current_surface_id_ = |
| 35 SurfaceId(current_surface_id_.frame_sink_id(), local_frame_id); |
| 36 referenced_surfaces_.clear(); |
| 37 } |
| 38 |
| 39 std::unordered_set<SurfaceId, SurfaceIdHash> referenced_surface_set( |
| 40 referenced_surfaces.begin(), referenced_surfaces.end()); |
| 41 ProcessNewReferences(referenced_surface_set); |
| 42 } |
| 43 |
| 44 void ReferencedSurfaceTracker::ProcessNewReferences( |
| 45 const std::unordered_set<SurfaceId, SurfaceIdHash>& |
| 46 new_referenced_surfaces) { |
| 47 // Removed references for each SurfaceId in |referenced_surfaces_| if they |
| 48 // aren't referenced anymore. Removing from a set invalidates iterators, so |
| 49 // create a new vector then remove everything in it. |
| 50 std::vector<SurfaceId> not_referenced; |
| 51 for (const SurfaceId& surface_id : referenced_surfaces_) { |
| 52 if (new_referenced_surfaces.count(surface_id) == 0) |
| 53 not_referenced.push_back(surface_id); |
| 54 } |
| 55 for (const SurfaceId& surface_id : not_referenced) |
| 56 RemoveSurfaceReference(surface_id); |
| 57 |
| 58 // Add references for each SurfaceId in |new_referenced_surfaces| if they |
| 59 // aren't already referenced. |
| 60 for (const SurfaceId& surface_id : new_referenced_surfaces) { |
| 61 if (referenced_surfaces_.count(surface_id) == 0) |
| 62 AddSurfaceReference(surface_id); |
| 63 } |
| 64 } |
| 65 |
| 66 void ReferencedSurfaceTracker::AddSurfaceReference( |
| 67 const SurfaceId& surface_id) { |
| 68 references_to_add_.push_back( |
| 69 SurfaceReference(current_surface_id_, surface_id)); |
| 70 referenced_surfaces_.insert(surface_id); |
| 71 } |
| 72 |
| 73 void ReferencedSurfaceTracker::RemoveSurfaceReference( |
| 74 const SurfaceId& surface_id) { |
| 75 references_to_remove_.push_back( |
| 76 SurfaceReference(current_surface_id_, surface_id)); |
| 77 referenced_surfaces_.erase(surface_id); |
| 78 } |
| 79 |
| 80 } // namespace cc |
| OLD | NEW |