Add SVGRenderingContext and move there the context related code from SVGRenderSupport
authorzherczeg@webkit.org <zherczeg@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Mar 2012 12:02:50 +0000 (12:02 +0000)
committerzherczeg@webkit.org <zherczeg@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Mar 2012 12:02:50 +0000 (12:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80413

Reviewed by Nikolas Zimmermann.

This is the first step of refactoring the rendering context for SVG. The
previous context was stateless before, which means the cleanup phase
needed to do a lot of checks to revert the initialization part and
was unaware of failed inititalization. Future code can also add
new local variables to the context.

This patch add a new SVGRenderingContext class, and moves there the context
initialization / cleanup code from SVGRenderSupport. All build systems were
updated.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* rendering/svg/RenderSVGAllInOne.cpp:
* rendering/svg/RenderSVGContainer.cpp:
(WebCore::RenderSVGContainer::paint):
* rendering/svg/RenderSVGForeignObject.cpp:
(WebCore::RenderSVGForeignObject::paint):
* rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::paint):
* rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::paintReplaced):
* rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::paint):
* rendering/svg/SVGInlineFlowBox.cpp:
(WebCore::SVGInlineFlowBox::paint):
* rendering/svg/SVGRenderSupport.cpp:
* rendering/svg/SVGRenderSupport.h:
* rendering/svg/SVGRenderingContext.cpp: Added.
(WebCore):
(WebCore::isRenderingMaskImage):
(WebCore::SVGRenderingContext::~SVGRenderingContext):
(WebCore::SVGRenderingContext::prepareToRenderSVGContent):
* rendering/svg/SVGRenderingContext.h: Added.
(WebCore):
(SVGRenderingContext):
(WebCore::SVGRenderingContext::SVGRenderingContext):
(WebCore::SVGRenderingContext::isRenderingPrepared):
* rendering/svg/SVGRootInlineBox.cpp:
(WebCore::SVGRootInlineBox::paint):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@110285 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/rendering/svg/RenderSVGAllInOne.cpp
Source/WebCore/rendering/svg/RenderSVGContainer.cpp
Source/WebCore/rendering/svg/RenderSVGForeignObject.cpp
Source/WebCore/rendering/svg/RenderSVGImage.cpp
Source/WebCore/rendering/svg/RenderSVGRoot.cpp
Source/WebCore/rendering/svg/RenderSVGShape.cpp
Source/WebCore/rendering/svg/SVGInlineFlowBox.cpp
Source/WebCore/rendering/svg/SVGRenderSupport.cpp
Source/WebCore/rendering/svg/SVGRenderSupport.h
Source/WebCore/rendering/svg/SVGRenderingContext.cpp [new file with mode: 0644]
Source/WebCore/rendering/svg/SVGRenderingContext.h [new file with mode: 0644]
Source/WebCore/rendering/svg/SVGRootInlineBox.cpp

index 51750de..b3ef488 100644 (file)
@@ -1733,6 +1733,7 @@ IF (ENABLE_SVG)
         rendering/svg/SVGPathData.cpp
         rendering/svg/SVGRenderSupport.cpp
         rendering/svg/SVGRenderTreeAsText.cpp
+        rendering/svg/SVGRenderingContext.cpp
         rendering/svg/SVGResources.cpp
         rendering/svg/SVGResourcesCache.cpp
         rendering/svg/SVGResourcesCycleSolver.cpp
