| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/PaintInvalidator.h" | 5 #include "core/paint/PaintInvalidator.h" |
| 6 | 6 |
| 7 #include "core/editing/FrameSelection.h" | 7 #include "core/editing/FrameSelection.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" |
| 11 #include "core/layout/LayoutBlockFlow.h" | 11 #include "core/layout/LayoutBlockFlow.h" |
| 12 #include "core/layout/LayoutObject.h" | 12 #include "core/layout/LayoutObject.h" |
| 13 #include "core/layout/LayoutTable.h" | 13 #include "core/layout/LayoutTable.h" |
| 14 #include "core/layout/LayoutView.h" | 14 #include "core/layout/LayoutView.h" |
| 15 #include "core/layout/svg/SVGLayoutSupport.h" | 15 #include "core/layout/svg/SVGLayoutSupport.h" |
| 16 #include "core/paint/ObjectPaintProperties.h" | 16 #include "core/paint/ObjectPaintProperties.h" |
| 17 #include "core/paint/PaintLayer.h" | 17 #include "core/paint/PaintLayer.h" |
| 18 #include "core/paint/PaintLayerScrollableArea.h" | 18 #include "core/paint/PaintLayerScrollableArea.h" |
| 19 #include "core/paint/PaintPropertyTreeBuilder.h" | 19 #include "core/paint/PaintPropertyTreeBuilder.h" |
| 20 | 20 |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 // TODO(wangxianzhu): Avoid using function when possible. For example, we can |
| 24 // avoid it by avoiding unnecessary conversions between LayoutRects and |
| 25 // FloatRects. |
| 26 static LayoutRect enclosingLayoutRectIfNotEmpty(const FloatRect& floatRect) { |
| 27 return floatRect.isEmpty() ? LayoutRect(floatRect) |
| 28 : enclosingLayoutRect(floatRect); |
| 29 } |
| 30 |
| 23 static LayoutRect slowMapToVisualRectInAncestorSpace( | 31 static LayoutRect slowMapToVisualRectInAncestorSpace( |
| 24 const LayoutObject& object, | 32 const LayoutObject& object, |
| 25 const LayoutBoxModelObject& ancestor, | 33 const LayoutBoxModelObject& ancestor, |
| 26 const FloatRect& rect) { | 34 const FloatRect& rect) { |
| 27 if (object.isSVG() && !object.isSVGRoot()) { | 35 if (object.isSVG() && !object.isSVGRoot()) { |
| 28 LayoutRect result; | 36 LayoutRect result; |
| 29 SVGLayoutSupport::mapToVisualRectInAncestorSpace(object, &ancestor, rect, | 37 SVGLayoutSupport::mapToVisualRectInAncestorSpace(object, &ancestor, rect, |
| 30 result); | 38 result); |
| 31 return result; | 39 return result; |
| 32 } | 40 } |
| 33 | 41 |
| 34 LayoutRect result(rect); | 42 LayoutRect result = enclosingLayoutRectIfNotEmpty(rect); |
| 35 if (object.isLayoutView()) | 43 if (object.isLayoutView()) |
| 36 toLayoutView(object).mapToVisualRectInAncestorSpace( | 44 toLayoutView(object).mapToVisualRectInAncestorSpace( |
| 37 &ancestor, result, InputIsInFrameCoordinates, DefaultVisualRectFlags); | 45 &ancestor, result, InputIsInFrameCoordinates, DefaultVisualRectFlags); |
| 38 else | 46 else |
| 39 object.mapToVisualRectInAncestorSpace(&ancestor, result); | 47 object.mapToVisualRectInAncestorSpace(&ancestor, result); |
| 40 return result; | 48 return result; |
| 41 } | 49 } |
| 42 | 50 |
| 43 // TODO(wangxianzhu): Combine this into PaintInvalidator::mapLocalRectToPaintInv
alidationBacking() when removing PaintInvalidationState. | 51 // TODO(wangxianzhu): Combine this into |
| 52 // PaintInvalidator::mapLocalRectToPaintInvalidationBacking() when removing |
| 53 // PaintInvalidationState. |
| 44 static LayoutRect mapLocalRectToPaintInvalidationBacking( | 54 static LayoutRect mapLocalRectToPaintInvalidationBacking( |
| 45 GeometryMapper& geometryMapper, | 55 GeometryMapper& geometryMapper, |
| 46 const LayoutObject& object, | 56 const LayoutObject& object, |
| 47 const FloatRect& localRect, | 57 const FloatRect& localRect, |
| 48 const PaintInvalidatorContext& context) { | 58 const PaintInvalidatorContext& context) { |
| 49 // TODO(wkorman): The flip below is required because visual rects are | 59 // TODO(wkorman): The flip below is required because visual rects are |
| 50 // currently in "physical coordinates with flipped block-flow direction" | 60 // currently in "physical coordinates with flipped block-flow direction" |
| 51 // (see LayoutBoxModelObject.h) but we need them to be in physical | 61 // (see LayoutBoxModelObject.h) but we need them to be in physical |
| 52 // coordinates. | 62 // coordinates. |
| 53 FloatRect rect = localRect; | 63 FloatRect rect = localRect; |
| 54 // Writing-mode flipping doesn't apply to non-root SVG. | 64 // Writing-mode flipping doesn't apply to non-root SVG. |
| 55 if (!object.isSVG() || object.isSVGRoot()) { | 65 if (!object.isSVG() || object.isSVGRoot()) { |
| 56 if (object.isBox()) { | 66 if (object.isBox()) { |
| 57 toLayoutBox(object).flipForWritingMode(rect); | 67 toLayoutBox(object).flipForWritingMode(rect); |
| 58 } else if (!(context.forcedSubtreeInvalidationFlags & | 68 } else if (!(context.forcedSubtreeInvalidationFlags & |
| 59 PaintInvalidatorContext::ForcedSubtreeSlowPathRect)) { | 69 PaintInvalidatorContext::ForcedSubtreeSlowPathRect)) { |
| 60 // For SPv2 and the GeometryMapper path, we also need to convert the rect | 70 // For SPv2 and the GeometryMapper path, we also need to convert the rect |
| 61 // for non-boxes into physical coordinates before applying paint offset. | 71 // for non-boxes into physical coordinates before applying paint offset. |
| 62 // (Otherwise we'll call mapToVisualrectInAncestorSpace() which requires | 72 // (Otherwise we'll call mapToVisualrectInAncestorSpace() which requires |
| 63 // physical coordinates for boxes, but "physical coordinates with flipped | 73 // physical coordinates for boxes, but "physical coordinates with flipped |
| 64 // block-flow direction" for non-boxes for which we don't need to flip.) | 74 // block-flow direction" for non-boxes for which we don't need to flip.) |
| 65 // TODO(wangxianzhu): Avoid containingBlock(). | 75 // TODO(wangxianzhu): Avoid containingBlock(). |
| 66 object.containingBlock()->flipForWritingMode(rect); | 76 object.containingBlock()->flipForWritingMode(rect); |
| 67 } | 77 } |
| 68 } | 78 } |
| 69 | 79 |
| 70 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | 80 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
| 71 // In SPv2, visual rects are in the space of their local transform node. | 81 // In SPv2, visual rects are in the space of their local transform node. |
| 72 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 82 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
| 73 return LayoutRect(rect); | 83 return enclosingLayoutRectIfNotEmpty(rect); |
| 74 } | 84 } |
| 75 | 85 |
| 76 LayoutRect result; | 86 LayoutRect result; |
| 77 if (context.forcedSubtreeInvalidationFlags & | 87 if (context.forcedSubtreeInvalidationFlags & |
| 78 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { | 88 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { |
| 79 result = slowMapToVisualRectInAncestorSpace( | 89 result = slowMapToVisualRectInAncestorSpace( |
| 80 object, *context.paintInvalidationContainer, rect); | 90 object, *context.paintInvalidationContainer, rect); |
| 81 } else if (object == context.paintInvalidationContainer) { | 91 } else if (object == context.paintInvalidationContainer) { |
| 82 result = LayoutRect(rect); | 92 result = enclosingLayoutRectIfNotEmpty(rect); |
| 83 } else { | 93 } else { |
| 84 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 94 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
| 85 | 95 |
| 86 PropertyTreeState currentTreeState( | 96 PropertyTreeState currentTreeState( |
| 87 context.treeBuilderContext.current.transform, | 97 context.treeBuilderContext.current.transform, |
| 88 context.treeBuilderContext.current.clip, | 98 context.treeBuilderContext.current.clip, |
| 89 context.treeBuilderContext.currentEffect, | 99 context.treeBuilderContext.currentEffect, |
| 90 context.treeBuilderContext.current.scroll); | 100 context.treeBuilderContext.current.scroll); |
| 91 const ObjectPaintProperties* containerPaintProperties = | 101 const ObjectPaintProperties* containerPaintProperties = |
| 92 context.paintInvalidationContainer->objectPaintProperties(); | 102 context.paintInvalidationContainer->objectPaintProperties(); |
| 93 auto containerContentsProperties = | 103 auto containerContentsProperties = |
| 94 containerPaintProperties->contentsProperties(); | 104 containerPaintProperties->contentsProperties(); |
| 95 | 105 |
| 96 bool success = false; | 106 bool success = false; |
| 97 result = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( | 107 result = enclosingLayoutRectIfNotEmpty( |
| 98 rect, currentTreeState, containerContentsProperties.propertyTreeState, | 108 geometryMapper.mapToVisualRectInDestinationSpace( |
| 99 success)); | 109 rect, currentTreeState, |
| 110 containerContentsProperties.propertyTreeState, success)); |
| 100 DCHECK(success); | 111 DCHECK(success); |
| 101 | 112 |
| 102 // Convert the result to the container's contents space. | 113 // Convert the result to the container's contents space. |
| 103 result.moveBy(-containerContentsProperties.paintOffset); | 114 result.moveBy(-containerContentsProperties.paintOffset); |
| 104 } | 115 } |
| 105 | 116 |
| 106 if (context.paintInvalidationContainer->layer()->groupedMapping()) | 117 if (context.paintInvalidationContainer->layer()->groupedMapping()) |
| 107 PaintLayer::mapRectInPaintInvalidationContainerToBacking( | 118 PaintLayer::mapRectInPaintInvalidationContainerToBacking( |
| 108 *context.paintInvalidationContainer, result); | 119 *context.paintInvalidationContainer, result); |
| 109 return result; | 120 return result; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 object.getMutableForPainting().clearPaintInvalidationFlags(); | 439 object.getMutableForPainting().clearPaintInvalidationFlags(); |
| 429 } | 440 } |
| 430 | 441 |
| 431 void PaintInvalidator::processPendingDelayedPaintInvalidations() { | 442 void PaintInvalidator::processPendingDelayedPaintInvalidations() { |
| 432 for (auto target : m_pendingDelayedPaintInvalidations) | 443 for (auto target : m_pendingDelayedPaintInvalidations) |
| 433 target->getMutableForPainting().setShouldDoFullPaintInvalidation( | 444 target->getMutableForPainting().setShouldDoFullPaintInvalidation( |
| 434 PaintInvalidationDelayedFull); | 445 PaintInvalidationDelayedFull); |
| 435 } | 446 } |
| 436 | 447 |
| 437 } // namespace blink | 448 } // namespace blink |
| OLD | NEW |