OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/surface_manager.h" | 5 #include "cc/surfaces/surface_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <queue> | 10 #include <queue> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // the queue and reuse it. | 101 // the queue and reuse it. |
102 auto it = | 102 auto it = |
103 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), | 103 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), |
104 [&surface_id](const std::unique_ptr<Surface>& surface) { | 104 [&surface_id](const std::unique_ptr<Surface>& surface) { |
105 return surface->surface_id() == surface_id; | 105 return surface->surface_id() == surface_id; |
106 }); | 106 }); |
107 DCHECK(it != surfaces_to_destroy_.end()); | 107 DCHECK(it != surfaces_to_destroy_.end()); |
108 std::unique_ptr<Surface> surface = std::move(*it); | 108 std::unique_ptr<Surface> surface = std::move(*it); |
109 surfaces_to_destroy_.erase(it); | 109 surfaces_to_destroy_.erase(it); |
110 surface->set_destroyed(false); | 110 surface->set_destroyed(false); |
111 // If the surface was used by another factory, we should update its factory. | |
112 // The old frames must be evicted because the new factory is not capable of | |
113 // returning their resources. | |
114 // TODO(samans): This should not be necessary once crbug.com/701988 is fixed. | |
115 if (surface->factory() == nullptr) { | |
116 DLOG(ERROR) << "Surface is being reused by another factory. " | |
117 "Resources can potentially leak. id=" | |
118 << surface_id; | |
119 surface->Reset(); | |
120 surface->set_factory(surface_factory); | |
121 } | |
122 DCHECK_EQ(surface_factory.get(), surface->factory().get()); | 111 DCHECK_EQ(surface_factory.get(), surface->factory().get()); |
123 return surface; | 112 return surface; |
124 } | 113 } |
125 | 114 |
126 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { | 115 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { |
127 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
128 | |
129 surface->set_destroyed(true); | 117 surface->set_destroyed(true); |
130 surfaces_to_destroy_.push_back(std::move(surface)); | 118 surfaces_to_destroy_.push_back(std::move(surface)); |
131 GarbageCollectSurfaces(); | 119 GarbageCollectSurfaces(); |
132 } | 120 } |
133 | 121 |
134 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, | 122 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, |
135 const SurfaceSequence& sequence) { | 123 const SurfaceSequence& sequence) { |
136 auto* surface = GetSurfaceForId(surface_id); | 124 auto* surface = GetSurfaceForId(surface_id); |
137 if (!surface) { | 125 if (!surface) { |
138 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 126 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); | 524 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
537 std::sort(children.begin(), children.end()); | 525 std::sort(children.begin(), children.end()); |
538 | 526 |
539 for (const SurfaceId& child_id : children) | 527 for (const SurfaceId& child_id : children) |
540 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 528 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
541 } | 529 } |
542 } | 530 } |
543 #endif // DCHECK_IS_ON() | 531 #endif // DCHECK_IS_ON() |
544 | 532 |
545 } // namespace cc | 533 } // namespace cc |
OLD | NEW |