index d1dd92b..d064e00 100644 (file)
@@ -1,3 +1,54 @@
+2012-03-09  Zoltan Herczeg  <zherczeg@webkit.org>
+
+        Add SVGRenderingContext and move there the context related code from SVGRenderSupport
+        https://bugs.webkit.org/show_bug.cgi?id=80413
+
+        Reviewed by Nikolas Zimmermann.
+
+        This is the first step of refactoring the rendering context for SVG. The
+        previous context was stateless before, which means the cleanup phase
+        needed to do a lot of checks to revert the initialization part and
+        was unaware of failed inititalization. Future code can also add
+        new local variables to the context.
+
+        This patch add a new SVGRenderingContext class, and moves there the context
+        initialization / cleanup code from SVGRenderSupport. All build systems were
+        updated.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/svg/RenderSVGAllInOne.cpp:
+        * rendering/svg/RenderSVGContainer.cpp:
+        (WebCore::RenderSVGContainer::paint):
+        * rendering/svg/RenderSVGForeignObject.cpp:
+        (WebCore::RenderSVGForeignObject::paint):
+        * rendering/svg/RenderSVGImage.cpp:
+        (WebCore::RenderSVGImage::paint):
+        * rendering/svg/RenderSVGRoot.cpp:
+        (WebCore::RenderSVGRoot::paintReplaced):
+        * rendering/svg/RenderSVGShape.cpp:
+        (WebCore::RenderSVGShape::paint):
+        * rendering/svg/SVGInlineFlowBox.cpp:
+        (WebCore::SVGInlineFlowBox::paint):
+        * rendering/svg/SVGRenderSupport.cpp:
+        * rendering/svg/SVGRenderSupport.h:
+        * rendering/svg/SVGRenderingContext.cpp: Added.
+        (WebCore):
+        (WebCore::isRenderingMaskImage):
+        (WebCore::SVGRenderingContext::~SVGRenderingContext):
+        (WebCore::SVGRenderingContext::prepareToRenderSVGContent):
+        * rendering/svg/SVGRenderingContext.h: Added.
+        (WebCore):
+        (SVGRenderingContext):
+        (WebCore::SVGRenderingContext::SVGRenderingContext):
+        (WebCore::SVGRenderingContext::isRenderingPrepared):
+        * rendering/svg/SVGRootInlineBox.cpp:
+        (WebCore::SVGRootInlineBox::paint):
+
 2012-03-09  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r110191, r110202, and r110279.
index 34782bf..4569419 100644 (file)
@@ -3943,6 +3943,8 @@ webcore_sources += \
        Source/WebCore/rendering/svg/SVGRenderSupport.h \
        Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp \
        Source/WebCore/rendering/svg/SVGRenderTreeAsText.h \
+       Source/WebCore/rendering/svg/SVGRenderingContext.cpp \
+       Source/WebCore/rendering/svg/SVGRenderingContext.h \
        Source/WebCore/rendering/svg/SVGResourcesCache.cpp \
        Source/WebCore/rendering/svg/SVGResourcesCache.h \
        Source/WebCore/rendering/svg/SVGResources.cpp \
index 7fa434b..8202504 100644 (file)
@@ -2522,6 +2522,7 @@ HEADERS += \
     rendering/svg/SVGPathData.h \
     rendering/svg/SVGRenderSupport.h \
     rendering/svg/SVGRenderTreeAsText.h \
+    rendering/svg/SVGRenderingContext.h \
     rendering/svg/SVGResources.h \
     rendering/svg/SVGResourcesCache.h \
     rendering/svg/SVGResourcesCycleSolver.h \
@@ -3465,6 +3466,7 @@ contains(DEFINES, ENABLE_SVG=1) {
               rendering/svg/SVGPathData.cpp \
               rendering/svg/SVGRenderSupport.cpp \
               rendering/svg/SVGRenderTreeAsText.cpp \
+              rendering/svg/SVGRenderingContext.cpp \
               rendering/svg/SVGResources.cpp \
               rendering/svg/SVGResourcesCache.cpp \
               rendering/svg/SVGResourcesCycleSolver.cpp \
index ee12128..9795baf 100644 (file)
             'rendering/svg/SVGRenderSupport.h',
             'rendering/svg/SVGRenderTreeAsText.cpp',
             'rendering/svg/SVGRenderTreeAsText.h',
+            'rendering/svg/SVGRenderingContext.cpp',
+            'rendering/svg/SVGRenderingContext.h',
             'rendering/svg/SVGResources.cpp',
             'rendering/svg/SVGResources.h',
             'rendering/svg/SVGResourcesCache.cpp',
             'rendering/svg/SVGRenderSupport.h',
             'rendering/svg/SVGRenderTreeAsText.cpp',
             'rendering/svg/SVGRenderTreeAsText.h',
+            'rendering/svg/SVGRenderingContext.cpp',
+            'rendering/svg/SVGRenderingContext.h',
             'rendering/svg/SVGResources.cpp',
             'rendering/svg/SVGResources.h',
             'rendering/svg/SVGResourcesCache.cpp',
index 6ac97a5..301c066 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\rendering\svg\SVGRenderingContext.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_All|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Production|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath="..\rendering\svg\SVGRenderingContext.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\rendering\svg\SVGResources.cpp"
                                >
                                <FileConfiguration
index a5df4be..124534d 100644 (file)
                18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */; };
                1921327411C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1921327111C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp */; };
                1921327511C0E6BB00456238 /* SVGFEConvolveMatrixElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1921327211C0E6BB00456238 /* SVGFEConvolveMatrixElement.h */; };
