OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "core/layout/svg/LayoutSVGResourceMasker.h" | 21 #include "core/layout/svg/LayoutSVGResourceMasker.h" |
22 | 22 |
23 #include "core/dom/ElementTraversal.h" | 23 #include "core/dom/ElementTraversal.h" |
24 #include "core/layout/svg/SVGLayoutSupport.h" | 24 #include "core/layout/svg/SVGLayoutSupport.h" |
25 #include "core/paint/CompositingRecorder.h" | |
26 #include "core/paint/SVGPaintContext.h" | 25 #include "core/paint/SVGPaintContext.h" |
27 #include "core/paint/TransformRecorder.h" | 26 #include "core/paint/TransformRecorder.h" |
fs
2015/03/02 13:24:51
Still needed? Same for DrawingDisplayItem.h.
Erik Dahlström (inactive)
2015/03/03 08:42:58
Done.
| |
28 #include "core/svg/SVGElement.h" | 27 #include "core/svg/SVGElement.h" |
29 #include "platform/graphics/paint/CompositingDisplayItem.h" | |
30 #include "platform/graphics/paint/DisplayItemList.h" | 28 #include "platform/graphics/paint/DisplayItemList.h" |
31 #include "platform/graphics/paint/DrawingDisplayItem.h" | 29 #include "platform/graphics/paint/DrawingDisplayItem.h" |
32 #include "platform/transforms/AffineTransform.h" | 30 #include "platform/transforms/AffineTransform.h" |
33 #include "third_party/skia/include/core/SkPicture.h" | 31 #include "third_party/skia/include/core/SkPicture.h" |
34 | 32 |
35 namespace blink { | 33 namespace blink { |
36 | 34 |
37 LayoutSVGResourceMasker::LayoutSVGResourceMasker(SVGMaskElement* node) | 35 LayoutSVGResourceMasker::LayoutSVGResourceMasker(SVGMaskElement* node) |
38 : LayoutSVGResourceContainer(node) | 36 : LayoutSVGResourceContainer(node) |
39 { | 37 { |
40 } | 38 } |
41 | 39 |
42 LayoutSVGResourceMasker::~LayoutSVGResourceMasker() | 40 LayoutSVGResourceMasker::~LayoutSVGResourceMasker() |
43 { | 41 { |
44 } | 42 } |
45 | 43 |
46 void LayoutSVGResourceMasker::removeAllClientsFromCache(bool markForInvalidation ) | 44 void LayoutSVGResourceMasker::removeAllClientsFromCache(bool markForInvalidation ) |
47 { | 45 { |
48 m_maskContentPicture.clear(); | 46 m_maskContentPicture.clear(); |
49 m_maskContentBoundaries = FloatRect(); | 47 m_maskContentBoundaries = FloatRect(); |
50 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval idation : ParentOnlyInvalidation); | 48 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval idation : ParentOnlyInvalidation); |
51 } | 49 } |
52 | 50 |
53 void LayoutSVGResourceMasker::removeClientFromCache(LayoutObject* client, bool m arkForInvalidation) | 51 void LayoutSVGResourceMasker::removeClientFromCache(LayoutObject* client, bool m arkForInvalidation) |
54 { | 52 { |
55 ASSERT(client); | 53 ASSERT(client); |
56 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati on : ParentOnlyInvalidation); | 54 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati on : ParentOnlyInvalidation); |
57 } | 55 } |
58 | 56 |
59 bool LayoutSVGResourceMasker::prepareEffect(LayoutObject* object, GraphicsContex t* context) | |
60 { | |
61 ASSERT(object); | |
62 ASSERT(context); | |
63 ASSERT(style()); | |
64 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); | |
65 | |
66 clearInvalidationMask(); | |
67 | |
68 FloatRect paintInvalidationRect = object->paintInvalidationRectInLocalCoordi nates(); | |
69 if (paintInvalidationRect.isEmpty() || !element()->hasChildren()) | |
70 return false; | |
71 | |
72 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
73 ASSERT(context->displayItemList()); | |
74 context->displayItemList()->add(BeginCompositingDisplayItem::create(obje ct->displayItemClient(), WebCoreCompositeToSkiaComposite(context->compositeOpera tionDeprecated(), WebBlendModeNormal), 1, &paintInvalidationRect)); | |
75 } else { | |
76 BeginCompositingDisplayItem beginCompositingContent(object->displayItemC lient(), WebCoreCompositeToSkiaComposite(context->compositeOperationDeprecated() , WebBlendModeNormal), 1, &paintInvalidationRect); | |
77 beginCompositingContent.replay(context); | |
78 } | |
79 | |
80 return true; | |
81 } | |
82 | |
83 void LayoutSVGResourceMasker::finishEffect(LayoutObject* object, GraphicsContext * context) | |
84 { | |
85 ASSERT(object); | |
86 ASSERT(context); | |
87 ASSERT(style()); | |
88 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); | |
89 | |
90 FloatRect paintInvalidationRect = object->paintInvalidationRectInLocalCoordi nates(); | |
91 { | |
92 ColorFilter maskLayerFilter = style()->svgStyle().maskType() == MT_LUMIN ANCE | |
93 ? ColorFilterLuminanceToAlpha : ColorFilterNone; | |
94 CompositingRecorder maskCompositing(context, object->displayItemClient() , SkXfermode::kDstIn_Mode, 1, &paintInvalidationRect, maskLayerFilter); | |
95 drawMaskForRenderer(context, object->displayItemClient(), object->object BoundingBox()); | |
96 } | |
97 | |
98 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
99 ASSERT(context->displayItemList()); | |
100 context->displayItemList()->add(EndCompositingDisplayItem::create(object ->displayItemClient())); | |
101 } else { | |
102 EndCompositingDisplayItem endCompositingContent(object->displayItemClien t()); | |
103 endCompositingContent.replay(context); | |
104 } | |
105 } | |
106 | |
107 void LayoutSVGResourceMasker::drawMaskForRenderer(GraphicsContext* context, Disp layItemClient client, const FloatRect& targetBoundingBox) | |
108 { | |
109 ASSERT(context); | |
110 | |
111 AffineTransform contentTransformation; | |
112 SVGUnitTypes::SVGUnitType contentUnits = toSVGMaskElement(element())->maskCo ntentUnits()->currentValue()->enumValue(); | |
113 if (contentUnits == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { | |
114 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox .y()); | |
115 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB oundingBox.height()); | |
116 } | |
117 | |
118 if (!m_maskContentPicture) { | |
119 SubtreeContentTransformScope contentTransformScope(contentTransformation ); | |
120 m_maskContentPicture = createContentPicture(); | |
121 } | |
122 | |
123 TransformRecorder recorder(*context, client, contentTransformation); | |
124 | |
125 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
126 ASSERT(context->displayItemList()); | |
127 context->displayItemList()->add(DrawingDisplayItem::create(client, Displ ayItem::SVGMask, m_maskContentPicture)); | |
128 } else { | |
129 DrawingDisplayItem maskPicture(client, DisplayItem::SVGMask, m_maskConte ntPicture); | |
130 maskPicture.replay(context); | |
131 } | |
132 } | |
133 | |
134 PassRefPtr<const SkPicture> LayoutSVGResourceMasker::createContentPicture() | 57 PassRefPtr<const SkPicture> LayoutSVGResourceMasker::createContentPicture() |
135 { | 58 { |
136 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat es) to avoid the intersection | 59 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat es) to avoid the intersection |
137 // with local clips/mask, which may yield incorrect results when mixing obje ctBoundingBox and | 60 // with local clips/mask, which may yield incorrect results when mixing obje ctBoundingBox and |
138 // userSpaceOnUse units (http://crbug.com/294900). | 61 // userSpaceOnUse units (http://crbug.com/294900). |
139 FloatRect bounds = strokeBoundingBox(); | 62 FloatRect bounds = strokeBoundingBox(); |
140 | 63 |
141 OwnPtr<DisplayItemList> displayItemList; | 64 OwnPtr<DisplayItemList> displayItemList; |
142 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 65 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
143 displayItemList = DisplayItemList::create(); | 66 displayItemList = DisplayItemList::create(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); | 121 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); |
199 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); | 122 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); |
200 maskRect = transform.mapRect(maskRect); | 123 maskRect = transform.mapRect(maskRect); |
201 } | 124 } |
202 | 125 |
203 maskRect.intersect(maskBoundaries); | 126 maskRect.intersect(maskBoundaries); |
204 return maskRect; | 127 return maskRect; |
205 } | 128 } |
206 | 129 |
207 } | 130 } |
OLD | NEW |