| 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" |
| 11 #include "cc/surfaces/surface.h" | 11 #include "cc/surfaces/surface.h" |
| 12 #include "cc/surfaces/surface_factory_client.h" | 12 #include "cc/surfaces/surface_factory_client.h" |
| 13 #include "cc/surfaces/surface_id_allocator.h" | 13 #include "cc/surfaces/surface_id_allocator.h" |
| 14 | 14 |
| 15 namespace cc { | 15 namespace cc { |
| 16 | 16 |
| 17 SurfaceManager::ClientSourceMapping::ClientSourceMapping() | 17 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping() |
| 18 : client(nullptr), source(nullptr) {} | 18 : client(nullptr), source(nullptr) {} |
| 19 | 19 |
| 20 SurfaceManager::ClientSourceMapping::ClientSourceMapping( | 20 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping( |
| 21 const ClientSourceMapping& other) = default; | 21 const FrameSinkSourceMapping& other) = default; |
| 22 | 22 |
| 23 SurfaceManager::ClientSourceMapping::~ClientSourceMapping() { | 23 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() { |
| 24 DCHECK(is_empty()) << "client: " << client | 24 DCHECK(is_empty()) << "client: " << client |
| 25 << ", children: " << children.size(); | 25 << ", children: " << children.size(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 SurfaceManager::SurfaceManager() { | 28 SurfaceManager::SurfaceManager() { |
| 29 thread_checker_.DetachFromThread(); | 29 thread_checker_.DetachFromThread(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 SurfaceManager::~SurfaceManager() { | 32 SurfaceManager::~SurfaceManager() { |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); | 33 DCHECK(thread_checker_.CalledOnValidThread()); |
| 34 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin(); | 34 for (SurfaceDestroyList::iterator it = surfaces_to_destroy_.begin(); |
| 35 it != surfaces_to_destroy_.end(); | 35 it != surfaces_to_destroy_.end(); |
| 36 ++it) { | 36 ++it) { |
| 37 DeregisterSurface((*it)->surface_id()); | 37 DeregisterSurface((*it)->surface_id()); |
| 38 } | 38 } |
| 39 surfaces_to_destroy_.clear(); | 39 surfaces_to_destroy_.clear(); |
| 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(frame_sink_source_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 DCHECK(!surface_map_.count(surface->surface_id())); |
| 51 surface_map_[surface->surface_id()] = surface; | 51 surface_map_[surface->surface_id()] = surface; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { | 54 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 SurfaceMap::iterator it = surface_map_.find(surface_id); | 56 SurfaceMap::iterator it = surface_map_.find(surface_id); |
| 57 DCHECK(it != surface_map_.end()); | 57 DCHECK(it != surface_map_.end()); |
| 58 surface_map_.erase(it); | 58 surface_map_.erase(it); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) { | 61 void SurfaceManager::Destroy(std::unique_ptr<Surface> surface) { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 surface->set_destroyed(true); | 63 surface->set_destroyed(true); |
| 64 surfaces_to_destroy_.push_back(std::move(surface)); | 64 surfaces_to_destroy_.push_back(std::move(surface)); |
| 65 GarbageCollectSurfaces(); | 65 GarbageCollectSurfaces(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void SurfaceManager::DidSatisfySequences(uint32_t client_id, | 68 void SurfaceManager::DidSatisfySequences(const FrameSinkId& frame_sink_id, |
| 69 std::vector<uint32_t>* sequence) { | 69 std::vector<uint32_t>* sequence) { |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(thread_checker_.CalledOnValidThread()); |
| 71 for (std::vector<uint32_t>::iterator it = sequence->begin(); | 71 for (std::vector<uint32_t>::iterator it = sequence->begin(); |
| 72 it != sequence->end(); | 72 it != sequence->end(); |
| 73 ++it) { | 73 ++it) { |
| 74 satisfied_sequences_.insert(SurfaceSequence(client_id, *it)); | 74 satisfied_sequences_.insert(SurfaceSequence(frame_sink_id, *it)); |
| 75 } | 75 } |
| 76 sequence->clear(); | 76 sequence->clear(); |
| 77 GarbageCollectSurfaces(); | 77 GarbageCollectSurfaces(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void SurfaceManager::RegisterSurfaceClientId(uint32_t client_id) { | 80 void SurfaceManager::RegisterFrameSinkId(const FrameSinkId& frame_sink_id) { |
| 81 bool inserted = valid_surface_client_ids_.insert(client_id).second; | 81 bool inserted = valid_frame_sink_ids_.insert(frame_sink_id).second; |
| 82 DCHECK(inserted); | 82 DCHECK(inserted); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void SurfaceManager::InvalidateSurfaceClientId(uint32_t client_id) { | 85 void SurfaceManager::InvalidateFrameSinkId(const FrameSinkId& frame_sink_id) { |
| 86 valid_surface_client_ids_.erase(client_id); | 86 valid_frame_sink_ids_.erase(frame_sink_id); |
| 87 GarbageCollectSurfaces(); | 87 GarbageCollectSurfaces(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SurfaceManager::GarbageCollectSurfaces() { | 90 void SurfaceManager::GarbageCollectSurfaces() { |
| 91 // Simple mark and sweep GC. | 91 // Simple mark and sweep GC. |
| 92 // TODO(jbauman): Reduce the amount of work when nothing needs to be | 92 // TODO(jbauman): Reduce the amount of work when nothing needs to be |
| 93 // destroyed. | 93 // destroyed. |
| 94 std::vector<SurfaceId> live_surfaces; | 94 std::vector<SurfaceId> live_surfaces; |
| 95 std::set<SurfaceId> live_surfaces_set; | 95 std::set<SurfaceId> live_surfaces_set; |
| 96 | 96 |
| 97 // GC roots are surfaces that have not been destroyed, or have not had all | 97 // GC roots are surfaces that have not been destroyed, or have not had all |
| 98 // their destruction dependencies satisfied. | 98 // their destruction dependencies satisfied. |
| 99 for (auto& map_entry : surface_map_) { | 99 for (auto& map_entry : surface_map_) { |
| 100 map_entry.second->SatisfyDestructionDependencies( | 100 map_entry.second->SatisfyDestructionDependencies(&satisfied_sequences_, |
| 101 &satisfied_sequences_, &valid_surface_client_ids_); | 101 &valid_frame_sink_ids_); |
| 102 if (!map_entry.second->destroyed() || | 102 if (!map_entry.second->destroyed() || |
| 103 map_entry.second->GetDestructionDependencyCount()) { | 103 map_entry.second->GetDestructionDependencyCount()) { |
| 104 live_surfaces_set.insert(map_entry.first); | 104 live_surfaces_set.insert(map_entry.first); |
| 105 live_surfaces.push_back(map_entry.first); | 105 live_surfaces.push_back(map_entry.first); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Mark all surfaces reachable from live surfaces by adding them to | 109 // Mark all surfaces reachable from live surfaces by adding them to |
| 110 // live_surfaces and live_surfaces_set. | 110 // live_surfaces and live_surfaces_set. |
| 111 for (size_t i = 0; i < live_surfaces.size(); i++) { | 111 for (size_t i = 0; i < live_surfaces.size(); i++) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 136 to_destroy.push_back(std::move(surf)); | 136 to_destroy.push_back(std::move(surf)); |
| 137 } else { | 137 } else { |
| 138 ++dest_it; | 138 ++dest_it; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 to_destroy.clear(); | 142 to_destroy.clear(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SurfaceManager::RegisterSurfaceFactoryClient( | 145 void SurfaceManager::RegisterSurfaceFactoryClient( |
| 146 uint32_t client_id, | 146 const FrameSinkId& frame_sink_id, |
| 147 SurfaceFactoryClient* client) { | 147 SurfaceFactoryClient* client) { |
| 148 DCHECK(client); | 148 DCHECK(client); |
| 149 DCHECK(!namespace_client_map_[client_id].client); | 149 DCHECK(!frame_sink_source_map_[frame_sink_id].client); |
| 150 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); | 150 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u); |
| 151 | 151 |
| 152 auto iter = namespace_client_map_.find(client_id); | 152 auto iter = frame_sink_source_map_.find(frame_sink_id); |
| 153 if (iter == namespace_client_map_.end()) { | 153 if (iter == frame_sink_source_map_.end()) { |
| 154 auto insert_result = namespace_client_map_.insert( | 154 auto insert_result = frame_sink_source_map_.insert( |
| 155 std::make_pair(client_id, ClientSourceMapping())); | 155 std::make_pair(frame_sink_id, FrameSinkSourceMapping())); |
| 156 DCHECK(insert_result.second); | 156 DCHECK(insert_result.second); |
| 157 iter = insert_result.first; | 157 iter = insert_result.first; |
| 158 } | 158 } |
| 159 iter->second.client = client; | 159 iter->second.client = client; |
| 160 | 160 |
| 161 // Propagate any previously set sources to the new client. | 161 // Propagate any previously set sources to the new client. |
| 162 if (iter->second.source) | 162 if (iter->second.source) |
| 163 client->SetBeginFrameSource(iter->second.source); | 163 client->SetBeginFrameSource(iter->second.source); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void SurfaceManager::UnregisterSurfaceFactoryClient(uint32_t client_id) { | 166 void SurfaceManager::UnregisterSurfaceFactoryClient( |
| 167 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); | 167 const FrameSinkId& frame_sink_id) { |
| 168 DCHECK_EQ(namespace_client_map_.count(client_id), 1u); | 168 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u); |
| 169 DCHECK_EQ(frame_sink_source_map_.count(frame_sink_id), 1u); |
| 169 | 170 |
| 170 auto iter = namespace_client_map_.find(client_id); | 171 auto iter = frame_sink_source_map_.find(frame_sink_id); |
| 171 if (iter->second.source) | 172 if (iter->second.source) |
| 172 iter->second.client->SetBeginFrameSource(nullptr); | 173 iter->second.client->SetBeginFrameSource(nullptr); |
| 173 iter->second.client = nullptr; | 174 iter->second.client = nullptr; |
| 174 | 175 |
| 175 // The SurfaceFactoryClient and hierarchy can be registered/unregistered | 176 // The SurfaceFactoryClient and hierarchy can be registered/unregistered |
| 176 // in either order, so empty namespace_client_map entries need to be | 177 // in either order, so empty namespace_client_map entries need to be |
| 177 // checked when removing either clients or relationships. | 178 // checked when removing either clients or relationships. |
| 178 if (iter->second.is_empty()) | 179 if (iter->second.is_empty()) |
| 179 namespace_client_map_.erase(iter); | 180 frame_sink_source_map_.erase(iter); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void SurfaceManager::RegisterBeginFrameSource(BeginFrameSource* source, | 183 void SurfaceManager::RegisterBeginFrameSource( |
| 183 uint32_t client_id) { | 184 BeginFrameSource* source, |
| 185 const FrameSinkId& frame_sink_id) { |
| 184 DCHECK(source); | 186 DCHECK(source); |
| 185 DCHECK_EQ(registered_sources_.count(source), 0u); | 187 DCHECK_EQ(registered_sources_.count(source), 0u); |
| 186 DCHECK_EQ(valid_surface_client_ids_.count(client_id), 1u); | 188 DCHECK_EQ(valid_frame_sink_ids_.count(frame_sink_id), 1u); |
| 187 | 189 |
| 188 registered_sources_[source] = client_id; | 190 registered_sources_[source] = frame_sink_id; |
| 189 RecursivelyAttachBeginFrameSource(client_id, source); | 191 RecursivelyAttachBeginFrameSource(frame_sink_id, source); |
| 190 } | 192 } |
| 191 | 193 |
| 192 void SurfaceManager::UnregisterBeginFrameSource(BeginFrameSource* source) { | 194 void SurfaceManager::UnregisterBeginFrameSource(BeginFrameSource* source) { |
| 193 DCHECK(source); | 195 DCHECK(source); |
| 194 DCHECK_EQ(registered_sources_.count(source), 1u); | 196 DCHECK_EQ(registered_sources_.count(source), 1u); |
| 195 | 197 |
| 196 uint32_t client_id = registered_sources_[source]; | 198 FrameSinkId frame_sink_id = registered_sources_[source]; |
| 197 registered_sources_.erase(source); | 199 registered_sources_.erase(source); |
| 198 | 200 |
| 199 if (namespace_client_map_.count(client_id) == 0u) | 201 if (frame_sink_source_map_.count(frame_sink_id) == 0u) |
| 200 return; | 202 return; |
| 201 | 203 |
| 202 // TODO(enne): these walks could be done in one step. | 204 // TODO(enne): these walks could be done in one step. |
| 203 // Remove this begin frame source from its subtree. | 205 // Remove this begin frame source from its subtree. |
| 204 RecursivelyDetachBeginFrameSource(client_id, source); | 206 RecursivelyDetachBeginFrameSource(frame_sink_id, source); |
| 205 // Then flush every remaining registered source to fix any sources that | 207 // Then flush every remaining registered source to fix any sources that |
| 206 // became null because of the previous step but that have an alternative. | 208 // became null because of the previous step but that have an alternative. |
| 207 for (auto source_iter : registered_sources_) | 209 for (auto source_iter : registered_sources_) |
| 208 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); | 210 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void SurfaceManager::RecursivelyAttachBeginFrameSource( | 213 void SurfaceManager::RecursivelyAttachBeginFrameSource( |
| 212 uint32_t client_id, | 214 const FrameSinkId& frame_sink_id, |
| 213 BeginFrameSource* source) { | 215 BeginFrameSource* source) { |
| 214 ClientSourceMapping& mapping = namespace_client_map_[client_id]; | 216 FrameSinkSourceMapping& mapping = frame_sink_source_map_[frame_sink_id]; |
| 215 if (!mapping.source) { | 217 if (!mapping.source) { |
| 216 mapping.source = source; | 218 mapping.source = source; |
| 217 if (mapping.client) | 219 if (mapping.client) |
| 218 mapping.client->SetBeginFrameSource(source); | 220 mapping.client->SetBeginFrameSource(source); |
| 219 } | 221 } |
| 220 for (size_t i = 0; i < mapping.children.size(); ++i) | 222 for (size_t i = 0; i < mapping.children.size(); ++i) |
| 221 RecursivelyAttachBeginFrameSource(mapping.children[i], source); | 223 RecursivelyAttachBeginFrameSource(mapping.children[i], source); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void SurfaceManager::RecursivelyDetachBeginFrameSource( | 226 void SurfaceManager::RecursivelyDetachBeginFrameSource( |
| 225 uint32_t client_id, | 227 const FrameSinkId& frame_sink_id, |
| 226 BeginFrameSource* source) { | 228 BeginFrameSource* source) { |
| 227 auto iter = namespace_client_map_.find(client_id); | 229 auto iter = frame_sink_source_map_.find(frame_sink_id); |
| 228 if (iter == namespace_client_map_.end()) | 230 if (iter == frame_sink_source_map_.end()) |
| 229 return; | 231 return; |
| 230 if (iter->second.source == source) { | 232 if (iter->second.source == source) { |
| 231 iter->second.source = nullptr; | 233 iter->second.source = nullptr; |
| 232 if (iter->second.client) | 234 if (iter->second.client) |
| 233 iter->second.client->SetBeginFrameSource(nullptr); | 235 iter->second.client->SetBeginFrameSource(nullptr); |
| 234 } | 236 } |
| 235 | 237 |
| 236 if (iter->second.is_empty()) { | 238 if (iter->second.is_empty()) { |
| 237 namespace_client_map_.erase(iter); | 239 frame_sink_source_map_.erase(iter); |
| 238 return; | 240 return; |
| 239 } | 241 } |
| 240 | 242 |
| 241 std::vector<uint32_t>& children = iter->second.children; | 243 std::vector<FrameSinkId>& children = iter->second.children; |
| 242 for (size_t i = 0; i < children.size(); ++i) { | 244 for (size_t i = 0; i < children.size(); ++i) { |
| 243 RecursivelyDetachBeginFrameSource(children[i], source); | 245 RecursivelyDetachBeginFrameSource(children[i], source); |
| 244 } | 246 } |
| 245 } | 247 } |
| 246 | 248 |
| 247 bool SurfaceManager::ChildContains(uint32_t child_namespace, | 249 bool SurfaceManager::ChildContains( |
| 248 uint32_t search_namespace) const { | 250 const FrameSinkId& child_frame_sink_id, |
| 249 auto iter = namespace_client_map_.find(child_namespace); | 251 const FrameSinkId& search_frame_sink_id) const { |
| 250 if (iter == namespace_client_map_.end()) | 252 auto iter = frame_sink_source_map_.find(child_frame_sink_id); |
| 253 if (iter == frame_sink_source_map_.end()) |
| 251 return false; | 254 return false; |
| 252 | 255 |
| 253 const std::vector<uint32_t>& children = iter->second.children; | 256 const std::vector<FrameSinkId>& children = iter->second.children; |
| 254 for (size_t i = 0; i < children.size(); ++i) { | 257 for (size_t i = 0; i < children.size(); ++i) { |
| 255 if (children[i] == search_namespace) | 258 if (children[i] == search_frame_sink_id) |
| 256 return true; | 259 return true; |
| 257 if (ChildContains(children[i], search_namespace)) | 260 if (ChildContains(children[i], search_frame_sink_id)) |
| 258 return true; | 261 return true; |
| 259 } | 262 } |
| 260 return false; | 263 return false; |
| 261 } | 264 } |
| 262 | 265 |
| 263 void SurfaceManager::RegisterSurfaceNamespaceHierarchy( | 266 void SurfaceManager::RegisterFrameSinkHierarchy( |
| 264 uint32_t parent_namespace, | 267 const FrameSinkId& parent_frame_sink_id, |
| 265 uint32_t child_namespace) { | 268 const FrameSinkId& child_frame_sink_id) { |
| 266 DCHECK_EQ(valid_surface_client_ids_.count(parent_namespace), 1u); | 269 DCHECK_EQ(valid_frame_sink_ids_.count(parent_frame_sink_id), 1u); |
| 267 DCHECK_EQ(valid_surface_client_ids_.count(child_namespace), 1u); | 270 DCHECK_EQ(valid_frame_sink_ids_.count(child_frame_sink_id), 1u); |
| 268 | 271 |
| 269 // If it's possible to reach the parent through the child's descendant chain, | 272 // If it's possible to reach the parent through the child's descendant chain, |
| 270 // then this will create an infinite loop. Might as well just crash here. | 273 // then this will create an infinite loop. Might as well just crash here. |
| 271 CHECK(!ChildContains(child_namespace, parent_namespace)); | 274 CHECK(!ChildContains(child_frame_sink_id, parent_frame_sink_id)); |
| 272 | 275 |
| 273 std::vector<uint32_t>& children = | 276 std::vector<FrameSinkId>& children = |
| 274 namespace_client_map_[parent_namespace].children; | 277 frame_sink_source_map_[parent_frame_sink_id].children; |
| 275 for (size_t i = 0; i < children.size(); ++i) | 278 for (size_t i = 0; i < children.size(); ++i) |
| 276 DCHECK_NE(children[i], child_namespace); | 279 DCHECK(children[i] != child_frame_sink_id); |
| 277 children.push_back(child_namespace); | 280 children.push_back(child_frame_sink_id); |
| 278 | 281 |
| 279 // If the parent has no source, then attaching it to this child will | 282 // If the parent has no source, then attaching it to this child will |
| 280 // not change any downstream sources. | 283 // not change any downstream sources. |
| 281 BeginFrameSource* parent_source = | 284 BeginFrameSource* parent_source = |
| 282 namespace_client_map_[parent_namespace].source; | 285 frame_sink_source_map_[parent_frame_sink_id].source; |
| 283 if (!parent_source) | 286 if (!parent_source) |
| 284 return; | 287 return; |
| 285 | 288 |
| 286 DCHECK_EQ(registered_sources_.count(parent_source), 1u); | 289 DCHECK_EQ(registered_sources_.count(parent_source), 1u); |
| 287 RecursivelyAttachBeginFrameSource(child_namespace, parent_source); | 290 RecursivelyAttachBeginFrameSource(child_frame_sink_id, parent_source); |
| 288 } | 291 } |
| 289 | 292 |
| 290 void SurfaceManager::UnregisterSurfaceNamespaceHierarchy( | 293 void SurfaceManager::UnregisterFrameSinkHierarchy( |
| 291 uint32_t parent_namespace, | 294 const FrameSinkId& parent_frame_sink_id, |
| 292 uint32_t child_namespace) { | 295 const FrameSinkId& child_frame_sink_id) { |
| 293 // Deliberately do not check validity of either parent or child namespace | 296 // Deliberately do not check validity of either parent or child namespace |
| 294 // here. They were valid during the registration, so were valid at some | 297 // here. They were valid during the registration, so were valid at some |
| 295 // point in time. This makes it possible to invalidate parent and child | 298 // point in time. This makes it possible to invalidate parent and child |
| 296 // namespaces independently of each other and not have an ordering dependency | 299 // namespaces independently of each other and not have an ordering dependency |
| 297 // of unregistering the hierarchy first before either of them. | 300 // of unregistering the hierarchy first before either of them. |
| 298 DCHECK_EQ(namespace_client_map_.count(parent_namespace), 1u); | 301 DCHECK_EQ(frame_sink_source_map_.count(parent_frame_sink_id), 1u); |
| 299 | 302 |
| 300 auto iter = namespace_client_map_.find(parent_namespace); | 303 auto iter = frame_sink_source_map_.find(parent_frame_sink_id); |
| 301 | 304 |
| 302 std::vector<uint32_t>& children = iter->second.children; | 305 std::vector<FrameSinkId>& children = iter->second.children; |
| 303 bool found_child = false; | 306 bool found_child = false; |
| 304 for (size_t i = 0; i < children.size(); ++i) { | 307 for (size_t i = 0; i < children.size(); ++i) { |
| 305 if (children[i] == child_namespace) { | 308 if (children[i] == child_frame_sink_id) { |
| 306 found_child = true; | 309 found_child = true; |
| 307 children[i] = children.back(); | 310 children[i] = children.back(); |
| 308 children.resize(children.size() - 1); | 311 children.resize(children.size() - 1); |
| 309 break; | 312 break; |
| 310 } | 313 } |
| 311 } | 314 } |
| 312 DCHECK(found_child); | 315 DCHECK(found_child); |
| 313 | 316 |
| 314 // The SurfaceFactoryClient and hierarchy can be registered/unregistered | 317 // The SurfaceFactoryClient and hierarchy can be registered/unregistered |
| 315 // in either order, so empty namespace_client_map entries need to be | 318 // in either order, so empty namespace_client_map entries need to be |
| 316 // checked when removing either clients or relationships. | 319 // checked when removing either clients or relationships. |
| 317 if (iter->second.is_empty()) { | 320 if (iter->second.is_empty()) { |
| 318 namespace_client_map_.erase(iter); | 321 frame_sink_source_map_.erase(iter); |
| 319 return; | 322 return; |
| 320 } | 323 } |
| 321 | 324 |
| 322 // If the parent does not have a begin frame source, then disconnecting it | 325 // If the parent does not have a begin frame source, then disconnecting it |
| 323 // will not change any of its children. | 326 // will not change any of its children. |
| 324 BeginFrameSource* parent_source = iter->second.source; | 327 BeginFrameSource* parent_source = iter->second.source; |
| 325 if (!parent_source) | 328 if (!parent_source) |
| 326 return; | 329 return; |
| 327 | 330 |
| 328 // TODO(enne): these walks could be done in one step. | 331 // TODO(enne): these walks could be done in one step. |
| 329 RecursivelyDetachBeginFrameSource(child_namespace, parent_source); | 332 RecursivelyDetachBeginFrameSource(child_frame_sink_id, parent_source); |
| 330 for (auto source_iter : registered_sources_) | 333 for (auto source_iter : registered_sources_) |
| 331 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); | 334 RecursivelyAttachBeginFrameSource(source_iter.second, source_iter.first); |
| 332 } | 335 } |
| 333 | 336 |
| 334 Surface* SurfaceManager::GetSurfaceForId(const SurfaceId& surface_id) { | 337 Surface* SurfaceManager::GetSurfaceForId(const SurfaceId& surface_id) { |
| 335 DCHECK(thread_checker_.CalledOnValidThread()); | 338 DCHECK(thread_checker_.CalledOnValidThread()); |
| 336 SurfaceMap::iterator it = surface_map_.find(surface_id); | 339 SurfaceMap::iterator it = surface_map_.find(surface_id); |
| 337 if (it == surface_map_.end()) | 340 if (it == surface_map_.end()) |
| 338 return NULL; | 341 return NULL; |
| 339 return it->second; | 342 return it->second; |
| 340 } | 343 } |
| 341 | 344 |
| 342 bool SurfaceManager::SurfaceModified(const SurfaceId& surface_id) { | 345 bool SurfaceManager::SurfaceModified(const SurfaceId& surface_id) { |
| 343 CHECK(thread_checker_.CalledOnValidThread()); | 346 CHECK(thread_checker_.CalledOnValidThread()); |
| 344 bool changed = false; | 347 bool changed = false; |
| 345 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_, | 348 FOR_EACH_OBSERVER(SurfaceDamageObserver, observer_list_, |
| 346 OnSurfaceDamaged(surface_id, &changed)); | 349 OnSurfaceDamaged(surface_id, &changed)); |
| 347 return changed; | 350 return changed; |
| 348 } | 351 } |
| 349 | 352 |
| 350 } // namespace cc | 353 } // namespace cc |
| OLD | NEW |