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

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

Issue 2651093003: Make scroll translation transform nodes reference scroll nodes (Closed)
Patch Set: Add note about scroll tree differences Created 3 years, 11 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/dom/DOMNodeIds.h" 7 #include "core/dom/DOMNodeIds.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 if (auto* existingContentClip = frameView.contentClip()) { 63 if (auto* existingContentClip = frameView.contentClip()) {
64 existingContentClip->update(std::move(parent), 64 existingContentClip->update(std::move(parent),
65 std::move(localTransformSpace), clipRect); 65 std::move(localTransformSpace), clipRect);
66 return false; 66 return false;
67 } 67 }
68 frameView.setContentClip(ClipPaintPropertyNode::create( 68 frameView.setContentClip(ClipPaintPropertyNode::create(
69 std::move(parent), std::move(localTransformSpace), clipRect)); 69 std::move(parent), std::move(localTransformSpace), clipRect));
70 return true; 70 return true;
71 } 71 }
72 72
73 // True if a new property was created, false if an existing one was updated.
74 static bool updateScrollTranslation(
75 FrameView& frameView,
76 PassRefPtr<const TransformPaintPropertyNode> parent,
77 const TransformationMatrix& matrix,
78 const FloatPoint3D& origin) {
79 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
80 if (auto* existingScrollTranslation = frameView.scrollTranslation()) {
81 existingScrollTranslation->update(std::move(parent), matrix, origin);
82 return false;
83 }
84 frameView.setScrollTranslation(
85 TransformPaintPropertyNode::create(std::move(parent), matrix, origin));
86 return true;
87 }
88
89 static CompositorElementId createDomNodeBasedCompositorElementId( 73 static CompositorElementId createDomNodeBasedCompositorElementId(
90 const LayoutObject& object) { 74 const LayoutObject& object) {
91 return createCompositorElementId(DOMNodeIds::idForNode(object.node()), 75 return createCompositorElementId(DOMNodeIds::idForNode(object.node()),
92 CompositorSubElementId::Primary); 76 CompositorSubElementId::Primary);
93 } 77 }
94 78
79 // True if a new property was created, false if an existing one was updated.
80 static bool updateScrollTranslation(
81 FrameView& frameView,
82 PassRefPtr<const TransformPaintPropertyNode> parent,
83 const TransformationMatrix& matrix,
84 const FloatPoint3D& origin,
85 PassRefPtr<const ScrollPaintPropertyNode> scroll) {
86 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
87 CompositorElementId compositorElementId =
88 createDomNodeBasedCompositorElementId(*frameView.layoutView());
89 if (auto* existingScrollTranslation = frameView.scrollTranslation()) {
90 existingScrollTranslation->update(
91 std::move(parent), matrix, origin, std::move(scroll), false, 0,
92 CompositingReasonNone, compositorElementId);
93 return false;
94 }
95 frameView.setScrollTranslation(TransformPaintPropertyNode::create(
96 std::move(parent), matrix, origin, std::move(scroll), false, 0,
97 CompositingReasonNone, compositorElementId));
98 return true;
99 }
100
95 // True if a new property was created or a main thread scrolling reason changed 101 // True if a new property was created or a main thread scrolling reason changed
96 // (which can affect descendants), false if an existing one was updated. 102 // (which can affect descendants), false if an existing one was updated.
97 static bool updateScroll( 103 static bool updateScroll(
98 FrameView& frameView, 104 FrameView& frameView,
99 PassRefPtr<const ScrollPaintPropertyNode> parent, 105 PassRefPtr<const ScrollPaintPropertyNode> parent,
100 PassRefPtr<const TransformPaintPropertyNode> scrollOffset,
101 const IntSize& clip, 106 const IntSize& clip,
102 const IntSize& bounds, 107 const IntSize& bounds,
103 bool userScrollableHorizontal, 108 bool userScrollableHorizontal,
104 bool userScrollableVertical, 109 bool userScrollableVertical,
105 MainThreadScrollingReasons mainThreadScrollingReasons) { 110 MainThreadScrollingReasons mainThreadScrollingReasons) {
106 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled()); 111 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
107
108 CompositorElementId compositorElementId =
109 createDomNodeBasedCompositorElementId(*frameView.layoutView());
110 if (auto* existingScroll = frameView.scroll()) { 112 if (auto* existingScroll = frameView.scroll()) {
111 auto existingReasons = existingScroll->mainThreadScrollingReasons(); 113 auto existingReasons = existingScroll->mainThreadScrollingReasons();
112 existingScroll->update(std::move(parent), std::move(scrollOffset), clip, 114 existingScroll->update(std::move(parent), clip, bounds,
113 bounds, userScrollableHorizontal, 115 userScrollableHorizontal, userScrollableVertical,
114 userScrollableVertical, mainThreadScrollingReasons, 116 mainThreadScrollingReasons);
115 compositorElementId);
116 return existingReasons != mainThreadScrollingReasons; 117 return existingReasons != mainThreadScrollingReasons;
117 } 118 }
118 frameView.setScroll(ScrollPaintPropertyNode::create( 119 frameView.setScroll(ScrollPaintPropertyNode::create(
119 std::move(parent), std::move(scrollOffset), clip, bounds, 120 std::move(parent), clip, bounds, userScrollableHorizontal,
120 userScrollableHorizontal, userScrollableVertical, 121 userScrollableVertical, mainThreadScrollingReasons));
121 mainThreadScrollingReasons, compositorElementId));
122 return true; 122 return true;
123 } 123 }
124 124
125 static MainThreadScrollingReasons mainThreadScrollingReasons( 125 static MainThreadScrollingReasons mainThreadScrollingReasons(
126 const FrameView& frameView, 126 const FrameView& frameView,
127 MainThreadScrollingReasons ancestorReasons) { 127 MainThreadScrollingReasons ancestorReasons) {
128 auto reasons = ancestorReasons; 128 auto reasons = ancestorReasons;
129 if (!frameView.frame().settings()->getThreadedScrollingEnabled()) 129 if (!frameView.frame().settings()->getThreadedScrollingEnabled())
130 reasons |= MainThreadScrollingReason::kThreadedScrollingDisabled; 130 reasons |= MainThreadScrollingReason::kThreadedScrollingDisabled;
131 if (frameView.hasBackgroundAttachmentFixedObjects()) 131 if (frameView.hasBackgroundAttachmentFixedObjects())
(...skipping 30 matching lines...) Expand all
162 frameView, context.current.transform, frameTranslate, FloatPoint3D()); 162 frameView, context.current.transform, frameTranslate, FloatPoint3D());
163 163
164 FloatRoundedRect contentClip( 164 FloatRoundedRect contentClip(
165 IntRect(IntPoint(), frameView.visibleContentSize())); 165 IntRect(IntPoint(), frameView.visibleContentSize()));
166 context.forceSubtreeUpdate |= 166 context.forceSubtreeUpdate |=
167 updateContentClip(frameView, context.current.clip, 167 updateContentClip(frameView, context.current.clip,
168 frameView.preTranslation(), contentClip); 168 frameView.preTranslation(), contentClip);
169 169
170 ScrollOffset scrollOffset = frameView.getScrollOffset(); 170 ScrollOffset scrollOffset = frameView.getScrollOffset();
171 if (frameView.isScrollable() || !scrollOffset.isZero()) { 171 if (frameView.isScrollable() || !scrollOffset.isZero()) {
172 TransformationMatrix frameScroll;
173 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height());
174 context.forceSubtreeUpdate |= updateScrollTranslation(
175 frameView, frameView.preTranslation(), frameScroll, FloatPoint3D());
176
177 IntSize scrollClip = frameView.visibleContentSize(); 172 IntSize scrollClip = frameView.visibleContentSize();
178 IntSize scrollBounds = frameView.contentsSize(); 173 IntSize scrollBounds = frameView.contentsSize();
179 bool userScrollableHorizontal = 174 bool userScrollableHorizontal =
180 frameView.userInputScrollable(HorizontalScrollbar); 175 frameView.userInputScrollable(HorizontalScrollbar);
181 bool userScrollableVertical = 176 bool userScrollableVertical =
182 frameView.userInputScrollable(VerticalScrollbar); 177 frameView.userInputScrollable(VerticalScrollbar);
183 178
184 auto ancestorReasons = 179 auto ancestorReasons =
185 context.current.scroll->mainThreadScrollingReasons(); 180 context.current.scroll->mainThreadScrollingReasons();
186 auto reasons = mainThreadScrollingReasons(frameView, ancestorReasons); 181 auto reasons = mainThreadScrollingReasons(frameView, ancestorReasons);
182 context.forceSubtreeUpdate |= updateScroll(
183 frameView, context.current.scroll, scrollClip, scrollBounds,
184 userScrollableHorizontal, userScrollableVertical, reasons);
187 185
188 context.forceSubtreeUpdate |= updateScroll( 186 TransformationMatrix frameScroll;
189 frameView, context.current.scroll, frameView.scrollTranslation(), 187 frameScroll.translate(-scrollOffset.width(), -scrollOffset.height());
190 scrollClip, scrollBounds, userScrollableHorizontal, 188 context.forceSubtreeUpdate |= updateScrollTranslation(
191 userScrollableVertical, reasons); 189 frameView, frameView.preTranslation(), frameScroll, FloatPoint3D(),
190 frameView.scroll());
192 } else { 191 } else {
193 if (frameView.scrollTranslation() || frameView.scroll()) { 192 if (frameView.scrollTranslation() || frameView.scroll()) {
194 // Ensure pre-existing properties are cleared if there is no scrolling. 193 // Ensure pre-existing properties are cleared if there is no scrolling.
195 frameView.setScrollTranslation(nullptr); 194 frameView.setScrollTranslation(nullptr);
196 frameView.setScroll(nullptr); 195 frameView.setScroll(nullptr);
197 196
198 // Rebuild all descendant properties because a property was removed. 197 // Rebuild all descendant properties because a property was removed.
199 context.forceSubtreeUpdate = true; 198 context.forceSubtreeUpdate = true;
200 } 199 }
201 } 200 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 LayoutPoint fractionalPaintOffset = 258 LayoutPoint fractionalPaintOffset =
260 LayoutPoint(context.current.paintOffset - roundedPaintOffset); 259 LayoutPoint(context.current.paintOffset - roundedPaintOffset);
261 260
262 if (object.needsPaintPropertyUpdate() || context.forceSubtreeUpdate) { 261 if (object.needsPaintPropertyUpdate() || context.forceSubtreeUpdate) {
263 if (usesPaintOffsetTranslation) { 262 if (usesPaintOffsetTranslation) {
264 auto& properties = object.getMutableForPainting().ensurePaintProperties(); 263 auto& properties = object.getMutableForPainting().ensurePaintProperties();
265 context.forceSubtreeUpdate |= properties.updatePaintOffsetTranslation( 264 context.forceSubtreeUpdate |= properties.updatePaintOffsetTranslation(
266 context.current.transform, 265 context.current.transform,
267 TransformationMatrix().translate(roundedPaintOffset.x(), 266 TransformationMatrix().translate(roundedPaintOffset.x(),
268 roundedPaintOffset.y()), 267 roundedPaintOffset.y()),
269 FloatPoint3D(), context.current.shouldFlattenInheritedTransform, 268 FloatPoint3D(), nullptr,
269 context.current.shouldFlattenInheritedTransform,
270 context.current.renderingContextId); 270 context.current.renderingContextId);
271 } else { 271 } else {
272 if (auto* properties = object.getMutableForPainting().paintProperties()) 272 if (auto* properties = object.getMutableForPainting().paintProperties())
273 context.forceSubtreeUpdate |= properties->clearPaintOffsetTranslation(); 273 context.forceSubtreeUpdate |= properties->clearPaintOffsetTranslation();
274 } 274 }
275 } 275 }
276 276
277 const auto* properties = object.paintProperties(); 277 const auto* properties = object.paintProperties();
278 if (properties && properties->paintOffsetTranslation()) { 278 if (properties && properties->paintOffsetTranslation()) {
279 context.current.transform = properties->paintOffsetTranslation(); 279 context.current.transform = properties->paintOffsetTranslation();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 383
384 if (style.hasTransform() || style.preserves3D() || 384 if (style.hasTransform() || style.preserves3D() ||
385 compositingReasons != CompositingReasonNone) { 385 compositingReasons != CompositingReasonNone) {
386 TransformationMatrix matrix; 386 TransformationMatrix matrix;
387 style.applyTransform( 387 style.applyTransform(
388 matrix, box.size(), ComputedStyle::ExcludeTransformOrigin, 388 matrix, box.size(), ComputedStyle::ExcludeTransformOrigin,
389 ComputedStyle::IncludeMotionPath, 389 ComputedStyle::IncludeMotionPath,
390 ComputedStyle::IncludeIndependentTransformProperties); 390 ComputedStyle::IncludeIndependentTransformProperties);
391 391
392 // TODO(trchen): transform-style should only be respected if a 392 // TODO(trchen): transform-style should only be respected if a
393 // PaintLayer 393 // PaintLayer is created. If a node with transform-style: preserve-3d
394 // is created. 394 // does not exist in an existing rendering context, it establishes a new
395 // If a node with transform-style: preserve-3d does not exist in an 395 // one.
396 // existing rendering context, it establishes a new one.
397 unsigned renderingContextId = context.current.renderingContextId; 396 unsigned renderingContextId = context.current.renderingContextId;
398 if (style.preserves3D() && !renderingContextId) 397 if (style.preserves3D() && !renderingContextId)
399 renderingContextId = PtrHash<const LayoutObject>::hash(&object); 398 renderingContextId = PtrHash<const LayoutObject>::hash(&object);
400 399
401 CompositorElementId compositorElementId = 400 CompositorElementId compositorElementId =
402 style.hasCurrentTransformAnimation() 401 style.hasCurrentTransformAnimation()
403 ? createDomNodeBasedCompositorElementId(object) 402 ? createDomNodeBasedCompositorElementId(object)
404 : CompositorElementId(); 403 : CompositorElementId();
405 404
406 auto& properties = 405 auto& properties =
407 object.getMutableForPainting().ensurePaintProperties(); 406 object.getMutableForPainting().ensurePaintProperties();
408 context.forceSubtreeUpdate |= properties.updateTransform( 407 context.forceSubtreeUpdate |= properties.updateTransform(
409 context.current.transform, matrix, transformOrigin(box), 408 context.current.transform, matrix, transformOrigin(box), nullptr,
410 context.current.shouldFlattenInheritedTransform, renderingContextId, 409 context.current.shouldFlattenInheritedTransform, renderingContextId,
411 compositingReasons, compositorElementId); 410 compositingReasons, compositorElementId);
412 hasTransform = true; 411 hasTransform = true;
413 } 412 }
414 } 413 }
415 if (!hasTransform) { 414 if (!hasTransform) {
416 if (auto* properties = object.getMutableForPainting().paintProperties()) 415 if (auto* properties = object.getMutableForPainting().paintProperties())
417 context.forceSubtreeUpdate |= properties->clearTransform(); 416 context.forceSubtreeUpdate |= properties->clearTransform();
418 } 417 }
419 } 418 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 if (object.isBox() && style.hasPerspective()) { 686 if (object.isBox() && style.hasPerspective()) {
688 // The perspective node must not flatten (else nothing will get 687 // The perspective node must not flatten (else nothing will get
689 // perspective), but it should still extend the rendering context as 688 // perspective), but it should still extend the rendering context as
690 // most transform nodes do. 689 // most transform nodes do.
691 TransformationMatrix matrix = 690 TransformationMatrix matrix =
692 TransformationMatrix().applyPerspective(style.perspective()); 691 TransformationMatrix().applyPerspective(style.perspective());
693 FloatPoint3D origin = perspectiveOrigin(toLayoutBox(object)) + 692 FloatPoint3D origin = perspectiveOrigin(toLayoutBox(object)) +
694 toLayoutSize(context.current.paintOffset); 693 toLayoutSize(context.current.paintOffset);
695 auto& properties = object.getMutableForPainting().ensurePaintProperties(); 694 auto& properties = object.getMutableForPainting().ensurePaintProperties();
696 context.forceSubtreeUpdate |= properties.updatePerspective( 695 context.forceSubtreeUpdate |= properties.updatePerspective(
697 context.current.transform, matrix, origin, 696 context.current.transform, matrix, origin, nullptr,
698 context.current.shouldFlattenInheritedTransform, 697 context.current.shouldFlattenInheritedTransform,
699 context.current.renderingContextId); 698 context.current.renderingContextId);
700 } else { 699 } else {
701 if (auto* properties = object.getMutableForPainting().paintProperties()) 700 if (auto* properties = object.getMutableForPainting().paintProperties())
702 context.forceSubtreeUpdate |= properties->clearPerspective(); 701 context.forceSubtreeUpdate |= properties->clearPerspective();
703 } 702 }
704 } 703 }
705 704
706 const auto* properties = object.paintProperties(); 705 const auto* properties = object.paintProperties();
707 if (properties && properties->perspective()) { 706 if (properties && properties->perspective()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 context.current.scroll->mainThreadScrollingReasons(); 765 context.current.scroll->mainThreadScrollingReasons();
767 auto reasons = mainThreadScrollingReasons(object, ancestorReasons); 766 auto reasons = mainThreadScrollingReasons(object, ancestorReasons);
768 bool scrollNodeNeededForMainThreadReasons = ancestorReasons != reasons; 767 bool scrollNodeNeededForMainThreadReasons = ancestorReasons != reasons;
769 768
770 const LayoutBox& box = toLayoutBox(object); 769 const LayoutBox& box = toLayoutBox(object);
771 const auto* scrollableArea = box.getScrollableArea(); 770 const auto* scrollableArea = box.getScrollableArea();
772 IntSize scrollOffset = box.scrolledContentOffset(); 771 IntSize scrollOffset = box.scrolledContentOffset();
773 if (scrollNodeNeededForMainThreadReasons || !scrollOffset.isZero() || 772 if (scrollNodeNeededForMainThreadReasons || !scrollOffset.isZero() ||
774 scrollableArea->scrollsOverflow()) { 773 scrollableArea->scrollsOverflow()) {
775 needsScrollProperties = true; 774 needsScrollProperties = true;
776 auto& properties =
777 object.getMutableForPainting().ensurePaintProperties();
778 TransformationMatrix matrix = TransformationMatrix().translate(
779 -scrollOffset.width(), -scrollOffset.height());
780 context.forceSubtreeUpdate |= properties.updateScrollTranslation(
781 context.current.transform, matrix, FloatPoint3D(),
782 context.current.shouldFlattenInheritedTransform,
783 context.current.renderingContextId);
784 775
785 IntSize scrollClip = scrollableArea->visibleContentRect().size(); 776 IntSize scrollClip = scrollableArea->visibleContentRect().size();
786 IntSize scrollBounds = scrollableArea->contentsSize(); 777 IntSize scrollBounds = scrollableArea->contentsSize();
787 bool userScrollableHorizontal = 778 bool userScrollableHorizontal =
788 scrollableArea->userInputScrollable(HorizontalScrollbar); 779 scrollableArea->userInputScrollable(HorizontalScrollbar);
789 bool userScrollableVertical = 780 bool userScrollableVertical =
790 scrollableArea->userInputScrollable(VerticalScrollbar); 781 scrollableArea->userInputScrollable(VerticalScrollbar);
791 782
792 // Main thread scrolling reasons depend on their ancestor's reasons 783 // Main thread scrolling reasons depend on their ancestor's reasons
793 // so ensure the entire subtree is updated when reasons change. 784 // so ensure the entire subtree is updated when reasons change.
785 auto& properties =
786 object.getMutableForPainting().ensurePaintProperties();
794 if (auto* existingScrollNode = properties.scroll()) { 787 if (auto* existingScrollNode = properties.scroll()) {
795 if (existingScrollNode->mainThreadScrollingReasons() != reasons) 788 if (existingScrollNode->mainThreadScrollingReasons() != reasons)
796 context.forceSubtreeUpdate = true; 789 context.forceSubtreeUpdate = true;
797 } 790 }
798 791
792 context.forceSubtreeUpdate |= properties.updateScroll(
793 context.current.scroll, scrollClip, scrollBounds,
794 userScrollableHorizontal, userScrollableVertical, reasons);
795
799 CompositorElementId compositorElementId = 796 CompositorElementId compositorElementId =
800 createDomNodeBasedCompositorElementId(object); 797 createDomNodeBasedCompositorElementId(object);
801 798 TransformationMatrix matrix = TransformationMatrix().translate(
802 context.forceSubtreeUpdate |= properties.updateScroll( 799 -scrollOffset.width(), -scrollOffset.height());
803 context.current.scroll, properties.scrollTranslation(), scrollClip, 800 context.forceSubtreeUpdate |= properties.updateScrollTranslation(
804 scrollBounds, userScrollableHorizontal, userScrollableVertical, 801 context.current.transform, matrix, FloatPoint3D(),
805 reasons, compositorElementId); 802 properties.scroll(),
803 context.current.shouldFlattenInheritedTransform,
804 context.current.renderingContextId, CompositingReasonNone,
805 compositorElementId);
806 } 806 }
807 } 807 }
808 808
809 if (!needsScrollProperties) { 809 if (!needsScrollProperties) {
810 // Ensure pre-existing properties are cleared. 810 // Ensure pre-existing properties are cleared.
811 if (auto* properties = object.getMutableForPainting().paintProperties()) { 811 if (auto* properties = object.getMutableForPainting().paintProperties()) {
812 context.forceSubtreeUpdate |= properties->clearScrollTranslation(); 812 context.forceSubtreeUpdate |= properties->clearScrollTranslation();
813 context.forceSubtreeUpdate |= properties->clearScroll(); 813 context.forceSubtreeUpdate |= properties->clearScroll();
814 } 814 }
815 } 815 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 updateOverflowClip(object, context); 996 updateOverflowClip(object, context);
997 updatePerspective(object, context); 997 updatePerspective(object, context);
998 updateSvgLocalToBorderBoxTransform(object, context); 998 updateSvgLocalToBorderBoxTransform(object, context);
999 updateScrollAndScrollTranslation(object, context); 999 updateScrollAndScrollTranslation(object, context);
1000 updateOutOfFlowContext(object, context); 1000 updateOutOfFlowContext(object, context);
1001 1001
1002 context.forceSubtreeUpdate |= object.subtreeNeedsPaintPropertyUpdate(); 1002 context.forceSubtreeUpdate |= object.subtreeNeedsPaintPropertyUpdate();
1003 } 1003 }
1004 1004
1005 } // namespace blink 1005 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698