Changeset 286851 in webkit
- Timestamp:
- Dec 10, 2021, 8:20:40 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp (modified) (12 diffs)
-
layout/formattingContexts/inline/InlineDisplayContentBuilder.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r286848 r286851 1 2021-12-10 Alan Bujtas <zalan@apple.com> 2 3 [LFC][IFC] Replace Vector<std::unique_ptr<DisplayBoxNode> with Vector<DisplayBoxTree::Node> 4 https://bugs.webkit.org/show_bug.cgi?id=234110 5 6 Reviewed by Antti Koivisto. 7 8 This patch switches over from using DisplayBoxNode* in AncestorStack to simple indexes to contain heap allocations. 9 10 * layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp: 11 (WebCore::Layout::DisplayBoxTree::DisplayBoxTree): 12 (WebCore::Layout::DisplayBoxTree::hasInlineBox const): 13 (WebCore::Layout::DisplayBoxTree::root const): 14 (WebCore::Layout::DisplayBoxTree::at): 15 (WebCore::Layout::DisplayBoxTree::at const): 16 (WebCore::Layout::DisplayBoxTree::append): 17 (WebCore::Layout::AncestorStack::unwind): 18 (WebCore::Layout::AncestorStack::push): 19 (WebCore::Layout::createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack): 20 (WebCore::Layout::InlineDisplayContentBuilder::ensureDisplayBoxForContainer): 21 (WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox): 22 (WebCore::Layout::InlineDisplayContentBuilder::processBidiContent): 23 (WebCore::Layout::DisplayBoxNode::DisplayBoxNode): Deleted. 24 (WebCore::Layout::DisplayBoxNode::appendChild): Deleted. 25 (WebCore::Layout::InlineDisplayContentBuilder::adjustVisualGeometryForChildNode): Deleted. 26 * layout/formattingContexts/inline/InlineDisplayContentBuilder.h: 27 1 28 2021-12-10 Alan Bujtas <zalan@apple.com> 2 29 -
trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.cpp
r286801 r286851 341 341 } 342 342 343 struct DisplayBoxNode { 344 WTF_MAKE_STRUCT_FAST_ALLOCATED; 345 DisplayBoxNode() = default; 346 DisplayBoxNode(size_t index, DisplayBoxNode* parent) 347 : index(index) 348 , parent(parent) 349 { 350 } 351 352 void appendChild(size_t childIndex) { children.append(makeUnique<DisplayBoxNode>(childIndex, this)); } 353 354 size_t index { 0 }; 355 DisplayBoxNode* parent { nullptr }; 356 Vector<std::unique_ptr<DisplayBoxNode>> children; 343 struct DisplayBoxTree { 344 public: 345 struct Node { 346 // Node's parent index in m_displayBoxNodes. 347 std::optional<size_t> parentIndex; 348 // Associated display box index in DisplayBoxes. 349 size_t displayBoxIndex { 0 }; 350 // Child indexes in m_displayBoxNodes. 351 Vector<size_t> children { }; 352 }; 353 354 DisplayBoxTree() 355 { 356 m_displayBoxNodes.append({ }); 357 } 358 359 bool hasInlineBox() const { return m_displayBoxNodes.size() > 1; } 360 const Node& root() const { return m_displayBoxNodes.first(); } 361 Node& at(size_t index) { return m_displayBoxNodes[index]; } 362 const Node& at(size_t index) const { return m_displayBoxNodes[index]; } 363 364 size_t append(size_t parentNodeIndex, size_t childDisplayBoxIndex) 365 { 366 auto childDisplayBoxNodeIndex = m_displayBoxNodes.size(); 367 m_displayBoxNodes.append({ parentNodeIndex, childDisplayBoxIndex }); 368 at(parentNodeIndex).children.append(childDisplayBoxNodeIndex); 369 return childDisplayBoxNodeIndex; 370 } 371 372 private: 373 Vector<Node, 10> m_displayBoxNodes; 357 374 }; 358 375 359 376 struct AncestorStack { 360 DisplayBoxNode*unwind(const ContainerBox& containerBox)377 std::optional<size_t> unwind(const ContainerBox& containerBox) 361 378 { 362 379 // Unwind the stack all the way to container box. 363 380 if (!m_set.contains(&containerBox)) 364 return nullptr;381 return { }; 365 382 while (m_set.last() != &containerBox) { 366 383 m_stack.removeLast(); … … 372 389 } 373 390 374 void push( DisplayBoxNode& displayBoxNode, const ContainerBox& containerBox)391 void push(size_t displayBoxNodeIndexForContainerBox, const ContainerBox& containerBox) 375 392 { 376 m_stack.append( &displayBoxNode);393 m_stack.append(displayBoxNodeIndexForContainerBox); 377 394 ASSERT(!m_set.contains(&containerBox)); 378 395 m_set.add(&containerBox); … … 380 397 381 398 private: 382 Vector< DisplayBoxNode*> m_stack;399 Vector<size_t> m_stack; 383 400 ListHashSet<const ContainerBox*> m_set; 384 401 }; 385 402 386 static inline DisplayBoxNode& createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack(const ContainerBox& containerBox, size_t displayBoxIndex, DisplayBoxNode& parentDisplayBoxNode, AncestorStack& ancestorStack) 387 { 388 parentDisplayBoxNode.appendChild(displayBoxIndex); 389 auto& displayBoxNode = *parentDisplayBoxNode.children.last(); 390 ancestorStack.push(displayBoxNode, containerBox); 391 return displayBoxNode; 392 } 393 394 DisplayBoxNode& InlineDisplayContentBuilder::ensureDisplayBoxForContainer(const ContainerBox& containerBox, AncestorStack& ancestorStack, DisplayBoxes& boxes) 403 static inline size_t createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack(const ContainerBox& containerBox, size_t displayBoxIndex, size_t parentDisplayBoxNodeIndex, DisplayBoxTree& displayBoxTree, AncestorStack& ancestorStack) 404 { 405 auto displayBoxNodeIndex = displayBoxTree.append(parentDisplayBoxNodeIndex, displayBoxIndex); 406 ancestorStack.push(displayBoxNodeIndex, containerBox); 407 return displayBoxNodeIndex; 408 } 409 410 size_t InlineDisplayContentBuilder::ensureDisplayBoxForContainer(const ContainerBox& containerBox, DisplayBoxTree& displayBoxTree, AncestorStack& ancestorStack, DisplayBoxes& boxes) 395 411 { 396 412 ASSERT(containerBox.isInlineBox() || &containerBox == &root()); 397 if (auto * lowestCommonAncestor= ancestorStack.unwind(containerBox))398 return *lowestCommonAncestor ;399 auto & enclosingDisplayBoxNodeForContainer = ensureDisplayBoxForContainer(containerBox.parent(), ancestorStack, boxes);413 if (auto lowestCommonAncestorIndex = ancestorStack.unwind(containerBox)) 414 return *lowestCommonAncestorIndex; 415 auto enclosingDisplayBoxNodeIndexForContainer = ensureDisplayBoxForContainer(containerBox.parent(), displayBoxTree, ancestorStack, boxes); 400 416 appendInlineDisplayBoxAtBidiBoundary(containerBox, boxes); 401 return createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack(containerBox, boxes.size() - 1, enclosingDisplayBoxNode ForContainer, ancestorStack);402 } 403 404 void InlineDisplayContentBuilder::adjustVisualGeometryFor ChildNode(const DisplayBoxNode& displayBoxNode, InlineLayoutUnit& contentRightInVisualOrder, InlineLayoutUnit lineBoxLogicalTop, DisplayBoxes& boxes, const LineBox& lineBox)417 return createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack(containerBox, boxes.size() - 1, enclosingDisplayBoxNodeIndexForContainer, displayBoxTree, ancestorStack); 418 } 419 420 void InlineDisplayContentBuilder::adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& contentRightInVisualOrder, InlineLayoutUnit lineBoxLogicalTop, const DisplayBoxTree& displayBoxTree, DisplayBoxes& boxes, const LineBox& lineBox) 405 421 { 406 422 // Non-inline box display boxes just need a horizontal adjustment while … … 408 424 // 1. horizontal adjustment and margin/border/padding start offsetting on the first box 409 425 // 2. right edge computation including descendant content width and margin/border/padding end offsetting on the last box 410 ASSERT(displayBoxNode.index); 411 auto& displayBox = boxes[displayBoxNode.index]; 426 auto& displayBox = boxes[displayBoxTree.at(displayBoxNodeIndex).displayBoxIndex]; 412 427 auto& layoutBox = displayBox.layoutBox(); 413 428 … … 434 449 beforeInlineBoxContent(); 435 450 436 for (auto & childDisplayBoxNode : displayBoxNode.children)437 adjustVisualGeometryFor ChildNode(*childDisplayBoxNode, contentRightInVisualOrder, lineBoxLogicalTop, boxes, lineBox);451 for (auto childDisplayBoxNodeIndex : displayBoxTree.at(displayBoxNodeIndex).children) 452 adjustVisualGeometryForDisplayBox(childDisplayBoxNodeIndex, contentRightInVisualOrder, lineBoxLogicalTop, displayBoxTree, boxes, lineBox); 438 453 439 454 auto afterInlineBoxContent = [&] { … … 464 479 465 480 AncestorStack ancestorStack; 466 DisplayBoxNode rootDisplayBoxNode ={ };467 ancestorStack.push( rootDisplayBoxNode, root());481 auto displayBoxTree = DisplayBoxTree { }; 482 ancestorStack.push({ }, root()); 468 483 469 484 auto contentStartInVisualOrder = InlineLayoutUnit { }; … … 496 511 }; 497 512 498 auto & parentDisplayBoxNode = ensureDisplayBoxForContainer(layoutBox.parent(), ancestorStack, boxes);513 auto parentDisplayBoxNodeIndex = ensureDisplayBoxForContainer(layoutBox.parent(), displayBoxTree, ancestorStack, boxes); 499 514 if (lineRun.isText()) { 500 515 auto visualRect = visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)); 501 516 appendTextDisplayBox(lineRun, visualRect, boxes); 502 517 contentRightInVisualOrder += visualRect.width(); 503 parentDisplayBoxNode.appendChild(boxes.size() - 1);518 displayBoxTree.append(parentDisplayBoxNodeIndex, boxes.size() - 1); 504 519 continue; 505 520 } … … 507 522 ASSERT(!visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)).width()); 508 523 appendSoftLineBreakDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForTextRun(lineRun)), boxes); 509 parentDisplayBoxNode.appendChild(boxes.size() - 1);524 displayBoxTree.append(parentDisplayBoxNodeIndex, boxes.size() - 1); 510 525 continue; 511 526 } … … 513 528 ASSERT(!visualRectRelativeToRoot(lineBox.logicalRectForLineBreakBox(layoutBox)).width()); 514 529 appendHardLineBreakDisplayBox(lineRun, visualRectRelativeToRoot(lineBox.logicalRectForLineBreakBox(layoutBox)), boxes); 515 parentDisplayBoxNode.appendChild(boxes.size() - 1);530 displayBoxTree.append(parentDisplayBoxNodeIndex, boxes.size() - 1); 516 531 continue; 517 532 } … … 522 537 appendAtomicInlineLevelDisplayBox(lineRun, visualRect, boxes); 523 538 contentRightInVisualOrder += boxGeometry.marginStart() + visualRect.width() + boxGeometry.marginEnd(); 524 parentDisplayBoxNode.appendChild(boxes.size() - 1);539 displayBoxTree.append(parentDisplayBoxNodeIndex, boxes.size() - 1); 525 540 continue; 526 541 } 527 542 if (lineRun.isInlineBoxStart() || lineRun.isLineSpanningInlineBoxStart()) { 528 543 appendInlineDisplayBoxAtBidiBoundary(layoutBox, boxes); 529 createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack(downcast<ContainerBox>(layoutBox), boxes.size() - 1, parentDisplayBoxNode , ancestorStack);544 createdDisplayBoxNodeForContainerBoxAndPushToAncestorStack(downcast<ContainerBox>(layoutBox), boxes.size() - 1, parentDisplayBoxNodeIndex, displayBoxTree, ancestorStack); 530 545 continue; 531 546 } … … 535 550 createDisplayBoxesInVisualOrder(); 536 551 537 if ( !rootDisplayBoxNode.children.isEmpty()) {552 if (displayBoxTree.hasInlineBox()) { 538 553 auto computeIsFirstIsLastBox = [&] { 539 554 HashMap<const Box*, size_t> lastDisplayBoxIndexes; … … 557 572 auto adjustVisualGeometryWithInlineBoxes = [&] { 558 573 auto contentRightInVisualOrder = lineBoxLogicalTopLeft.x() + contentStartInVisualOrder; 559 for (auto& childDisplayBoxNode : rootDisplayBoxNode.children) 560 adjustVisualGeometryForChildNode(*childDisplayBoxNode, contentRightInVisualOrder, lineBoxLogicalTopLeft.y(), boxes, lineBox); 574 575 for (auto childDisplayBoxNodeIndex : displayBoxTree.root().children) 576 adjustVisualGeometryForDisplayBox(childDisplayBoxNodeIndex, contentRightInVisualOrder, lineBoxLogicalTopLeft.y(), displayBoxTree, boxes, lineBox); 561 577 }; 562 578 adjustVisualGeometryWithInlineBoxes(); -
trunk/Source/WebCore/layout/formattingContexts/inline/InlineDisplayContentBuilder.h
r286789 r286851 36 36 struct AncestorStack; 37 37 class ContainerBox; 38 struct DisplayBox Node;38 struct DisplayBoxTree; 39 39 class InlineFormattingState; 40 40 class LineBox; … … 63 63 64 64 void setInlineBoxGeometry(const Box&, const InlineRect&, bool isFirstInlineBoxFragment); 65 void adjustVisualGeometryFor ChildNode(const DisplayBoxNode&, InlineLayoutUnit& accumulatedOffset, InlineLayoutUnit lineBoxLogicalTop, DisplayBoxes&, const LineBox&);66 DisplayBoxNode& ensureDisplayBoxForContainer(const ContainerBox&, AncestorStack&, DisplayBoxes&);65 void adjustVisualGeometryForDisplayBox(size_t displayBoxNodeIndex, InlineLayoutUnit& accumulatedOffset, InlineLayoutUnit lineBoxLogicalTop, const DisplayBoxTree&, DisplayBoxes&, const LineBox&); 66 size_t ensureDisplayBoxForContainer(const ContainerBox&, DisplayBoxTree&, AncestorStack&, DisplayBoxes&); 67 67 68 68 const ContainerBox& root() const { return m_formattingContextRoot; }
Note:
See TracChangeset
for help on using the changeset viewer.