| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 4 * Copyright 2014 The Chromium Authors. All rights reserved. | 4 * Copyright 2014 The Chromium Authors. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 #include "core/rendering/svg/RenderSVGResourcePattern.h" | 23 #include "core/layout/svg/LayoutSVGResourcePattern.h" |
| 24 | 24 |
| 25 #include "core/dom/ElementTraversal.h" | 25 #include "core/dom/ElementTraversal.h" |
| 26 #include "core/layout/svg/SVGLayoutSupport.h" | 26 #include "core/layout/svg/SVGLayoutSupport.h" |
| 27 #include "core/paint/SVGPaintContext.h" | 27 #include "core/paint/SVGPaintContext.h" |
| 28 #include "core/paint/TransformRecorder.h" | 28 #include "core/paint/TransformRecorder.h" |
| 29 #include "core/svg/SVGFitToViewBox.h" | 29 #include "core/svg/SVGFitToViewBox.h" |
| 30 #include "core/svg/SVGPatternElement.h" | 30 #include "core/svg/SVGPatternElement.h" |
| 31 #include "platform/graphics/GraphicsContext.h" | 31 #include "platform/graphics/GraphicsContext.h" |
| 32 #include "platform/graphics/paint/DisplayItemList.h" | 32 #include "platform/graphics/paint/DisplayItemList.h" |
| 33 #include "third_party/skia/include/core/SkPicture.h" | 33 #include "third_party/skia/include/core/SkPicture.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 struct PatternData { | 37 struct PatternData { |
| 38 WTF_MAKE_FAST_ALLOCATED; | 38 WTF_MAKE_FAST_ALLOCATED; |
| 39 public: | 39 public: |
| 40 RefPtr<Pattern> pattern; | 40 RefPtr<Pattern> pattern; |
| 41 AffineTransform transform; | 41 AffineTransform transform; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 RenderSVGResourcePattern::RenderSVGResourcePattern(SVGPatternElement* node) | 44 LayoutSVGResourcePattern::LayoutSVGResourcePattern(SVGPatternElement* node) |
| 45 : RenderSVGResourcePaintServer(node) | 45 : LayoutSVGResourcePaintServer(node) |
| 46 , m_shouldCollectPatternAttributes(true) | 46 , m_shouldCollectPatternAttributes(true) |
| 47 #if ENABLE(OILPAN) | 47 #if ENABLE(OILPAN) |
| 48 , m_attributesWrapper(PatternAttributesWrapper::create()) | 48 , m_attributesWrapper(PatternAttributesWrapper::create()) |
| 49 #endif | 49 #endif |
| 50 { | 50 { |
| 51 } | 51 } |
| 52 | 52 |
| 53 void RenderSVGResourcePattern::removeAllClientsFromCache(bool markForInvalidatio
n) | 53 void LayoutSVGResourcePattern::removeAllClientsFromCache(bool markForInvalidatio
n) |
| 54 { | 54 { |
| 55 m_patternMap.clear(); | 55 m_patternMap.clear(); |
| 56 m_shouldCollectPatternAttributes = true; | 56 m_shouldCollectPatternAttributes = true; |
| 57 markAllClientsForInvalidation(markForInvalidation ? PaintInvalidation : Pare
ntOnlyInvalidation); | 57 markAllClientsForInvalidation(markForInvalidation ? PaintInvalidation : Pare
ntOnlyInvalidation); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void RenderSVGResourcePattern::removeClientFromCache(LayoutObject* client, bool
markForInvalidation) | 60 void LayoutSVGResourcePattern::removeClientFromCache(LayoutObject* client, bool
markForInvalidation) |
| 61 { | 61 { |
| 62 ASSERT(client); | 62 ASSERT(client); |
| 63 m_patternMap.remove(client); | 63 m_patternMap.remove(client); |
| 64 markClientForInvalidation(client, markForInvalidation ? PaintInvalidation :
ParentOnlyInvalidation); | 64 markClientForInvalidation(client, markForInvalidation ? PaintInvalidation :
ParentOnlyInvalidation); |
| 65 } | 65 } |
| 66 | 66 |
| 67 PatternData* RenderSVGResourcePattern::patternForRenderer(const LayoutObject& ob
ject) | 67 PatternData* LayoutSVGResourcePattern::patternForRenderer(const LayoutObject& ob
ject) |
| 68 { | 68 { |
| 69 ASSERT(!m_shouldCollectPatternAttributes); | 69 ASSERT(!m_shouldCollectPatternAttributes); |
| 70 | 70 |
| 71 // FIXME: the double hash lookup is needed to guard against paint-time inval
idation | 71 // FIXME: the double hash lookup is needed to guard against paint-time inval
idation |
| 72 // (painting animated images may trigger layout invals which delete our map
entry). | 72 // (painting animated images may trigger layout invals which delete our map
entry). |
| 73 // Hopefully that will be addressed at some point, and then we can optimize
the lookup. | 73 // Hopefully that will be addressed at some point, and then we can optimize
the lookup. |
| 74 if (PatternData* currentData = m_patternMap.get(&object)) | 74 if (PatternData* currentData = m_patternMap.get(&object)) |
| 75 return currentData; | 75 return currentData; |
| 76 | 76 |
| 77 return m_patternMap.set(&object, buildPatternData(object)).storedValue->valu
e.get(); | 77 return m_patternMap.set(&object, buildPatternData(object)).storedValue->valu
e.get(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 PassOwnPtr<PatternData> RenderSVGResourcePattern::buildPatternData(const LayoutO
bject& object) | 80 PassOwnPtr<PatternData> LayoutSVGResourcePattern::buildPatternData(const LayoutO
bject& object) |
| 81 { | 81 { |
| 82 // If we couldn't determine the pattern content element root, stop here. | 82 // If we couldn't determine the pattern content element root, stop here. |
| 83 const PatternAttributes& attributes = this->attributes(); | 83 const PatternAttributes& attributes = this->attributes(); |
| 84 if (!attributes.patternContentElement()) | 84 if (!attributes.patternContentElement()) |
| 85 return nullptr; | 85 return nullptr; |
| 86 | 86 |
| 87 // An empty viewBox disables rendering. | 87 // An empty viewBox disables rendering. |
| 88 if (attributes.hasViewBox() && attributes.viewBox().isEmpty()) | 88 if (attributes.hasViewBox() && attributes.viewBox().isEmpty()) |
| 89 return nullptr; | 89 return nullptr; |
| 90 | 90 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 114 | 114 |
| 115 // Compute pattern space transformation. | 115 // Compute pattern space transformation. |
| 116 patternData->transform.translate(tileBounds.x(), tileBounds.y()); | 116 patternData->transform.translate(tileBounds.x(), tileBounds.y()); |
| 117 AffineTransform patternTransform = attributes.patternTransform(); | 117 AffineTransform patternTransform = attributes.patternTransform(); |
| 118 if (!patternTransform.isIdentity()) | 118 if (!patternTransform.isIdentity()) |
| 119 patternData->transform = patternTransform * patternData->transform; | 119 patternData->transform = patternTransform * patternData->transform; |
| 120 | 120 |
| 121 return patternData.release(); | 121 return patternData.release(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 SVGPaintServer RenderSVGResourcePattern::preparePaintServer(const LayoutObject&
object) | 124 SVGPaintServer LayoutSVGResourcePattern::preparePaintServer(const LayoutObject&
object) |
| 125 { | 125 { |
| 126 clearInvalidationMask(); | 126 clearInvalidationMask(); |
| 127 | 127 |
| 128 SVGPatternElement* patternElement = toSVGPatternElement(element()); | 128 SVGPatternElement* patternElement = toSVGPatternElement(element()); |
| 129 if (!patternElement) | 129 if (!patternElement) |
| 130 return SVGPaintServer::invalid(); | 130 return SVGPaintServer::invalid(); |
| 131 | 131 |
| 132 if (m_shouldCollectPatternAttributes) { | 132 if (m_shouldCollectPatternAttributes) { |
| 133 patternElement->synchronizeAnimatedSVGAttribute(anyQName()); | 133 patternElement->synchronizeAnimatedSVGAttribute(anyQName()); |
| 134 | 134 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 149 | 149 |
| 150 PatternData* patternData = patternForRenderer(object); | 150 PatternData* patternData = patternForRenderer(object); |
| 151 if (!patternData || !patternData->pattern) | 151 if (!patternData || !patternData->pattern) |
| 152 return SVGPaintServer::invalid(); | 152 return SVGPaintServer::invalid(); |
| 153 | 153 |
| 154 patternData->pattern->setPatternSpaceTransform(patternData->transform); | 154 patternData->pattern->setPatternSpaceTransform(patternData->transform); |
| 155 | 155 |
| 156 return SVGPaintServer(patternData->pattern); | 156 return SVGPaintServer(patternData->pattern); |
| 157 } | 157 } |
| 158 | 158 |
| 159 PassRefPtr<const SkPicture> RenderSVGResourcePattern::asPicture(const FloatRect&
tileBounds, | 159 PassRefPtr<const SkPicture> LayoutSVGResourcePattern::asPicture(const FloatRect&
tileBounds, |
| 160 const AffineTransform& tileTransform) const | 160 const AffineTransform& tileTransform) const |
| 161 { | 161 { |
| 162 ASSERT(!m_shouldCollectPatternAttributes); | 162 ASSERT(!m_shouldCollectPatternAttributes); |
| 163 | 163 |
| 164 AffineTransform contentTransform; | 164 AffineTransform contentTransform; |
| 165 if (attributes().patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECT
BOUNDINGBOX) | 165 if (attributes().patternContentUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECT
BOUNDINGBOX) |
| 166 contentTransform = tileTransform; | 166 contentTransform = tileTransform; |
| 167 | 167 |
| 168 // Draw the content into a Picture. | 168 // Draw the content into a Picture. |
| 169 OwnPtr<DisplayItemList> displayItemList; | 169 OwnPtr<DisplayItemList> displayItemList; |
| 170 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 170 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 171 displayItemList = DisplayItemList::create(); | 171 displayItemList = DisplayItemList::create(); |
| 172 GraphicsContext recordingContext(nullptr, displayItemList.get()); | 172 GraphicsContext recordingContext(nullptr, displayItemList.get()); |
| 173 recordingContext.beginRecording(FloatRect(FloatPoint(), tileBounds.size())); | 173 recordingContext.beginRecording(FloatRect(FloatPoint(), tileBounds.size())); |
| 174 | 174 |
| 175 ASSERT(attributes().patternContentElement()); | 175 ASSERT(attributes().patternContentElement()); |
| 176 RenderSVGResourceContainer* patternRenderer = | 176 LayoutSVGResourceContainer* patternRenderer = |
| 177 toRenderSVGResourceContainer(attributes().patternContentElement()->rende
rer()); | 177 toLayoutSVGResourceContainer(attributes().patternContentElement()->rende
rer()); |
| 178 ASSERT(patternRenderer); | 178 ASSERT(patternRenderer); |
| 179 ASSERT(!patternRenderer->needsLayout()); | 179 ASSERT(!patternRenderer->needsLayout()); |
| 180 | 180 |
| 181 SubtreeContentTransformScope contentTransformScope(contentTransform); | 181 SubtreeContentTransformScope contentTransformScope(contentTransform); |
| 182 | 182 |
| 183 { | 183 { |
| 184 TransformRecorder transformRecorder(recordingContext, patternRenderer->d
isplayItemClient(), tileTransform); | 184 TransformRecorder transformRecorder(recordingContext, patternRenderer->d
isplayItemClient(), tileTransform); |
| 185 for (LayoutObject* child = patternRenderer->firstChild(); child; child =
child->nextSibling()) | 185 for (LayoutObject* child = patternRenderer->firstChild(); child; child =
child->nextSibling()) |
| 186 SVGPaintContext::paintSubtree(&recordingContext, child); | 186 SVGPaintContext::paintSubtree(&recordingContext, child); |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (displayItemList) | 189 if (displayItemList) |
| 190 displayItemList->replay(&recordingContext); | 190 displayItemList->replay(&recordingContext); |
| 191 return recordingContext.endRecording(); | 191 return recordingContext.endRecording(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 } | 194 } |
| OLD | NEW |