Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: Source/core/layout/svg/LayoutSVGResourceMasker.cpp

Issue 967543002: [S.P.] Move svg mask painting to SVGMaskPainter (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review fixes Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/layout/svg/LayoutSVGResourceMasker.h ('k') | Source/core/paint/SVGMaskPainter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
28 #include "core/svg/SVGElement.h" 26 #include "core/svg/SVGElement.h"
29 #include "platform/graphics/paint/CompositingDisplayItem.h"
30 #include "platform/graphics/paint/DisplayItemList.h" 27 #include "platform/graphics/paint/DisplayItemList.h"
31 #include "platform/graphics/paint/DrawingDisplayItem.h"
32 #include "platform/transforms/AffineTransform.h" 28 #include "platform/transforms/AffineTransform.h"
33 #include "third_party/skia/include/core/SkPicture.h" 29 #include "third_party/skia/include/core/SkPicture.h"
34 30
35 namespace blink { 31 namespace blink {
36 32
37 LayoutSVGResourceMasker::LayoutSVGResourceMasker(SVGMaskElement* node) 33 LayoutSVGResourceMasker::LayoutSVGResourceMasker(SVGMaskElement* node)
38 : LayoutSVGResourceContainer(node) 34 : LayoutSVGResourceContainer(node)
39 { 35 {
40 } 36 }
41 37
42 LayoutSVGResourceMasker::~LayoutSVGResourceMasker() 38 LayoutSVGResourceMasker::~LayoutSVGResourceMasker()
43 { 39 {
44 } 40 }
45 41
46 void LayoutSVGResourceMasker::removeAllClientsFromCache(bool markForInvalidation ) 42 void LayoutSVGResourceMasker::removeAllClientsFromCache(bool markForInvalidation )
47 { 43 {
48 m_maskContentPicture.clear(); 44 m_maskContentPicture.clear();
49 m_maskContentBoundaries = FloatRect(); 45 m_maskContentBoundaries = FloatRect();
50 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval idation : ParentOnlyInvalidation); 46 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval idation : ParentOnlyInvalidation);
51 } 47 }
52 48
53 void LayoutSVGResourceMasker::removeClientFromCache(LayoutObject* client, bool m arkForInvalidation) 49 void LayoutSVGResourceMasker::removeClientFromCache(LayoutObject* client, bool m arkForInvalidation)
54 { 50 {
55 ASSERT(client); 51 ASSERT(client);
56 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati on : ParentOnlyInvalidation); 52 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati on : ParentOnlyInvalidation);
57 } 53 }
58 54
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() 55 PassRefPtr<const SkPicture> LayoutSVGResourceMasker::createContentPicture()
135 { 56 {
136 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat es) to avoid the intersection 57 // 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 58 // with local clips/mask, which may yield incorrect results when mixing obje ctBoundingBox and
138 // userSpaceOnUse units (http://crbug.com/294900). 59 // userSpaceOnUse units (http://crbug.com/294900).
139 FloatRect bounds = strokeBoundingBox(); 60 FloatRect bounds = strokeBoundingBox();
140 61
141 OwnPtr<DisplayItemList> displayItemList; 62 OwnPtr<DisplayItemList> displayItemList;
142 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) 63 if (RuntimeEnabledFeatures::slimmingPaintEnabled())
143 displayItemList = DisplayItemList::create(); 64 displayItemList = DisplayItemList::create();
(...skipping 13 matching lines...) Expand all
157 continue; 78 continue;
158 79
159 SVGPaintContext::paintSubtree(&context, renderer); 80 SVGPaintContext::paintSubtree(&context, renderer);
160 } 81 }
161 82
162 if (displayItemList) 83 if (displayItemList)
163 displayItemList->replay(&context); 84 displayItemList->replay(&context);
164 return context.endRecording(); 85 return context.endRecording();
165 } 86 }
166 87
88 PassRefPtr<const SkPicture> LayoutSVGResourceMasker::getContentPicture(AffineTra nsform& contentTransformation, const FloatRect& targetBoundingBox)
89 {
90 SVGUnitTypes::SVGUnitType contentUnits = toSVGMaskElement(element())->maskCo ntentUnits()->currentValue()->enumValue();
91 if (contentUnits == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
92 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox .y());
93 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB oundingBox.height());
94 }
95
96 if (!m_maskContentPicture) {
97 SubtreeContentTransformScope contentTransformScope(contentTransformation );
98 m_maskContentPicture = createContentPicture();
99 }
100
101 return m_maskContentPicture;
102 }
103
167 void LayoutSVGResourceMasker::calculateMaskContentPaintInvalidationRect() 104 void LayoutSVGResourceMasker::calculateMaskContentPaintInvalidationRect()
168 { 105 {
169 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) { 106 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) {
170 LayoutObject* renderer = childElement->renderer(); 107 LayoutObject* renderer = childElement->renderer();
171 if (!renderer) 108 if (!renderer)
172 continue; 109 continue;
173 const LayoutStyle* style = renderer->style(); 110 const LayoutStyle* style = renderer->style();
174 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 111 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
175 continue; 112 continue;
176 m_maskContentBoundaries.unite(renderer->localToParentTransform().mapRect (renderer->paintInvalidationRectInLocalCoordinates())); 113 m_maskContentBoundaries.unite(renderer->localToParentTransform().mapRect (renderer->paintInvalidationRectInLocalCoordinates()));
(...skipping 21 matching lines...) Expand all
198 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 135 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
199 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 136 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
200 maskRect = transform.mapRect(maskRect); 137 maskRect = transform.mapRect(maskRect);
201 } 138 }
202 139
203 maskRect.intersect(maskBoundaries); 140 maskRect.intersect(maskBoundaries);
204 return maskRect; 141 return maskRect;
205 } 142 }
206 143
207 } 144 }
OLDNEW
« no previous file with comments | « Source/core/layout/svg/LayoutSVGResourceMasker.h ('k') | Source/core/paint/SVGMaskPainter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698