+               197B180C1506353200E4ADA8 /* SVGRenderingContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 197B180B150634C000E4ADA8 /* SVGRenderingContext.h */; };
                19BFF64B11C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 19BFF64611C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElement.h */; };
                19BFF64C11C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElement.mm in Sources */ = {isa = PBXBuildFile; fileRef = 19BFF64711C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElement.mm */; };
                19BFF64D11C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElementInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 19BFF64811C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElementInternal.h */; };
                1921327111C0E6BB00456238 /* SVGFEConvolveMatrixElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFEConvolveMatrixElement.cpp; sourceTree = "<group>"; };
                1921327211C0E6BB00456238 /* SVGFEConvolveMatrixElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGFEConvolveMatrixElement.h; sourceTree = "<group>"; };
                1921327311C0E6BB00456238 /* SVGFEConvolveMatrixElement.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SVGFEConvolveMatrixElement.idl; sourceTree = "<group>"; };
+               197B180A150634C000E4ADA8 /* SVGRenderingContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SVGRenderingContext.cpp; sourceTree = "<group>"; };
+               197B180B150634C000E4ADA8 /* SVGRenderingContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SVGRenderingContext.h; sourceTree = "<group>"; };
                19BFF64611C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMSVGFEConvolveMatrixElement.h; sourceTree = "<group>"; };
                19BFF64711C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElement.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMSVGFEConvolveMatrixElement.mm; sourceTree = "<group>"; };
                19BFF64811C0F2AC00B8C04D /* DOMSVGFEConvolveMatrixElementInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMSVGFEConvolveMatrixElementInternal.h; sourceTree = "<group>"; };
                                436708B312D9CA4B00044234 /* SVGRenderSupport.h */,
                                436708B412D9CA4B00044234 /* SVGRenderTreeAsText.cpp */,
                                436708B512D9CA4B00044234 /* SVGRenderTreeAsText.h */,
+                               197B180A150634C000E4ADA8 /* SVGRenderingContext.cpp */,
+                               197B180B150634C000E4ADA8 /* SVGRenderingContext.h */,
                                436708B612D9CA4B00044234 /* SVGResources.cpp */,
                                436708B712D9CA4B00044234 /* SVGResources.h */,
                                436708B812D9CA4B00044234 /* SVGResourcesCache.cpp */,
                                BC22747B0E8366E200E7F975 /* SVGRenderStyleDefs.h in Headers */,
                                436708F212D9CA4B00044234 /* SVGRenderSupport.h in Headers */,
                                436708F412D9CA4B00044234 /* SVGRenderTreeAsText.h in Headers */,
+                               197B180C1506353200E4ADA8 /* SVGRenderingContext.h in Headers */,
                                436708F612D9CA4B00044234 /* SVGResources.h in Headers */,
                                436708F812D9CA4B00044234 /* SVGResourcesCache.h in Headers */,
                                436708FA12D9CA4B00044234 /* SVGResourcesCycleSolver.h in Headers */,
index be6c83f..8f8c86e 100644 (file)
@@ -62,6 +62,7 @@
 #include "SVGPathData.cpp"
 #include "SVGRenderSupport.cpp"
 #include "SVGRenderTreeAsText.cpp"
+#include "SVGRenderingContext.cpp"
 #include "SVGResources.cpp"
 #include "SVGResourcesCache.cpp"
 #include "SVGResourcesCycleSolver.cpp"
index f4acca0..e16bfa3 100644 (file)
@@ -31,7 +31,7 @@
 #include "RenderSVGResource.h"
 #include "RenderSVGResourceFilter.h"
 #include "RenderView.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 #include "SVGResources.h"
 #include "SVGResourcesCache.h"
 #include "SVGStyledElement.h"
@@ -114,18 +114,18 @@ void RenderSVGContainer::paint(PaintInfo& paintInfo, const LayoutPoint&)
 
         childPaintInfo.applyTransform(localToParentTransform());
 
+        SVGRenderingContext renderingContext;
         bool continueRendering = true;
