| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // the queue and reuse it. | 115 // the queue and reuse it. |
| 116 auto it = | 116 auto it = |
| 117 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), | 117 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), |
| 118 [&surface_id](const std::unique_ptr<Surface>& surface) { | 118 [&surface_id](const std::unique_ptr<Surface>& surface) { |
| 119 return surface->surface_id() == surface_id; | 119 return surface->surface_id() == surface_id; |
| 120 }); | 120 }); |
| 121 DCHECK(it != surfaces_to_destroy_.end()); | 121 DCHECK(it != surfaces_to_destroy_.end()); |
| 122 std::unique_ptr<Surface> surface = std::move(*it); | 122 std::unique_ptr<Surface> surface = std::move(*it); |
| 123 surfaces_to_destroy_.erase(it); | 123 surfaces_to_destroy_.erase(it); |
| 124 surface->set_destroyed(false); | 124 surface->set_destroyed(false); |
| 125 // If the surface was used by another factory, we should update its factory. |
| 126 // The old frames must be evicted because the new factory is not capable of |
| 127 // returning their resources. |
| 128 // TODO(samans): This should not be necessary once crbug.com/701988 is fixed. |
| 129 if (surface->factory() == nullptr) { |
| 130 DLOG(ERROR) << "Surface is being reused by another factory. " |
| 131 "Resources can potentially leak. id=" |
| 132 << surface_id; |
| 133 surface->Reset(); |
| 134 surface->set_factory(surface_factory); |
| 135 } |
| 125 DCHECK_EQ(surface_factory.get(), surface->factory().get()); | 136 DCHECK_EQ(surface_factory.get(), surface->factory().get()); |
| 126 return surface; | 137 return surface; |
| 127 } | 138 } |
| 128 | 139 |
| 129 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { | 140 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { |
| 130 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
| 142 |
| 131 surface->set_destroyed(true); | 143 surface->set_destroyed(true); |
| 132 surfaces_to_destroy_.push_back(std::move(surface)); | 144 surfaces_to_destroy_.push_back(std::move(surface)); |
| 133 GarbageCollectSurfaces(); | 145 GarbageCollectSurfaces(); |
| 134 } | 146 } |
| 135 | 147 |
| 136 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, | 148 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, |
| 137 const SurfaceSequence& sequence) { | 149 const SurfaceSequence& sequence) { |
| 138 auto* surface = GetSurfaceForId(surface_id); | 150 auto* surface = GetSurfaceForId(surface_id); |
| 139 if (!surface) { | 151 if (!surface) { |
| 140 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 152 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); | 700 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
| 689 std::sort(children.begin(), children.end()); | 701 std::sort(children.begin(), children.end()); |
| 690 | 702 |
| 691 for (const SurfaceId& child_id : children) | 703 for (const SurfaceId& child_id : children) |
| 692 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 704 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
| 693 } | 705 } |
| 694 } | 706 } |
| 695 #endif // DCHECK_IS_ON() | 707 #endif // DCHECK_IS_ON() |
| 696 | 708 |
| 697 } // namespace cc | 709 } // namespace cc |
| OLD | NEW |