| 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 "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 // All hierarchies, sources, and surface factory clients should be | 41 // All hierarchies, sources, and surface factory clients should be |
| 42 // unregistered prior to SurfaceManager destruction. | 42 // unregistered prior to SurfaceManager destruction. |
| 43 DCHECK_EQ(namespace_client_map_.size(), 0u); | 43 DCHECK_EQ(namespace_client_map_.size(), 0u); |
| 44 DCHECK_EQ(registered_sources_.size(), 0u); | 44 DCHECK_EQ(registered_sources_.size(), 0u); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SurfaceManager::RegisterSurface(Surface* surface) { | 47 void SurfaceManager::RegisterSurface(Surface* surface) { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 DCHECK(surface); | 49 DCHECK(surface); |
| 50 DCHECK(!surface_map_.count(surface->surface_id())); | 50 // We may submit a new CompositorFrame with the same surface ID |
| 51 // before the previous one has been garbage collected. |
| 51 surface_map_[surface->surface_id()] = surface; | 52 surface_map_[surface->surface_id()] = surface; |
| 52 } | 53 } |
| 53 | 54 |
| 54 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { | 55 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 SurfaceMap::iterator it = surface_map_.find(surface_id); | 57 SurfaceMap::iterator it = surface_map_.find(surface_id); |
| 57 DCHECK(it != surface_map_.end()); | 58 if (it == surface_map_.end()) |
| 59 return; |
| 58 surface_map_.erase(it); | 60 surface_map_.erase(it); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) { | 63 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 surface->set_destroyed(true); | 65 surface->set_destroyed(true); |
| 64 surfaces_to_destroy_.push_back(std::move(surface)); | 66 surfaces_to_destroy_.push_back(std::move(surface)); |
| 65 GarbageCollectSurfaces(); | 67 GarbageCollectSurfaces(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void SurfaceManager::DidSatisfySequences(uint32_t client_id, | 70 void SurfaceManager::DidSatisfySequences(uint32_t client_id, |
| 69 std::vector<uint32_t>* sequence) { | 71 std::vector<uint32_t>* sequence) { |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
| 71 for (std::vector<uint32_t>::iterator it = sequence->begin(); | 73 for (std::vector<uint32_t>::iterator it = sequence->begin(); |
| 72 it != sequence->end(); | 74 it != sequence->end(); |
| 73 ++it) { | 75 ++it) { |
| 74 satisfied_sequences_.insert(SurfaceSequence(client_id, *it)); | 76 satisfied_sequences_.insert(SurfaceSequence(client_id, *it)); |
| 75 } | 77 } |
| 76 sequence->clear(); | 78 sequence->clear(); |
| 77 GarbageCollectSurfaces(); | 79 GarbageCollectSurfaces(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 void SurfaceManager::RegisterSurfaceClientId(uint32_t client_id) { | |
| 81 bool inserted = valid_surface_client_ids_.insert(client_id).second; | |
| 82 DCHECK(inserted); | |
| 83 } | |
| 84 | |
| 85 void SurfaceManager::InvalidateSurfaceClientId(uint32_t client_id) { | |
| 86 valid_surface_client_ids_.erase(client_id); | |
| 87 GarbageCollectSurfaces(); | |
| 88 } | |
| 89 | |
| 90 void SurfaceManager::GarbageCollectSurfaces() { | 82 void SurfaceManager::GarbageCollectSurfaces() { |
| 91 // Simple mark and sweep GC. | 83 // Simple mark and sweep GC. |
| 92 // TODO(jbauman): Reduce the amount of work when nothing needs to be | 84 // TODO(jbauman): Reduce the amount of work when nothing needs to be |
| 93 // destroyed. | 85 // destroyed. |
| 94 std::vector<SurfaceId> live_surfaces; | 86 std::vector<SurfaceId> live_surfaces; |
| 95 std::set<SurfaceId> live_surfaces_set; | 87 std::set<SurfaceId> live_surfaces_set; |
| 96 | 88 |
| 97 // GC roots are surfaces that have not been destroyed, or have not had all | 89 // GC roots are surfaces that have not been destroyed, or have not had all |
| 98 // their destruction dependencies satisfied. | 90 // their destruction dependencies satisfied. |
| 99 for (auto& map_entry : surface_map_) { | 91 for (auto& map_entry : surface_map_) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 dest_it = surfaces_to_destroy_.erase(dest_it); | 127 dest_it = surfaces_to_destroy_.erase(dest_it); |
| 136 to_destroy.push_back(std::move(surf)); | 128 to_destroy.push_back(std::move(surf)); |
| 137 } else { | 129 } else { |
| 138 ++dest_it; | 130 ++dest_it; |
| 139 } | 131 } |
| 140 } | 132 } |
| 141 | 133 |
| 142 to_destroy.clear(); | 134 to_destroy.clear(); |
| 143 } | 135 } |
| 144 | 136 |
| 145 void SurfaceManager::RegisterSurfaceFactoryClient( | 137 void SurfaceManager::RegisterClient(uint32_t client_id, |
| 146 uint32_t client_id, | 138 SurfaceFactoryClient* client) { |
| 147 SurfaceFactoryClient* client) { | |
| 148 DCHECK(client); | 139 DCHECK(client); |
| 140 bool inserted = valid_surface_client_ids_.insert(client_id).second; |
| 141 DCHECK(inserted); |
| 149 DCHECK(!namespace_client_map_[client_id].client); | 142 DCHECK(!namespace_client_map_[client_id].client); |
| 150 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); | |
| 151 | 143 |
| 152 auto iter = namespace_client_map_.find(client_id); | 144 auto iter = namespace_client_map_.find(client_id); |
| 153 if (iter == namespace_client_map_.end()) { | 145 if (iter == namespace_client_map_.end()) { |
| 154 auto insert_result = namespace_client_map_.insert( | 146 auto insert_result = namespace_client_map_.insert( |
| 155 std::make_pair(client_id, ClientSourceMapping())); | 147 std::make_pair(client_id, ClientSourceMapping())); |
| 156 DCHECK(insert_result.second); | 148 DCHECK(insert_result.second); |
| 157 iter = insert_result.first; | 149 iter = insert_result.first; |
| 158 } | 150 } |
| 159 iter->second.client = client; | 151 iter->second.client = client; |
| 160 | 152 |
| 161 // Propagate any previously set sources to the new client. | 153 // Propagate any previously set sources to the new client. |
| 162 if (iter->second.source) | 154 if (iter->second.source) |
| 163 client->SetBeginFrameSource(iter->second.source); | 155 client->SetBeginFrameSource(iter->second.source); |
| 164 } | 156 } |
| 165 | 157 |
| 166 void SurfaceManager::UnregisterSurfaceFactoryClient(uint32_t client_id) { | 158 void SurfaceManager::UnregisterClient(uint32_t client_id) { |
| 167 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); | 159 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); |
| 168 DCHECK_EQ(namespace_client_map_.count(client_id), 1u); | 160 DCHECK_EQ(namespace_client_map_.count(client_id), 1u); |
| 169 | 161 |
| 170 auto iter = namespace_client_map_.find(client_id); | 162 auto iter = namespace_client_map_.find(client_id); |
| 171 if (iter->second.source) | 163 if (iter->second.source) |
| 172 iter->second.client->SetBeginFrameSource(nullptr); | 164 iter->second.client->SetBeginFrameSource(nullptr); |
| 173 iter->second.client = nullptr; | 165 iter->second.client = nullptr; |
| 174 | 166 |
| 175 // The SurfaceFactoryClient and hierarchy can be registered/unregistered | 167 // The SurfaceFactoryClient and hierarchy can be registered/unregistered |
| 176 // in either order, so empty namespace_client_map entries need to be | 168 // in either order, so empty namespace_client_map entries need to be |
| 177 // checked when removing either clients or relationships. | 169 // checked when removing either clients or relationships. |
| 178 if (iter->second.is_empty()) | 170 if (iter->second.is_empty()) |
| 179 namespace_client_map_.erase(iter); | 171 namespace_client_map_.erase(iter); |
| 172 |
| 173 valid_surface_client_ids_.erase(client_id); |
| 174 GarbageCollectSurfaces(); |
| 180 } | 175 } |
| 181 | 176 |
| 182 void SurfaceManager::RegisterBeginFrameSource(BeginFrameSource* source, | 177 void SurfaceManager::RegisterBeginFrameSource(BeginFrameSource* source, |
| 183 uint32_t client_id) { | 178 uint32_t client_id) { |
| 184 DCHECK(source); | 179 DCHECK(source); |
| 185 DCHECK_EQ(registered_sources_.count(source), 0u); | 180 DCHECK_EQ(registered_sources_.count(source), 0u); |
| 186 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); | 181 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); |
| 187 | 182 |
| 188 registered_sources_[source] = client_id; | 183 registered_sources_[source] = client_id; |
| 189 RecursivelyAttachBeginFrameSource(client_id, source); | 184 RecursivelyAttachBeginFrameSource(client_id, source); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 336 |
| 342 bool SurfaceManager::SurfaceModified(const SurfaceId& surface_id) { | 337 bool SurfaceManager::SurfaceModified(const SurfaceId& surface_id) { |
| 343 CHECK(thread_checker_.CalledOnValidThread()); | 338 CHECK(thread_checker_.CalledOnValidThread()); |
| 344 bool changed = false; | 339 bool changed = false; |
| 345 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_, | 340 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_, |
| 346 OnSurfaceDamaged(surface_id, &changed)); | 341 OnSurfaceDamaged(surface_id, &changed)); |
| 347 return changed; | 342 return changed; |
| 348 } | 343 } |
| 349 | 344 |
| 350 } // namespace cc | 345 } // namespace cc |
| OLD | NEW |