| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 { | 42 { |
| 43 ASSERT(context); | 43 ASSERT(context); |
| 44 ASSERT(clipperState == ClipperNotApplied); | 44 ASSERT(clipperState == ClipperNotApplied); |
| 45 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout()); | 45 ASSERT_WITH_SECURITY_IMPLICATION(!m_clip.needsLayout()); |
| 46 | 46 |
| 47 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle()) | 47 if (paintInvalidationRect.isEmpty() || m_clip.hasCycle()) |
| 48 return false; | 48 return false; |
| 49 | 49 |
| 50 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); | 50 SVGClipExpansionCycleHelper inClipExpansionChange(m_clip); |
| 51 | 51 |
| 52 AffineTransform animatedLocalTransform = toSVGClipPathElement(m_clip.element
())->calculateAnimatedLocalTransform(); | 52 AffineTransform contentTransformation = m_clip.calculateContentTransformatio
n(&target, targetBoundingBox); |
| 53 // When drawing a clip for non-SVG elements, the CTM does not include the zo
om factor. | |
| 54 // In this case, we need to apply the zoom scale explicitly - but only for c
lips with | |
| 55 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve
d lengths). | |
| 56 if (!target.isSVG() && m_clip.clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE
_USERSPACEONUSE) { | |
| 57 ASSERT(m_clip.style()); | |
| 58 animatedLocalTransform.scale(m_clip.style()->effectiveZoom()); | |
| 59 } | |
| 60 | 53 |
| 61 // First, try to apply the clip as a clipPath. | 54 // First, try to apply the clip as a clipPath. |
| 62 if (m_clip.tryPathOnlyClipping(target, context, animatedLocalTransform, targ
etBoundingBox)) { | 55 if (m_clip.tryPathOnlyClipping(target, context, contentTransformation)) { |
| 63 clipperState = ClipperAppliedPath; | 56 clipperState = ClipperAppliedPath; |
| 64 return true; | 57 return true; |
| 65 } | 58 } |
| 66 | 59 |
| 67 // Fall back to masking. | 60 // Fall back to masking. |
| 68 clipperState = ClipperAppliedMask; | 61 clipperState = ClipperAppliedMask; |
| 69 | 62 |
| 70 // Begin compositing the clip mask. | 63 // Begin compositing the clip mask. |
| 71 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcOver
_Mode, 1, &paintInvalidationRect); | 64 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcOver
_Mode, 1, &paintInvalidationRect); |
| 72 { | 65 { |
| 73 TransformRecorder recorder(*context, target, animatedLocalTransform); | |
| 74 | |
| 75 // clipPath can also be clipped by another clipPath. | 66 // clipPath can also be clipped by another clipPath. |
| 76 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj
ect(&m_clip); | 67 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj
ect(&m_clip); |
| 77 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp
er() : 0; | 68 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp
er() : 0; |
| 78 ClipperState clipPathClipperState = ClipperNotApplied; | 69 ClipperState clipPathClipperState = ClipperNotApplied; |
| 79 if (clipPathClipper && !SVGClipPainter(*clipPathClipper).applyClippingTo
Context(m_clip, targetBoundingBox, paintInvalidationRect, context, clipPathClipp
erState)) { | 70 if (clipPathClipper) { |
| 80 // End the clip mask's compositor. | 71 FloatRect contentBoundingBox = contentTransformation.mapRect(targetB
oundingBox); |
| 81 CompositingRecorder::endCompositing(*context, target); | 72 if (!SVGClipPainter(*clipPathClipper).applyClippingToContext(m_clip,
contentBoundingBox, paintInvalidationRect, context, clipPathClipperState)) { |
| 82 return false; | 73 // End the clip mask's compositor. |
| 74 CompositingRecorder::endCompositing(*context, target); |
| 75 return false; |
| 76 } |
| 83 } | 77 } |
| 84 | 78 |
| 85 drawClipMaskContent(context, target, targetBoundingBox); | 79 drawClipMaskContent(context, target, contentTransformation); |
| 86 | 80 |
| 87 if (clipPathClipper) | 81 if (clipPathClipper) |
| 88 SVGClipPainter(*clipPathClipper).postApplyStatefulResource(m_clip, c
ontext, clipPathClipperState); | 82 SVGClipPainter(*clipPathClipper).postApplyStatefulResource(m_clip, c
ontext, clipPathClipperState); |
| 89 } | 83 } |
| 90 | 84 |
| 91 // Masked content layer start. | 85 // Masked content layer start. |
| 92 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcIn_M
ode, 1, &paintInvalidationRect); | 86 CompositingRecorder::beginCompositing(*context, target, SkXfermode::kSrcIn_M
ode, 1, &paintInvalidationRect); |
| 93 | 87 |
| 94 return true; | 88 return true; |
| 95 } | 89 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 113 CompositingRecorder::endCompositing(*context, target); | 107 CompositingRecorder::endCompositing(*context, target); |
| 114 | 108 |
| 115 // Transfer clip mask -> bg (SrcOver) | 109 // Transfer clip mask -> bg (SrcOver) |
| 116 CompositingRecorder::endCompositing(*context, target); | 110 CompositingRecorder::endCompositing(*context, target); |
| 117 break; | 111 break; |
| 118 default: | 112 default: |
| 119 ASSERT_NOT_REACHED(); | 113 ASSERT_NOT_REACHED(); |
| 120 } | 114 } |
| 121 } | 115 } |
| 122 | 116 |
| 123 void SVGClipPainter::drawClipMaskContent(GraphicsContext* context, const LayoutO
bject& layoutObject, const FloatRect& targetBoundingBox) | 117 void SVGClipPainter::drawClipMaskContent(GraphicsContext* context, const LayoutO
bject& layoutObject, const AffineTransform& contentTransformation) |
| 124 { | 118 { |
| 125 ASSERT(context); | 119 ASSERT(context); |
| 126 | 120 |
| 127 AffineTransform contentTransformation; | 121 RefPtr<const SkPicture> clipContentPicture = m_clip.createContentPicture(con
tentTransformation, context); |
| 128 RefPtr<const SkPicture> clipContentPicture = m_clip.createContentPicture(con
tentTransformation, targetBoundingBox, context); | |
| 129 | 122 |
| 130 TransformRecorder recorder(*context, layoutObject, contentTransformation); | 123 TransformRecorder recorder(*context, layoutObject, contentTransformation); |
| 131 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 124 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 132 ASSERT(context->displayItemList()); | 125 ASSERT(context->displayItemList()); |
| 133 if (context->displayItemList()->displayItemConstructionIsDisabled()) | 126 if (context->displayItemList()->displayItemConstructionIsDisabled()) |
| 134 return; | 127 return; |
| 135 context->displayItemList()->add(DrawingDisplayItem::create(layoutObject,
DisplayItem::SVGClip, clipContentPicture)); | 128 context->displayItemList()->add(DrawingDisplayItem::create(layoutObject,
DisplayItem::SVGClip, clipContentPicture)); |
| 136 } else { | 129 } else { |
| 137 DrawingDisplayItem clipPicture(layoutObject, DisplayItem::SVGClip, clipC
ontentPicture); | 130 DrawingDisplayItem clipPicture(layoutObject, DisplayItem::SVGClip, clipC
ontentPicture); |
| 138 clipPicture.replay(*context); | 131 clipPicture.replay(*context); |
| 139 } | 132 } |
| 140 } | 133 } |
| 141 | 134 |
| 142 } | 135 } |
| OLD | NEW |