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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "cc/surfaces/direct_surface_reference_factory.h" | 14 #include "cc/surfaces/direct_surface_reference_factory.h" |
| 15 #include "cc/surfaces/surface.h" | 15 #include "cc/surfaces/surface.h" |
| 16 #include "cc/surfaces/surface_factory_client.h" | 16 #include "cc/surfaces/surface_factory_client.h" |
| 17 #include "cc/surfaces/surface_id_allocator.h" | 17 #include "cc/surfaces/surface_id_allocator.h" |
| 18 | 18 |
| 19 #if DCHECK_IS_ON() | |
| 20 #include <sstream> | |
| 21 #endif | |
| 22 | |
| 19 namespace cc { | 23 namespace cc { |
| 20 | 24 |
| 21 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping() | 25 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping() |
| 22 : client(nullptr), source(nullptr) {} | 26 : client(nullptr), source(nullptr) {} |
| 23 | 27 |
| 24 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping( | 28 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping( |
| 25 const FrameSinkSourceMapping& other) = default; | 29 const FrameSinkSourceMapping& other) = default; |
| 26 | 30 |
| 27 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() { | 31 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() { |
| 28 DCHECK(is_empty()) << "client: " << client | 32 DCHECK(is_empty()) << "client: " << client |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 47 DeregisterSurface((*it)->surface_id()); | 51 DeregisterSurface((*it)->surface_id()); |
| 48 } | 52 } |
| 49 surfaces_to_destroy_.clear(); | 53 surfaces_to_destroy_.clear(); |
| 50 | 54 |
| 51 // All hierarchies, sources, and surface factory clients should be | 55 // All hierarchies, sources, and surface factory clients should be |
| 52 // unregistered prior to SurfaceManager destruction. | 56 // unregistered prior to SurfaceManager destruction. |
| 53 DCHECK_EQ(frame_sink_source_map_.size(), 0u); | 57 DCHECK_EQ(frame_sink_source_map_.size(), 0u); |
| 54 DCHECK_EQ(registered_sources_.size(), 0u); | 58 DCHECK_EQ(registered_sources_.size(), 0u); |
| 55 } | 59 } |
| 56 | 60 |
| 61 #if DCHECK_IS_ON() | |
| 62 std::string SurfaceManager::SurfaceReferencesToString() { | |
| 63 std::stringstream str; | |
| 64 SurfaceReferencesToStringImpl(root_surface_id_, "", &str); | |
| 65 return str.str(); | |
| 66 } | |
| 67 #endif | |
| 68 | |
| 57 void SurfaceManager::RegisterSurface(Surface* surface) { | 69 void SurfaceManager::RegisterSurface(Surface* surface) { |
| 58 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 DCHECK(surface); | 71 DCHECK(surface); |
| 60 DCHECK(!surface_map_.count(surface->surface_id())); | 72 DCHECK(!surface_map_.count(surface->surface_id())); |
| 61 surface_map_[surface->surface_id()] = surface; | 73 surface_map_[surface->surface_id()] = surface; |
| 62 } | 74 } |
| 63 | 75 |
| 64 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { | 76 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 SurfaceMap::iterator it = surface_map_.find(surface_id); | 78 SurfaceMap::iterator it = surface_map_.find(surface_id); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 return 0; | 175 return 0; |
| 164 return iter->second.size(); | 176 return iter->second.size(); |
| 165 } | 177 } |
| 166 | 178 |
| 167 void SurfaceManager::GarbageCollectSurfacesFromRoot() { | 179 void SurfaceManager::GarbageCollectSurfacesFromRoot() { |
| 168 DCHECK_EQ(lifetime_type_, LifetimeType::REFERENCES); | 180 DCHECK_EQ(lifetime_type_, LifetimeType::REFERENCES); |
| 169 | 181 |
| 170 if (surfaces_to_destroy_.empty()) | 182 if (surfaces_to_destroy_.empty()) |
| 171 return; | 183 return; |
| 172 | 184 |
| 173 std::unordered_set<SurfaceId, SurfaceIdHash> reachable_surfaces; | 185 SurfaceIdSet reachable_surfaces; |
| 174 | 186 |
| 175 // Walk down from the root and mark each SurfaceId we encounter as reachable. | 187 // Walk down from the root and mark each SurfaceId we encounter as reachable. |
| 176 std::queue<SurfaceId> surface_queue; | 188 std::queue<SurfaceId> surface_queue; |
| 177 surface_queue.push(root_surface_id_); | 189 surface_queue.push(root_surface_id_); |
| 178 while (!surface_queue.empty()) { | 190 while (!surface_queue.empty()) { |
| 179 const SurfaceId& surface_id = surface_queue.front(); | 191 const SurfaceId& surface_id = surface_queue.front(); |
| 180 auto iter = parent_to_child_refs_.find(surface_id); | 192 auto iter = parent_to_child_refs_.find(surface_id); |
| 181 if (iter != parent_to_child_refs_.end()) { | 193 if (iter != parent_to_child_refs_.end()) { |
| 182 for (const SurfaceId& child_id : iter->second) { | 194 for (const SurfaceId& child_id : iter->second) { |
| 183 // Check for cycles when inserting into |reachable_surfaces|. | 195 // Check for cycles when inserting into |reachable_surfaces|. |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 observer.OnSurfaceDamaged(surface_id, &changed); | 513 observer.OnSurfaceDamaged(surface_id, &changed); |
| 502 return changed; | 514 return changed; |
| 503 } | 515 } |
| 504 | 516 |
| 505 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { | 517 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { |
| 506 CHECK(thread_checker_.CalledOnValidThread()); | 518 CHECK(thread_checker_.CalledOnValidThread()); |
| 507 for (auto& observer : observer_list_) | 519 for (auto& observer : observer_list_) |
| 508 observer.OnSurfaceCreated(surface_info); | 520 observer.OnSurfaceCreated(surface_info); |
| 509 } | 521 } |
| 510 | 522 |
| 523 #if DCHECK_IS_ON() | |
| 524 void SurfaceManager::SurfaceReferencesToStringImpl(const SurfaceId& surface_id, | |
| 525 std::string indent, | |
| 526 std::stringstream* str) { | |
| 527 *str << indent; | |
| 528 | |
| 529 // Print the current line for |surface_id|. | |
| 530 Surface* surface = GetSurfaceForId(surface_id); | |
| 531 if (surface) { | |
| 532 *str << surface->surface_id().ToString(); | |
| 533 *str << (surface->destroyed() ? " destroyed " : " live "); | |
| 534 | |
| 535 if (surface->HasFrame()) { | |
| 536 *str << surface->GetEligibleFrame() | |
|
danakj
2017/01/18 16:57:11
can you try using a temp var to split this into tw
kylechar
2017/01/18 18:04:58
Done.
| |
| 537 .render_pass_list.back() | |
| 538 ->output_rect.size() | |
| 539 .ToString(); | |
| 540 } | |
| 541 } else { | |
| 542 *str << surface_id; | |
| 543 } | |
| 544 *str << "\n"; | |
| 545 | |
| 546 // If the current surface has references to children, sort children and print | |
| 547 // references for each child. | |
| 548 auto iter = parent_to_child_refs_.find(surface_id); | |
| 549 if (iter != parent_to_child_refs_.end()) { | |
| 550 std::vector<SurfaceId> children(iter->second.begin(), iter->second.end()); | |
| 551 std::sort(children.begin(), children.end()); | |
| 552 | |
| 553 for (const SurfaceId& child_id : children) | |
| 554 SurfaceReferencesToStringImpl(child_id, indent + " ", str); | |
| 555 } | |
| 556 } | |
| 557 #endif // DCHECK_IS_ON() | |
| 558 | |
| 511 } // namespace cc | 559 } // namespace cc |
| OLD | NEW |