| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/paint/SVGClipPainter.h" | 6 #include "core/paint/SVGClipPainter.h" |
| 7 | 7 |
| 8 #include "core/dom/ElementTraversal.h" | 8 #include "core/dom/ElementTraversal.h" |
| 9 #include "core/layout/svg/LayoutSVGResourceClipper.h" | 9 #include "core/layout/svg/LayoutSVGResourceClipper.h" |
| 10 #include "core/layout/svg/SVGResources.h" | 10 #include "core/layout/svg/SVGResources.h" |
| 11 #include "core/layout/svg/SVGResourcesCache.h" | 11 #include "core/layout/svg/SVGResourcesCache.h" |
| 12 #include "core/paint/CompositingRecorder.h" | 12 #include "core/paint/CompositingRecorder.h" |
| 13 #include "core/paint/LayoutObjectDrawingRecorder.h" | 13 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 14 #include "core/paint/PaintInfo.h" | 14 #include "core/paint/PaintInfo.h" |
| 15 #include "core/paint/TransformRecorder.h" | 15 #include "core/paint/TransformRecorder.h" |
| 16 #include "platform/graphics/paint/ClipPathDisplayItem.h" | 16 #include "platform/graphics/paint/ClipPathDisplayItem.h" |
| 17 #include "platform/graphics/paint/CompositingDisplayItem.h" | 17 #include "platform/graphics/paint/CompositingDisplayItem.h" |
| 18 #include "platform/graphics/paint/DisplayItemList.h" | 18 #include "platform/graphics/paint/DisplayItemList.h" |
| 19 #include "platform/graphics/paint/DrawingDisplayItem.h" | 19 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 20 #include "wtf/TemporaryChange.h" | |
| 21 | 20 |
| 22 namespace blink { | 21 namespace blink { |
| 23 | 22 |
| 24 bool SVGClipPainter::applyStatefulResource(const LayoutObject& object, GraphicsC
ontext* context, ClipperState& clipperState) | 23 namespace { |
| 25 { | |
| 26 ASSERT(context); | |
| 27 | |
| 28 m_clip.clearInvalidationMask(); | |
| 29 | |
| 30 return applyClippingToContext(object, object.objectBoundingBox(), object.pai
ntInvalidationRectInLocalCoordinates(), context, clipperState); | |
| 31 } | |
| 32 | 24 |
| 33 class SVGClipExpansionCycleHelper { | 25 class SVGClipExpansionCycleHelper { |
| 34 public: | 26 public: |
| 35 SVGClipExpansionCycleHelper(LayoutSVGResourceClipper& clip) : m_clip(clip) {
clip.beginClipExpansion(); } | 27 SVGClipExpansionCycleHelper(LayoutSVGResourceClipper& clip) : m_clip(clip) {
clip.beginClipExpansion(); } |
| 36 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); } | 28 ~SVGClipExpansionCycleHelper() { m_clip.endClipExpansion(); } |
| 37 private: | 29 private: |
| 38 LayoutSVGResourceClipper& m_clip; | 30 LayoutSVGResourceClipper& m_clip; |
| 39 }; | 31 }; |
| 40 | 32 |
| 41 bool SVGClipPainter::applyClippingToContext(const LayoutObject& target, const Fl
oatRect& targetBoundingBox, | 33 } |
| 34 |
| 35 bool SVGClipPainter::prepareEffect(const LayoutObject& target, const FloatRect&
targetBoundingBox, |
| 42 const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperSta
te& clipperState) | 36 const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperSta
te& clipperState) |
| 43 { | 37 { |
| 44 ASSERT(context); | 38 ASSERT(context); |
| 45 ASSERT(clipperState == ClipperNotApplied); | 39 ASSERT(clipperState == ClipperNotApplied); |
| 46 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout()); | 40 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout()); |
| 47 | 41 |
| 42 m_clip.clearInvalidationMask(); |
| 43 |
| 48 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle()) | 44 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle()) |
| 49 return false; | 45 return false; |
| 50 | 46 |
| 51 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); | 47 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); |
| 52 | 48 |
| 53 AffineTransform animatedLocalTransform = toSVGClipPathElement(m_clip.element
())->calculateAnimatedLocalTransform(); | 49 AffineTransform animatedLocalTransform = toSVGClipPathElement(m_clip.element
())->calculateAnimatedLocalTransform(); |
| 54 // When drawing a clip for non-SVG elements, the CTM does not include the zo
om factor. | 50 // When drawing a clip for non-SVG elements, the CTM does not include the zo
om factor. |
| 55 // In this case, we need to apply the zoom scale explicitly - but only for c
lips with | 51 // In this case, we need to apply the zoom scale explicitly - but only for c
lips with |
| 56 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve
d lengths). | 52 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve
d lengths). |
| 57 if (!target.isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE
_USERSPACEONUSE) { | 53 if (!target.isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE
_USERSPACEONUSE) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 | 66 |
| 71 // Begin compositing the clip mask. | 67 // Begin compositing the clip mask. |
| 72 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcOver
_Mode, 1, &paintInvalidationRect); | 68 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcOver
_Mode, 1, &paintInvalidationRect); |
| 73 { | 69 { |
| 74 TransformRecorder recorder(*context, target, animatedLocalTransform); | 70 TransformRecorder recorder(*context, target, animatedLocalTransform); |
| 75 | 71 |
| 76 // clipPath can also be clipped by another clipPath. | 72 // clipPath can also be clipped by another clipPath. |
| 77 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj
ect(&m_clip); | 73 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj
ect(&m_clip); |
| 78 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp
er() : 0; | 74 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp
er() : 0; |
| 79 ClipperState clipPathClipperState = ClipperNotApplied; | 75 ClipperState clipPathClipperState = ClipperNotApplied; |
| 80 if (clipPathClipper && !SVGClipPainter(*clipPathClipper).applyClippingTo
Context(m_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClipp
erState)) { | 76 if (clipPathClipper && !SVGClipPainter(*clipPathClipper).prepareEffect(m
_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClipperState))
{ |
| 81 // End the clip mask's compositor. | 77 // End the clip mask's compositor. |
| 82 CompositingRecorder::endCompositing(*context, target); | 78 CompositingRecorder::endCompositing(*context, target); |
| 83 return false; | 79 return false; |
| 84 } | 80 } |
| 85 | 81 |
| 86 drawClipMaskContent(context, target, targetBoundingBox, paintInvalidatio
nRect); | 82 drawClipMaskContent(context, target, targetBoundingBox, paintInvalidatio
nRect); |
| 87 | 83 |
| 88 if (clipPathClipper) | 84 if (clipPathClipper) |
| 89 SVGClipPainter(*clipPathClipper).postApplyStatefulResource(m_clip, c
ontext, clipPathClipperState); | 85 SVGClipPainter(*clipPathClipper).finishEffect(m_clip, context, clipP
athClipperState); |
| 90 } | 86 } |
| 91 | 87 |
| 92 // Masked content layer start. | 88 // Masked content layer start. |
| 93 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcIn_M
ode, 1, &paintInvalidationRect); | 89 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcIn_M
ode, 1, &paintInvalidationRect); |
| 94 | 90 |
| 95 return true; | 91 return true; |
| 96 } | 92 } |
| 97 | 93 |
| 98 void SVGClipPainter::postApplyStatefulResource(const LayoutObject& target, Graph
icsContext* context, ClipperState& clipperState) | 94 void SVGClipPainter::finishEffect(const LayoutObject& target, GraphicsContext* c
ontext, ClipperState& clipperState) |
| 99 { | 95 { |
| 100 switch (clipperState) { | 96 switch (clipperState) { |
| 101 case ClipperAppliedPath: | 97 case ClipperAppliedPath: |
| 102 // Path-only clipping, no layers to restore but we need to emit an end t
o the clip path display item. | 98 // Path-only clipping, no layers to restore but we need to emit an end t
o the clip path display item. |
| 103 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 99 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 104 if (!context->displayItemList()->displayItemConstructionIsDisabled()
) { | 100 if (!context->displayItemList()->displayItemConstructionIsDisabled()
) { |
| 105 if (context->displayItemList()->lastDisplayItemIsNoopBegin()) | 101 if (context->displayItemList()->lastDisplayItemIsNoopBegin()) |
| 106 context->displayItemList()->removeLastDisplayItem(); | 102 context->displayItemList()->removeLastDisplayItem(); |
| 107 else | 103 else |
| 108 context->displayItemList()->createAndAppend<EndClipPathDispl
ayItem>(target); | 104 context->displayItemList()->createAndAppend<EndClipPathDispl
ayItem>(target); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 135 return; | 131 return; |
| 136 | 132 |
| 137 LayoutObjectDrawingRecorder drawingRecorder(*context, layoutObject, DisplayI
tem::SVGClip, targetPaintInvalidationRect); | 133 LayoutObjectDrawingRecorder drawingRecorder(*context, layoutObject, DisplayI
tem::SVGClip, targetPaintInvalidationRect); |
| 138 context->save(); | 134 context->save(); |
| 139 context->concatCTM(contentTransformation); | 135 context->concatCTM(contentTransformation); |
| 140 context->drawPicture(clipContentPicture.get()); | 136 context->drawPicture(clipContentPicture.get()); |
| 141 context->restore(); | 137 context->restore(); |
| 142 } | 138 } |
| 143 | 139 |
| 144 } | 140 } |
| OLD | NEW |