Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Unified Diff: cc/surfaces/surface_manager.cc

Issue 2625203004: Add debug method to print surface references. (Closed)
Patch Set: Cleanup. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« cc/surfaces/surface_manager.h ('K') | « cc/surfaces/surface_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/surfaces/surface_manager.cc
diff --git a/cc/surfaces/surface_manager.cc b/cc/surfaces/surface_manager.cc
index c4dcc5b46cf5eb58a3ee195ddbba829760429155..8bce2c0ef7a84cf72eb1cf7b457d833f419e6dd6 100644
--- a/cc/surfaces/surface_manager.cc
+++ b/cc/surfaces/surface_manager.cc
@@ -18,6 +18,24 @@
namespace cc {
+namespace {
+
+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
+ std::string str = surface.surface_id().ToString();
+ str += surface.destroyed() ? " destroyed " : " live";
+
+ if (surface.HasFrame()) {
+ str += surface.GetEligibleFrame()
+ .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
+ ->output_rect.size()
+ .ToString();
+ }
+
+ return str;
+}
+
+} // namespace
+
SurfaceManager::FrameSinkSourceMapping::FrameSinkSourceMapping()
: client(nullptr), source(nullptr) {}
@@ -54,6 +72,17 @@ SurfaceManager::~SurfaceManager() {
DCHECK_EQ(registered_sources_.size(), 0u);
}
+#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+
+std::string SurfaceManager::PrintSurfaceReferences() {
+ std::stringstream str;
+ // 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.
+ PrintSurfaceReferencesImpl(root_surface_id_, "", &str);
+ return str.str();
+}
+
+#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.
+
void SurfaceManager::RegisterSurface(Surface* surface) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(surface);
@@ -170,7 +199,7 @@ void SurfaceManager::GarbageCollectSurfacesFromRoot() {
if (surfaces_to_destroy_.empty())
return;
- std::unordered_set<SurfaceId, SurfaceIdHash> reachable_surfaces;
+ SurfaceIdSet reachable_surfaces;
// Walk down from the root and mark each SurfaceId we encounter as reachable.
std::queue<SurfaceId> surface_queue;
@@ -508,4 +537,30 @@ void SurfaceManager::SurfaceCreated(const SurfaceInfo& surface_info) {
observer.OnSurfaceCreated(surface_info);
}
+#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+
+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
+ std::string indent,
+ std::stringstream* str) {
+ Surface* surface = GetSurfaceForId(surface_id);
+
+ *str << indent;
+ *str << (surface ? SurfaceToString(*surface) : surface_id.ToString());
+ *str << "\n";
+
+ // If the current surface has references to children, sort children and print
+ // references for each child.
+ auto iter = parent_to_child_refs_.find(surface_id);
+ if (iter != parent_to_child_refs_.end()) {
+ 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
+ std::vector<SurfaceId> list(children.begin(), children.end());
+ std::sort(list.begin(), list.end());
+
+ for (const SurfaceId& child_id : list)
+ PrintSurfaceReferencesImpl(child_id, indent + " ", str);
+ }
+}
+
+#endif // !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
+
} // namespace cc
« cc/surfaces/surface_manager.h ('K') | « cc/surfaces/surface_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698