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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilder.cpp

Issue 1407543003: Preliminary paint property walk implementation for SPv2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test fixture Created 5 years, 2 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
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 "core/paint/PaintPropertyTreeBuilder.h"
7
8 #include "core/frame/FrameView.h"
9 #include "core/layout/LayoutView.h"
10 #include "core/paint/ObjectPaintProperties.h"
11 #include "core/paint/PaintLayer.h"
12 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
13 #include "platform/transforms/TransformationMatrix.h"
14
15 namespace blink {
16
17 struct PaintPropertyTreeBuilder::Context {
18 Context() : currentTransform(nullptr), transformForOutOfFlowPositioned(nullp tr), transformForFixedPositioned(nullptr) { }
19
20 TransformPaintPropertyNode* currentTransform;
21 LayoutPoint paintOffset;
22
23 TransformPaintPropertyNode* transformForOutOfFlowPositioned;
24 LayoutPoint paintOffsetForOutOfFlowPositioned;
25
26 TransformPaintPropertyNode* transformForFixedPositioned;
27 LayoutPoint paintOffsetForFixedPositioned;
28 };
29
30 void PaintPropertyTreeBuilder::buildPropertyTrees(FrameView& rootFrame)
31 {
32 walk(rootFrame, Context());
33 }
34
35 void PaintPropertyTreeBuilder::walk(FrameView& frameView, const Context& context )
36 {
37 Context localContext(context);
38 RefPtr<TransformPaintPropertyNode> newTransformNodeForPreTranslation;
39 RefPtr<TransformPaintPropertyNode> newTransformNodeForScrollTranslation;
40
41 TransformationMatrix frameTranslate;
42 frameTranslate.translate(frameView.x(), frameView.y());
43 // The frame owner applies paint offset already.
44 // This assumption may change in the future.
45 ASSERT(context.paintOffset == LayoutPoint());
46 newTransformNodeForPreTranslation = TransformPaintPropertyNode::create(frame Translate, FloatPoint3D(), context.currentTransform);
47 localContext.transformForFixedPositioned = newTransformNodeForPreTranslation .get();
48 localContext.paintOffsetForFixedPositioned = LayoutPoint();
49
50 // This is going away in favor of Settings::rootLayerScrolls.
51 DoubleSize scrollOffset = frameView.scrollOffsetDouble();
52 TransformationMatrix frameScroll;
53 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height());
54 newTransformNodeForScrollTranslation = TransformPaintPropertyNode::create(fr ameScroll, FloatPoint3D(), newTransformNodeForPreTranslation);
55 localContext.currentTransform = localContext.transformForOutOfFlowPositioned = newTransformNodeForScrollTranslation.get();
56 localContext.paintOffset = localContext.paintOffsetForOutOfFlowPositioned = LayoutPoint();
57
58 frameView.setPreTranslation(newTransformNodeForPreTranslation.release());
59 frameView.setScrollTranslation(newTransformNodeForScrollTranslation.release( ));
60
61 if (LayoutView* layoutView = frameView.layoutView())
62 walk(*layoutView, localContext);
63 }
64
65 static bool shouldCreatePreTranslationNode(LayoutBoxModelObject& object)
66 {
67 // TODO(trchen): Eliminate PaintLayer dependency.
68 PaintLayer* layer = object.layer();
69 if (!layer)
70 return false;
71
72 return layer->paintsWithTransform(GlobalPaintNormalPhase);
73 }
74
75 static FloatPoint3D transformOrigin(const LayoutBox& box)
76 {
77 const ComputedStyle& style = box.styleRef();
78
79 FloatSize borderBoxSize(box.size());
80 return FloatPoint3D(floatValueForLength(style.transformOriginX(), borderBoxS ize.width()), floatValueForLength(style.transformOriginY(), borderBoxSize.height ()), style.transformOriginZ());
81 }
82
83 static FloatPoint perspectiveOrigin(const LayoutBox& box)
84 {
85 const ComputedStyle& style = box.styleRef();
86
87 FloatSize borderBoxSize(box.size());
88 return FloatPoint(floatValueForLength(style.perspectiveOriginX(), borderBoxS ize.width()), floatValueForLength(style.perspectiveOriginY(), borderBoxSize.heig ht()));
89 }
90
91 void PaintPropertyTreeBuilder::walk(LayoutBoxModelObject& object, const Context& context)
92 {
93 ASSERT(object.isBox() != object.isLayoutInline()); // Either or.
94
95 Context localContext(context);
96 RefPtr<TransformPaintPropertyNode> newTransformNodeForPreTranslation;
97 RefPtr<TransformPaintPropertyNode> newTransformNodeForTransform;
98 RefPtr<TransformPaintPropertyNode> newTransformNodeForPerspective;
99 RefPtr<TransformPaintPropertyNode> newTransformNodeForScrollTranslation;
100
101 // Step 1: Figure out the layout space of the current object.
102 const ComputedStyle& style = object.styleRef();
103 // TODO(trchen): There is some insanity going on with tables. Double check r esults.
104 switch (style.position()) {
105 case StaticPosition:
106 break;
107 case RelativePosition:
108 localContext.paintOffset += object.offsetForInFlowPosition();
109 break;
110 case AbsolutePosition:
111 localContext.currentTransform = context.transformForOutOfFlowPositioned;
112 localContext.paintOffset = context.paintOffsetForOutOfFlowPositioned;
113 break;
114 case StickyPosition:
115 localContext.paintOffset += object.offsetForInFlowPosition();
116 break;
117 case FixedPosition:
118 localContext.currentTransform = context.transformForFixedPositioned;
119 localContext.paintOffset = context.paintOffsetForFixedPositioned;
120 break;
121 default:
122 ASSERT_NOT_REACHED();
123 }
124 if (object.isBox())
125 localContext.paintOffset += toLayoutBox(object).locationOffset();
126
127 // Step 2: Create a transform node to consolidate paint offset (if needed).
128 if (shouldCreatePreTranslationNode(object) && localContext.paintOffset != La youtPoint()) {
129 TransformationMatrix matrix;
130 matrix.translate(localContext.paintOffset.x(), localContext.paintOffset. y());
131 newTransformNodeForPreTranslation = TransformPaintPropertyNode::create(m atrix, FloatPoint3D(), localContext.currentTransform);
132 localContext.currentTransform = newTransformNodeForPreTranslation.get();
133 localContext.paintOffset = LayoutPoint();
134 }
135
136 // Step 3: Create a transform node for CSS transform (if presents).
137 bool hasTransform = object.isBox() && style.hasTransform();
138 if (hasTransform) {
139 TransformationMatrix matrix;
140 style.applyTransform(matrix, toLayoutBox(object).size(), ComputedStyle:: ExcludeTransformOrigin, ComputedStyle::IncludeMotionPath, ComputedStyle::Include IndependentTransformProperties);
141 newTransformNodeForTransform = TransformPaintPropertyNode::create(matrix , transformOrigin(toLayoutBox(object)), localContext.currentTransform);
142 localContext.currentTransform = newTransformNodeForTransform.get();
143 ASSERT(localContext.paintOffset == LayoutPoint());
144 }
145 // At this point, the current space is the space we paint the element itself .
146
147 // Step 3: Create a transform node for CSS perspective (if presents).
148 if (object.isBox() && style.hasPerspective()) {
149 TransformationMatrix matrix;
150 matrix.applyPerspective(style.perspective());
151 newTransformNodeForPerspective = TransformPaintPropertyNode::create(matr ix, perspectiveOrigin(toLayoutBox(object)), localContext.currentTransform);
152 localContext.currentTransform = newTransformNodeForPerspective.get();
153 ASSERT(localContext.paintOffset == LayoutPoint());
154 }
155
156 // Step 4: Create a transform node for overflow clip (if presents).
157 if (object.hasOverflowClip()) {
158 PaintLayer* layer = object.layer();
159 ASSERT(layer);
160 DoubleSize scrollOffset = layer->scrollableArea()->scrollOffset();
161 if (!scrollOffset.isZero() || layer->scrollsOverflow()) {
162 TransformationMatrix matrix;
163 matrix.translate(-scrollOffset.width(), -scrollOffset.height());
164 newTransformNodeForScrollTranslation = TransformPaintPropertyNode::c reate(matrix, FloatPoint3D(), localContext.currentTransform);
165 localContext.currentTransform = newTransformNodeForScrollTranslation .get();
166 }
167 }
168 // At this point, the current space is the space we paint in-flow children.
169
170 // Step 5: Update the context for out-of-flow descendants (if position conta iner is established).
171 if (style.position() != StaticPosition || hasTransform) {
172 localContext.transformForOutOfFlowPositioned = localContext.currentTrans form;
173 localContext.paintOffsetForOutOfFlowPositioned = localContext.paintOffse t;
174 }
175 if (hasTransform) {
176 localContext.transformForFixedPositioned = localContext.currentTransform ;
177 localContext.paintOffsetForFixedPositioned = localContext.paintOffset;
178 }
179
180 // Step 6: Memorize the nodes we created for future reference during paint.
181 if (newTransformNodeForPreTranslation || newTransformNodeForTransform || new TransformNodeForPerspective || newTransformNodeForScrollTranslation) {
182 ObjectPaintProperties& properties = object.ensureObjectPaintProperties() ;
183 properties.setPreTranslation(newTransformNodeForPreTranslation.release() );
184 properties.setTransform(newTransformNodeForTransform.release());
185 properties.setPerspective(newTransformNodeForPerspective.release());
186 properties.setScrollTranslation(newTransformNodeForScrollTranslation.rel ease());
187 } else {
188 object.clearObjectPaintProperties();
189 }
190
191 // Step 7: Recur.
192 if (object.isSVGRoot()) {
193 // TODO(trchen): Implement SVG walk.
194 return;
195 }
196
197 for (LayoutObject* child = object.slowFirstChild(); child; child = child->ne xtSibling()) {
198 if (child->isText())
199 continue;
200 walk(toLayoutBoxModelObject(*child), localContext);
201 }
202 }
203
204 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698