| 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/embedded_surface_tracker.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace cc { | |
| 12 | |
| 13 EmbeddedSurfaceTracker::EmbeddedSurfaceTracker() {} | |
| 14 | |
| 15 EmbeddedSurfaceTracker::~EmbeddedSurfaceTracker() {} | |
| 16 | |
| 17 void EmbeddedSurfaceTracker::SetCurrentSurfaceId(const SurfaceId& surface_id) { | |
| 18 DCHECK(surface_id.is_valid()); | |
| 19 DCHECK_NE(current_surface_id_, surface_id); | |
| 20 | |
| 21 // The last submitted CompositorFrame for |current_surface_id_| still embeds | |
| 22 // the surfaces in |references_to_remove_| and hasn't embedded the surfaces in | |
| 23 // |references_to_add_| yet. | |
| 24 references_to_remove_.clear(); | |
| 25 references_to_add_.clear(); | |
| 26 | |
| 27 current_surface_id_ = surface_id; | |
| 28 | |
| 29 // Add references from updated |current_surface_id_| to all embedded surfaces. | |
| 30 for (auto& map_entry : embedded_surfaces_) | |
| 31 AddReference(current_surface_id_, map_entry.second); | |
| 32 } | |
| 33 | |
| 34 bool EmbeddedSurfaceTracker::EmbedSurface(const SurfaceId& embedded_id) { | |
| 35 auto iter = embedded_surfaces_.find(embedded_id.frame_sink_id()); | |
| 36 | |
| 37 // This is the first surface for the FrameSinkId. | |
| 38 if (iter == embedded_surfaces_.end()) { | |
| 39 if (HasValidSurfaceId()) | |
| 40 AddReference(current_surface_id_, embedded_id); | |
| 41 | |
| 42 // Add record that surface is embedded. | |
| 43 embedded_surfaces_[embedded_id.frame_sink_id()] = embedded_id; | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 47 // This is not the first surface for the FrameSinkId, we are unembedding the | |
| 48 // old surface and embedding the new surface. | |
| 49 SurfaceId& stored_surface_id = iter->second; | |
| 50 DCHECK_NE(stored_surface_id, embedded_id); | |
| 51 | |
| 52 if (HasValidSurfaceId()) { | |
| 53 RemoveReference(current_surface_id_, stored_surface_id); | |
| 54 AddReference(current_surface_id_, embedded_id); | |
| 55 } | |
| 56 | |
| 57 stored_surface_id = embedded_id; | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 void EmbeddedSurfaceTracker::UnembedSurface(const FrameSinkId& frame_sink_id) { | |
| 62 auto iter = embedded_surfaces_.find(frame_sink_id); | |
| 63 if (iter == embedded_surfaces_.end()) | |
| 64 return; | |
| 65 | |
| 66 if (HasValidSurfaceId()) | |
| 67 RemoveReference(current_surface_id_, iter->second); | |
| 68 | |
| 69 // Remove record that surface is embedded. | |
| 70 embedded_surfaces_.erase(iter); | |
| 71 } | |
| 72 | |
| 73 std::vector<SurfaceReference> EmbeddedSurfaceTracker::GetReferencesToAdd() { | |
| 74 std::vector<SurfaceReference> references; | |
| 75 std::swap(references, references_to_add_); | |
| 76 return references; | |
| 77 } | |
| 78 | |
| 79 std::vector<SurfaceReference> EmbeddedSurfaceTracker::GetReferencesToRemove() { | |
| 80 std::vector<SurfaceReference> references; | |
| 81 std::swap(references, references_to_remove_); | |
| 82 return references; | |
| 83 } | |
| 84 | |
| 85 void EmbeddedSurfaceTracker::AddReference(const SurfaceId& parent_id, | |
| 86 const SurfaceId& child_id) { | |
| 87 references_to_add_.push_back(SurfaceReference(parent_id, child_id)); | |
| 88 } | |
| 89 | |
| 90 void EmbeddedSurfaceTracker::RemoveReference(const SurfaceId& parent_id, | |
| 91 const SurfaceId& child_id) { | |
| 92 references_to_remove_.push_back(SurfaceReference(parent_id, child_id)); | |
| 93 } | |
| 94 | |
| 95 } // namespace cc | |
| OLD | NEW |