Chromium Code Reviews| 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 16:30:08
const SurfaceId&
Saman Sami
2017/03/09 20:45:50
Done.
| |
| 101 base::WeakPtr<SurfaceFactory> surface_factory) { | |
|
Fady Samuel
2017/03/09 16:30:08
Does thsi need to be a weakptr?
Saman Sami
2017/03/09 20:45:50
Surface keeps a weak ptr to its factory.
| |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 103 | |
| 104 if (!surface_id.is_valid() || !surface_factory) | |
|
Fady Samuel
2017/03/09 16:30:08
DCHECK instead? It seems like a bug otherwise.
Saman Sami
2017/03/09 20:45:50
Done.
| |
| 105 return nullptr; | |
| 106 | |
| 107 auto surface_iter = surface_map_.find(surface_id); | |
| 108 | |
| 109 // If the SurfaceId is not registered, simply create the surface and return. | |
| 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 the SurfaceId is registered but the registered surface is not | |
| 117 // destroyed, we can't create a new surface with the same SurfaceId. | |
| 118 if (!surface_iter->second->destroyed()) | |
|
Fady Samuel
2017/03/09 16:30:08
This is a bug right? DCHECK instead?
Saman Sami
2017/03/09 20:45:50
Done.
| |
| 119 return nullptr; | |
| 120 | |
| 121 // If the SurfaceId is registered and the registered surface is destroyed, | |
| 122 // we can remove it from the garbage collector's queue and reuse it. | |
| 123 std::unique_ptr<Surface> surface; | |
| 124 for (auto it = surfaces_to_destroy_.begin(); it != surfaces_to_destroy_.end(); | |
|
Fady Samuel
2017/03/09 16:30:08
Use std::find? http://en.cppreference.com/w/cpp/al
Saman Sami
2017/03/09 20:45:50
Done.
| |
| 125 it++) { | |
| 126 if ((*it)->surface_id() == surface_id) { | |
| 127 surface = std::move(*it); | |
| 128 surfaces_to_destroy_.erase(it); | |
| 129 break; | |
| 130 } | |
| 131 } | |
| 132 DCHECK(surface); | |
| 133 DCHECK_EQ(surface_factory.get(), surface->factory().get()); | |
| 134 surface->set_destroyed(false); | |
| 135 return surface; | |
| 136 } | |
| 137 | |
| 138 void SurfaceManager::DestroySurface(std::unique_ptr<Surface> surface) { | |
| 107 DCHECK(thread_checker_.CalledOnValidThread()); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
| 108 surface->set_destroyed(true); | 140 surface->set_destroyed(true); |
| 109 surfaces_to_destroy_.push_back(std::move(surface)); | 141 surfaces_to_destroy_.push_back(std::move(surface)); |
| 110 GarbageCollectSurfaces(); | 142 GarbageCollectSurfaces(); |
| 111 } | 143 } |
| 112 | 144 |
| 113 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, | 145 void SurfaceManager::RequireSequence(const SurfaceId& surface_id, |
| 114 const SurfaceSequence& sequence) { | 146 const SurfaceSequence& sequence) { |
| 115 auto* surface = GetSurfaceForId(surface_id); | 147 auto* surface = GetSurfaceForId(surface_id); |
| 116 if (!surface) { | 148 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()); | 689 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); |
| 658 std::sort(children.begin(), children.end()); | 690 std::sort(children.begin(), children.end()); |
| 659 | 691 |
| 660 for (const SurfaceId& child_id : children) | 692 for (const SurfaceId& child_id : children) |
| 661 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | 693 SurfaceReferencesToStringImpl(child_id, indent + " ", str); |
| 662 } | 694 } |
| 663 } | 695 } |
| 664 #endif // DCHECK_IS_ON() | 696 #endif // DCHECK_IS_ON() |
| 665 | 697 |
| 666 } // namespace cc | 698 } // namespace cc |
| OLD | NEW |