-        if (childPaintInfo.phase == PaintPhaseForeground)
-            continueRendering = SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo);
+        if (childPaintInfo.phase == PaintPhaseForeground) {
+            renderingContext.prepareToRenderSVGContent(this, childPaintInfo);
+            continueRendering = renderingContext.isRenderingPrepared();
+        }
 
         if (continueRendering) {
             childPaintInfo.updatePaintingRootForChildren(this);
             for (RenderObject* child = firstChild(); child; child = child->nextSibling())
                 child->paint(childPaintInfo, IntPoint());
         }
-
-        if (paintInfo.phase == PaintPhaseForeground)
-            SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, paintInfo.context);
     }
     
     // FIXME: This really should be drawn from local coordinates, but currently we hack it
index dadcaed..676e8f4 100644 (file)
@@ -29,7 +29,7 @@
 #include "RenderSVGResource.h"
 #include "RenderView.h"
 #include "SVGForeignObjectElement.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 #include "SVGResourcesCache.h"
 #include "SVGSVGElement.h"
 #include "TransformState.h"
@@ -59,9 +59,12 @@ void RenderSVGForeignObject::paint(PaintInfo& paintInfo, const LayoutPoint&)
     if (SVGRenderSupport::isOverflowHidden(this))
         childPaintInfo.context->clip(m_viewport);
 
+    SVGRenderingContext renderingContext;
     bool continueRendering = true;
-    if (paintInfo.phase == PaintPhaseForeground)
-        continueRendering = SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo);
+    if (paintInfo.phase == PaintPhaseForeground) {
+        renderingContext.prepareToRenderSVGContent(this, childPaintInfo);
+        continueRendering = renderingContext.isRenderingPrepared();
+    }
 
     if (continueRendering) {
         // Paint all phases of FO elements atomically, as though the FO element established its
@@ -81,9 +84,6 @@ void RenderSVGForeignObject::paint(PaintInfo& paintInfo, const LayoutPoint&)
             RenderBlock::paint(childPaintInfo, childPoint);
         }
     }
-
-    if (paintInfo.phase == PaintPhaseForeground)
-        SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, paintInfo.context);
 }
 
 LayoutRect RenderSVGForeignObject::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer) const
index e095629..56be5cd 100644 (file)
@@ -41,7 +41,7 @@
 #include "SVGImageElement.h"
 #include "SVGLength.h"
 #include "SVGPreserveAspectRatio.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 #include "SVGResources.h"
 #include "SVGResourcesCache.h"
 
@@ -124,9 +124,9 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&)
         childPaintInfo.applyTransform(m_localTransform);
 
         if (childPaintInfo.phase == PaintPhaseForeground) {
-            PaintInfo savedInfo(childPaintInfo);
+            SVGRenderingContext renderingContext(this, childPaintInfo);
 
-            if (SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo)) {
+            if (renderingContext.isRenderingPrepared()) {
                 RefPtr<Image> image = m_imageResource->image();
                 FloatRect destRect = m_objectBoundingBox;
                 FloatRect srcRect(0, 0, image->width(), image->height());
@@ -136,8 +136,6 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&)
 
                 childPaintInfo.context->drawImage(image.get(), ColorSpaceDeviceRGB, destRect, srcRect);
             }
-
-            SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, savedInfo.context);
         }
 
         if (drawsOutline)
index ac9cc5d..b99701d 100644 (file)
@@ -38,7 +38,7 @@
 #include "RenderSVGResource.h"
 #include "RenderView.h"
 #include "SVGLength.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 #include "SVGResources.h"
 #include "SVGResourcesCache.h"
 #include "SVGSVGElement.h"
@@ -277,16 +277,16 @@ void RenderSVGRoot::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& adjus
     // Transform from our paint container's coordinate system to our local coords.
     childPaintInfo.applyTransform(AffineTransform::translation(adjustedPaintOffset.x() - x(), adjustedPaintOffset.y() - y()) * localToParentTransform());
 
+    SVGRenderingContext renderingContext;
     bool continueRendering = true;
-    if (childPaintInfo.phase == PaintPhaseForeground)
-        continueRendering = SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo);
+    if (childPaintInfo.phase == PaintPhaseForeground) {
+        renderingContext.prepareToRenderSVGContent(this, childPaintInfo);
+        continueRendering = renderingContext.isRenderingPrepared();
+    }
 
     if (continueRendering)
         RenderBox::paint(childPaintInfo, LayoutPoint());
 
-    if (childPaintInfo.phase == PaintPhaseForeground)
-        SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, paintInfo.context);
-
     childPaintInfo.context->restore();
 }
 
