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

Side by Side Diff: Source/platform/graphics/paint/DisplayItemTransformTreeBuilder.cpp

Issue 1296963002: Put transform tree building in DisplayItemPropertyTreeBuilder. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove unused include. Created 5 years, 4 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
OLDNEW
(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/DisplayItemTransformTreeBuilder.h"
7
8 #include "platform/graphics/paint/DisplayItem.h"
9 #include "platform/graphics/paint/DisplayItemTransformTree.h"
10 #include "platform/graphics/paint/Transform3DDisplayItem.h"
11
12 namespace blink {
13
14 DisplayItemTransformTreeBuilder::DisplayItemTransformTreeBuilder()
15 : m_transformTree(adoptPtr(new DisplayItemTransformTree))
16 , m_rangeBeginIndex(0)
17 , m_currentIndex(0)
18 {
19 pushCurrentTransformNode(0 /* root node */, FloatSize());
20 }
21
22 DisplayItemTransformTreeBuilder::~DisplayItemTransformTreeBuilder()
23 {
24 }
25
26 PassOwnPtr<DisplayItemTransformTree> DisplayItemTransformTreeBuilder::releaseTra nsformTree()
27 {
28 ASSERT(m_currentTransformNodeStack.size() == 1);
29 ASSERT(currentTransformNodeData().ignoredBeginCount == 0);
30
31 finishRange();
32 return m_transformTree.release();
33 }
34
35 namespace {
36
37 enum BeginDisplayItemClassification { NotATransform = 0, Only2DTranslation, Requ iresTransformNode };
38
39 // Classifies a display item based on whether it is a transform, and if so,
40 // whether it should be get a transform node.
41 // If it is a transform (including a translation), the TransformationMatrix
42 // will be copied to output parameter.
43 static BeginDisplayItemClassification classifyBeginItem(const DisplayItem& begin DisplayItem, TransformationMatrix* transform)
44 {
45 ASSERT(beginDisplayItem.isBegin());
46
47 if (DisplayItem::isTransform3DType(beginDisplayItem.type())) {
48 const auto& begin3D = static_cast<const BeginTransform3DDisplayItem&>(be ginDisplayItem);
49 *transform = begin3D.transform();
50 if (transform->isIdentityOr2DTranslation())
51 return Only2DTranslation;
52 return RequiresTransformNode;
53 }
54 return NotATransform;
55 }
56
57 } // namespace
58
59 void DisplayItemTransformTreeBuilder::processDisplayItem(const DisplayItem& disp layItem)
60 {
61 if (displayItem.isBegin()) {
62 TransformationMatrix matrix;
63 switch (classifyBeginItem(displayItem, &matrix)) {
64 case NotATransform:
65 // Remember to ignore this begin later on.
66 currentTransformNodeData().ignoredBeginCount++;
67 break;
68 case Only2DTranslation:
69 // Adjust the offset associated with the current transform node.
70 finishRange();
71 pushCurrentTransformNode(
72 currentTransformNodeData().transformNode,
73 currentTransformNodeData().offset + matrix.to2DTranslation());
74 break;
75 case RequiresTransformNode:
76 // Emit a transform node.
77 finishRange();
78 size_t newNode = m_transformTree->createNewNode(
79 currentTransformNodeData().transformNode,
80 matrix);
81 pushCurrentTransformNode(newNode, FloatSize());
82 break;
83 }
84 } else if (displayItem.isEnd()) {
85 if (currentTransformNodeData().ignoredBeginCount) {
86 // Ignored this end display item.
87 currentTransformNodeData().ignoredBeginCount--;
88 } else {
89 // We've closed the scope of a transform.
90 finishRange();
91 popCurrentTransformNode();
92 ASSERT(!m_currentTransformNodeStack.isEmpty());
93 }
94 }
95 m_currentIndex++;
96 }
97
98 void DisplayItemTransformTreeBuilder::finishRange()
99 {
100 // Don't emit an empty range record.
101 if (m_rangeBeginIndex != m_currentIndex) {
102 const auto& current = currentTransformNodeData();
103 m_transformTree->appendRangeRecord(m_rangeBeginIndex, m_currentIndex, cu rrent.transformNode, current.offset);
104 }
105
106 // The current display item is a boundary.
107 // The earliest the next range could begin is the next one.
108 m_rangeBeginIndex = m_currentIndex + 1;
109 }
110
111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698