Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "platform/graphics/paint/DisplayItemPropertyTreeBuilder.h" | |
| 7 | |
| 8 #include "platform/graphics/paint/DisplayItem.h" | |
| 9 #include "platform/graphics/paint/DisplayItemClipTree.h" | |
| 10 #include "platform/graphics/paint/DisplayItemTransformTree.h" | |
| 11 #include "platform/graphics/paint/Transform3DDisplayItem.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 DisplayItemPropertyTreeBuilder::DisplayItemPropertyTreeBuilder() | |
| 16 : m_transformTree(adoptPtr(new DisplayItemTransformTree)) | |
| 17 , m_clipTree(adoptPtr(new DisplayItemClipTree)) | |
| 18 , m_rangeBeginIndex(0) | |
| 19 , m_currentIndex(0) | |
| 20 { | |
| 21 m_stateStack.append(State()); | |
| 22 } | |
| 23 | |
| 24 DisplayItemPropertyTreeBuilder::~DisplayItemPropertyTreeBuilder() | |
| 25 { | |
| 26 } | |
| 27 | |
| 28 PassOwnPtr<DisplayItemTransformTree> DisplayItemPropertyTreeBuilder::releaseTran sformTree() | |
| 29 { | |
| 30 ASSERT(m_stateStack.size() == 1); | |
| 31 ASSERT(currentState().ignoredBeginCount == 0); | |
| 32 finishRange(); | |
| 33 return m_transformTree.release(); | |
| 34 } | |
| 35 | |
| 36 PassOwnPtr<DisplayItemClipTree> DisplayItemPropertyTreeBuilder::releaseClipTree( ) | |
| 37 { | |
| 38 ASSERT(m_stateStack.size() == 1); | |
| 39 ASSERT(currentState().ignoredBeginCount == 0); | |
| 40 finishRange(); | |
| 41 return m_clipTree.release(); | |
| 42 } | |
| 43 | |
| 44 Vector<DisplayItemPropertyTreeBuilder::RangeRecord> DisplayItemPropertyTreeBuild er::releaseRangeRecords() | |
| 45 { | |
| 46 Vector<RangeRecord> output; | |
| 47 output.swap(m_rangeRecords); | |
| 48 return output; | |
| 49 } | |
| 50 | |
| 51 void DisplayItemPropertyTreeBuilder::processDisplayItem(const DisplayItem& displ ayItem) | |
| 52 { | |
| 53 if (displayItem.isBegin()) | |
| 54 processBeginItem(displayItem); | |
| 55 else if (displayItem.isEnd()) | |
| 56 processEndItem(displayItem); | |
| 57 m_currentIndex++; | |
| 58 } | |
| 59 | |
| 60 namespace { | |
| 61 | |
| 62 enum TransformKind { NotATransform = 0, Only2DTranslation, RequiresTransformNode }; | |
| 63 enum ClipKind { NotAClip = 0, RequiresClipNode }; | |
| 64 | |
| 65 struct BeginDisplayItemClassification { | |
|
pdr.
2015/08/17 22:25:07
This seems overabstracted.
WDYT about just adding
jbroman
2015/08/17 23:57:19
Then the "copying out the matrix" bit will require
pdr.
2015/08/18 04:31:42
I still don't follow but I may be missing somethin
jbroman
2015/08/18 14:18:16
Yes, I do expect that display items may create nod
| |
| 66 TransformKind transformKind = NotATransform; | |
| 67 TransformationMatrix matrix; | |
| 68 ClipKind clipKind = NotAClip; | |
| 69 FloatRect clipRect; | |
| 70 }; | |
| 71 | |
| 72 // Classifies a begin display item based on how it affects the property trees. | |
| 73 static BeginDisplayItemClassification classifyBeginItem(const DisplayItem& begin DisplayItem) | |
| 74 { | |
| 75 ASSERT(beginDisplayItem.isBegin()); | |
| 76 | |
| 77 BeginDisplayItemClassification result; | |
| 78 DisplayItem::Type type = beginDisplayItem.type(); | |
| 79 if (DisplayItem::isTransform3DType(type)) { | |
| 80 const auto& begin3D = static_cast<const BeginTransform3DDisplayItem&>(be ginDisplayItem); | |
| 81 result.matrix = begin3D.transform(); | |
| 82 result.transformKind = result.matrix.isIdentityOr2DTranslation() ? Only2 DTranslation : RequiresTransformNode; | |
| 83 } | |
| 84 return result; | |
| 85 } | |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 89 void DisplayItemPropertyTreeBuilder::processBeginItem(const DisplayItem& display Item) | |
| 90 { | |
| 91 BeginDisplayItemClassification classification = classifyBeginItem(displayIte m); | |
| 92 | |
| 93 if (!classification.transformKind && !classification.clipKind) { | |
| 94 currentState().ignoredBeginCount++; | |
| 95 return; | |
| 96 } | |
| 97 | |
| 98 finishRange(); | |
| 99 State newState(currentState()); | |
| 100 newState.ignoredBeginCount = 0; | |
| 101 | |
| 102 switch (classification.transformKind) { | |
| 103 case NotATransform: | |
| 104 break; | |
| 105 case Only2DTranslation: | |
| 106 // Adjust the offset associated with the current transform node. | |
| 107 newState.offset += classification.matrix.to2DTranslation(); | |
| 108 break; | |
| 109 case RequiresTransformNode: | |
| 110 // Emit a transform node. | |
| 111 newState.transformNode = m_transformTree->createNewNode( | |
| 112 newState.transformNode, classification.matrix); | |
| 113 newState.offset = FloatSize(); | |
| 114 break; | |
| 115 } | |
| 116 | |
| 117 switch (classification.clipKind) { | |
| 118 case NotAClip: | |
| 119 break; | |
| 120 case RequiresClipNode: | |
| 121 // Emit a clip node. | |
| 122 FloatRect adjustedClipRect = classification.clipRect; | |
| 123 adjustedClipRect.move(newState.offset); | |
| 124 newState.clipNode = m_clipTree->createNewNode( | |
| 125 newState.clipNode, newState.transformNode, adjustedClipRect); | |
| 126 break; | |
| 127 } | |
| 128 | |
| 129 m_stateStack.append(newState); | |
| 130 } | |
| 131 | |
| 132 void DisplayItemPropertyTreeBuilder::processEndItem(const DisplayItem& displayIt em) | |
| 133 { | |
| 134 if (currentState().ignoredBeginCount) { | |
| 135 // Ignored this end display item. | |
| 136 currentState().ignoredBeginCount--; | |
| 137 } else { | |
| 138 // We've closed the scope of some property. | |
| 139 finishRange(); | |
| 140 m_stateStack.removeLast(); | |
| 141 ASSERT(!m_stateStack.isEmpty()); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 void DisplayItemPropertyTreeBuilder::finishRange() | |
| 146 { | |
| 147 // Don't emit an empty range record. | |
| 148 if (m_rangeBeginIndex < m_currentIndex) { | |
| 149 const auto& current = currentState(); | |
| 150 RangeRecord rangeRecord; | |
| 151 rangeRecord.displayListBeginIndex = m_rangeBeginIndex; | |
| 152 rangeRecord.displayListEndIndex = m_currentIndex; | |
| 153 rangeRecord.transformNodeIndex = current.transformNode; | |
| 154 rangeRecord.offset = current.offset; | |
| 155 rangeRecord.clipNodeIndex = current.clipNode; | |
| 156 m_rangeRecords.append(rangeRecord); | |
| 157 } | |
| 158 | |
| 159 // The current display item is a boundary. | |
| 160 // The earliest the next range could begin is the next one. | |
| 161 m_rangeBeginIndex = m_currentIndex + 1; | |
| 162 } | |
| 163 | |
| 164 } // namespace blink | |
| OLD | NEW |