index 3fb795f..c438d30 100755 (executable)
@@ -41,7 +41,7 @@
 #include "RenderSVGResourceSolidColor.h"
 #include "SVGPathData.h"
 #include "SVGPathElement.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 #include "SVGResources.h"
 #include "SVGResourcesCache.h"
 #include "SVGStyledTransformableElement.h"
@@ -333,9 +333,9 @@ void RenderSVGShape::paint(PaintInfo& paintInfo, const IntPoint&)
         childPaintInfo.applyTransform(m_localTransform);
 
         if (childPaintInfo.phase == PaintPhaseForeground) {
-            PaintInfo savedInfo(childPaintInfo);
+            SVGRenderingContext renderingContext(this, childPaintInfo);
 
-            if (SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo)) {
+            if (renderingContext.isRenderingPrepared()) {
                 const SVGRenderStyle* svgStyle = style()->svgStyle();
                 if (svgStyle->shapeRendering() == SR_CRISPEDGES)
                     childPaintInfo.context->setShouldAntialias(false);
@@ -345,8 +345,6 @@ void RenderSVGShape::paint(PaintInfo& paintInfo, const IntPoint&)
                 if (svgStyle->hasMarkers())
                     m_markerLayoutInfo.drawMarkers(childPaintInfo);
             }
-
-            SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, savedInfo.context);
         }
 
         if (drawsOutline)
index cdeec61..21a9092 100644 (file)
@@ -29,7 +29,7 @@
 #include "RenderSVGInlineText.h"
 #include "RenderedDocumentMarker.h"
 #include "SVGInlineTextBox.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 
 using namespace std;
 
@@ -57,19 +57,15 @@ void SVGInlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUni
     RenderObject* boxRenderer = renderer();
     ASSERT(boxRenderer);
 
-    PaintInfo childPaintInfo(paintInfo);
-    GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
-
-    if (SVGRenderSupport::prepareToRenderSVGContent(boxRenderer, childPaintInfo)) {
+    SVGRenderingContext renderingContext(boxRenderer, paintInfo, SVGRenderingContext::SaveGraphicsContext);
+    if (renderingContext.isRenderingPrepared()) {
         for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
             if (child->isSVGInlineTextBox())
                 computeTextMatchMarkerRectForRenderer(toRenderSVGInlineText(static_cast<SVGInlineTextBox*>(child)->textRenderer()));
 
-            child->paint(childPaintInfo, LayoutPoint(), 0, 0);
+            child->paint(paintInfo, LayoutPoint(), 0, 0);
         }
     }
-
-    SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
 }
 
 FloatRect SVGInlineFlowBox::calculateBoundaries() const
index cbd3ee6..e262422 100644 (file)
 #if ENABLE(SVG)
 #include "SVGRenderSupport.h"
 
-#include "Frame.h"
-#include "FrameView.h"
-#include "ImageBuffer.h"
 #include "NodeRenderStyle.h"
 #include "RenderLayer.h"
-#include "RenderSVGPath.h"
 #include "RenderSVGResource.h"
 #include "RenderSVGResourceClipper.h"
 #include "RenderSVGResourceFilter.h"
@@ -80,106 +76,6 @@ void SVGRenderSupport::mapLocalToContainer(const RenderObject* object, RenderBox
     object->parent()->mapLocalToContainer(repaintContainer, false, true, transformState, wasFixed);
 }
 
