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

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

Issue 2330863003: Switch to null root property tree nodes [spv2] (Closed)
Patch Set: Rebase from space Created 4 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/PaintPropertyTreeBuilder.h" 5 #include "core/paint/PaintPropertyTreeBuilder.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/layout/LayoutInline.h" 10 #include "core/layout/LayoutInline.h"
11 #include "core/layout/LayoutPart.h" 11 #include "core/layout/LayoutPart.h"
12 #include "core/layout/LayoutView.h" 12 #include "core/layout/LayoutView.h"
13 #include "core/layout/svg/LayoutSVGRoot.h" 13 #include "core/layout/svg/LayoutSVGRoot.h"
14 #include "core/paint/ObjectPaintProperties.h" 14 #include "core/paint/ObjectPaintProperties.h"
15 #include "core/paint/PaintLayer.h" 15 #include "core/paint/PaintLayer.h"
16 #include "core/paint/SVGRootPainter.h" 16 #include "core/paint/SVGRootPainter.h"
17 #include "platform/transforms/TransformationMatrix.h" 17 #include "platform/transforms/TransformationMatrix.h"
18 #include "wtf/PtrUtil.h" 18 #include "wtf/PtrUtil.h"
19 #include <memory> 19 #include <memory>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 void PaintPropertyTreeBuilder::buildTreeRootNodes(FrameView& rootFrame, PaintPro pertyTreeBuilderContext& context)
24 {
25 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled())
26 return;
27
28 if (!rootFrame.rootTransform() || rootFrame.rootTransform()->parent()) {
29 rootFrame.setRootTransform(TransformPaintPropertyNode::create(nullptr, T ransformationMatrix(), FloatPoint3D()));
30 rootFrame.setRootClip(ClipPaintPropertyNode::create(nullptr, rootFrame.r ootTransform(), FloatRoundedRect(LayoutRect::infiniteIntRect())));
31 rootFrame.setRootEffect(EffectPaintPropertyNode::create(nullptr, 1.0));
32 rootFrame.setRootScroll(ScrollPaintPropertyNode::create(nullptr, rootFra me.rootTransform(), IntSize(), IntSize(), false, false));
33 } else {
34 DCHECK(rootFrame.rootClip() && !rootFrame.rootClip()->parent());
35 DCHECK(rootFrame.rootEffect() && !rootFrame.rootEffect()->parent());
36 }
37
38 context.current.transform = context.absolutePosition.transform = context.fix edPosition.transform = rootFrame.rootTransform();
39 context.current.scroll = rootFrame.rootScroll();
40 context.current.clip = context.absolutePosition.clip = context.fixedPosition .clip = rootFrame.rootClip();
41 context.currentEffect = rootFrame.rootEffect();
42 }
43
44 void createOrUpdateFrameViewPreTranslation(FrameView& frameView, 23 void createOrUpdateFrameViewPreTranslation(FrameView& frameView,
45 PassRefPtr<const TransformPaintPropertyNode> parent, 24 PassRefPtr<const TransformPaintPropertyNode> parent,
46 const TransformationMatrix& matrix, 25 const TransformationMatrix& matrix,
47 const FloatPoint3D& origin) 26 const FloatPoint3D& origin)
48 { 27 {
49 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled()); 28 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
50 if (TransformPaintPropertyNode* existingPreTranslation = frameView.preTransl ation()) 29 if (TransformPaintPropertyNode* existingPreTranslation = frameView.preTransl ation())
51 existingPreTranslation->update(parent, matrix, origin); 30 existingPreTranslation->update(parent, matrix, origin);
52 else 31 else
53 frameView.setPreTranslation(TransformPaintPropertyNode::create(parent, m atrix, origin)); 32 frameView.setPreTranslation(TransformPaintPropertyNode::create(parent, m atrix, origin));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 LayoutView* layoutView = frameView.layoutView(); 76 LayoutView* layoutView = frameView.layoutView();
98 if (!layoutView) 77 if (!layoutView)
99 return; 78 return;
100 79
101 TransformationMatrix frameTranslate; 80 TransformationMatrix frameTranslate;
102 frameTranslate.translate( 81 frameTranslate.translate(
103 frameView.x() + layoutView->location().x() + context.current.paintOf fset.x(), 82 frameView.x() + layoutView->location().x() + context.current.paintOf fset.x(),
104 frameView.y() + layoutView->location().y() + context.current.paintOf fset.y()); 83 frameView.y() + layoutView->location().y() + context.current.paintOf fset.y());
105 context.current.transform = layoutView->getMutableForPainting().ensureOb jectPaintProperties().createOrUpdatePaintOffsetTranslation( 84 context.current.transform = layoutView->getMutableForPainting().ensureOb jectPaintProperties().createOrUpdatePaintOffsetTranslation(
106 context.current.transform, frameTranslate, FloatPoint3D()); 85 context.current.transform, frameTranslate, FloatPoint3D());
107 context.current.scroll = layoutView->getMutableForPainting().ensureObjec tPaintProperties().createOrUpdateScroll(
108 context.current.scroll, context.current.transform, IntSize(), IntSiz e(), false, false);
109 context.current.paintOffset = LayoutPoint(); 86 context.current.paintOffset = LayoutPoint();
110 context.current.renderingContextID = 0; 87 context.current.renderingContextID = 0;
111 context.current.shouldFlattenInheritedTransform = true; 88 context.current.shouldFlattenInheritedTransform = true;
112 context.absolutePosition = context.current; 89 context.absolutePosition = context.current;
113 context.containerForAbsolutePosition = nullptr; // This will get set in updateOutOfFlowContext(). 90 context.containerForAbsolutePosition = nullptr; // This will get set in updateOutOfFlowContext().
114 context.fixedPosition = context.current; 91 context.fixedPosition = context.current;
115 return; 92 return;
116 } 93 }
117 94
118 TransformationMatrix frameTranslate; 95 TransformationMatrix frameTranslate;
119 frameTranslate.translate(frameView.x() + context.current.paintOffset.x(), fr ameView.y() + context.current.paintOffset.y()); 96 frameTranslate.translate(frameView.x() + context.current.paintOffset.x(), fr ameView.y() + context.current.paintOffset.y());
120 createOrUpdateFrameViewPreTranslation(frameView, context.current.transform, frameTranslate, FloatPoint3D()); 97 createOrUpdateFrameViewPreTranslation(frameView, context.current.transform, frameTranslate, FloatPoint3D());
121 98
122 FloatRoundedRect contentClip(IntRect(IntPoint(), frameView.visibleContentSiz e())); 99 FloatRoundedRect contentClip(IntRect(IntPoint(), frameView.visibleContentSiz e()));
123 createOrUpdateFrameViewContentClip(frameView, context.current.clip, frameVie w.preTranslation(), contentClip); 100 createOrUpdateFrameViewContentClip(frameView, context.current.clip, frameVie w.preTranslation(), contentClip);
124 101
125 DoubleSize scrollOffset = frameView.scrollOffsetDouble(); 102 DoubleSize scrollOffset = frameView.scrollOffsetDouble();
126 TransformationMatrix frameScroll; 103 if (frameView.isScrollable() || !scrollOffset.isZero()) {
127 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height()); 104 TransformationMatrix frameScroll;
128 // TODO(pdr): A scroll translation should not be needed when frameView.isScr ollable() is false. 105 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height());
129 createOrUpdateFrameViewScrollTranslation(frameView, frameView.preTranslation (), frameScroll, FloatPoint3D()); 106 createOrUpdateFrameViewScrollTranslation(frameView, frameView.preTransla tion(), frameScroll, FloatPoint3D());
130 107
131 if (frameView.isScrollable()) {
132 IntSize scrollClip = frameView.visibleContentSize(); 108 IntSize scrollClip = frameView.visibleContentSize();
133 IntSize scrollBounds = frameView.contentsSize(); 109 IntSize scrollBounds = frameView.contentsSize();
134 bool userScrollableHorizontal = frameView.userInputScrollable(Horizontal Scrollbar); 110 bool userScrollableHorizontal = frameView.userInputScrollable(Horizontal Scrollbar);
135 bool userScrollableVertical = frameView.userInputScrollable(VerticalScro llbar); 111 bool userScrollableVertical = frameView.userInputScrollable(VerticalScro llbar);
136 createOrUpdateFrameViewScroll(frameView, context.current.scroll, frameVi ew.scrollTranslation(), scrollClip, scrollBounds, userScrollableHorizontal, user ScrollableVertical); 112 createOrUpdateFrameViewScroll(frameView, context.current.scroll, frameVi ew.scrollTranslation(), scrollClip, scrollBounds, userScrollableHorizontal, user ScrollableVertical);
137 } else { 113 } else {
114 frameView.setScrollTranslation(nullptr);
138 frameView.setScroll(nullptr); 115 frameView.setScroll(nullptr);
139 } 116 }
140 117
141 // Initialize the context for current, absolute and fixed position cases. 118 // Initialize the context for current, absolute and fixed position cases.
142 // They are the same, except that scroll translation does not apply to 119 // They are the same, except that scroll translation does not apply to
143 // fixed position descendants. 120 // fixed position descendants.
144 const ScrollPaintPropertyNode* initialScroll = context.current.scroll; 121 const ScrollPaintPropertyNode* initialScroll = context.current.scroll;
145 context.current.transform = frameView.scrollTranslation(); 122 context.current.transform = frameView.scrollTranslation() ? frameView.scroll Translation() : frameView.preTranslation();
146 context.current.paintOffset = LayoutPoint(); 123 context.current.paintOffset = LayoutPoint();
147 context.current.clip = frameView.contentClip(); 124 context.current.clip = frameView.contentClip();
148 context.current.scroll = frameView.scroll() ? frameView.scroll() : initialSc roll; 125 context.current.scroll = frameView.scroll() ? frameView.scroll() : initialSc roll;
149 context.current.renderingContextID = 0; 126 context.current.renderingContextID = 0;
150 context.current.shouldFlattenInheritedTransform = true; 127 context.current.shouldFlattenInheritedTransform = true;
151 context.absolutePosition = context.current; 128 context.absolutePosition = context.current;
152 context.containerForAbsolutePosition = nullptr; 129 context.containerForAbsolutePosition = nullptr;
153 context.fixedPosition = context.current; 130 context.fixedPosition = context.current;
154 context.fixedPosition.transform = frameView.preTranslation(); 131 context.fixedPosition.transform = frameView.preTranslation();
155 context.fixedPosition.scroll = initialScroll; 132 context.fixedPosition.scroll = initialScroll;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return; 221 return;
245 } 222 }
246 } 223 }
247 224
248 if (ObjectPaintProperties* properties = object.getMutableForPainting().objec tPaintProperties()) 225 if (ObjectPaintProperties* properties = object.getMutableForPainting().objec tPaintProperties())
249 properties->clearTransform(); 226 properties->clearTransform();
250 } 227 }
251 228
252 void PaintPropertyTreeBuilder::updateEffect(const LayoutObject& object, PaintPro pertyTreeBuilderContext& context) 229 void PaintPropertyTreeBuilder::updateEffect(const LayoutObject& object, PaintPro pertyTreeBuilderContext& context)
253 { 230 {
254 if (object.isLayoutView() && !context.currentEffect) {
255 const LayoutView& layoutView = toLayoutView(object);
256 DCHECK(RuntimeEnabledFeatures::rootLayerScrollingEnabled());
257 DCHECK(layoutView.frameView()->frame().isMainFrame());
258 context.currentEffect = layoutView.getMutableForPainting().ensureObjectP aintProperties().createOrUpdateEffect(nullptr, 1.0);
259 return;
260 }
261
262 if (!object.styleRef().hasOpacity()) { 231 if (!object.styleRef().hasOpacity()) {
263 if (ObjectPaintProperties* properties = object.getMutableForPainting().o bjectPaintProperties()) 232 if (ObjectPaintProperties* properties = object.getMutableForPainting().o bjectPaintProperties())
264 properties->clearEffect(); 233 properties->clearEffect();
265 return; 234 return;
266 } 235 }
267 236
268 context.currentEffect = object.getMutableForPainting().ensureObjectPaintProp erties().createOrUpdateEffect( 237 context.currentEffect = object.getMutableForPainting().ensureObjectPaintProp erties().createOrUpdateEffect(
269 context.currentEffect, object.styleRef().opacity()); 238 context.currentEffect, object.styleRef().opacity());
270 } 239 }
271 240
(...skipping 20 matching lines...) Expand all
292 // Avoid adding an ObjectPaintProperties for non-boxes to save memory, since we don't need them at the moment. 261 // Avoid adding an ObjectPaintProperties for non-boxes to save memory, since we don't need them at the moment.
293 if (!object.isBox() && !object.hasLayer()) 262 if (!object.isBox() && !object.hasLayer())
294 return; 263 return;
295 264
296 std::unique_ptr<ObjectPaintProperties::LocalBorderBoxProperties> borderBoxCo ntext = 265 std::unique_ptr<ObjectPaintProperties::LocalBorderBoxProperties> borderBoxCo ntext =
297 wrapUnique(new ObjectPaintProperties::LocalBorderBoxProperties); 266 wrapUnique(new ObjectPaintProperties::LocalBorderBoxProperties);
298 borderBoxContext->paintOffset = context.current.paintOffset; 267 borderBoxContext->paintOffset = context.current.paintOffset;
299 borderBoxContext->geometryPropertyTreeState = GeometryPropertyTreeState(cont ext.current.transform, context.current.clip, context.currentEffect); 268 borderBoxContext->geometryPropertyTreeState = GeometryPropertyTreeState(cont ext.current.transform, context.current.clip, context.currentEffect);
300 borderBoxContext->scroll = context.current.scroll; 269 borderBoxContext->scroll = context.current.scroll;
301 270
302 if (!context.current.clip) {
303 DCHECK(object.isLayoutView());
304 DCHECK(toLayoutView(object).frameView()->frame().isMainFrame());
305 DCHECK(RuntimeEnabledFeatures::rootLayerScrollingEnabled());
306 borderBoxContext->geometryPropertyTreeState.clip = ClipPaintPropertyNode ::create(nullptr, context.current.transform, FloatRoundedRect(LayoutRect::infini teIntRect()));
307 context.current.clip = borderBoxContext->geometryPropertyTreeState.clip. get();
308 }
309
310 object.getMutableForPainting().ensureObjectPaintProperties().setLocalBorderB oxProperties(std::move(borderBoxContext)); 271 object.getMutableForPainting().ensureObjectPaintProperties().setLocalBorderB oxProperties(std::move(borderBoxContext));
311 272
312 } 273 }
313 274
314 // TODO(trchen): Remove this once we bake the paint offset into frameRect. 275 // TODO(trchen): Remove this once we bake the paint offset into frameRect.
315 void PaintPropertyTreeBuilder::updateScrollbarPaintOffset(const LayoutObject& ob ject, const PaintPropertyTreeBuilderContext& context) 276 void PaintPropertyTreeBuilder::updateScrollbarPaintOffset(const LayoutObject& ob ject, const PaintPropertyTreeBuilderContext& context)
316 { 277 {
317 IntPoint roundedPaintOffset = roundedIntPoint(context.current.paintOffset); 278 IntPoint roundedPaintOffset = roundedIntPoint(context.current.paintOffset);
318 if (roundedPaintOffset != IntPoint() && object.isBoxModelObject()) { 279 if (roundedPaintOffset != IntPoint() && object.isBoxModelObject()) {
319 if (PaintLayerScrollableArea* scrollableArea = toLayoutBoxModelObject(ob ject).getScrollableArea()) { 280 if (PaintLayerScrollableArea* scrollableArea = toLayoutBoxModelObject(ob ject).getScrollableArea()) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 context.current.shouldFlattenInheritedTransform = false; 375 context.current.shouldFlattenInheritedTransform = false;
415 context.current.renderingContextID = 0; 376 context.current.renderingContextID = 0;
416 } 377 }
417 378
418 void PaintPropertyTreeBuilder::updateScrollAndScrollTranslation(const LayoutObje ct& object, PaintPropertyTreeBuilderContext& context) 379 void PaintPropertyTreeBuilder::updateScrollAndScrollTranslation(const LayoutObje ct& object, PaintPropertyTreeBuilderContext& context)
419 { 380 {
420 if (object.isBoxModelObject() && object.hasOverflowClip()) { 381 if (object.isBoxModelObject() && object.hasOverflowClip()) {
421 PaintLayer* layer = toLayoutBoxModelObject(object).layer(); 382 PaintLayer* layer = toLayoutBoxModelObject(object).layer();
422 DCHECK(layer); 383 DCHECK(layer);
423 DoubleSize scrollOffset = layer->getScrollableArea()->scrollOffset(); 384 DoubleSize scrollOffset = layer->getScrollableArea()->scrollOffset();
424 bool forceScrollingForLayoutView = object.isLayoutView() && RuntimeEnabl edFeatures::rootLayerScrollingEnabled(); 385 if (!scrollOffset.isZero() || layer->scrollsOverflow()) {
425 if (forceScrollingForLayoutView || !scrollOffset.isZero() || layer->scro llsOverflow()) {
426 TransformationMatrix matrix = TransformationMatrix().translate(-scro llOffset.width(), -scrollOffset.height()); 386 TransformationMatrix matrix = TransformationMatrix().translate(-scro llOffset.width(), -scrollOffset.height());
427 context.current.transform = object.getMutableForPainting().ensureObj ectPaintProperties().createOrUpdateScrollTranslation( 387 context.current.transform = object.getMutableForPainting().ensureObj ectPaintProperties().createOrUpdateScrollTranslation(
428 context.current.transform, matrix, FloatPoint3D(), context.curre nt.shouldFlattenInheritedTransform, context.current.renderingContextID); 388 context.current.transform, matrix, FloatPoint3D(), context.curre nt.shouldFlattenInheritedTransform, context.current.renderingContextID);
429 389
430 IntSize scrollClip = layer->getScrollableArea()->visibleContentRect( ).size(); 390 IntSize scrollClip = layer->getScrollableArea()->visibleContentRect( ).size();
431 IntSize scrollBounds = layer->getScrollableArea()->contentsSize(); 391 IntSize scrollBounds = layer->getScrollableArea()->contentsSize();
432 bool userScrollableHorizontal = layer->getScrollableArea()->userInpu tScrollable(HorizontalScrollbar); 392 bool userScrollableHorizontal = layer->getScrollableArea()->userInpu tScrollable(HorizontalScrollbar);
433 bool userScrollableVertical = layer->getScrollableArea()->userInputS crollable(VerticalScrollbar); 393 bool userScrollableVertical = layer->getScrollableArea()->userInputS crollable(VerticalScrollbar);
434 const ScrollPaintPropertyNode* parentScrollNode = forceScrollingForL ayoutView ? nullptr : context.current.scroll;
435 context.current.scroll = object.getMutableForPainting().ensureObject PaintProperties().createOrUpdateScroll( 394 context.current.scroll = object.getMutableForPainting().ensureObject PaintProperties().createOrUpdateScroll(
436 parentScrollNode, context.current.transform, scrollClip, scrollB ounds, userScrollableHorizontal, userScrollableVertical); 395 context.current.scroll, context.current.transform, scrollClip, s crollBounds, userScrollableHorizontal, userScrollableVertical);
437 396
438 context.current.shouldFlattenInheritedTransform = false; 397 context.current.shouldFlattenInheritedTransform = false;
439 return; 398 return;
440 } 399 }
441 } 400 }
442 401
443 if (ObjectPaintProperties* properties = object.getMutableForPainting().objec tPaintProperties()) { 402 if (ObjectPaintProperties* properties = object.getMutableForPainting().objec tPaintProperties()) {
444 properties->clearScrollTranslation(); 403 properties->clearScrollTranslation();
445 properties->clearScroll(); 404 properties->clearScroll();
446 } 405 }
447 } 406 }
448 407
449 void PaintPropertyTreeBuilder::updateOutOfFlowContext(const LayoutObject& object , PaintPropertyTreeBuilderContext& context) 408 void PaintPropertyTreeBuilder::updateOutOfFlowContext(const LayoutObject& object , PaintPropertyTreeBuilderContext& context)
450 { 409 {
451 if (object.canContainAbsolutePositionObjects()) { 410 if (object.canContainAbsolutePositionObjects()) {
452 context.absolutePosition = context.current; 411 context.absolutePosition = context.current;
453 context.containerForAbsolutePosition = &object; 412 context.containerForAbsolutePosition = &object;
454 } 413 }
455 414
456 if (object.isLayoutView()) { 415 if (object.isLayoutView()) {
457 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 416 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
458 context.fixedPosition = context.current; 417 context.fixedPosition = context.current;
459 const TransformPaintPropertyNode* transform = object.objectPaintProp erties()->paintOffsetTranslation(); 418 const TransformPaintPropertyNode* transform = object.objectPaintProp erties()->paintOffsetTranslation();
460 DCHECK(transform); 419 DCHECK(transform);
461 context.fixedPosition.transform = transform; 420 context.fixedPosition.transform = transform;
421 context.fixedPosition.scroll = nullptr;
462 } 422 }
463 } else if (object.canContainFixedPositionObjects()) { 423 } else if (object.canContainFixedPositionObjects()) {
464 context.fixedPosition = context.current; 424 context.fixedPosition = context.current;
465 } else if (object.getMutableForPainting().objectPaintProperties() && object. objectPaintProperties()->cssClip()) { 425 } else if (object.getMutableForPainting().objectPaintProperties() && object. objectPaintProperties()->cssClip()) {
466 // CSS clip applies to all descendants, even if this object is not a con taining block 426 // CSS clip applies to all descendants, even if this object is not a con taining block
467 // ancestor of the descendant. It is okay for absolute-position descenda nts because 427 // ancestor of the descendant. It is okay for absolute-position descenda nts because
468 // having CSS clip implies being absolute position container. However fo r fixed-position 428 // having CSS clip implies being absolute position container. However fo r fixed-position
469 // descendants we need to insert the clip here if we are not a containin g block ancestor 429 // descendants we need to insert the clip here if we are not a containin g block ancestor
470 // of them. 430 // of them.
471 auto* cssClip = object.getMutableForPainting().objectPaintProperties()-> cssClip(); 431 auto* cssClip = object.getMutableForPainting().objectPaintProperties()-> cssClip();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 return; 515 return;
556 516
557 updateOverflowClip(object, context); 517 updateOverflowClip(object, context);
558 updatePerspective(object, context); 518 updatePerspective(object, context);
559 updateSvgLocalToBorderBoxTransform(object, context); 519 updateSvgLocalToBorderBoxTransform(object, context);
560 updateScrollAndScrollTranslation(object, context); 520 updateScrollAndScrollTranslation(object, context);
561 updateOutOfFlowContext(object, context); 521 updateOutOfFlowContext(object, context);
562 } 522 }
563 523
564 } // namespace blink 524 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698