| 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/SVGMaskPainter.h" | 6 #include "core/paint/SVGMaskPainter.h" |
| 7 | 7 |
| 8 #include "core/layout/svg/LayoutSVGResourceMasker.h" | 8 #include "core/layout/svg/LayoutSVGResourceMasker.h" |
| 9 #include "core/paint/CompositingRecorder.h" | 9 #include "core/paint/CompositingRecorder.h" |
| 10 #include "core/paint/LayoutObjectDrawingRecorder.h" | 10 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 11 #include "core/paint/PaintInfo.h" | 11 #include "core/paint/PaintInfo.h" |
| 12 #include "core/paint/TransformRecorder.h" | 12 #include "core/paint/TransformRecorder.h" |
| 13 #include "platform/graphics/paint/CompositingDisplayItem.h" | 13 #include "platform/graphics/paint/CompositingDisplayItem.h" |
| 14 #include "platform/graphics/paint/DisplayItemList.h" | |
| 15 #include "platform/graphics/paint/DrawingDisplayItem.h" | 14 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 15 #include "platform/graphics/paint/PaintController.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 bool SVGMaskPainter::prepareEffect(const LayoutObject& object, GraphicsContext*
context) | 19 bool SVGMaskPainter::prepareEffect(const LayoutObject& object, GraphicsContext*
context) |
| 20 { | 20 { |
| 21 ASSERT(context); | 21 ASSERT(context); |
| 22 ASSERT(m_mask.style()); | 22 ASSERT(m_mask.style()); |
| 23 ASSERT_WITH_SECURITY_IMPLICATION(!m_mask.needsLayout()); | 23 ASSERT_WITH_SECURITY_IMPLICATION(!m_mask.needsLayout()); |
| 24 | 24 |
| 25 m_mask.clearInvalidationMask(); | 25 m_mask.clearInvalidationMask(); |
| 26 | 26 |
| 27 FloatRect paintInvalidationRect = object.paintInvalidationRectInLocalCoordin
ates(); | 27 FloatRect paintInvalidationRect = object.paintInvalidationRectInLocalCoordin
ates(); |
| 28 if (paintInvalidationRect.isEmpty() || !m_mask.element()->hasChildren()) | 28 if (paintInvalidationRect.isEmpty() || !m_mask.element()->hasChildren()) |
| 29 return false; | 29 return false; |
| 30 | 30 |
| 31 ASSERT(context->displayItemList()); | 31 ASSERT(context->paintController()); |
| 32 context->displayItemList()->createAndAppend<BeginCompositingDisplayItem>(obj
ect, SkXfermode::kSrcOver_Mode, 1, &paintInvalidationRect); | 32 context->paintController()->createAndAppend<BeginCompositingDisplayItem>(obj
ect, SkXfermode::kSrcOver_Mode, 1, &paintInvalidationRect); |
| 33 return true; | 33 return true; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void SVGMaskPainter::finishEffect(const LayoutObject& object, GraphicsContext* c
ontext) | 36 void SVGMaskPainter::finishEffect(const LayoutObject& object, GraphicsContext* c
ontext) |
| 37 { | 37 { |
| 38 ASSERT(context); | 38 ASSERT(context); |
| 39 ASSERT(m_mask.style()); | 39 ASSERT(m_mask.style()); |
| 40 ASSERT_WITH_SECURITY_IMPLICATION(!m_mask.needsLayout()); | 40 ASSERT_WITH_SECURITY_IMPLICATION(!m_mask.needsLayout()); |
| 41 | 41 |
| 42 FloatRect paintInvalidationRect = object.paintInvalidationRectInLocalCoordin
ates(); | 42 FloatRect paintInvalidationRect = object.paintInvalidationRectInLocalCoordin
ates(); |
| 43 { | 43 { |
| 44 ColorFilter maskLayerFilter = m_mask.style()->svgStyle().maskType() == M
T_LUMINANCE | 44 ColorFilter maskLayerFilter = m_mask.style()->svgStyle().maskType() == M
T_LUMINANCE |
| 45 ? ColorFilterLuminanceToAlpha : ColorFilterNone; | 45 ? ColorFilterLuminanceToAlpha : ColorFilterNone; |
| 46 CompositingRecorder maskCompositing(*context, object, SkXfermode::kDstIn
_Mode, 1, &paintInvalidationRect, maskLayerFilter); | 46 CompositingRecorder maskCompositing(*context, object, SkXfermode::kDstIn
_Mode, 1, &paintInvalidationRect, maskLayerFilter); |
| 47 drawMaskForLayoutObject(context, object, object.objectBoundingBox(), pai
ntInvalidationRect); | 47 drawMaskForLayoutObject(context, object, object.objectBoundingBox(), pai
ntInvalidationRect); |
| 48 } | 48 } |
| 49 | 49 |
| 50 ASSERT(context->displayItemList()); | 50 ASSERT(context->paintController()); |
| 51 context->displayItemList()->endItem<EndCompositingDisplayItem>(object); | 51 context->paintController()->endItem<EndCompositingDisplayItem>(object); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SVGMaskPainter::drawMaskForLayoutObject(GraphicsContext* context, const Lay
outObject& layoutObject, const FloatRect& targetBoundingBox, const FloatRect& ta
rgetPaintInvalidationRect) | 54 void SVGMaskPainter::drawMaskForLayoutObject(GraphicsContext* context, const Lay
outObject& layoutObject, const FloatRect& targetBoundingBox, const FloatRect& ta
rgetPaintInvalidationRect) |
| 55 { | 55 { |
| 56 ASSERT(context); | 56 ASSERT(context); |
| 57 | 57 |
| 58 AffineTransform contentTransformation; | 58 AffineTransform contentTransformation; |
| 59 RefPtr<const SkPicture> maskContentPicture = m_mask.createContentPicture(con
tentTransformation, targetBoundingBox, context); | 59 RefPtr<const SkPicture> maskContentPicture = m_mask.createContentPicture(con
tentTransformation, targetBoundingBox, context); |
| 60 | 60 |
| 61 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, layout
Object, DisplayItem::SVGMask, LayoutPoint())) | 61 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(*context, layout
Object, DisplayItem::SVGMask, LayoutPoint())) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 LayoutObjectDrawingRecorder drawingRecorder(*context, layoutObject, DisplayI
tem::SVGMask, targetPaintInvalidationRect, LayoutPoint()); | 64 LayoutObjectDrawingRecorder drawingRecorder(*context, layoutObject, DisplayI
tem::SVGMask, targetPaintInvalidationRect, LayoutPoint()); |
| 65 context->save(); | 65 context->save(); |
| 66 context->concatCTM(contentTransformation); | 66 context->concatCTM(contentTransformation); |
| 67 context->drawPicture(maskContentPicture.get()); | 67 context->drawPicture(maskContentPicture.get()); |
| 68 context->restore(); | 68 context->restore(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 } | 71 } |
| OLD | NEW |