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 SurfaceId surface_id, | |
Fady Samuel
2017/03/09 21:32:16
looks like you missed making this const SurfaceId&
Saman Sami
2017/03/09 21:45:17
Sorry one of my commits got deleted and I had to r
| |
101 base::WeakPtr<SurfaceFactory> surface_factory) { | |
102 DCHECK(thread_checker_.CalledOnValidThread()); | |
103 DCHECK(surface_id.is_valid() && surface_factory); | |
104 | |
105 // If no surface with this SurfaceId exists, simply create the surface and | |
106 // return. | |
107 auto surface_iter = surface_map_.find(surface_id); | |
108 if (surface_iter == surface_map_.end()) { | |
109 auto surface = base::MakeUnique<Surface>(surface_id, surface_factory); | |
110 surface_map_[surface->surface_id()] = surface.get(); | |
111 return surface; | |
112 } | |
113 | |
114 // If a surface with this SurfaceId exists and it's not marked as destroyed, | |
115 // we should not receive a request to create a new surface with the same | |
116 // SurfaceId. | |
117 DCHECK(surface_iter->second->destroyed()); | |
118 | |
119 // If a surface with this SurfaceId exists and it's marked as destroyed, | |
120 // it means it's in the garbage collector's queue. We simply take it out of | |
121 // the queue and reuse it. | |
122 auto it = | |
123 std::find_if(surfaces_to_destroy_.begin(), surfaces_to_destroy_.end(), | |
124 [&surface_id](const std::unique_ptr<Surface>& surface) { | |
125 return surface->surface_id() == surface_id; | |
126 }); | |
127 DCHECK(it != surfaces_to_destroy_.end()); | |
128 std::unique_ptr<Surface> surface = std::move(*it); | |
129 surfaces_to_destroy_.erase(it); | |
130 surface->set_destroyed(false); | |
131 DCHECK_EQ(surface_factory.get(), surface->factory().get()); | |
132 return surface; | |
133 } | |
134 | |
135 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { | |
107 DCHECK(thread_checker_.CalledOnValidThread()); | 136 DCHECK(thread_checker_.CalledOnValidThread()); |
108 surface->set_destroyed(true); | 137 surface->set_destroyed(true); |
109 surfaces_to_destroy_.push_back(std::move(surface)); | 138 surfaces_to_destroy_.push_back(std::move(surface)); |
110 GarbageCollectSurfaces(); | 139 GarbageCollectSurfaces(); |
111 } | 140 } |
112 | 141 |
113 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, | 142 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, |
114 const SurfaceSequence& sequence) { | 143 const SurfaceSequence& sequence) { |
115 auto* surface = GetSurfaceForId(surface_id); | 144 auto* surface = GetSurfaceForId(surface_id); |
116 if (!surface) { | 145 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()); | 686 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
658 std::sort(children.begin(), children.end()); | 687 std::sort(children.begin(), children.end()); |
659 | 688 |
660 for (const SurfaceId& child_id : children) | 689 for (const SurfaceId& child_id : children) |
661 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 690 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
662 } | 691 } |
663 } | 692 } |
664 #endif // DCHECK_IS_ON() | 693 #endif // DCHECK_IS_ON() |
665 | 694 |
666 } // namespace cc | 695 } // namespace cc |
OLD | NEW |