| OLD | NEW |
| 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/SVGClipPainter.h" | 5 #include "core/paint/SVGClipPainter.h" |
| 6 | 6 |
| 7 #include "core/dom/ElementTraversal.h" | 7 #include "core/dom/ElementTraversal.h" |
| 8 #include "core/layout/svg/LayoutSVGResourceClipper.h" | 8 #include "core/layout/svg/LayoutSVGResourceClipper.h" |
| 9 #include "core/layout/svg/SVGLayoutSupport.h" | 9 #include "core/layout/svg/SVGLayoutSupport.h" |
| 10 #include "core/layout/svg/SVGResources.h" | 10 #include "core/layout/svg/SVGResources.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); } | 32 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); } |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 LayoutSVGResourceClipper& m_clip; | 35 LayoutSVGResourceClipper& m_clip; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 bool SVGClipPainter::prepareEffect(const LayoutObject& target, | 40 bool SVGClipPainter::prepareEffect(const LayoutObject& target, |
| 41 const FloatRect& targetBoundingBox, | 41 const FloatRect& targetBoundingBox, |
| 42 const FloatRect& paintInvalidationRect, | 42 const FloatRect& visualRect, |
| 43 const FloatPoint& layerPositionOffset, | 43 const FloatPoint& layerPositionOffset, |
| 44 GraphicsContext& context, | 44 GraphicsContext& context, |
| 45 ClipperState& clipperState) { | 45 ClipperState& clipperState) { |
| 46 DCHECK_EQ(clipperState, ClipperState::NotApplied); | 46 DCHECK_EQ(clipperState, ClipperState::NotApplied); |
| 47 SECURITY_DCHECK(!m_clip.needsLayout()); | 47 SECURITY_DCHECK(!m_clip.needsLayout()); |
| 48 | 48 |
| 49 m_clip.clearInvalidationMask(); | 49 m_clip.clearInvalidationMask(); |
| 50 | 50 |
| 51 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle()) | 51 if (visualRect.isEmpty() || m_clip.hasCycle()) |
| 52 return false; | 52 return false; |
| 53 | 53 |
| 54 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); | 54 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); |
| 55 | 55 |
| 56 AffineTransform animatedLocalTransform = | 56 AffineTransform animatedLocalTransform = |
| 57 toSVGClipPathElement(m_clip.element())->calculateAnimatedLocalTransform(); | 57 toSVGClipPathElement(m_clip.element())->calculateAnimatedLocalTransform(); |
| 58 // When drawing a clip for non-SVG elements, the CTM does not include the zoom | 58 // When drawing a clip for non-SVG elements, the CTM does not include the zoom |
| 59 // factor. In this case, we need to apply the zoom scale explicitly - but | 59 // factor. In this case, we need to apply the zoom scale explicitly - but |
| 60 // only for clips with userSpaceOnUse units (the zoom is accounted for | 60 // only for clips with userSpaceOnUse units (the zoom is accounted for |
| 61 // objectBoundingBox-resolved lengths). | 61 // objectBoundingBox-resolved lengths). |
| (...skipping 14 matching lines...) Expand all Loading... |
| 76 context.getPaintController().createAndAppend<BeginClipPathDisplayItem>( | 76 context.getPaintController().createAndAppend<BeginClipPathDisplayItem>( |
| 77 target, clipPath); | 77 target, clipPath); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Fall back to masking. | 81 // Fall back to masking. |
| 82 clipperState = ClipperState::AppliedMask; | 82 clipperState = ClipperState::AppliedMask; |
| 83 | 83 |
| 84 // Begin compositing the clip mask. | 84 // Begin compositing the clip mask. |
| 85 CompositingRecorder::beginCompositing(context, target, SkBlendMode::kSrcOver, | 85 CompositingRecorder::beginCompositing(context, target, SkBlendMode::kSrcOver, |
| 86 1, &paintInvalidationRect); | 86 1, &visualRect); |
| 87 { | 87 { |
| 88 if (!drawClipAsMask(context, target, targetBoundingBox, | 88 if (!drawClipAsMask(context, target, targetBoundingBox, visualRect, |
| 89 paintInvalidationRect, animatedLocalTransform, | 89 animatedLocalTransform, layerPositionOffset)) { |
| 90 layerPositionOffset)) { | |
| 91 // End the clip mask's compositor. | 90 // End the clip mask's compositor. |
| 92 CompositingRecorder::endCompositing(context, target); | 91 CompositingRecorder::endCompositing(context, target); |
| 93 return false; | 92 return false; |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 | 95 |
| 97 // Masked content layer start. | 96 // Masked content layer start. |
| 98 CompositingRecorder::beginCompositing(context, target, SkBlendMode::kSrcIn, 1, | 97 CompositingRecorder::beginCompositing(context, target, SkBlendMode::kSrcIn, 1, |
| 99 &paintInvalidationRect); | 98 &visualRect); |
| 100 | 99 |
| 101 return true; | 100 return true; |
| 102 } | 101 } |
| 103 | 102 |
| 104 void SVGClipPainter::finishEffect(const LayoutObject& target, | 103 void SVGClipPainter::finishEffect(const LayoutObject& target, |
| 105 GraphicsContext& context, | 104 GraphicsContext& context, |
| 106 ClipperState& clipperState) { | 105 ClipperState& clipperState) { |
| 107 switch (clipperState) { | 106 switch (clipperState) { |
| 108 case ClipperState::AppliedPath: | 107 case ClipperState::AppliedPath: |
| 109 // Path-only clipping, no layers to restore but we need to emit an end to | 108 // Path-only clipping, no layers to restore but we need to emit an end to |
| 110 // the clip path display item. | 109 // the clip path display item. |
| 111 context.getPaintController().endItem<EndClipPathDisplayItem>(target); | 110 context.getPaintController().endItem<EndClipPathDisplayItem>(target); |
| 112 break; | 111 break; |
| 113 case ClipperState::AppliedMask: | 112 case ClipperState::AppliedMask: |
| 114 // Transfer content -> clip mask (SrcIn) | 113 // Transfer content -> clip mask (SrcIn) |
| 115 CompositingRecorder::endCompositing(context, target); | 114 CompositingRecorder::endCompositing(context, target); |
| 116 | 115 |
| 117 // Transfer clip mask -> bg (SrcOver) | 116 // Transfer clip mask -> bg (SrcOver) |
| 118 CompositingRecorder::endCompositing(context, target); | 117 CompositingRecorder::endCompositing(context, target); |
| 119 break; | 118 break; |
| 120 default: | 119 default: |
| 121 NOTREACHED(); | 120 NOTREACHED(); |
| 122 } | 121 } |
| 123 } | 122 } |
| 124 | 123 |
| 125 bool SVGClipPainter::drawClipAsMask( | 124 bool SVGClipPainter::drawClipAsMask(GraphicsContext& context, |
| 126 GraphicsContext& context, | 125 const LayoutObject& layoutObject, |
| 127 const LayoutObject& layoutObject, | 126 const FloatRect& targetBoundingBox, |
| 128 const FloatRect& targetBoundingBox, | 127 const FloatRect& targetVisualRect, |
| 129 const FloatRect& targetPaintInvalidationRect, | 128 const AffineTransform& localTransform, |
| 130 const AffineTransform& localTransform, | 129 const FloatPoint& layerPositionOffset) { |
| 131 const FloatPoint& layerPositionOffset) { | |
| 132 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 130 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( |
| 133 context, layoutObject, DisplayItem::kSVGClip)) | 131 context, layoutObject, DisplayItem::kSVGClip)) |
| 134 return true; | 132 return true; |
| 135 | 133 |
| 136 SkPictureBuilder maskPictureBuilder(targetPaintInvalidationRect, nullptr, | 134 SkPictureBuilder maskPictureBuilder(targetVisualRect, nullptr, &context); |
| 137 &context); | |
| 138 GraphicsContext& maskContext = maskPictureBuilder.context(); | 135 GraphicsContext& maskContext = maskPictureBuilder.context(); |
| 139 { | 136 { |
| 140 TransformRecorder recorder(maskContext, layoutObject, localTransform); | 137 TransformRecorder recorder(maskContext, layoutObject, localTransform); |
| 141 | 138 |
| 142 // Apply any clip-path clipping this clipPath (nested shape/clipPath.) | 139 // Apply any clip-path clipping this clipPath (nested shape/clipPath.) |
| 143 Optional<ClipPathClipper> nestedClipPathClipper; | 140 Optional<ClipPathClipper> nestedClipPathClipper; |
| 144 if (ClipPathOperation* clipPathOperation = m_clip.styleRef().clipPath()) | 141 if (ClipPathOperation* clipPathOperation = m_clip.styleRef().clipPath()) |
| 145 nestedClipPathClipper.emplace(maskContext, *clipPathOperation, m_clip, | 142 nestedClipPathClipper.emplace(maskContext, *clipPathOperation, m_clip, |
| 146 targetBoundingBox, layerPositionOffset); | 143 targetBoundingBox, layerPositionOffset); |
| 147 | 144 |
| 148 { | 145 { |
| 149 AffineTransform contentTransform; | 146 AffineTransform contentTransform; |
| 150 if (m_clip.clipPathUnits() == | 147 if (m_clip.clipPathUnits() == |
| 151 SVGUnitTypes::kSvgUnitTypeObjectboundingbox) { | 148 SVGUnitTypes::kSvgUnitTypeObjectboundingbox) { |
| 152 contentTransform.translate(targetBoundingBox.x(), | 149 contentTransform.translate(targetBoundingBox.x(), |
| 153 targetBoundingBox.y()); | 150 targetBoundingBox.y()); |
| 154 contentTransform.scaleNonUniform(targetBoundingBox.width(), | 151 contentTransform.scaleNonUniform(targetBoundingBox.width(), |
| 155 targetBoundingBox.height()); | 152 targetBoundingBox.height()); |
| 156 } | 153 } |
| 157 SubtreeContentTransformScope contentTransformScope(contentTransform); | 154 SubtreeContentTransformScope contentTransformScope(contentTransform); |
| 158 | 155 |
| 159 TransformRecorder contentTransformRecorder(maskContext, layoutObject, | 156 TransformRecorder contentTransformRecorder(maskContext, layoutObject, |
| 160 contentTransform); | 157 contentTransform); |
| 161 maskContext.getPaintController().createAndAppend<DrawingDisplayItem>( | 158 maskContext.getPaintController().createAndAppend<DrawingDisplayItem>( |
| 162 layoutObject, DisplayItem::kSVGClip, m_clip.createContentPicture()); | 159 layoutObject, DisplayItem::kSVGClip, m_clip.createContentPicture()); |
| 163 } | 160 } |
| 164 } | 161 } |
| 165 | 162 |
| 166 LayoutObjectDrawingRecorder drawingRecorder(context, layoutObject, | 163 LayoutObjectDrawingRecorder drawingRecorder( |
| 167 DisplayItem::kSVGClip, | 164 context, layoutObject, DisplayItem::kSVGClip, targetVisualRect); |
| 168 targetPaintInvalidationRect); | |
| 169 sk_sp<SkPicture> maskPicture = maskPictureBuilder.endRecording(); | 165 sk_sp<SkPicture> maskPicture = maskPictureBuilder.endRecording(); |
| 170 context.drawPicture(maskPicture.get()); | 166 context.drawPicture(maskPicture.get()); |
| 171 return true; | 167 return true; |
| 172 } | 168 } |
| 173 | 169 |
| 174 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |