| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 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/SVGResourcesCycleSolver.h" | 21 #include "core/layout/svg/SVGResourcesCycleSolver.h" |
| 22 | 22 |
| 23 // Set to a value > 0, to debug the resource cache. | 23 // Set to a value > 0, to debug the resource cache. |
| 24 #define DEBUG_CYCLE_DETECTION 0 | 24 #define DEBUG_CYCLE_DETECTION 0 |
| 25 | 25 |
| 26 #include "core/layout/svg/LayoutSVGResourceClipper.h" |
| 27 #include "core/layout/svg/LayoutSVGResourceFilter.h" |
| 28 #include "core/layout/svg/LayoutSVGResourceMarker.h" |
| 29 #include "core/layout/svg/LayoutSVGResourceMasker.h" |
| 30 #include "core/layout/svg/LayoutSVGResourcePaintServer.h" |
| 26 #include "core/layout/svg/SVGResources.h" | 31 #include "core/layout/svg/SVGResources.h" |
| 27 #include "core/layout/svg/SVGResourcesCache.h" | 32 #include "core/layout/svg/SVGResourcesCache.h" |
| 28 #include "core/rendering/svg/RenderSVGResourceClipper.h" | |
| 29 #include "core/rendering/svg/RenderSVGResourceFilter.h" | |
| 30 #include "core/rendering/svg/RenderSVGResourceMarker.h" | |
| 31 #include "core/rendering/svg/RenderSVGResourceMasker.h" | |
| 32 #include "core/rendering/svg/RenderSVGResourcePaintServer.h" | |
| 33 | 33 |
| 34 namespace blink { | 34 namespace blink { |
| 35 | 35 |
| 36 SVGResourcesCycleSolver::SVGResourcesCycleSolver(LayoutObject* renderer, SVGReso
urces* resources) | 36 SVGResourcesCycleSolver::SVGResourcesCycleSolver(LayoutObject* renderer, SVGReso
urces* resources) |
| 37 : m_renderer(renderer) | 37 : m_renderer(renderer) |
| 38 , m_resources(resources) | 38 , m_resources(resources) |
| 39 { | 39 { |
| 40 ASSERT(m_renderer); | 40 ASSERT(m_renderer); |
| 41 ASSERT(m_resources); | 41 ASSERT(m_resources); |
| 42 } | 42 } |
| 43 | 43 |
| 44 SVGResourcesCycleSolver::~SVGResourcesCycleSolver() | 44 SVGResourcesCycleSolver::~SVGResourcesCycleSolver() |
| 45 { | 45 { |
| 46 } | 46 } |
| 47 | 47 |
| 48 struct ActiveFrame { | 48 struct ActiveFrame { |
| 49 typedef SVGResourcesCycleSolver::ResourceSet ResourceSet; | 49 typedef SVGResourcesCycleSolver::ResourceSet ResourceSet; |
| 50 | 50 |
| 51 ActiveFrame(ResourceSet& activeSet, RenderSVGResourceContainer* resource) | 51 ActiveFrame(ResourceSet& activeSet, LayoutSVGResourceContainer* resource) |
| 52 : m_activeSet(activeSet) | 52 : m_activeSet(activeSet) |
| 53 , m_resource(resource) | 53 , m_resource(resource) |
| 54 { | 54 { |
| 55 m_activeSet.add(m_resource); | 55 m_activeSet.add(m_resource); |
| 56 } | 56 } |
| 57 ~ActiveFrame() | 57 ~ActiveFrame() |
| 58 { | 58 { |
| 59 m_activeSet.remove(m_resource); | 59 m_activeSet.remove(m_resource); |
| 60 } | 60 } |
| 61 | 61 |
| 62 ResourceSet& m_activeSet; | 62 ResourceSet& m_activeSet; |
| 63 RenderSVGResourceContainer* m_resource; | 63 LayoutSVGResourceContainer* m_resource; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 bool SVGResourcesCycleSolver::resourceContainsCycles(RenderSVGResourceContainer*
resource) | 66 bool SVGResourcesCycleSolver::resourceContainsCycles(LayoutSVGResourceContainer*
resource) |
| 67 { | 67 { |
| 68 // If we've traversed this sub-graph before and no cycles were observed, the
n | 68 // If we've traversed this sub-graph before and no cycles were observed, the
n |
| 69 // reuse that result. | 69 // reuse that result. |
| 70 if (m_dagCache.contains(resource)) | 70 if (m_dagCache.contains(resource)) |
| 71 return false; | 71 return false; |
| 72 | 72 |
| 73 ActiveFrame frame(m_activeResources, resource); | 73 ActiveFrame frame(m_activeResources, resource); |
| 74 | 74 |
| 75 LayoutObject* node = resource; | 75 LayoutObject* node = resource; |
| 76 while (node) { | 76 while (node) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void SVGResourcesCycleSolver::resolveCycles() | 103 void SVGResourcesCycleSolver::resolveCycles() |
| 104 { | 104 { |
| 105 ASSERT(m_activeResources.isEmpty()); | 105 ASSERT(m_activeResources.isEmpty()); |
| 106 | 106 |
| 107 // If the starting LayoutObject is a resource container itself, then add it | 107 // If the starting LayoutObject is a resource container itself, then add it |
| 108 // to the active set (to break direct self-references.) | 108 // to the active set (to break direct self-references.) |
| 109 if (m_renderer->isSVGResourceContainer()) | 109 if (m_renderer->isSVGResourceContainer()) |
| 110 m_activeResources.add(toRenderSVGResourceContainer(m_renderer)); | 110 m_activeResources.add(toLayoutSVGResourceContainer(m_renderer)); |
| 111 | 111 |
| 112 ResourceSet localResources; | 112 ResourceSet localResources; |
| 113 m_resources->buildSetOfResources(localResources); | 113 m_resources->buildSetOfResources(localResources); |
| 114 | 114 |
| 115 // This performs a depth-first search for a back-edge in all the | 115 // This performs a depth-first search for a back-edge in all the |
| 116 // (potentially disjoint) graphs formed by the resources referenced by | 116 // (potentially disjoint) graphs formed by the resources referenced by |
| 117 // |m_renderer|. | 117 // |m_renderer|. |
| 118 ResourceSet::iterator end = localResources.end(); | 118 ResourceSet::iterator end = localResources.end(); |
| 119 for (ResourceSet::iterator it = localResources.begin(); it != end; ++it) { | 119 for (ResourceSet::iterator it = localResources.begin(); it != end; ++it) { |
| 120 if (m_activeResources.contains(*it) || resourceContainsCycles(*it)) | 120 if (m_activeResources.contains(*it) || resourceContainsCycles(*it)) |
| 121 breakCycle(*it); | 121 breakCycle(*it); |
| 122 } | 122 } |
| 123 | 123 |
| 124 m_activeResources.clear(); | 124 m_activeResources.clear(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void SVGResourcesCycleSolver::breakCycle(RenderSVGResourceContainer* resourceLea
dingToCycle) | 127 void SVGResourcesCycleSolver::breakCycle(LayoutSVGResourceContainer* resourceLea
dingToCycle) |
| 128 { | 128 { |
| 129 ASSERT(resourceLeadingToCycle); | 129 ASSERT(resourceLeadingToCycle); |
| 130 if (resourceLeadingToCycle == m_resources->linkedResource()) { | 130 if (resourceLeadingToCycle == m_resources->linkedResource()) { |
| 131 m_resources->resetLinkedResource(); | 131 m_resources->resetLinkedResource(); |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 | 134 |
| 135 switch (resourceLeadingToCycle->resourceType()) { | 135 switch (resourceLeadingToCycle->resourceType()) { |
| 136 case MaskerResourceType: | 136 case MaskerResourceType: |
| 137 ASSERT(resourceLeadingToCycle == m_resources->masker()); | 137 ASSERT(resourceLeadingToCycle == m_resources->masker()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 163 ASSERT(resourceLeadingToCycle == m_resources->clipper()); | 163 ASSERT(resourceLeadingToCycle == m_resources->clipper()); |
| 164 m_resources->resetClipper(); | 164 m_resources->resetClipper(); |
| 165 break; | 165 break; |
| 166 default: | 166 default: |
| 167 ASSERT_NOT_REACHED(); | 167 ASSERT_NOT_REACHED(); |
| 168 break; | 168 break; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 } | 172 } |
| OLD | NEW |