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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 void SurfaceManager::SetDependencyTracker( | 81 void SurfaceManager::SetDependencyTracker( |
82 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker) { | 82 std::unique_ptr<SurfaceDependencyTracker> dependency_tracker) { |
83 dependency_tracker_ = std::move(dependency_tracker); | 83 dependency_tracker_ = std::move(dependency_tracker); |
84 } | 84 } |
85 | 85 |
86 void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) { | 86 void SurfaceManager::RequestSurfaceResolution(Surface* pending_surface) { |
87 if (dependency_tracker_) | 87 if (dependency_tracker_) |
88 dependency_tracker_->RequestSurfaceResolution(pending_surface); | 88 dependency_tracker_->RequestSurfaceResolution(pending_surface); |
89 } | 89 } |
90 | 90 |
91 void SurfaceManager::RegisterSurface(Surface* surface) { | |
92 DCHECK(thread_checker_.CalledOnValidThread()); | |
93 DCHECK(surface); | |
94 DCHECK(!surface_map_.count(surface->surface_id())); | |
95 surface_map_[surface->surface_id()] = surface; | |
96 } | |
97 | |
98 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { | 91 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { |
99 DCHECK(thread_checker_.CalledOnValidThread()); | 92 DCHECK(thread_checker_.CalledOnValidThread()); |
100 SurfaceMap::iterator it = surface_map_.find(surface_id); | 93 SurfaceMap::iterator it = surface_map_.find(surface_id); |
101 DCHECK(it != surface_map_.end()); | 94 DCHECK(it != surface_map_.end()); |
102 surface_map_.erase(it); | 95 surface_map_.erase(it); |
103 RemoveAllSurfaceReferences(surface_id); | 96 RemoveAllSurfaceReferences(surface_id); |
104 } | 97 } |
105 | 98 |
106 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) { | 99 std::unique_ptr<Surface> SurfaceManager::CreateSurface( |
| 100 base::WeakPtr<SurfaceFactory> surface_factory, |
| 101 const LocalSurfaceId& local_surface_id) { |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); |
| 103 DCHECK(local_surface_id.is_valid() && surface_factory); |
| 104 |
| 105 SurfaceId surface_id(surface_factory->frame_sink_id(), local_surface_id); |
| 106 |
| 107 // If no surface with this SurfaceId exists, simply create the surface and |
| 108 // return. |
| 109 auto surface_iter = surface_map_.find(surface_id); |
| 110 if (surface_iter == surface_map_.end()) { |
| 111 auto surface = base::MakeUnique<Surface>(surface_id, surface_factory); |
| 112 surface_map_[surface->surface_id()] = surface.get(); |
| 113 return surface; |
| 114 } |
| 115 |
| 116 // If a surface with this SurfaceId exists and it's not marked as destroyed, |
| 117 // we should not receive a request to create a new surface with the same |
| 118 // SurfaceId. |
| 119 DCHECK(surface_iter->second->destroyed()); |
| 120 |
| 121 // If a surface with this SurfaceId exists and it's marked as destroyed, |
| 122 // it means it's in the garbage collector's queue. We simply take it out of |
| 123 // the queue and reuse it. |
| 124 auto it = |
| 125 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), |
| 126 [&surface_id](const std::unique_ptr<Surface>& surface) { |
| 127 return surface->surface_id() == surface_id; |
| 128 }); |
| 129 DCHECK(it != surfaces_to_destroy_.end()); |
| 130 std::unique_ptr<Surface> surface = std::move(*it); |
| 131 surfaces_to_destroy_.erase(it); |
| 132 surface->set_destroyed(false); |
| 133 DCHECK_EQ(surface_factory.get(), surface->factory().get()); |
| 134 return surface; |
| 135 } |
| 136 |
| 137 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { |
107 DCHECK(thread_checker_.CalledOnValidThread()); | 138 DCHECK(thread_checker_.CalledOnValidThread()); |
108 surface->set_destroyed(true); | 139 surface->set_destroyed(true); |
109 surfaces_to_destroy_.push_back(std::move(surface)); | 140 surfaces_to_destroy_.push_back(std::move(surface)); |
110 GarbageCollectSurfaces(); | 141 GarbageCollectSurfaces(); |
111 } | 142 } |
112 | 143 |
113 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, | 144 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, |
114 const SurfaceSequence& sequence) { | 145 const SurfaceSequence& sequence) { |
115 auto* surface = GetSurfaceForId(surface_id); | 146 auto* surface = GetSurfaceForId(surface_id); |
116 if (!surface) { | 147 if (!surface) { |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); | 688 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
658 std::sort(children.begin(), children.end()); | 689 std::sort(children.begin(), children.end()); |
659 | 690 |
660 for (const SurfaceId& child_id : children) | 691 for (const SurfaceId& child_id : children) |
661 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 692 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
662 } | 693 } |
663 } | 694 } |
664 #endif // DCHECK_IS_ON() | 695 #endif // DCHECK_IS_ON() |
665 | 696 |
666 } // namespace cc | 697 } // namespace cc |
OLD | NEW |