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 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 namespace { | |
| 22 | |
| 23 std::string SurfaceToString(const Surface& surface) { | |
|
danakj
2017/01/17 23:21:57
seems like this should use the stringstream?
kylechar
2017/01/18 15:06:18
Sure. It's not that useful as a function on it's o
| |
| 24 std::string str = surface.surface_id().ToString(); | |
| 25 str += surface.destroyed() ? " destroyed " : " live"; | |
| 26 | |
| 27 if (surface.HasFrame()) { | |
| 28 str += surface.GetEligibleFrame() | |
| 29 .render_pass_list[0] | |
|
danakj
2017/01/17 23:21:57
dont u want the back? why the topmost one?
kylechar
2017/01/18 15:06:18
I probably do want the back one if you're asking :
danakj
2017/01/18 16:50:40
A renderpass is an indirect surface that we draw i
| |
| 30 ->output_rect.size() | |
| 31 .ToString(); | |
| 32 } | |
| 33 | |
| 34 return str; | |
| 35 } | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 21 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping() | 39 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping() |
| 22 : client(nullptr), source(nullptr) {} | 40 : client(nullptr), source(nullptr) {} |
| 23 | 41 |
| 24 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping( | 42 SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping( |
| 25 const FrameSinkSourceMapping& other) = default; | 43 const FrameSinkSourceMapping& other) = default; |
| 26 | 44 |
| 27 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() { | 45 SurfaceManager::FrameSinkSourceMapping::~FrameSinkSourceMapping() { |
| 28 DCHECK(is_empty()) << "client: " << client | 46 DCHECK(is_empty()) << "client: " << client |
| 29 << ", children: " << children.size(); | 47 << ", children: " << children.size(); |
| 30 } | 48 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 47 DeregisterSurface((*it)->surface_id()); | 65 DeregisterSurface((*it)->surface_id()); |
| 48 } | 66 } |
| 49 surfaces_to_destroy_.clear(); | 67 surfaces_to_destroy_.clear(); |
| 50 | 68 |
| 51 // All hierarchies, sources, and surface factory clients should be | 69 // All hierarchies, sources, and surface factory clients should be |
| 52 // unregistered prior to SurfaceManager destruction. | 70 // unregistered prior to SurfaceManager destruction. |
| 53 DCHECK_EQ(frame_sink_source_map_.size(), 0u); | 71 DCHECK_EQ(frame_sink_source_map_.size(), 0u); |
| 54 DCHECK_EQ(registered_sources_.size(), 0u); | 72 DCHECK_EQ(registered_sources_.size(), 0u); |
| 55 } | 73 } |
| 56 | 74 |
| 75 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | |
| 76 | |
| 77 std::string SurfaceManager::PrintSurfaceReferences() { | |
| 78 std::stringstream str; | |
| 79 // Starting a |root_surface_id_| will print all reachable surfaces. | |
|
danakj
2017/01/17 23:21:57
starting at? seems mostly duplicating the header t
kylechar
2017/01/18 15:06:18
Removed.
| |
| 80 PrintSurfaceReferencesImpl(root_surface_id_, "", &str); | |
| 81 return str.str(); | |
| 82 } | |
| 83 | |
| 84 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | |
|
danakj
2017/01/17 23:21:57
i dont think u need the // here when its only like
kylechar
2017/01/18 15:06:18
Done.
| |
| 85 | |
| 57 void SurfaceManager::RegisterSurface(Surface* surface) { | 86 void SurfaceManager::RegisterSurface(Surface* surface) { |
| 58 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
| 59 DCHECK(surface); | 88 DCHECK(surface); |
| 60 DCHECK(!surface_map_.count(surface->surface_id())); | 89 DCHECK(!surface_map_.count(surface->surface_id())); |
| 61 surface_map_[surface->surface_id()] = surface; | 90 surface_map_[surface->surface_id()] = surface; |
| 62 } | 91 } |
| 63 | 92 |
| 64 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { | 93 void SurfaceManager::DeregisterSurface(const SurfaceId& surface_id) { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 SurfaceMap::iterator it = surface_map_.find(surface_id); | 95 SurfaceMap::iterator it = surface_map_.find(surface_id); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 return 0; | 192 return 0; |
| 164 return iter->second.size(); | 193 return iter->second.size(); |
| 165 } | 194 } |
| 166 | 195 |
| 167 void SurfaceManager::GarbageCollectSurfacesFromRoot() { | 196 void SurfaceManager::GarbageCollectSurfacesFromRoot() { |
| 168 DCHECK_EQ(lifetime_type_, LifetimeType::REFERENCES); | 197 DCHECK_EQ(lifetime_type_, LifetimeType::REFERENCES); |
| 169 | 198 |
| 170 if (surfaces_to_destroy_.empty()) | 199 if (surfaces_to_destroy_.empty()) |
| 171 return; | 200 return; |
| 172 | 201 |
| 173 std::unordered_set<SurfaceId, SurfaceIdHash> reachable_surfaces; | 202 SurfaceIdSet reachable_surfaces; |
| 174 | 203 |
| 175 // Walk down from the root and mark each SurfaceId we encounter as reachable. | 204 // Walk down from the root and mark each SurfaceId we encounter as reachable. |
| 176 std::queue<SurfaceId> surface_queue; | 205 std::queue<SurfaceId> surface_queue; |
| 177 surface_queue.push(root_surface_id_); | 206 surface_queue.push(root_surface_id_); |
| 178 while (!surface_queue.empty()) { | 207 while (!surface_queue.empty()) { |
| 179 const SurfaceId& surface_id = surface_queue.front(); | 208 const SurfaceId& surface_id = surface_queue.front(); |
| 180 auto iter = parent_to_child_refs_.find(surface_id); | 209 auto iter = parent_to_child_refs_.find(surface_id); |
| 181 if (iter != parent_to_child_refs_.end()) { | 210 if (iter != parent_to_child_refs_.end()) { |
| 182 for (const SurfaceId& child_id : iter->second) { | 211 for (const SurfaceId& child_id : iter->second) { |
| 183 // Check for cycles when inserting into |reachable_surfaces|. | 212 // 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); | 530 observer.OnSurfaceDamaged(surface_id, &changed); |
| 502 return changed; | 531 return changed; |
| 503 } | 532 } |
| 504 | 533 |
| 505 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { | 534 void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) { |
| 506 CHECK(thread_checker_.CalledOnValidThread()); | 535 CHECK(thread_checker_.CalledOnValidThread()); |
| 507 for (auto& observer : observer_list_) | 536 for (auto& observer : observer_list_) |
| 508 observer.OnSurfaceCreated(surface_info); | 537 observer.OnSurfaceCreated(surface_info); |
| 509 } | 538 } |
| 510 | 539 |
| 540 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | |
| 541 | |
| 542 void SurfaceManager::PrintSurfaceReferencesImpl(const SurfaceId& surface_id, | |
|
danakj
2017/01/17 23:21:57
You could do this with a lambda and then the strin
kylechar
2017/01/18 15:06:18
It's possible but the lambda definition isn't the
danakj
2017/01/18 16:53:47
Ah, std::function is banned. http://chromium-cpp.a
| |
| 543 std::string indent, | |
| 544 std::stringstream* str) { | |
| 545 Surface* surface = GetSurfaceForId(surface_id); | |
| 546 | |
| 547 *str << indent; | |
| 548 *str << (surface ? SurfaceToString(*surface) : surface_id.ToString()); | |
| 549 *str << "\n"; | |
| 550 | |
| 551 // If the current surface has references to children, sort children and print | |
| 552 // references for each child. | |
| 553 auto iter = parent_to_child_refs_.find(surface_id); | |
| 554 if (iter != parent_to_child_refs_.end()) { | |
| 555 const SurfaceIdSet& children = iter->second; | |
|
danakj
2017/01/17 23:21:57
Set is a misleading name, it sounds ordered alread
kylechar
2017/01/18 15:06:18
It's not really necessary, so removed the variable
| |
| 556 std::vector<SurfaceId> list(children.begin(), children.end()); | |
| 557 std::sort(list.begin(), list.end()); | |
| 558 | |
| 559 for (const SurfaceId& child_id : list) | |
| 560 PrintSurfaceReferencesImpl(child_id, indent + " ", str); | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 #endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) | |
| 565 | |
| 511 } // namespace cc | 566 } // namespace cc |
| OLD | NEW |