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

Side by Side Diff: Source/core/rendering/FastTextAutosizer.cpp

Issue 186443002: [Do Not Submit] Fingerprint and Supercluster debugging logic Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #ifndef NDEBUG 67 #ifndef NDEBUG
68 , m_renderViewInfoPrepared(false) 68 , m_renderViewInfoPrepared(false)
69 , m_blocksThatHaveBegunLayout() 69 , m_blocksThatHaveBegunLayout()
70 #endif 70 #endif
71 , m_superclusters() 71 , m_superclusters()
72 , m_clusterStack() 72 , m_clusterStack()
73 , m_fingerprintMapper() 73 , m_fingerprintMapper()
74 { 74 {
75 } 75 }
76 76
77 static void printFingerprintAndSuperclusterStats(FastTextAutosizer::Supercluster Map& superclusters, FastTextAutosizer::FingerprintMapper& fingerprintMapper)
78 {
79 fprintf(stderr, "fingerprint and supercluster stats\n");
80 fprintf(stderr, "==================================\n");
81 fprintf(stderr, "Superclusters:\n");
82 int superclusterNumber = 0;
83 for (FastTextAutosizer::SuperclusterMap::iterator superIter = superclusters. begin(); superIter != superclusters.end(); ++superIter) {
84 superclusterNumber++;
85 fprintf(stderr, " #%d) supercluster fingerprint %u and blocks: ", superc lusterNumber, superIter->key);
86 const FastTextAutosizer::BlockSet* roots = superIter->value->m_roots;
87 bool isFirst = true;
88 for (FastTextAutosizer::BlockSet::iterator blockIter = roots->begin(); b lockIter != roots->end(); ++blockIter) {
89 const RenderBlock* block = (*blockIter);
90 if (!isFirst)
91 fprintf(stderr, ", ");
92 fprintf(stderr, "%p/%s", block, block->node() ? block->node()->nodeN ame().utf8().data() : "unknown");
93 isFirst = false;
94 }
95 fprintf(stderr, "\n");
96 }
97 fprintf(stderr, "Fingerprints for blocks:\n");
98 int blockNumber = 0;
99 for (FastTextAutosizer::FingerprintMapper::FingerprintMap::iterator fingerIt er = fingerprintMapper.m_fingerprints.begin(); fingerIter != fingerprintMapper.m _fingerprints.end(); ++fingerIter) {
100 blockNumber++;
101 const RenderObject* block = fingerIter->key;
102 fprintf(stderr, " #%d) block %p/%s has fingerprint %u\n", blockNumber, b lock, block->node() ? block->node()->nodeName().utf8().data() : "unknown", finge rIter->value);
103 }
104 fprintf(stderr, "Blocks for fingerprints:\n");
105 int fingerprintNumber = 0;
106 for (FastTextAutosizer::FingerprintMapper::ReverseFingerprintMap::iterator b locksIter = fingerprintMapper.m_blocksForFingerprint.begin(); blocksIter != fing erprintMapper.m_blocksForFingerprint.end(); ++blocksIter) {
107 fingerprintNumber++;
108 fprintf(stderr, " #%d) fingerprint %u and blocks: ", fingerprintNumber, blocksIter->key);
109 FastTextAutosizer::BlockSet* blocks = blocksIter->value.get();
110 bool isFirst = true;
111 for (FastTextAutosizer::BlockSet::iterator blockIter = blocks->begin(); blockIter != blocks->end(); ++blockIter) {
112 const RenderBlock* block = (*blockIter);
113 if (!isFirst)
114 fprintf(stderr, ", ");
115 fprintf(stderr, "%p/%s", block, block->node() ? block->node()->nodeN ame().utf8().data() : "unknown");
116 isFirst = false;
117 }
118 fprintf(stderr, "\n");
119 }
120 }
121
77 void FastTextAutosizer::record(const RenderBlock* block) 122 void FastTextAutosizer::record(const RenderBlock* block)
78 { 123 {
79 if (!enabled()) 124 if (!enabled())
80 return; 125 return;
81 126
82 ASSERT(!m_blocksThatHaveBegunLayout.contains(block)); 127 ASSERT(!m_blocksThatHaveBegunLayout.contains(block));
83 128
84 if (!isFingerprintingCandidate(block)) 129 if (!isFingerprintingCandidate(block))
85 return; 130 return;
86 131
87 if (Fingerprint fingerprint = computeFingerprint(block)) 132 if (Fingerprint fingerprint = computeFingerprint(block))
88 m_fingerprintMapper.addTentativeClusterRoot(block, fingerprint); 133 m_fingerprintMapper.addTentativeClusterRoot(block, fingerprint);
134 fprintf(stderr, "after record(%p)\n", block);
135 printFingerprintAndSuperclusterStats(m_superclusters, m_fingerprintMapper);
89 } 136 }
90 137
91 void FastTextAutosizer::destroy(const RenderBlock* block) 138 void FastTextAutosizer::destroy(const RenderBlock* block)
92 { 139 {
93 if (!enabled()) 140 if (!enabled())
94 return; 141 return;
95 ASSERT(!m_blocksThatHaveBegunLayout.contains(block)); 142 ASSERT(!m_blocksThatHaveBegunLayout.contains(block));
96 143
97 m_fingerprintMapper.remove(block); 144 m_fingerprintMapper.remove(block);
145 fprintf(stderr, "after destroy(%p)\n", block);
146 printFingerprintAndSuperclusterStats(m_superclusters, m_fingerprintMapper);
98 } 147 }
99 148
100 void FastTextAutosizer::prepareClusterStack(const RenderObject* renderer) 149 void FastTextAutosizer::prepareClusterStack(const RenderObject* renderer)
101 { 150 {
102 if (!renderer) 151 if (!renderer)
103 return; 152 return;
104 prepareClusterStack(renderer->parent()); 153 prepareClusterStack(renderer->parent());
105 154
106 if (renderer->isRenderBlock()) { 155 if (renderer->isRenderBlock()) {
107 const RenderBlock* block = toRenderBlock(renderer); 156 const RenderBlock* block = toRenderBlock(renderer);
108 #ifndef NDEBUG 157 #ifndef NDEBUG
109 m_blocksThatHaveBegunLayout.add(block); 158 m_blocksThatHaveBegunLayout.add(block);
110 #endif 159 #endif
111 if (Cluster* cluster = maybeCreateCluster(block)) 160 if (Cluster* cluster = maybeCreateCluster(block))
112 m_clusterStack.append(adoptPtr(cluster)); 161 m_clusterStack.append(adoptPtr(cluster));
113 } 162 }
114 } 163 }
115 164
116 void FastTextAutosizer::beginLayout(RenderBlock* block) 165 void FastTextAutosizer::beginLayout(RenderBlock* block)
117 { 166 {
167 fprintf(stderr, "beginLayout(%p)\n", block);
168 printFingerprintAndSuperclusterStats(m_superclusters, m_fingerprintMapper);
169
118 ASSERT(enabled()); 170 ASSERT(enabled());
119 #ifndef NDEBUG 171 #ifndef NDEBUG
120 m_blocksThatHaveBegunLayout.add(block); 172 m_blocksThatHaveBegunLayout.add(block);
121 #endif 173 #endif
122 174
123 if (!m_firstBlock) { 175 if (!m_firstBlock) {
124 prepareRenderViewInfo(); 176 prepareRenderViewInfo();
125 prepareClusterStack(block->parent()); 177 prepareClusterStack(block->parent());
126 m_firstBlock = block; 178 m_firstBlock = block;
127 } else if (block == currentCluster()->m_root) { 179 } else if (block == currentCluster()->m_root) {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste r->m_parent) : 1.0f; 512 cluster->m_multiplier = cluster->m_parent ? clusterMultiplier(cluste r->m_parent) : 1.0f;
461 } 513 }
462 } 514 }
463 ASSERT(cluster->m_multiplier); 515 ASSERT(cluster->m_multiplier);
464 return cluster->m_multiplier; 516 return cluster->m_multiplier;
465 } 517 }
466 518
467 float FastTextAutosizer::superclusterMultiplier(Supercluster* supercluster) 519 float FastTextAutosizer::superclusterMultiplier(Supercluster* supercluster)
468 { 520 {
469 if (!supercluster->m_multiplier) { 521 if (!supercluster->m_multiplier) {
522 fprintf(stderr, "superclusterMultiplier\n");
523 printFingerprintAndSuperclusterStats(m_superclusters, m_fingerprintMappe r);
470 const BlockSet* roots = supercluster->m_roots; 524 const BlockSet* roots = supercluster->m_roots;
471 BlockSet widthProviders; 525 BlockSet widthProviders;
472 for (BlockSet::iterator it = roots->begin(); it != roots->end(); ++it) 526 for (BlockSet::iterator it = roots->begin(); it != roots->end(); ++it)
473 widthProviders.add(clusterWidthProvider(*it)); 527 widthProviders.add(clusterWidthProvider(*it));
474 const RenderBlock* widthProvider = deepestCommonAncestor(widthProviders) ; 528 const RenderBlock* widthProvider = deepestCommonAncestor(widthProviders) ;
475 529
476 bool anyClusterHasEnoughTextToAutosize = false; 530 bool anyClusterHasEnoughTextToAutosize = false;
477 for (BlockSet::iterator it = roots->begin(); it != roots->end(); ++it) { 531 for (BlockSet::iterator it = roots->begin(); it != roots->end(); ++it) {
478 if (clusterWouldHaveEnoughTextToAutosize(*it, widthProvider)) { 532 if (clusterWouldHaveEnoughTextToAutosize(*it, widthProvider)) {
479 anyClusterHasEnoughTextToAutosize = true; 533 anyClusterHasEnoughTextToAutosize = true;
480 break; 534 break;
481 } 535 }
482 } 536 }
483 537
484 supercluster->m_multiplier = anyClusterHasEnoughTextToAutosize ? multipl ierFromBlock(widthProvider) : 1.0f; 538 supercluster->m_multiplier = anyClusterHasEnoughTextToAutosize ? multipl ierFromBlock(widthProvider) : 1.0f;
485 } 539 }
486 ASSERT(supercluster->m_multiplier); 540 ASSERT(supercluster->m_multiplier);
487 return supercluster->m_multiplier; 541 return supercluster->m_multiplier;
488 } 542 }
489 543
490 const RenderBlock* FastTextAutosizer::clusterWidthProvider(const RenderBlock* ro ot) 544 const RenderBlock* FastTextAutosizer::clusterWidthProvider(const RenderBlock* ro ot)
491 { 545 {
546 fprintf(stderr, "clusterWidthProvider(%p)\n", root);
492 if (root->isTableCell()) 547 if (root->isTableCell())
493 return toRenderTableCell(root)->table(); 548 return toRenderTableCell(root)->table();
494 if (root->isTable()) 549 if (root->isTable())
495 return toRenderTable(root); 550 return toRenderTable(root);
496 551
497 return deepestBlockContainingAllText(root); 552 return deepestBlockContainingAllText(root);
498 } 553 }
499 554
500 float FastTextAutosizer::widthFromBlock(const RenderBlock* block) 555 float FastTextAutosizer::widthFromBlock(const RenderBlock* block)
501 { 556 {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 752 }
698 753
699 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO bject* current, const RenderObject* stayWithin) 754 RenderObject* FastTextAutosizer::nextChildSkippingChildrenOfBlocks(const RenderO bject* current, const RenderObject* stayWithin)
700 { 755 {
701 if (current == stayWithin || !current->isRenderBlock()) 756 if (current == stayWithin || !current->isRenderBlock())
702 return current->nextInPreOrder(stayWithin); 757 return current->nextInPreOrder(stayWithin);
703 return current->nextInPreOrderAfterChildren(stayWithin); 758 return current->nextInPreOrderAfterChildren(stayWithin);
704 } 759 }
705 760
706 } // namespace WebCore 761 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698