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