-static inline bool isRenderingMaskImage(RenderObject* object)
-{
-    if (object->frame() && object->frame()->view())
-        return object->frame()->view()->paintBehavior() & PaintBehaviorRenderingSVGMask;
-    return false;
-}
-
-bool SVGRenderSupport::prepareToRenderSVGContent(RenderObject* object, PaintInfo& paintInfo)
-{
-    ASSERT(object);
-
-    RenderStyle* style = object->style();
-    ASSERT(style);
-
-    const SVGRenderStyle* svgStyle = style->svgStyle();
-    ASSERT(svgStyle);
-
-    // Setup transparency layers before setting up SVG resources!
-    bool isRenderingMask = isRenderingMaskImage(object);
-    float opacity = isRenderingMask ? 1 : style->opacity();
-    const ShadowData* shadow = svgStyle->shadow();
-    if (opacity < 1 || shadow) {
-        FloatRect repaintRect = object->repaintRectInLocalCoordinates();
-
-        if (opacity < 1) {
-            paintInfo.context->clip(repaintRect);
-            paintInfo.context->beginTransparencyLayer(opacity);
-        }
-
-        if (shadow) {
-            paintInfo.context->clip(repaintRect);
-            paintInfo.context->setShadow(IntSize(roundToInt(shadow->x()), roundToInt(shadow->y())), shadow->blur(), shadow->color(), style->colorSpace());
-            paintInfo.context->beginTransparencyLayer(1);
-        }
-    }
-
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(object);
-    if (!resources) {
-#if ENABLE(FILTERS)
-        if (svgStyle->hasFilter())
-            return false;
-#endif
-        return true;
-    }
-
-    if (!isRenderingMask) {
-        if (RenderSVGResourceMasker* masker = resources->masker()) {
-            if (!masker->applyResource(object, style, paintInfo.context, ApplyToDefaultMode))
-                return false;
-        }
-    }
-
-    if (RenderSVGResourceClipper* clipper = resources->clipper()) {
-        if (!clipper->applyResource(object, style, paintInfo.context, ApplyToDefaultMode))
-            return false;
-    }
-
-#if ENABLE(FILTERS)
-    if (!isRenderingMask) {
-        if (RenderSVGResourceFilter* filter = resources->filter()) {
-            if (!filter->applyResource(object, style, paintInfo.context, ApplyToDefaultMode))
-                return false;
-        }
-    }
-#endif
-
-    return true;
-}
-
-void SVGRenderSupport::finishRenderSVGContent(RenderObject* object, PaintInfo& paintInfo, GraphicsContext* savedContext)
-{
-#if !ENABLE(FILTERS)
-    UNUSED_PARAM(savedContext);
-#endif
-
-    ASSERT(object);
-
-    const RenderStyle* style = object->style();
-    ASSERT(style);
-
-    const SVGRenderStyle* svgStyle = style->svgStyle();
-    ASSERT(svgStyle);
-
-#if ENABLE(FILTERS)
-    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(object);
-    if (resources) {
-        if (RenderSVGResourceFilter* filter = resources->filter()) {
-            filter->postApplyResource(static_cast<RenderSVGShape*>(object), paintInfo.context, ApplyToDefaultMode, 0, 0);
-            paintInfo.context = savedContext;
-        }
-    }
-#endif
-
-    if (style->opacity() < 1 && !isRenderingMaskImage(object))
-        paintInfo.context->endTransparencyLayer();
-
-    if (svgStyle->shadow())
-        paintInfo.context->endTransparencyLayer();
-}
-
 void SVGRenderSupport::computeContainerBoundingBoxes(const RenderObject* container, FloatRect& objectBoundingBox, FloatRect& strokeBoundingBox, FloatRect& repaintBoundingBox)
 {
     bool isFirstChild = true;
index c7b2fdc..51c9d1b 100644 (file)
@@ -42,10 +42,6 @@ class TransformState;
 // SVGRendererSupport is a helper class sharing code between all SVG renderers.
 class SVGRenderSupport {
 public:
-    // Used by all SVG renderers who apply clip/filter/etc. resources to the renderer content
-    static bool prepareToRenderSVGContent(RenderObject*, PaintInfo&);
-    static void finishRenderSVGContent(RenderObject*, PaintInfo&, GraphicsContext* savedContext);
-
     // Shares child layouting code between RenderSVGRoot/RenderSVG(Hidden)Container
     static void layoutChildren(RenderObject*, bool selfNeedsLayout);
 
diff --git a/Source/WebCore/rendering/svg/SVGRenderingContext.cpp b/Source/WebCore/rendering/svg/SVGRenderingContext.cpp
new file mode 100644 (file)
index 0000000..0f13dcf
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2007, 2008 Rob Buis <buis@kde.org>
+ * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ * Copyright (C) 2009 Google, Inc.  All rights reserved.
+ * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
+ * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "SVGRenderingContext.h"
+
+#include "Frame.h"
+#include "FrameView.h"
+#include "RenderSVGResource.h"
+#include "RenderSVGResourceClipper.h"
+#include "RenderSVGResourceFilter.h"
+#include "RenderSVGResourceMasker.h"
+#include "SVGImageBufferTools.h"
+#include "SVGResources.h"
+#include "SVGResourcesCache.h"
+
+namespace WebCore {
+
+static inline bool isRenderingMaskImage(RenderObject* object)
+{
+    if (object->frame() && object->frame()->view())
+        return object->frame()->view()->paintBehavior() & PaintBehaviorRenderingSVGMask;
+    return false;
+}
+
+SVGRenderingContext::~SVGRenderingContext()
+{
+    // Fast path if we don't need to restore anything.
+    if (!(m_renderingFlags & ActionsNeeded))
+        return;
+
+    ASSERT(m_object && m_paintInfo);
+
+#if ENABLE(FILTERS)
+    if (m_renderingFlags & EndFilterLayer) {
+        ASSERT(m_filter);
+        m_filter->postApplyResource(static_cast<RenderSVGShape*>(m_object), m_paintInfo->context, ApplyToDefaultMode, 0, 0);
+        m_paintInfo->context = m_savedContext;
+    }
+#endif
+
+    if (m_renderingFlags & EndOpacityLayer)
+        m_paintInfo->context->endTransparencyLayer();
+
+    if (m_renderingFlags & EndShadowLayer)
+        m_paintInfo->context->endTransparencyLayer();
+
+    if (m_renderingFlags & RestoreGraphicsContext)
+        m_paintInfo->context->restore();
+}
+
+void SVGRenderingContext::prepareToRenderSVGContent(RenderObject* object, PaintInfo& paintInfo, NeedsGraphicsContextSave needsGraphicsContextSave)
+{
+    ASSERT(object);
+
+#ifndef NDEBUG
+    // This function must not be called twice!
+    ASSERT(!(m_renderingFlags & PrepareToRenderSVGContentWasCalled));
+    m_renderingFlags |= PrepareToRenderSVGContentWasCalled;
+#endif
+
+    m_object = object;
+    m_paintInfo = &paintInfo;
+#if ENABLE(FILTERS)
+    m_filter = 0;
+#endif
+
+    // We need to save / restore the context even if the initialization failed.
+    if (needsGraphicsContextSave == SaveGraphicsContext) {
+        m_paintInfo->context->save();
+        m_renderingFlags |= RestoreGraphicsContext;
+    }
+
+    RenderStyle* style = m_object->style();
+    ASSERT(style);
+
+    const SVGRenderStyle* svgStyle = style->svgStyle();
+    ASSERT(svgStyle);
+
+    // Setup transparency layers before setting up SVG resources!
+    bool isRenderingMask = isRenderingMaskImage(m_object);
+    float opacity = isRenderingMask ? 1 : style->opacity();
+    const ShadowData* shadow = svgStyle->shadow();
+    if (opacity < 1 || shadow) {
+        FloatRect repaintRect = m_object->repaintRectInLocalCoordinates();
+
+        if (opacity < 1) {
+            m_paintInfo->context->clip(repaintRect);
+            m_paintInfo->context->beginTransparencyLayer(opacity);
+            m_renderingFlags |= EndOpacityLayer;
+        }
+
+        if (shadow) {
+            m_paintInfo->context->clip(repaintRect);
+            m_paintInfo->context->setShadow(IntSize(roundToInt(shadow->x()), roundToInt(shadow->y())), shadow->blur(), shadow->color(), style->colorSpace());
+            m_paintInfo->context->beginTransparencyLayer(1);
+            m_renderingFlags |= EndShadowLayer;
+        }
+    }
+
+    SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(m_object);
+    if (!resources) {
+#if ENABLE(FILTERS)
+        if (svgStyle->hasFilter())
+            return;
+#endif
+        m_renderingFlags |= RenderingPrepared;
+        return;
+    }
+
+    if (!isRenderingMask) {
+        if (RenderSVGResourceMasker* masker = resources->masker()) {
+            if (!masker->applyResource(m_object, style, m_paintInfo->context, ApplyToDefaultMode))
+                return;
+        }
+    }
+
+    if (RenderSVGResourceClipper* clipper = resources->clipper()) {
+        if (!clipper->applyResource(m_object, style, m_paintInfo->context, ApplyToDefaultMode))
+            return;
+    }
+
+#if ENABLE(FILTERS)
+    if (!isRenderingMask) {
+        m_filter = resources->filter();
+        if (m_filter) {
+            m_savedContext = m_paintInfo->context;
+            // Return with false here may mean that we don't need to draw the content
+            // (because it was either drawn before or empty) but we still need to apply the filter.
+            m_renderingFlags |= EndFilterLayer;
+            if (!m_filter->applyResource(m_object, style, m_paintInfo->context, ApplyToDefaultMode))
+                return;
+        }
+    }
+#endif
+
+    m_renderingFlags |= RenderingPrepared;
+}
+
+}
+
+#endif
diff --git a/Source/WebCore/rendering/svg/SVGRenderingContext.h b/Source/WebCore/rendering/svg/SVGRenderingContext.h
new file mode 100644 (file)
index 0000000..3452089
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * Copyright (C) 2007 Rob Buis <buis@kde.org>
+ * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ * Copyright (C) 2009 Google, Inc.  All rights reserved.
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ * Copyright (C) 2012 Zoltan Herczeg <zherczeg@webkit.org>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SVGRenderingContext_h
+#define SVGRenderingContext_h
+
+#if ENABLE(SVG)
+#include "ImageBuffer.h"
+#include "LayoutTypes.h"
+#include "PaintInfo.h"
+
+namespace WebCore {
+
+class AffineTransform;
+class RenderObject;
+class FloatRect;
+class RenderSVGResourceFilter;
+
+// SVGRenderingContext 
+class SVGRenderingContext {
+public:
+    enum NeedsGraphicsContextSave {
+        SaveGraphicsContext,
+        DontSaveGraphicsContext,
+    };
+
+    // Does not start rendering.
+    SVGRenderingContext()
+        : m_renderingFlags(0)
+        , m_object(0)
+        , m_paintInfo(0)
+        , m_savedContext(0)
+        , m_filter(0)
+    {
+    }
+
+    SVGRenderingContext(RenderObject* object, PaintInfo& paintinfo, NeedsGraphicsContextSave needsGraphicsContextSave = DontSaveGraphicsContext)
+        : m_renderingFlags(0)
+        , m_object(0)
+        , m_paintInfo(0)
+        , m_savedContext(0)
+        , m_filter(0)
+    {
+        prepareToRenderSVGContent(object, paintinfo, needsGraphicsContextSave);
+    }
+
+    // Automatically finishes context rendering.
+    ~SVGRenderingContext();
+
+    // Used by all SVG renderers who apply clip/filter/etc. resources to the renderer content.
+    void prepareToRenderSVGContent(RenderObject*, PaintInfo&, NeedsGraphicsContextSave = DontSaveGraphicsContext);
+    bool isRenderingPrepared() const { return m_renderingFlags & RenderingPrepared; }
+
+private:
+    // To properly revert partially successful initializtions in the destructor, we record all successful steps.
+    enum RenderingFlags {
+        RenderingPrepared = 1,
+        RestoreGraphicsContext = 1 << 1,
+        EndOpacityLayer = 1 << 2,
+        EndShadowLayer = 1 << 3,
+        EndFilterLayer = 1 << 4,
+        PrepareToRenderSVGContentWasCalled = 1 << 5
+    };
+
+    // List of those flags which require actions during the destructor.
+    const static int ActionsNeeded = RestoreGraphicsContext | EndOpacityLayer | EndShadowLayer | EndFilterLayer;
+
+    int m_renderingFlags;
+    RenderObject* m_object;
+    PaintInfo* m_paintInfo;
+    GraphicsContext* m_savedContext;
+#if ENABLE(FILTERS)
+    RenderSVGResourceFilter* m_filter;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif // SVGRenderingContext_h
index ae495ec..57146c9 100644 (file)
@@ -31,7 +31,7 @@
 #include "SVGInlineFlowBox.h"
 #include "SVGInlineTextBox.h"
 #include "SVGNames.h"
-#include "SVGRenderSupport.h"
+#include "SVGRenderingContext.h"
 #include "SVGTextPositioningElement.h"
 
 namespace WebCore {
@@ -57,18 +57,15 @@ void SVGRootInlineBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUni
         }
     }
 
-    GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
-
-    if (SVGRenderSupport::prepareToRenderSVGContent(boxRenderer, childPaintInfo)) {
+    SVGRenderingContext renderingContext(boxRenderer, paintInfo, SVGRenderingContext::SaveGraphicsContext);
+    if (renderingContext.isRenderingPrepared()) {
         for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
             if (child->isSVGInlineTextBox())
                 SVGInlineFlowBox::computeTextMatchMarkerRectForRenderer(toRenderSVGInlineText(static_cast<SVGInlineTextBox*>(child)->textRenderer()));
 
-            child->paint(childPaintInfo, LayoutPoint(), 0, 0);
+            child->paint(paintInfo, LayoutPoint(), 0, 0);
         }
     }
-
-    SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
 }
 
 void SVGRootInlineBox::computePerCharacterLayoutInformation()