| 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/SVGMaskPainter.h" | 5 #include "core/paint/SVGMaskPainter.h" |
| 6 | 6 |
| 7 #include "core/layout/svg/LayoutSVGResourceMasker.h" | 7 #include "core/layout/svg/LayoutSVGResourceMasker.h" |
| 8 #include "core/paint/LayoutObjectDrawingRecorder.h" | 8 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 9 #include "core/paint/PaintInfo.h" | 9 #include "core/paint/PaintInfo.h" |
| 10 #include "core/paint/TransformRecorder.h" | 10 #include "core/paint/TransformRecorder.h" |
| 11 #include "platform/graphics/paint/CompositingDisplayItem.h" | 11 #include "platform/graphics/paint/CompositingDisplayItem.h" |
| 12 #include "platform/graphics/paint/CompositingRecorder.h" | 12 #include "platform/graphics/paint/CompositingRecorder.h" |
| 13 #include "platform/graphics/paint/DrawingDisplayItem.h" | 13 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 14 #include "platform/graphics/paint/PaintController.h" | 14 #include "platform/graphics/paint/PaintController.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 bool SVGMaskPainter::prepareEffect(const LayoutObject& object, | 18 bool SVGMaskPainter::prepareEffect(const LayoutObject& object, |
| 19 GraphicsContext& context) { | 19 GraphicsContext& context) { |
| 20 ASSERT(m_mask.style()); | 20 ASSERT(m_mask.style()); |
| 21 SECURITY_DCHECK(!m_mask.needsLayout()); | 21 SECURITY_DCHECK(!m_mask.needsLayout()); |
| 22 | 22 |
| 23 m_mask.clearInvalidationMask(); | 23 m_mask.clearInvalidationMask(); |
| 24 | 24 |
| 25 FloatRect paintInvalidationRect = | 25 FloatRect visualRect = object.visualRectInLocalSVGCoordinates(); |
| 26 object.paintInvalidationRectInLocalSVGCoordinates(); | 26 if (visualRect.isEmpty() || !m_mask.element()->hasChildren()) |
| 27 if (paintInvalidationRect.isEmpty() || !m_mask.element()->hasChildren()) | |
| 28 return false; | 27 return false; |
| 29 | 28 |
| 30 context.getPaintController().createAndAppend<BeginCompositingDisplayItem>( | 29 context.getPaintController().createAndAppend<BeginCompositingDisplayItem>( |
| 31 object, SkBlendMode::kSrcOver, 1, &paintInvalidationRect); | 30 object, SkBlendMode::kSrcOver, 1, &visualRect); |
| 32 return true; | 31 return true; |
| 33 } | 32 } |
| 34 | 33 |
| 35 void SVGMaskPainter::finishEffect(const LayoutObject& object, | 34 void SVGMaskPainter::finishEffect(const LayoutObject& object, |
| 36 GraphicsContext& context) { | 35 GraphicsContext& context) { |
| 37 ASSERT(m_mask.style()); | 36 ASSERT(m_mask.style()); |
| 38 SECURITY_DCHECK(!m_mask.needsLayout()); | 37 SECURITY_DCHECK(!m_mask.needsLayout()); |
| 39 | 38 |
| 40 FloatRect paintInvalidationRect = | 39 FloatRect visualRect = object.visualRectInLocalSVGCoordinates(); |
| 41 object.paintInvalidationRectInLocalSVGCoordinates(); | |
| 42 { | 40 { |
| 43 ColorFilter maskLayerFilter = | 41 ColorFilter maskLayerFilter = |
| 44 m_mask.style()->svgStyle().maskType() == MT_LUMINANCE | 42 m_mask.style()->svgStyle().maskType() == MT_LUMINANCE |
| 45 ? ColorFilterLuminanceToAlpha | 43 ? ColorFilterLuminanceToAlpha |
| 46 : ColorFilterNone; | 44 : ColorFilterNone; |
| 47 CompositingRecorder maskCompositing(context, object, SkBlendMode::kDstIn, 1, | 45 CompositingRecorder maskCompositing(context, object, SkBlendMode::kDstIn, 1, |
| 48 &paintInvalidationRect, | 46 &visualRect, maskLayerFilter); |
| 49 maskLayerFilter); | |
| 50 drawMaskForLayoutObject(context, object, object.objectBoundingBox(), | 47 drawMaskForLayoutObject(context, object, object.objectBoundingBox(), |
| 51 paintInvalidationRect); | 48 visualRect); |
| 52 } | 49 } |
| 53 | 50 |
| 54 context.getPaintController().endItem<EndCompositingDisplayItem>(object); | 51 context.getPaintController().endItem<EndCompositingDisplayItem>(object); |
| 55 } | 52 } |
| 56 | 53 |
| 57 void SVGMaskPainter::drawMaskForLayoutObject( | 54 void SVGMaskPainter::drawMaskForLayoutObject( |
| 58 GraphicsContext& context, | 55 GraphicsContext& context, |
| 59 const LayoutObject& layoutObject, | 56 const LayoutObject& layoutObject, |
| 60 const FloatRect& targetBoundingBox, | 57 const FloatRect& targetBoundingBox, |
| 61 const FloatRect& targetPaintInvalidationRect) { | 58 const FloatRect& targetVisualRect) { |
| 62 AffineTransform contentTransformation; | 59 AffineTransform contentTransformation; |
| 63 sk_sp<const SkPicture> maskContentPicture = m_mask.createContentPicture( | 60 sk_sp<const SkPicture> maskContentPicture = m_mask.createContentPicture( |
| 64 contentTransformation, targetBoundingBox, context); | 61 contentTransformation, targetBoundingBox, context); |
| 65 | 62 |
| 66 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | 63 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( |
| 67 context, layoutObject, DisplayItem::kSVGMask)) | 64 context, layoutObject, DisplayItem::kSVGMask)) |
| 68 return; | 65 return; |
| 69 | 66 |
| 70 LayoutObjectDrawingRecorder drawingRecorder(context, layoutObject, | 67 LayoutObjectDrawingRecorder drawingRecorder( |
| 71 DisplayItem::kSVGMask, | 68 context, layoutObject, DisplayItem::kSVGMask, targetVisualRect); |
| 72 targetPaintInvalidationRect); | |
| 73 context.save(); | 69 context.save(); |
| 74 context.concatCTM(contentTransformation); | 70 context.concatCTM(contentTransformation); |
| 75 context.drawPicture(maskContentPicture.get()); | 71 context.drawPicture(maskContentPicture.get()); |
| 76 context.restore(); | 72 context.restore(); |
| 77 } | 73 } |
| 78 | 74 |
| 79 } // namespace blink | 75 } // namespace blink |
| OLD | NEW |