| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 5 * Copyright (C) 2011 Dirk Schulze <krit@webkit.org> | 5 * Copyright (C) 2011 Dirk Schulze <krit@webkit.org> |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "core/layout/svg/SVGResourcesCache.h" | 32 #include "core/layout/svg/SVGResourcesCache.h" |
| 33 #include "core/paint/CompositingRecorder.h" | 33 #include "core/paint/CompositingRecorder.h" |
| 34 #include "core/paint/TransformRecorder.h" | 34 #include "core/paint/TransformRecorder.h" |
| 35 #include "core/svg/SVGUseElement.h" | 35 #include "core/svg/SVGUseElement.h" |
| 36 #include "platform/RuntimeEnabledFeatures.h" | 36 #include "platform/RuntimeEnabledFeatures.h" |
| 37 #include "platform/graphics/paint/ClipPathDisplayItem.h" | 37 #include "platform/graphics/paint/ClipPathDisplayItem.h" |
| 38 #include "platform/graphics/paint/CompositingDisplayItem.h" | 38 #include "platform/graphics/paint/CompositingDisplayItem.h" |
| 39 #include "platform/graphics/paint/DisplayItemList.h" | 39 #include "platform/graphics/paint/DisplayItemList.h" |
| 40 #include "platform/graphics/paint/DrawingDisplayItem.h" | 40 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 41 #include "third_party/skia/include/core/SkPicture.h" | 41 #include "third_party/skia/include/core/SkPicture.h" |
| 42 #include "wtf/TemporaryChange.h" | |
| 43 | 42 |
| 44 namespace blink { | 43 namespace blink { |
| 45 | 44 |
| 46 LayoutSVGResourceClipper::LayoutSVGResourceClipper(SVGClipPathElement* node) | 45 LayoutSVGResourceClipper::LayoutSVGResourceClipper(SVGClipPathElement* node) |
| 47 : LayoutSVGResourceContainer(node) | 46 : LayoutSVGResourceContainer(node) |
| 48 , m_inClipExpansion(false) | 47 , m_inClipExpansion(false) |
| 49 { | 48 { |
| 50 } | 49 } |
| 51 | 50 |
| 52 LayoutSVGResourceClipper::~LayoutSVGResourceClipper() | 51 LayoutSVGResourceClipper::~LayoutSVGResourceClipper() |
| 53 { | 52 { |
| 54 } | 53 } |
| 55 | 54 |
| 56 void LayoutSVGResourceClipper::removeAllClientsFromCache(bool markForInvalidatio
n) | 55 void LayoutSVGResourceClipper::removeAllClientsFromCache(bool markForInvalidatio
n) |
| 57 { | 56 { |
| 58 m_clipContentPicture.clear(); | 57 m_clipContentPicture.clear(); |
| 59 m_clipBoundaries = FloatRect(); | 58 m_clipBoundaries = FloatRect(); |
| 60 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval
idation : ParentOnlyInvalidation); | 59 markAllClientsForInvalidation(markForInvalidation ? LayoutAndBoundariesInval
idation : ParentOnlyInvalidation); |
| 61 } | 60 } |
| 62 | 61 |
| 63 void LayoutSVGResourceClipper::removeClientFromCache(LayoutObject* client, bool
markForInvalidation) | 62 void LayoutSVGResourceClipper::removeClientFromCache(LayoutObject* client, bool
markForInvalidation) |
| 64 { | 63 { |
| 65 ASSERT(client); | 64 ASSERT(client); |
| 66 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati
on : ParentOnlyInvalidation); | 65 markClientForInvalidation(client, markForInvalidation ? BoundariesInvalidati
on : ParentOnlyInvalidation); |
| 67 } | 66 } |
| 68 | 67 |
| 69 bool LayoutSVGResourceClipper::applyStatefulResource(LayoutObject* object, Graph
icsContext*& context, ClipperState& clipperState) | |
| 70 { | |
| 71 ASSERT(object); | |
| 72 ASSERT(context); | |
| 73 | |
| 74 clearInvalidationMask(); | |
| 75 | |
| 76 return applyClippingToContext(object, object->objectBoundingBox(), object->p
aintInvalidationRectInLocalCoordinates(), context, clipperState); | |
| 77 } | |
| 78 | |
| 79 bool LayoutSVGResourceClipper::tryPathOnlyClipping(DisplayItemClient client, Gra
phicsContext* context, | 68 bool LayoutSVGResourceClipper::tryPathOnlyClipping(DisplayItemClient client, Gra
phicsContext* context, |
| 80 const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundi
ngBox) { | 69 const AffineTransform& animatedLocalTransform, const FloatRect& objectBoundi
ngBox) { |
| 81 // If the current clip-path gets clipped itself, we have to fallback to mask
ing. | 70 // If the current clip-path gets clipped itself, we have to fallback to mask
ing. |
| 82 if (!style()->svgStyle().clipperResource().isEmpty()) | 71 if (!style()->svgStyle().clipperResource().isEmpty()) |
| 83 return false; | 72 return false; |
| 84 WindRule clipRule = RULE_NONZERO; | 73 WindRule clipRule = RULE_NONZERO; |
| 85 Path clipPath = Path(); | 74 Path clipPath = Path(); |
| 86 | 75 |
| 87 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 76 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
| 88 LayoutObject* renderer = childElement->renderer(); | 77 LayoutObject* renderer = childElement->renderer(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | 128 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { |
| 140 context->displayItemList()->add(BeginClipPathDisplayItem::create(client,
clipPath, clipRule)); | 129 context->displayItemList()->add(BeginClipPathDisplayItem::create(client,
clipPath, clipRule)); |
| 141 } else { | 130 } else { |
| 142 BeginClipPathDisplayItem clipPathDisplayItem(client, clipPath, clipRule)
; | 131 BeginClipPathDisplayItem clipPathDisplayItem(client, clipPath, clipRule)
; |
| 143 clipPathDisplayItem.replay(context); | 132 clipPathDisplayItem.replay(context); |
| 144 } | 133 } |
| 145 | 134 |
| 146 return true; | 135 return true; |
| 147 } | 136 } |
| 148 | 137 |
| 149 bool LayoutSVGResourceClipper::applyClippingToContext(LayoutObject* target, cons
t FloatRect& targetBoundingBox, | 138 PassRefPtr<const SkPicture> LayoutSVGResourceClipper::createContentPicture(Affin
eTransform& contentTransformation, const FloatRect& targetBoundingBox) |
| 150 const FloatRect& paintInvalidationRect, GraphicsContext* context, ClipperSta
te& clipperState) | |
| 151 { | 139 { |
| 152 ASSERT(target); | 140 ASSERT(frame()); |
| 153 ASSERT(context); | |
| 154 ASSERT(clipperState == ClipperNotApplied); | |
| 155 ASSERT_WITH_SECURITY_IMPLICATION(!needsLayout()); | |
| 156 | 141 |
| 157 if (paintInvalidationRect.isEmpty() || m_inClipExpansion) | |
| 158 return false; | |
| 159 TemporaryChange<bool> inClipExpansionChange(m_inClipExpansion, true); | |
| 160 | |
| 161 AffineTransform animatedLocalTransform = toSVGClipPathElement(element())->ca
lculateAnimatedLocalTransform(); | |
| 162 // When drawing a clip for non-SVG elements, the CTM does not include the zo
om factor. | |
| 163 // In this case, we need to apply the zoom scale explicitly - but only for c
lips with | |
| 164 // userSpaceOnUse units (the zoom is accounted for objectBoundingBox-resolve
d lengths). | |
| 165 if (!target->isSVG() && clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_USERS
PACEONUSE) { | |
| 166 ASSERT(style()); | |
| 167 animatedLocalTransform.scale(style()->effectiveZoom()); | |
| 168 } | |
| 169 | |
| 170 // First, try to apply the clip as a clipPath. | |
| 171 if (tryPathOnlyClipping(target->displayItemClient(), context, animatedLocalT
ransform, targetBoundingBox)) { | |
| 172 clipperState = ClipperAppliedPath; | |
| 173 return true; | |
| 174 } | |
| 175 | |
| 176 // Fall back to masking. | |
| 177 clipperState = ClipperAppliedMask; | |
| 178 | |
| 179 // Begin compositing the clip mask. | |
| 180 CompositingRecorder::beginCompositing(context, target->displayItemClient(),
SkXfermode::kSrcOver_Mode, 1, &paintInvalidationRect); | |
| 181 { | |
| 182 TransformRecorder recorder(*context, target->displayItemClient(), animat
edLocalTransform); | |
| 183 | |
| 184 // clipPath can also be clipped by another clipPath. | |
| 185 SVGResources* resources = SVGResourcesCache::cachedResourcesForLayoutObj
ect(this); | |
| 186 LayoutSVGResourceClipper* clipPathClipper = resources ? resources->clipp
er() : 0; | |
| 187 ClipperState clipPathClipperState = ClipperNotApplied; | |
| 188 if (clipPathClipper && !clipPathClipper->applyClippingToContext(this, ta
rgetBoundingBox, paintInvalidationRect, context, clipPathClipperState)) { | |
| 189 // End the clip mask's compositor. | |
| 190 CompositingRecorder::endCompositing(context, target->displayItemClie
nt()); | |
| 191 return false; | |
| 192 } | |
| 193 | |
| 194 drawClipMaskContent(context, target->displayItemClient(), targetBounding
Box); | |
| 195 | |
| 196 if (clipPathClipper) | |
| 197 clipPathClipper->postApplyStatefulResource(this, context, clipPathCl
ipperState); | |
| 198 } | |
| 199 | |
| 200 // Masked content layer start. | |
| 201 CompositingRecorder::beginCompositing(context, target->displayItemClient(),
SkXfermode::kSrcIn_Mode, 1, &paintInvalidationRect); | |
| 202 | |
| 203 return true; | |
| 204 } | |
| 205 | |
| 206 void LayoutSVGResourceClipper::postApplyStatefulResource(LayoutObject* target, G
raphicsContext*& context, ClipperState& clipperState) | |
| 207 { | |
| 208 switch (clipperState) { | |
| 209 case ClipperAppliedPath: | |
| 210 // Path-only clipping, no layers to restore but we need to emit an end t
o the clip path display item. | |
| 211 { | |
| 212 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
| 213 context->displayItemList()->add(EndClipPathDisplayItem::create(t
arget->displayItemClient())); | |
| 214 } else { | |
| 215 EndClipPathDisplayItem endClipPathDisplayItem(target->displayIte
mClient()); | |
| 216 endClipPathDisplayItem.replay(context); | |
| 217 } | |
| 218 } | |
| 219 break; | |
| 220 case ClipperAppliedMask: | |
| 221 // Transfer content -> clip mask (SrcIn) | |
| 222 CompositingRecorder::endCompositing(context, target->displayItemClient()
); | |
| 223 | |
| 224 // Transfer clip mask -> bg (SrcOver) | |
| 225 CompositingRecorder::endCompositing(context, target->displayItemClient()
); | |
| 226 break; | |
| 227 default: | |
| 228 ASSERT_NOT_REACHED(); | |
| 229 } | |
| 230 } | |
| 231 | |
| 232 void LayoutSVGResourceClipper::drawClipMaskContent(GraphicsContext* context, Dis
playItemClient client, const FloatRect& targetBoundingBox) | |
| 233 { | |
| 234 ASSERT(context); | |
| 235 | |
| 236 AffineTransform contentTransformation; | |
| 237 if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { | 142 if (clipPathUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) { |
| 238 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox
.y()); | 143 contentTransformation.translate(targetBoundingBox.x(), targetBoundingBox
.y()); |
| 239 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB
oundingBox.height()); | 144 contentTransformation.scaleNonUniform(targetBoundingBox.width(), targetB
oundingBox.height()); |
| 240 } | 145 } |
| 241 | 146 |
| 242 if (!m_clipContentPicture) { | 147 if (m_clipContentPicture) |
| 243 SubtreeContentTransformScope contentTransformScope(contentTransformation
); | 148 return m_clipContentPicture; |
| 244 m_clipContentPicture = createPicture(); | |
| 245 } | |
| 246 | 149 |
| 247 TransformRecorder recorder(*context, client, contentTransformation); | 150 SubtreeContentTransformScope contentTransformScope(contentTransformation); |
| 248 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) { | |
| 249 ASSERT(context->displayItemList()); | |
| 250 context->displayItemList()->add(DrawingDisplayItem::create(client, Displ
ayItem::SVGClip, m_clipContentPicture)); | |
| 251 } else { | |
| 252 DrawingDisplayItem clipPicture(client, DisplayItem::SVGClip, m_clipConte
ntPicture); | |
| 253 clipPicture.replay(context); | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 PassRefPtr<const SkPicture> LayoutSVGResourceClipper::createPicture() | |
| 258 { | |
| 259 ASSERT(frame()); | |
| 260 | 151 |
| 261 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat
es) to avoid the intersection | 152 // Using strokeBoundingBox (instead of paintInvalidationRectInLocalCoordinat
es) to avoid the intersection |
| 262 // with local clips/mask, which may yield incorrect results when mixing obje
ctBoundingBox and | 153 // with local clips/mask, which may yield incorrect results when mixing obje
ctBoundingBox and |
| 263 // userSpaceOnUse units (http://crbug.com/294900). | 154 // userSpaceOnUse units (http://crbug.com/294900). |
| 264 FloatRect bounds = strokeBoundingBox(); | 155 FloatRect bounds = strokeBoundingBox(); |
| 265 | 156 |
| 266 OwnPtr<DisplayItemList> displayItemList; | 157 OwnPtr<DisplayItemList> displayItemList; |
| 267 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 158 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 268 displayItemList = DisplayItemList::create(); | 159 displayItemList = DisplayItemList::create(); |
| 269 GraphicsContext context(nullptr, displayItemList.get()); | 160 GraphicsContext context(nullptr, displayItemList.get()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // - fill-opacity/stroke-opacity/opacity set to 1 | 193 // - fill-opacity/stroke-opacity/opacity set to 1 |
| 303 // - masker/filter not applied when rendering the children | 194 // - masker/filter not applied when rendering the children |
| 304 // - fill is set to the initial fill paint server (solid, black) | 195 // - fill is set to the initial fill paint server (solid, black) |
| 305 // - stroke is set to the initial stroke paint server (none) | 196 // - stroke is set to the initial stroke paint server (none) |
| 306 PaintInfo info(&context, LayoutRect::infiniteIntRect(), PaintPhaseForegr
ound, PaintBehaviorRenderingClipPathAsMask); | 197 PaintInfo info(&context, LayoutRect::infiniteIntRect(), PaintPhaseForegr
ound, PaintBehaviorRenderingClipPathAsMask); |
| 307 renderer->paint(info, IntPoint()); | 198 renderer->paint(info, IntPoint()); |
| 308 } | 199 } |
| 309 | 200 |
| 310 if (displayItemList) | 201 if (displayItemList) |
| 311 displayItemList->replay(&context); | 202 displayItemList->replay(&context); |
| 312 return context.endRecording(); | 203 m_clipContentPicture = context.endRecording(); |
| 204 return m_clipContentPicture; |
| 313 } | 205 } |
| 314 | 206 |
| 315 void LayoutSVGResourceClipper::calculateClipContentPaintInvalidationRect() | 207 void LayoutSVGResourceClipper::calculateClipContentPaintInvalidationRect() |
| 316 { | 208 { |
| 317 // This is a rough heuristic to appraise the clip size and doesn't consider
clip on clip. | 209 // This is a rough heuristic to appraise the clip size and doesn't consider
clip on clip. |
| 318 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { | 210 for (SVGElement* childElement = Traversal<SVGElement>::firstChild(*element()
); childElement; childElement = Traversal<SVGElement>::nextSibling(*childElement
)) { |
| 319 LayoutObject* renderer = childElement->renderer(); | 211 LayoutObject* renderer = childElement->renderer(); |
| 320 if (!renderer) | 212 if (!renderer) |
| 321 continue; | 213 continue; |
| 322 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen
t(*childElement)) | 214 if (!renderer->isSVGShape() && !renderer->isSVGText() && !isSVGUseElemen
t(*childElement)) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 AffineTransform transform; | 269 AffineTransform transform; |
| 378 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); | 270 transform.translate(objectBoundingBox.x(), objectBoundingBox.y()); |
| 379 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h
eight()); | 271 transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.h
eight()); |
| 380 return transform.mapRect(m_clipBoundaries); | 272 return transform.mapRect(m_clipBoundaries); |
| 381 } | 273 } |
| 382 | 274 |
| 383 return m_clipBoundaries; | 275 return m_clipBoundaries; |
| 384 } | 276 } |
| 385 | 277 |
| 386 } | 278 } |
| OLD | NEW |