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

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

Issue 908243002: Move rendering/svg/RenderSVGResource* to layout/svg. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
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/rendering/svg/RenderSVGResourceMasker.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/SVGPaintContext.h" 25 #include "core/paint/SVGPaintContext.h"
26 #include "core/svg/SVGElement.h" 26 #include "core/svg/SVGElement.h"
27 #include "platform/graphics/GraphicsContextStateSaver.h" 27 #include "platform/graphics/GraphicsContextStateSaver.h"
28 #include "platform/transforms/AffineTransform.h" 28 #include "platform/transforms/AffineTransform.h"
29 #include "third_party/skia/include/core/SkPicture.h" 29 #include "third_party/skia/include/core/SkPicture.h"
30 30
31 namespace blink { 31 namespace blink {
32 32
33 RenderSVGResourceMasker::RenderSVGResourceMasker(SVGMaskElement* node) 33 LayoutSVGResourceMasker::LayoutSVGResourceMasker(SVGMaskElement* node)
34 : RenderSVGResourceContainer(node) 34 : LayoutSVGResourceContainer(node)
35 { 35 {
36 } 36 }
37 37
38 RenderSVGResourceMasker::~RenderSVGResourceMasker() 38 LayoutSVGResourceMasker::~LayoutSVGResourceMasker()
39 { 39 {
40 } 40 }
41 41
42 void RenderSVGResourceMasker::removeAllClientsFromCache(bool markForInvalidation ) 42 void LayoutSVGResourceMasker::removeAllClientsFromCache(bool markForInvalidation )
43 { 43 {
44 m_maskContentPicture.clear(); 44 m_maskContentPicture.clear();
45 m_maskContentBoundaries = FloatRect(); 45 m_maskContentBoundaries = FloatRect();
46 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval idation : ParentOnlyInvalidation); 46 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval idation : ParentOnlyInvalidation);
47 } 47 }
48 48
49 void RenderSVGResourceMasker::removeClientFromCache(LayoutObject* client, bool m arkForInvalidation) 49 void LayoutSVGResourceMasker::removeClientFromCache(LayoutObject* client, bool m arkForInvalidation)
50 { 50 {
51 ASSERT(client); 51 ASSERT(client);
52 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati on : ParentOnlyInvalidation); 52 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati on : ParentOnlyInvalidation);
53 } 53 }
54 54
55 bool RenderSVGResourceMasker::prepareEffect(LayoutObject* object, GraphicsContex t* context) 55 bool LayoutSVGResourceMasker::prepareEffect(LayoutObject* object, GraphicsContex t* context)
56 { 56 {
57 ASSERT(object); 57 ASSERT(object);
58 ASSERT(context); 58 ASSERT(context);
59 ASSERT(style()); 59 ASSERT(style());
60 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); 60 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout());
61 61
62 clearInvalidationMask(); 62 clearInvalidationMask();
63 63
64 FloatRect paintInvalidationRect = object->paintInvalidationRectInLocalCoordi nates(); 64 FloatRect paintInvalidationRect = object->paintInvalidationRectInLocalCoordi nates();
65 if (paintInvalidationRect.isEmpty() || !element()->hasChildren()) 65 if (paintInvalidationRect.isEmpty() || !element()->hasChildren())
66 return false; 66 return false;
67 67
68 // Content layer start. 68 // Content layer start.
69 context->beginTransparencyLayer(1, &paintInvalidationRect); 69 context->beginTransparencyLayer(1, &paintInvalidationRect);
70 70
71 return true; 71 return true;
72 } 72 }
73 73
74 void RenderSVGResourceMasker::finishEffect(LayoutObject* object, GraphicsContext * context) 74 void LayoutSVGResourceMasker::finishEffect(LayoutObject* object, GraphicsContext * context)
75 { 75 {
76 ASSERT(object); 76 ASSERT(object);
77 ASSERT(context); 77 ASSERT(context);
78 ASSERT(style()); 78 ASSERT(style());
79 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); 79 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout());
80 80
81 FloatRect paintInvalidationRect = object->paintInvalidationRectInLocalCoordi nates(); 81 FloatRect paintInvalidationRect = object->paintInvalidationRectInLocalCoordi nates();
82 82
83 const SVGLayoutStyle& svgStyle = style()->svgStyle(); 83 const SVGLayoutStyle& svgStyle = style()->svgStyle();
84 ColorFilter maskLayerFilter = svgStyle.maskType() == MT_LUMINANCE 84 ColorFilter maskLayerFilter = svgStyle.maskType() == MT_LUMINANCE
(...skipping 10 matching lines...) Expand all
95 95
96 drawMaskForRenderer(context, object->objectBoundingBox()); 96 drawMaskForRenderer(context, object->objectBoundingBox());
97 } 97 }
98 98
99 // Transfer mask layer -> content layer (DstIn) 99 // Transfer mask layer -> content layer (DstIn)
100 context->endLayer(); 100 context->endLayer();
101 // Transfer content layer -> backdrop (SrcOver) 101 // Transfer content layer -> backdrop (SrcOver)
102 context->endLayer(); 102 context->endLayer();
103 } 103 }
104 104
105 void RenderSVGResourceMasker::drawMaskForRenderer(GraphicsContext* context, cons t FloatRect& targetBoundingBox) 105 void LayoutSVGResourceMasker::drawMaskForRenderer(GraphicsContext* context, cons t FloatRect& targetBoundingBox)
106 { 106 {
107 ASSERT(context); 107 ASSERT(context);
108 108
109 AffineTransform contentTransformation; 109 AffineTransform contentTransformation;
110 SVGUnitTypes::SVGUnitType contentUnits = toSVGMaskElement(element())->maskCo ntentUnits()->currentValue()->enumValue(); 110 SVGUnitTypes::SVGUnitType contentUnits = toSVGMaskElement(element())->maskCo ntentUnits()->currentValue()->enumValue();
111 if (contentUnits == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { 111 if (contentUnits == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
112 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox .y()); 112 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox .y());
113 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB oundingBox.height()); 113 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB oundingBox.height());
114 context->concatCTM(contentTransformation); 114 context->concatCTM(contentTransformation);
115 } 115 }
116 116
117 if (!m_maskContentPicture) { 117 if (!m_maskContentPicture) {
118 SubtreeContentTransformScope contentTransformScope(contentTransformation ); 118 SubtreeContentTransformScope contentTransformScope(contentTransformation );
119 createPicture(context); 119 createPicture(context);
120 } 120 }
121 121
122 context->drawPicture(m_maskContentPicture.get()); 122 context->drawPicture(m_maskContentPicture.get());
123 } 123 }
124 124
125 void RenderSVGResourceMasker::createPicture(GraphicsContext* context) 125 void LayoutSVGResourceMasker::createPicture(GraphicsContext* context)
126 { 126 {
127 ASSERT(context); 127 ASSERT(context);
128 128
129 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat es) to avoid the intersection 129 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat es) to avoid the intersection
130 // with local clips/mask, which may yield incorrect results when mixing obje ctBoundingBox and 130 // with local clips/mask, which may yield incorrect results when mixing obje ctBoundingBox and
131 // userSpaceOnUse units (http://crbug.com/294900). 131 // userSpaceOnUse units (http://crbug.com/294900).
132 FloatRect bounds = strokeBoundingBox(); 132 FloatRect bounds = strokeBoundingBox();
133 context->beginRecording(bounds); 133 context->beginRecording(bounds);
134 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) { 134 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) {
135 LayoutObject* renderer = childElement->renderer(); 135 LayoutObject* renderer = childElement->renderer();
136 if (!renderer) 136 if (!renderer)
137 continue; 137 continue;
138 const LayoutStyle* style = renderer->style(); 138 const LayoutStyle* style = renderer->style();
139 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 139 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
140 continue; 140 continue;
141 141
142 SVGPaintContext::paintSubtree(context, renderer); 142 SVGPaintContext::paintSubtree(context, renderer);
143 } 143 }
144 m_maskContentPicture = context->endRecording(); 144 m_maskContentPicture = context->endRecording();
145 } 145 }
146 146
147 void RenderSVGResourceMasker::calculateMaskContentPaintInvalidationRect() 147 void LayoutSVGResourceMasker::calculateMaskContentPaintInvalidationRect()
148 { 148 {
149 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) { 149 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element() ); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement )) {
150 LayoutObject* renderer = childElement->renderer(); 150 LayoutObject* renderer = childElement->renderer();
151 if (!renderer) 151 if (!renderer)
152 continue; 152 continue;
153 const LayoutStyle* style = renderer->style(); 153 const LayoutStyle* style = renderer->style();
154 if (!style || style->display() == NONE || style->visibility() != VISIBLE ) 154 if (!style || style->display() == NONE || style->visibility() != VISIBLE )
155 continue; 155 continue;
156 m_maskContentBoundaries.unite(renderer->localToParentTransform().mapRect (renderer->paintInvalidationRectInLocalCoordinates())); 156 m_maskContentBoundaries.unite(renderer->localToParentTransform().mapRect (renderer->paintInvalidationRectInLocalCoordinates()));
157 } 157 }
158 } 158 }
159 159
160 FloatRect RenderSVGResourceMasker::resourceBoundingBox(const LayoutObject* objec t) 160 FloatRect LayoutSVGResourceMasker::resourceBoundingBox(const LayoutObject* objec t)
161 { 161 {
162 SVGMaskElement* maskElement = toSVGMaskElement(element()); 162 SVGMaskElement* maskElement = toSVGMaskElement(element());
163 ASSERT(maskElement); 163 ASSERT(maskElement);
164 164
165 FloatRect objectBoundingBox = object->objectBoundingBox(); 165 FloatRect objectBoundingBox = object->objectBoundingBox();
166 FloatRect maskBoundaries = SVGLengthContext::resolveRectangle<SVGMaskElement >(maskElement, maskElement->maskUnits()->currentValue()->enumValue(), objectBoun dingBox); 166 FloatRect maskBoundaries = SVGLengthContext::resolveRectangle<SVGMaskElement >(maskElement, maskElement->maskUnits()->currentValue()->enumValue(), objectBoun dingBox);
167 167
168 // Resource was not layouted yet. Give back clipping rect of the mask. 168 // Resource was not layouted yet. Give back clipping rect of the mask.
169 if (selfNeedsLayout()) 169 if (selfNeedsLayout())
170 return maskBoundaries; 170 return maskBoundaries;
171 171
172 if (m_maskContentBoundaries.isEmpty()) 172 if (m_maskContentBoundaries.isEmpty())
173 calculateMaskContentPaintInvalidationRect(); 173 calculateMaskContentPaintInvalidationRect();
174 174
175 FloatRect maskRect = m_maskContentBoundaries; 175 FloatRect maskRect = m_maskContentBoundaries;
176 if (maskElement->maskContentUnits()->currentValue()->value() == SVGUnitTypes ::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { 176 if (maskElement->maskContentUnits()->currentValue()->value() == SVGUnitTypes ::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) {
177 AffineTransform transform; 177 AffineTransform transform;
178 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); 178 transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
179 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight()); 179 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h eight());
180 maskRect = transform.mapRect(maskRect); 180 maskRect = transform.mapRect(maskRect);
181 } 181 }
182 182
183 maskRect.intersect(maskBoundaries); 183 maskRect.intersect(maskBoundaries);
184 return maskRect; 184 return maskRect;
185 } 185 }
186 186
187 } 187 }
OLDNEW
« no previous file with comments | « Source/core/layout/svg/LayoutSVGResourceMasker.h ('k') | Source/core/layout/svg/LayoutSVGResourcePaintServer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698