2011-04-21 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Apr 2011 15:55:57 +0000 (15:55 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Apr 2011 15:55:57 +0000 (15:55 +0000)
        Reviewed by Eric Seidel.

        Create RIAA class for GraphicsContext::save() and restore()
        https://bugs.webkit.org/show_bug.cgi?id=58807

        Use GraphicsContextStateSaver in a lot more places.

        * html/canvas/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::drawImage):
        (WebCore::CanvasRenderingContext2D::drawTextInternal):
        * platform/ScrollView.cpp:
        (WebCore::ScrollView::wheelEvent):
        * platform/graphics/GeneratedImage.cpp:
        (WebCore::GeneratedImage::draw):
        * platform/graphics/GraphicsContext.h:
        (WebCore::GraphicsContextStateSaver::save):
        (WebCore::GraphicsContextStateSaver::restore):
        * platform/graphics/ShadowBlur.cpp:
        (WebCore::ShadowBlur::drawShadowBuffer):
        (WebCore::ShadowBlur::drawRectShadowWithoutTiling):
        (WebCore::ShadowBlur::drawInsetShadowWithoutTiling):
        (WebCore::ShadowBlur::drawInsetShadowWithTiling):
        (WebCore::ShadowBlur::drawRectShadowWithTiling):
        (WebCore::ShadowBlur::drawLayerPieces):
        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm:
        (WebCore::MediaPlayerPrivateAVFoundationObjC::paint):
        * platform/graphics/cg/ImageCG.cpp:
        (WebCore::BitmapImage::draw):
        (WebCore::Image::drawPattern):
        * platform/graphics/cg/PDFDocumentImage.cpp:
        (WebCore::PDFDocumentImage::draw):
        * platform/graphics/filters/FEComposite.cpp:
        (WebCore::FEComposite::apply):
        * platform/graphics/filters/SourceAlpha.cpp:
        (WebCore::SourceAlpha::apply):
        * platform/graphics/mac/MediaPlayerPrivateQTKit.mm:
        (WebCore::MediaPlayerPrivateQTKit::paint):
        * platform/mac/ScrollbarThemeMac.mm:
        (WebCore::ScrollbarThemeMac::paint):
        * platform/mac/ThemeMac.mm:
        (WebCore::paintCheckbox):
        (WebCore::paintRadio):
        (WebCore::paintStepper):
        * rendering/EllipsisBox.cpp:
        (WebCore::EllipsisBox::paintSelection):
        * rendering/InlineFlowBox.cpp:
        (WebCore::InlineFlowBox::paintFillLayer):
        (WebCore::InlineFlowBox::paintBoxDecorations):
        (WebCore::InlineFlowBox::paintMask):
        * rendering/InlineTextBox.cpp:
        (WebCore::InlineTextBox::paint):
        (WebCore::InlineTextBox::paintSelection):
        (WebCore::InlineTextBox::paintCompositionBackground):
        (WebCore::InlineTextBox::paintDecoration):
        (WebCore::InlineTextBox::paintTextMatchMarker):
        * rendering/RenderBlock.cpp:
        (WebCore::RenderBlock::paintColumnContents):
        (WebCore::RenderBlock::paintSelection):
        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::paintBoxDecorationsWithSize):
        * rendering/RenderBoxModelObject.cpp:
        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
        (WebCore::RenderBoxModelObject::paintBorder):
        * rendering/RenderEmbeddedObject.cpp:
        (WebCore::RenderEmbeddedObject::paintReplaced):
        * rendering/RenderFieldset.cpp:
        (WebCore::RenderFieldset::paintBoxDecorations):
        * rendering/RenderFileUploadControl.cpp:
        (WebCore::RenderFileUploadControl::paintObject):
        * rendering/RenderLayer.cpp:
        (WebCore::RenderLayer::paintResizer):
        (WebCore::RenderLayer::paintLayer):
        (WebCore::RenderLayer::paintChildLayerIntoColumns):
        * rendering/RenderListMarker.cpp:
        (WebCore::RenderListMarker::paint):
        * rendering/RenderMediaControls.cpp:
        (WebCore::RenderMediaControls::paintMediaControlsPart):
        * rendering/RenderTableCell.cpp:
        (WebCore::RenderTableCell::paintBackgroundsBehindCell):
        * rendering/RenderTextControl.cpp:
        (WebCore::RenderTextControl::paintPlaceholder):
        * rendering/RenderThemeMac.mm:
        (WebCore::RenderThemeMac::paintMenuList):
        (WebCore::RenderThemeMac::paintMeter):
        (WebCore::RenderThemeMac::paintProgressBar):
        (WebCore::RenderThemeMac::paintMenuListButtonGradients):
        (WebCore::RenderThemeMac::paintMenuListButton):
        (WebCore::RenderThemeMac::paintSliderTrack):
        (WebCore::RenderThemeMac::paintSliderThumb):
        (WebCore::RenderThemeMac::paintSearchField):
        (WebCore::RenderThemeMac::paintSearchFieldCancelButton):
        (WebCore::RenderThemeMac::paintSearchFieldResultsButton):
        (WebCore::RenderThemeMac::paintMediaSliderTrack):
        (WebCore::RenderThemeMac::paintMediaCurrentTime):
        (WebCore::RenderThemeMac::paintMediaTimeRemaining):
        * rendering/mathml/RenderMathMLBlock.cpp:
        (WebCore::RenderMathMLBlock::paint):
        * rendering/mathml/RenderMathMLFraction.cpp:
        (WebCore::RenderMathMLFraction::paint):
        * rendering/mathml/RenderMathMLRoot.cpp:
        (WebCore::RenderMathMLRoot::paint):
        * rendering/mathml/RenderMathMLSquareRoot.cpp:
        (WebCore::RenderMathMLSquareRoot::paint):
        * rendering/svg/RenderSVGContainer.cpp:
        (WebCore::RenderSVGContainer::paint):
        * rendering/svg/RenderSVGForeignObject.cpp:
        (WebCore::RenderSVGForeignObject::paint):
        * rendering/svg/RenderSVGImage.cpp:
        (WebCore::RenderSVGImage::paint):
        * rendering/svg/RenderSVGPath.cpp:
        (WebCore::RenderSVGPath::fillAndStrokePath):
        (WebCore::RenderSVGPath::paint):
        * rendering/svg/RenderSVGResourceClipper.cpp:
        (WebCore::RenderSVGResourceClipper::applyClippingToContext):
        * rendering/svg/RenderSVGResourceMarker.cpp:
        (WebCore::RenderSVGResourceMarker::draw):
        * rendering/svg/RenderSVGText.cpp:
        (WebCore::RenderSVGText::paint):
        * rendering/svg/SVGInlineFlowBox.cpp:
        (WebCore::SVGInlineFlowBox::paint):
        * rendering/svg/SVGInlineTextBox.cpp:
        (WebCore::SVGInlineTextBox::paintSelectionBackground):
        (WebCore::SVGInlineTextBox::paint):
        (WebCore::SVGInlineTextBox::paintDecorationWithStyle):
        * rendering/svg/SVGRootInlineBox.cpp:
        (WebCore::SVGRootInlineBox::paint):
        * svg/SVGFont.cpp:
        (WebCore::Font::drawTextUsingSVGFont):
        * svg/graphics/SVGImage.cpp:
        (WebCore::SVGImage::draw):

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

45 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/platform/ScrollView.cpp
Source/WebCore/platform/graphics/GeneratedImage.cpp
Source/WebCore/platform/graphics/GraphicsContext.h
Source/WebCore/platform/graphics/ShadowBlur.cpp
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/cg/ImageCG.cpp
Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp
Source/WebCore/platform/graphics/filters/FEComposite.cpp
Source/WebCore/platform/graphics/filters/SourceAlpha.cpp
Source/WebCore/platform/graphics/mac/MediaPlayerPrivateQTKit.mm
Source/WebCore/platform/mac/ScrollbarThemeMac.mm
Source/WebCore/platform/mac/ThemeMac.mm
Source/WebCore/rendering/EllipsisBox.cpp
Source/WebCore/rendering/InlineFlowBox.cpp
Source/WebCore/rendering/InlineTextBox.cpp
Source/WebCore/rendering/RenderBlock.cpp
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBoxModelObject.cpp
Source/WebCore/rendering/RenderEmbeddedObject.cpp
Source/WebCore/rendering/RenderFieldset.cpp
Source/WebCore/rendering/RenderFileUploadControl.cpp
Source/WebCore/rendering/RenderLayer.cpp
Source/WebCore/rendering/RenderListMarker.cpp
Source/WebCore/rendering/RenderMediaControls.cpp
Source/WebCore/rendering/RenderTableCell.cpp
Source/WebCore/rendering/RenderTextControl.cpp
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/mathml/RenderMathMLBlock.cpp
Source/WebCore/rendering/mathml/RenderMathMLFraction.cpp
Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp
Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp
Source/WebCore/rendering/svg/RenderSVGContainer.cpp
Source/WebCore/rendering/svg/RenderSVGForeignObject.cpp
Source/WebCore/rendering/svg/RenderSVGImage.cpp
Source/WebCore/rendering/svg/RenderSVGPath.cpp
Source/WebCore/rendering/svg/RenderSVGResourceClipper.cpp
Source/WebCore/rendering/svg/RenderSVGResourceMarker.cpp
Source/WebCore/rendering/svg/RenderSVGText.cpp
Source/WebCore/rendering/svg/SVGInlineFlowBox.cpp
Source/WebCore/rendering/svg/SVGInlineTextBox.cpp
Source/WebCore/rendering/svg/SVGRootInlineBox.cpp
Source/WebCore/svg/SVGFont.cpp
Source/WebCore/svg/graphics/SVGImage.cpp

index e72871f..3f4a7ff 100644 (file)
@@ -1,3 +1,136 @@
+2011-04-21  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Eric Seidel.
+
+        Create RIAA class for GraphicsContext::save() and restore()
+        https://bugs.webkit.org/show_bug.cgi?id=58807
+
+        Use GraphicsContextStateSaver in a lot more places.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawImage):
+        (WebCore::CanvasRenderingContext2D::drawTextInternal):
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::wheelEvent):
+        * platform/graphics/GeneratedImage.cpp:
+        (WebCore::GeneratedImage::draw):
+        * platform/graphics/GraphicsContext.h:
+        (WebCore::GraphicsContextStateSaver::save):
+        (WebCore::GraphicsContextStateSaver::restore):
+        * platform/graphics/ShadowBlur.cpp:
+        (WebCore::ShadowBlur::drawShadowBuffer):
+        (WebCore::ShadowBlur::drawRectShadowWithoutTiling):
+        (WebCore::ShadowBlur::drawInsetShadowWithoutTiling):
+        (WebCore::ShadowBlur::drawInsetShadowWithTiling):
+        (WebCore::ShadowBlur::drawRectShadowWithTiling):
+        (WebCore::ShadowBlur::drawLayerPieces):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::paint):
+        * platform/graphics/cg/ImageCG.cpp:
+        (WebCore::BitmapImage::draw):
+        (WebCore::Image::drawPattern):
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::PDFDocumentImage::draw):
+        * platform/graphics/filters/FEComposite.cpp:
+        (WebCore::FEComposite::apply):
+        * platform/graphics/filters/SourceAlpha.cpp:
+        (WebCore::SourceAlpha::apply):
+        * platform/graphics/mac/MediaPlayerPrivateQTKit.mm:
+        (WebCore::MediaPlayerPrivateQTKit::paint):
+        * platform/mac/ScrollbarThemeMac.mm:
+        (WebCore::ScrollbarThemeMac::paint):
+        * platform/mac/ThemeMac.mm:
+        (WebCore::paintCheckbox):
+        (WebCore::paintRadio):
+        (WebCore::paintStepper):
+        * rendering/EllipsisBox.cpp:
+        (WebCore::EllipsisBox::paintSelection):
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::paintFillLayer):
+        (WebCore::InlineFlowBox::paintBoxDecorations):
+        (WebCore::InlineFlowBox::paintMask):
+        * rendering/InlineTextBox.cpp:
+        (WebCore::InlineTextBox::paint):
+        (WebCore::InlineTextBox::paintSelection):
+        (WebCore::InlineTextBox::paintCompositionBackground):
+        (WebCore::InlineTextBox::paintDecoration):
+        (WebCore::InlineTextBox::paintTextMatchMarker):
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::paintColumnContents):
+        (WebCore::RenderBlock::paintSelection):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::paintBoxDecorationsWithSize):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
+        (WebCore::RenderBoxModelObject::paintBorder):
+        * rendering/RenderEmbeddedObject.cpp:
+        (WebCore::RenderEmbeddedObject::paintReplaced):
+        * rendering/RenderFieldset.cpp:
+        (WebCore::RenderFieldset::paintBoxDecorations):
+        * rendering/RenderFileUploadControl.cpp:
+        (WebCore::RenderFileUploadControl::paintObject):
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::paintResizer):
+        (WebCore::RenderLayer::paintLayer):
+        (WebCore::RenderLayer::paintChildLayerIntoColumns):
+        * rendering/RenderListMarker.cpp:
+        (WebCore::RenderListMarker::paint):
+        * rendering/RenderMediaControls.cpp:
+        (WebCore::RenderMediaControls::paintMediaControlsPart):
+        * rendering/RenderTableCell.cpp:
+        (WebCore::RenderTableCell::paintBackgroundsBehindCell):
+        * rendering/RenderTextControl.cpp:
+        (WebCore::RenderTextControl::paintPlaceholder):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::paintMenuList):
+        (WebCore::RenderThemeMac::paintMeter):
+        (WebCore::RenderThemeMac::paintProgressBar):
+        (WebCore::RenderThemeMac::paintMenuListButtonGradients):
+        (WebCore::RenderThemeMac::paintMenuListButton):
+        (WebCore::RenderThemeMac::paintSliderTrack):
+        (WebCore::RenderThemeMac::paintSliderThumb):
+        (WebCore::RenderThemeMac::paintSearchField):
+        (WebCore::RenderThemeMac::paintSearchFieldCancelButton):
+        (WebCore::RenderThemeMac::paintSearchFieldResultsButton):
+        (WebCore::RenderThemeMac::paintMediaSliderTrack):
+        (WebCore::RenderThemeMac::paintMediaCurrentTime):
+        (WebCore::RenderThemeMac::paintMediaTimeRemaining):
+        * rendering/mathml/RenderMathMLBlock.cpp:
+        (WebCore::RenderMathMLBlock::paint):
+        * rendering/mathml/RenderMathMLFraction.cpp:
+        (WebCore::RenderMathMLFraction::paint):
+        * rendering/mathml/RenderMathMLRoot.cpp:
+        (WebCore::RenderMathMLRoot::paint):
+        * rendering/mathml/RenderMathMLSquareRoot.cpp:
+        (WebCore::RenderMathMLSquareRoot::paint):
+        * rendering/svg/RenderSVGContainer.cpp:
+        (WebCore::RenderSVGContainer::paint):
+        * rendering/svg/RenderSVGForeignObject.cpp:
+        (WebCore::RenderSVGForeignObject::paint):
+        * rendering/svg/RenderSVGImage.cpp:
+        (WebCore::RenderSVGImage::paint):
+        * rendering/svg/RenderSVGPath.cpp:
+        (WebCore::RenderSVGPath::fillAndStrokePath):
+        (WebCore::RenderSVGPath::paint):
+        * rendering/svg/RenderSVGResourceClipper.cpp:
+        (WebCore::RenderSVGResourceClipper::applyClippingToContext):
+        * rendering/svg/RenderSVGResourceMarker.cpp:
+        (WebCore::RenderSVGResourceMarker::draw):
+        * rendering/svg/RenderSVGText.cpp:
+        (WebCore::RenderSVGText::paint):
+        * rendering/svg/SVGInlineFlowBox.cpp:
+        (WebCore::SVGInlineFlowBox::paint):
+        * rendering/svg/SVGInlineTextBox.cpp:
+        (WebCore::SVGInlineTextBox::paintSelectionBackground):
+        (WebCore::SVGInlineTextBox::paint):
+        (WebCore::SVGInlineTextBox::paintDecorationWithStyle):
+        * rendering/svg/SVGRootInlineBox.cpp:
+        (WebCore::SVGRootInlineBox::paint):
+        * svg/SVGFont.cpp:
+        (WebCore::Font::drawTextUsingSVGFont):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::draw):
+
 2011-04-20  Andrey Kosyakov  <caseq@chromium.org>
 
         Reviewed by Pavel Feldman.
index ab6427e..2ffd09c 100644 (file)
@@ -1432,13 +1432,13 @@ void CanvasRenderingContext2D::drawImage(HTMLVideoElement* video, const FloatRec
     FloatRect sourceRect = c->roundToDevicePixels(srcRect);
     FloatRect destRect = c->roundToDevicePixels(dstRect);
 
-    c->save();
+    GraphicsContextStateSaver stateSaver(*c);
     c->clip(destRect);
     c->translate(destRect.x(), destRect.y());
     c->scale(FloatSize(destRect.width() / sourceRect.width(), destRect.height() / sourceRect.height()));
     c->translate(-sourceRect.x(), -sourceRect.y());
     video->paintCurrentFrameInContext(c, IntRect(IntPoint(), size(video)));
-    c->restore();
+    stateSaver.restore();
     didDraw(destRect);
 }
 #endif
@@ -1917,12 +1917,10 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
 
         maskImageContext->drawBidiText(font, textRun, location);
 
-        c->save();
+        GraphicsContextStateSaver stateSaver(*c);
         c->clipToImageBuffer(maskImage.get(), maskRect);
         drawStyle->applyFillColor(c);
         c->fillRect(maskRect);
-        c->restore();
-
         return;
     }
 #endif
index 7caf820..cab0eab 100644 (file)
@@ -990,21 +990,21 @@ void ScrollView::paint(GraphicsContext* context, const IntRect& rect)
     IntRect documentDirtyRect = rect;
     documentDirtyRect.intersect(frameRect());
 
-    context->save();
+    {
+        GraphicsContextStateSaver stateSaver(*context);
 
-    context->translate(x(), y());
-    documentDirtyRect.move(-x(), -y());
-
-    if (!paintsEntireContents()) {
-        context->translate(-scrollX(), -scrollY());
-        documentDirtyRect.move(scrollX(), scrollY());
+        context->translate(x(), y());
+        documentDirtyRect.move(-x(), -y());
 
-        context->clip(visibleContentRect());
-    }
+        if (!paintsEntireContents()) {
+            context->translate(-scrollX(), -scrollY());
+            documentDirtyRect.move(scrollX(), scrollY());
 
-    paintContents(context, documentDirtyRect);
+            context->clip(visibleContentRect());
+        }
 
-    context->restore();
+        paintContents(context, documentDirtyRect);
+    }
 
     IntRect horizontalOverhangRect;
     IntRect verticalOverhangRect;
@@ -1015,15 +1015,13 @@ void ScrollView::paint(GraphicsContext* context, const IntRect& rect)
 
     // Now paint the scrollbars.
     if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar)) {
-        context->save();
+        GraphicsContextStateSaver stateSaver(*context);
         IntRect scrollViewDirtyRect = rect;
         scrollViewDirtyRect.intersect(frameRect());
         context->translate(x(), y());
         scrollViewDirtyRect.move(-x(), -y());
 
         paintScrollbars(context, scrollViewDirtyRect);
-
-        context->restore();
     }
 
     // Paint the panScroll Icon
index f2c175b..3f0a6fa 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 
 void GeneratedImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, ColorSpace, CompositeOperator compositeOp)
 {
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     context->setCompositeOperation(compositeOp);
     context->clip(dstRect);
     context->translate(dstRect.x(), dstRect.y());
@@ -44,7 +44,6 @@ void GeneratedImage::draw(GraphicsContext* context, const FloatRect& dstRect, co
         context->scale(FloatSize(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height()));
     context->translate(-srcRect.x(), -srcRect.y());
     context->fillRect(FloatRect(FloatPoint(), m_size), *m_generator.get());
-    context->restore();
 }
 
 void GeneratedImage::drawPattern(GraphicsContext* context, const FloatRect& srcRect, const AffineTransform& patternTransform,
index c2ea509..a6fd6da 100644 (file)
@@ -569,12 +569,19 @@ namespace WebCore {
                 m_context.restore();
         }
         
-        void saveState()
+        void save()
         {
             ASSERT(!m_saveAndRestore);
             m_context.save();
             m_saveAndRestore = true;
         }
+
+        void restore()
+        {
+            ASSERT(m_saveAndRestore);
+            m_context.restore();
+            m_saveAndRestore = false;
+        }
         
     private:
         GraphicsContext& m_context;
index 92a0404..218efef 100644 (file)
@@ -409,7 +409,7 @@ void ShadowBlur::drawShadowBuffer(GraphicsContext* graphicsContext)
     if (!m_layerImage)
         return;
 
-    graphicsContext->save();
+    GraphicsContextStateSaver stateSaver(*graphicsContext);
 
     IntSize bufferSize = m_layerImage->size();
     if (bufferSize != m_layerSize) {
@@ -422,8 +422,6 @@ void ShadowBlur::drawShadowBuffer(GraphicsContext* graphicsContext)
 
     graphicsContext->clearShadow();
     graphicsContext->fillRect(FloatRect(m_layerOrigin, m_sourceRect.size()));
-    
-    graphicsContext->restore();
 }
 
 static void computeSliceSizesFromRadii(const IntSize& twiceRadius, const RoundedIntRect::Radii& radii, int& leftSlice, int& rightSlice, int& topSlice, int& bottomSlice)
@@ -514,7 +512,7 @@ void ShadowBlur::drawRectShadowWithoutTiling(GraphicsContext* graphicsContext, c
     bufferRelativeShadowedRect.move(m_layerContextTranslation);
     if (!ScratchBuffer::shared().matchesLastShadow(m_blurRadius, Color::black, ColorSpaceDeviceRGB, bufferRelativeShadowedRect, radii)) {
         GraphicsContext* shadowContext = m_layerImage->context();
-        shadowContext->save();
+        GraphicsContextStateSaver stateSaver(*shadowContext);
 
         // Add a pixel to avoid later edge aliasing when rotated.
         shadowContext->clearRect(FloatRect(0, 0, m_layerSize.width() + 1, m_layerSize.height() + 1));
@@ -529,8 +527,6 @@ void ShadowBlur::drawRectShadowWithoutTiling(GraphicsContext* graphicsContext, c
         }
 
         blurShadowBuffer(expandedIntSize(m_layerSize));
-
-        shadowContext->restore();
         
         ScratchBuffer::shared().setLastShadowValues(m_blurRadius, Color::black, ColorSpaceDeviceRGB, bufferRelativeShadowedRect, radii);
     }
@@ -554,7 +550,7 @@ void ShadowBlur::drawInsetShadowWithoutTiling(GraphicsContext* graphicsContext,
 
     if (!ScratchBuffer::shared().matchesLastInsetShadow(m_blurRadius, Color::black, ColorSpaceDeviceRGB, bufferRelativeRect, bufferRelativeHoleRect, holeRadii)) {
         GraphicsContext* shadowContext = m_layerImage->context();
-        shadowContext->save();
+        GraphicsContextStateSaver stateSaver(*shadowContext);
 
         // Add a pixel to avoid later edge aliasing when rotated.
         shadowContext->clearRect(FloatRect(0, 0, m_layerSize.width() + 1, m_layerSize.height() + 1));
@@ -573,8 +569,6 @@ void ShadowBlur::drawInsetShadowWithoutTiling(GraphicsContext* graphicsContext,
 
         blurShadowBuffer(expandedIntSize(m_layerSize));
 
-        shadowContext->restore();
-
         ScratchBuffer::shared().setLastInsetShadowValues(m_blurRadius, Color::black, ColorSpaceDeviceRGB, bufferRelativeRect, bufferRelativeHoleRect, holeRadii);
     }
     
@@ -617,7 +611,7 @@ void ShadowBlur::drawInsetShadowWithoutTiling(GraphicsContext* graphicsContext,
 
 void ShadowBlur::drawInsetShadowWithTiling(GraphicsContext* graphicsContext, const FloatRect& rect, const FloatRect& holeRect, const RoundedIntRect::Radii& radii, const IntSize& templateSize)
 {
-    graphicsContext->save();
+    GraphicsContextStateSaver stateSaver(*graphicsContext);
     graphicsContext->clearShadow();
 
     const IntSize roundedRadius = expandedIntSize(m_blurRadius);
@@ -634,7 +628,7 @@ void ShadowBlur::drawInsetShadowWithTiling(GraphicsContext* graphicsContext, con
     if (!ScratchBuffer::shared().matchesLastInsetShadow(m_blurRadius, m_color, m_colorSpace, templateBounds, templateHole, radii)) {
         // Draw shadow into a new ImageBuffer.
         GraphicsContext* shadowContext = m_layerImage->context();
-        shadowContext->save();
+        GraphicsContextStateSaver shadowStateSaver(*shadowContext);
         shadowContext->clearRect(templateBounds);
         shadowContext->setFillRule(RULE_EVENODD);
         shadowContext->setFillColor(Color::black, ColorSpaceDeviceRGB);
@@ -649,7 +643,6 @@ void ShadowBlur::drawInsetShadowWithTiling(GraphicsContext* graphicsContext, con
         shadowContext->fillPath(path);
 
         blurAndColorShadowBuffer(templateSize);
-        shadowContext->restore();
     
         ScratchBuffer::shared().setLastInsetShadowValues(m_blurRadius, m_color, m_colorSpace, templateBounds, templateHole, radii);
     }
@@ -668,23 +661,22 @@ void ShadowBlur::drawInsetShadowWithTiling(GraphicsContext* graphicsContext, con
     exteriorPath.addRect(boundingRect);
     exteriorPath.addRect(destHoleBounds);
 
-    graphicsContext->save();
-    graphicsContext->setFillRule(RULE_EVENODD);
-    graphicsContext->setFillColor(m_color, m_colorSpace);
-    graphicsContext->fillPath(exteriorPath);
-    graphicsContext->restore();
+    {
+        GraphicsContextStateSaver fillStateSaver(*graphicsContext);
+        graphicsContext->setFillRule(RULE_EVENODD);
+        graphicsContext->setFillColor(m_color, m_colorSpace);
+        graphicsContext->fillPath(exteriorPath);
+    }
     
     drawLayerPieces(graphicsContext, destHoleBounds, radii, roundedRadius, templateSize, InnerShadow);
 
-    graphicsContext->restore();
-
     m_layerImage = 0;
     ScratchBuffer::shared().scheduleScratchBufferPurge();
 }
 
 void ShadowBlur::drawRectShadowWithTiling(GraphicsContext* graphicsContext, const FloatRect& shadowedRect, const RoundedIntRect::Radii& radii, const IntSize& templateSize)
 {
-    graphicsContext->save();
+    GraphicsContextStateSaver stateSaver(*graphicsContext);
     graphicsContext->clearShadow();
 
     const IntSize roundedRadius = expandedIntSize(m_blurRadius);
@@ -699,7 +691,8 @@ void ShadowBlur::drawRectShadowWithTiling(GraphicsContext* graphicsContext, cons
     if (!ScratchBuffer::shared().matchesLastShadow(m_blurRadius, m_color, m_colorSpace, templateShadow, radii)) {
         // Draw shadow into the ImageBuffer.
         GraphicsContext* shadowContext = m_layerImage->context();
-        shadowContext->save();
+        GraphicsContextStateSaver shadowStateSaver(*shadowContext);
+
         shadowContext->clearRect(FloatRect(0, 0, templateSize.width(), templateSize.height()));
         shadowContext->setFillColor(Color::black, ColorSpaceDeviceRGB);
         
@@ -712,7 +705,6 @@ void ShadowBlur::drawRectShadowWithTiling(GraphicsContext* graphicsContext, cons
         }
 
         blurAndColorShadowBuffer(templateSize);
-        shadowContext->restore();
 
         ScratchBuffer::shared().setLastShadowValues(m_blurRadius, m_color, m_colorSpace, templateShadow, radii);
     }
@@ -724,8 +716,6 @@ void ShadowBlur::drawRectShadowWithTiling(GraphicsContext* graphicsContext, cons
 
     drawLayerPieces(graphicsContext, shadowBounds, radii, roundedRadius, templateSize, OuterShadow);
 
-    graphicsContext->restore();
-
     m_layerImage = 0;
     ScratchBuffer::shared().scheduleScratchBufferPurge();
 }
@@ -746,12 +736,9 @@ void ShadowBlur::drawLayerPieces(GraphicsContext* graphicsContext, const FloatRe
     if (direction == OuterShadow) {
         FloatRect shadowInterior(shadowBounds.x() + leftSlice, shadowBounds.y() + topSlice, centerWidth, centerHeight);
         if (!shadowInterior.isEmpty()) {
-            graphicsContext->save();
-            
+            GraphicsContextStateSaver stateSaver(*graphicsContext);
             graphicsContext->setFillColor(m_color, m_colorSpace);
             graphicsContext->fillRect(shadowInterior);
-            
-            graphicsContext->restore();
         }
     }
 
index cf0298d..c46f632 100644 (file)
@@ -569,13 +569,12 @@ void MediaPlayerPrivateAVFoundationObjC::paint(GraphicsContext* context, const I
 
     RetainPtr<CGImageRef> image = createImageForTimeInRect(currentTime(), rect);
     if (image) {
-        context->save();
+        GraphicsContextStateSaver stateSaver(*context);
         context->translate(rect.x(), rect.y() + rect.height());
         context->scale(FloatSize(1.0f, -1.0f));
         context->setImageInterpolationQuality(InterpolationLow);
         IntRect paintRect(IntPoint(0, 0), IntSize(rect.width(), rect.height()));
         CGContextDrawImage(context->platformContext(), CGRectMake(0, 0, paintRect.width(), paintRect.height()), image.get());
-        context->restore();
         image = 0;
     }
 
index 24b7275..f404c4d 100644 (file)
@@ -185,7 +185,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const F
         return;
 
     CGContextRef context = ctxt->platformContext();
-    ctxt->save();
+    GraphicsContextStateSaver stateSaver(*ctxt);
 
     bool shouldUseSubimage = false;
 
@@ -245,7 +245,7 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& destRect, const F
     // Draw the image.
     CGContextDrawImage(context, adjustedDestRect, image.get());
 
-    ctxt->restore();
+    stateSaver.restore();
 
     if (imageObserver())
         imageObserver()->didDraw(this);
@@ -269,7 +269,7 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const
         return;
 
     CGContextRef context = ctxt->platformContext();
-    ctxt->save();
+    GraphicsContextStateSaver stateSaver(*ctxt);
     CGContextClipToRect(context, destRect);
     ctxt->setCompositeOperation(op);
     CGContextTranslateCTM(context, destRect.x(), destRect.y() + destRect.height());
@@ -328,10 +328,8 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const
     RetainPtr<CGPatternRef> pattern(AdoptCF, CGPatternCreate(subImage.get(), CGRectMake(0, 0, tileRect.width(), tileRect.height()),
                                              matrix, tileRect.width(), tileRect.height(), 
                                              kCGPatternTilingConstantSpacing, true, &patternCallbacks));
-    if (!pattern) {
-        ctxt->restore();
+    if (!pattern)
         return;
-    }
 
     RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
     
@@ -350,7 +348,7 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const
     }
 #endif
 
-    ctxt->restore();
+    stateSaver.restore();
 
     if (imageObserver())
         imageObserver()->didDraw(this);
index a7d465f..28b0446 100644 (file)
@@ -158,29 +158,29 @@ void PDFDocumentImage::draw(GraphicsContext* context, const FloatRect& dstRect,
     if (!m_document || m_currentPage == -1)
         return;
 
-    context->save();
+    {
+        GraphicsContextStateSaver stateSaver(*context);
 
-    context->setCompositeOperation(op);
+        context->setCompositeOperation(op);
 
-    float hScale = dstRect.width() / srcRect.width();
-    float vScale = dstRect.height() / srcRect.height();
+        float hScale = dstRect.width() / srcRect.width();
+        float vScale = dstRect.height() / srcRect.height();
 
-    // Scale and translate so the document is rendered in the correct location,
-    // including accounting for the fact that a GraphicsContext is always flipped
-    // and doing appropriate flipping.
-    CGContextTranslateCTM(context->platformContext(), dstRect.x() - srcRect.x() * hScale, dstRect.y() - srcRect.y() * vScale);
-    CGContextScaleCTM(context->platformContext(), hScale, vScale);
-    CGContextScaleCTM(context->platformContext(), 1, -1);
-    CGContextTranslateCTM(context->platformContext(), 0, -srcRect.height());
-    CGContextClipToRect(context->platformContext(), CGRectIntegral(srcRect));
+        // Scale and translate so the document is rendered in the correct location,
+        // including accounting for the fact that a GraphicsContext is always flipped
+        // and doing appropriate flipping.
+        CGContextTranslateCTM(context->platformContext(), dstRect.x() - srcRect.x() * hScale, dstRect.y() - srcRect.y() * vScale);
+        CGContextScaleCTM(context->platformContext(), hScale, vScale);
+        CGContextScaleCTM(context->platformContext(), 1, -1);
+        CGContextTranslateCTM(context->platformContext(), 0, -srcRect.height());
+        CGContextClipToRect(context->platformContext(), CGRectIntegral(srcRect));
 
-    // Rotate translate image into position according to doc properties.
-    adjustCTM(context);
+        // Rotate translate image into position according to doc properties.
+        adjustCTM(context);
 
-    CGContextTranslateCTM(context->platformContext(), -m_mediaBox.x(), -m_mediaBox.y());
-    CGContextDrawPDFPage(context->platformContext(), CGPDFDocumentGetPage(m_document, m_currentPage + 1));
-
-    context->restore();
+        CGContextTranslateCTM(context->platformContext(), -m_mediaBox.x(), -m_mediaBox.y());
+        CGContextDrawPDFPage(context->platformContext(), CGPDFDocumentGetPage(m_document, m_currentPage + 1));
+    }
 
     if (imageObserver())
         imageObserver()->didDraw(this);
index eead000..d73498e 100644 (file)
@@ -233,12 +233,12 @@ void FEComposite::apply()
         filterContext->drawImageBuffer(in2->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()));
         filterContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
         break;
-    case FECOMPOSITE_OPERATOR_IN:
-        filterContext->save();
+    case FECOMPOSITE_OPERATOR_IN: {
+        GraphicsContextStateSaver stateSaver(*filterContext);
         filterContext->clipToImageBuffer(in2->asImageBuffer(), drawingRegionOfInputImage(in2->absolutePaintRect()));
         filterContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
-        filterContext->restore();
         break;
+    }
     case FECOMPOSITE_OPERATOR_OUT:
         filterContext->drawImageBuffer(in->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in->absolutePaintRect()));
         filterContext->drawImageBuffer(in2->asImageBuffer(), ColorSpaceDeviceRGB, drawingRegionOfInputImage(in2->absolutePaintRect()), srcRect, CompositeDestinationOut);
index 45d74f5..77e2115 100644 (file)
@@ -65,10 +65,9 @@ void SourceAlpha::apply()
 
     FloatRect imageRect(FloatPoint(), absolutePaintRect().size());
     GraphicsContext* filterContext = resultImage->context();
-    filterContext->save();
+    GraphicsContextStateSaver stateSaver(*filterContext);
     filterContext->clipToImageBuffer(filter->sourceImage(), imageRect);
     filterContext->fillRect(imageRect, Color::black, ColorSpaceDeviceRGB);
-    filterContext->restore();
 }
 
 void SourceAlpha::dump()
index a9ebc1a..772c687 100644 (file)
@@ -1319,7 +1319,7 @@ void MediaPlayerPrivateQTKit::paint(GraphicsContext* context, const IntRect& r)
 
     [m_objcObserver.get() setDelayCallbacks:YES];
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     context->translate(r.x(), r.y() + r.height());
     context->scale(FloatSize(1.0f, -1.0f));
     context->setImageInterpolationQuality(InterpolationLow);
@@ -1384,7 +1384,6 @@ void MediaPlayerPrivateQTKit::paint(GraphicsContext* context, const IntRect& r)
     }
 #endif
 
-    context->restore();
     END_BLOCK_OBJC_EXCEPTIONS;
     [m_objcObserver.get() setDelayCallbacks:NO];
 }
index 5504f5c..932a6f0 100644 (file)
@@ -450,7 +450,7 @@ bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, co
     ScrollAnimatorMac* scrollAnimator = static_cast<ScrollAnimatorMac*>(scrollbar->scrollableArea()->scrollAnimator());
     scrollAnimator->setIsDrawingIntoLayer(context->isCALayerContext());
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     context->clip(damageRect);
     context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y());
     LocalCurrentGraphicsContext localContext(context);
@@ -461,8 +461,6 @@ bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, co
                             scrollbar->frameRect());
 
     scrollAnimator->setIsDrawingIntoLayer(false);
-
-    context->restore();
     return true;
 #endif
 
index 918bc07..b146cd3 100644 (file)
@@ -260,7 +260,7 @@ static void paintCheckbox(ControlStates states, GraphicsContext* context, const
     NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor);
     LocalCurrentGraphicsContext localContext(context);
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
 
     NSControlSize controlSize = [checkboxCell controlSize];
     IntSize zoomedSize = checkboxSizes()[controlSize];
@@ -278,8 +278,6 @@ static void paintCheckbox(ControlStates states, GraphicsContext* context, const
     
     [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
     [checkboxCell setControlView:nil];
-
-    context->restore();
     
     END_BLOCK_OBJC_EXCEPTIONS
 }
@@ -338,7 +336,7 @@ static void paintRadio(ControlStates states, GraphicsContext* context, const Int
     NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor);
     LocalCurrentGraphicsContext localContext(context);
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
 
     NSControlSize controlSize = [radioCell controlSize];
     IntSize zoomedSize = radioSizes()[controlSize];
@@ -358,8 +356,6 @@ static void paintRadio(ControlStates states, GraphicsContext* context, const Int
     [radioCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
     [radioCell setControlView:nil];
     END_BLOCK_OBJC_EXCEPTIONS
-
-    context->restore();
 }
 
 // Buttons
@@ -532,7 +528,7 @@ static void paintStepper(ControlStates states, GraphicsContext* context, const I
         drawInfo.kind = kThemeIncDecButton;
 
     IntRect rect(zoomedRect);
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     if (zoomFactor != 1.0f) {
         rect.setWidth(rect.width() / zoomFactor);
         rect.setHeight(rect.height() / zoomFactor);
@@ -549,7 +545,6 @@ static void paintStepper(ControlStates states, GraphicsContext* context, const I
     if (bounds.origin.y != backgroundBounds.origin.y)
         bounds.origin.y += bounds.origin.y - backgroundBounds.origin.y;
     HIThemeDrawButton(&bounds, &drawInfo, context->platformContext(), kHIThemeOrientationNormal, 0);
-    context->restore();
 }
 
 // This will ensure that we always return a valid NSView, even if ScrollView doesn't have an associated document NSView.
index 1641ee5..506a036 100644 (file)
@@ -90,13 +90,12 @@ void EllipsisBox::paintSelection(GraphicsContext* context, int tx, int ty, Rende
     if (textColor == c)
         c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     int y = root()->selectionTop();
     int h = root()->selectionHeight();
     context->clip(IntRect(m_x + tx, y + ty, m_logicalWidth, h));
     context->drawHighlightForText(font, TextRun(m_str.characters(), m_str.length(), false, 0, 0, TextRun::AllowTrailingExpansion, false, style->visuallyOrdered()),
         IntPoint(m_x + tx, m_y + ty + y), h, c, style->colorSpace());
-    context->restore();
 }
 
 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, int lineTop, int lineBottom)
index 0900ce4..beccc9e 100644 (file)
@@ -1056,10 +1056,10 @@ void InlineFlowBox::paintFillLayer(const PaintInfo& paintInfo, const Color& c, c
         int stripY = ty - (isHorizontal() ? 0 : logicalOffsetOnLine);
         int stripWidth = isHorizontal() ? totalLogicalWidth : width();
         int stripHeight = isHorizontal() ? height() : totalLogicalWidth;
-        paintInfo.context->save();
+
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
         paintInfo.context->clip(IntRect(tx, ty, width(), height()));
         boxModelObject()->paintFillLayerExtended(paintInfo, c, fillLayer, stripX, stripY, stripWidth, stripHeight, BackgroundBleedNone, this, w, h, op);
-        paintInfo.context->restore();
     }
 }
 
@@ -1147,10 +1147,10 @@ void InlineFlowBox::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty)
                 int stripY = ty - (isHorizontal() ? 0 : logicalOffsetOnLine);
                 int stripWidth = isHorizontal() ? totalLogicalWidth : w;
                 int stripHeight = isHorizontal() ? h : totalLogicalWidth;
-                context->save();
+
+                GraphicsContextStateSaver stateSaver(*context);
                 context->clip(IntRect(tx, ty, w, h));
                 boxModelObject()->paintBorder(context, stripX, stripY, stripWidth, stripHeight, renderer()->style());
-                context->restore();
             }
         }
     }
@@ -1227,10 +1227,10 @@ void InlineFlowBox::paintMask(PaintInfo& paintInfo, int tx, int ty)
         int stripY = ty - (isHorizontal() ? 0 : logicalOffsetOnLine);
         int stripWidth = isHorizontal() ? totalLogicalWidth : w;
         int stripHeight = isHorizontal() ? h : totalLogicalWidth;
-        paintInfo.context->save();
+
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
         paintInfo.context->clip(IntRect(tx, ty, w, h));
         boxModelObject()->paintNinePieceImage(paintInfo.context, stripX, stripY, stripWidth, stripHeight, renderer()->style(), maskNinePieceImage, compositeOp);
-        paintInfo.context->restore();
     }
     
     if (pushTransparencyLayer)
index 5815b8b..ab83236 100644 (file)
@@ -672,8 +672,7 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty, int /*lineTop*/,
     if (!paintSelectedTextOnly) {
         // For stroked painting, we have to change the text drawing mode.  It's probably dangerous to leave that mutated as a side
         // effect, so only when we know we're stroking, do a save/restore.
-        if (textStrokeWidth > 0)
-            context->save();
+        GraphicsContextStateSaver stateSaver(*context, textStrokeWidth > 0);
 
         updateGraphicsContext(context, textFillColor, textStrokeColor, textStrokeWidth, styleToUse->colorSpace());
         if (!paintSelectedTextSeparately || ePos <= sPos) {
@@ -700,15 +699,11 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty, int /*lineTop*/,
             if (combinedText)
                 context->concatCTM(rotation(boxRect, Counterclockwise));
         }
-
-        if (textStrokeWidth > 0)
-            context->restore();
     }
 
     if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) {
         // paint only the text that is selected
-        if (selectionStrokeWidth > 0)
-            context->save();
+        GraphicsContextStateSaver stateSaver(*context, selectionStrokeWidth > 0);
 
         updateGraphicsContext(context, selectionFillColor, selectionStrokeColor, selectionStrokeWidth, styleToUse->colorSpace());
         paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, length, textOrigin, boxRect, selectionShadow, selectionStrokeWidth > 0, isHorizontal());
@@ -726,8 +721,6 @@ void InlineTextBox::paint(PaintInfo& paintInfo, int tx, int ty, int /*lineTop*/,
             if (combinedText)
                 context->concatCTM(rotation(boxRect, Counterclockwise));
         }
-        if (selectionStrokeWidth > 0)
-            context->restore();
     }
 
     // Paint decorations
@@ -806,7 +799,7 @@ void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b
     if (textColor == c)
         c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     updateGraphicsContext(context, c, c, 0, style->colorSpace());  // Don't draw text at all!
     
     // If the text is truncated, let the thing being painted in the truncation
@@ -827,7 +820,6 @@ void InlineTextBox::paintSelection(GraphicsContext* context, const FloatPoint& b
     context->drawHighlightForText(font, TextRun(characters, length, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), 
                                   !isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered()),
                                   localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);
-    context->restore();
 }
 
 void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const FloatPoint& boxOrigin, RenderStyle* style, const Font& font, int startPos, int endPos)
@@ -839,7 +831,7 @@ void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const F
     if (sPos >= ePos)
         return;
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
 
     Color c = Color(225, 221, 85);
     
@@ -851,7 +843,6 @@ void InlineTextBox::paintCompositionBackground(GraphicsContext* context, const F
     context->drawHighlightForText(font, TextRun(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(),
                                   !isLeftToRightDirection(), m_dirOverride || style->visuallyOrdered()),
                                   localOrigin, selHeight, c, style->colorSpace(), sPos, ePos);
-    context->restore();
 }
 
 #if PLATFORM(MAC)
@@ -904,7 +895,7 @@ void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint&
     bool setClip = false;
     int extraOffset = 0;
     if (!linesAreOpaque && shadow && shadow->next()) {
-        context->save();
+        context->save(); // FIXME: where is the balancing restore()?
         FloatRect clipRect(localOrigin, FloatSize(width, baseline + 2));
         for (const ShadowData* s = shadow; s; s = s->next()) {
             FloatRect shadowRect(localOrigin, FloatSize(width, baseline + 2));
@@ -1067,11 +1058,10 @@ void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPoint&
         Color color = marker.activeMatch ?
             renderer()->theme()->platformActiveTextSearchHighlightColor() :
             renderer()->theme()->platformInactiveTextSearchHighlightColor();
-        pt->save();
+        GraphicsContextStateSaver stateSaver(*pt);
         updateGraphicsContext(pt, color, color, 0, style->colorSpace());  // Don't draw text at all!
         pt->clip(FloatRect(boxOrigin.x(), boxOrigin.y() - deltaY, m_logicalWidth, selHeight));
         pt->drawHighlightForText(font, run, FloatPoint(boxOrigin.x(), boxOrigin.y() - deltaY), selHeight, color, style->colorSpace(), sPos, ePos);
-        pt->restore();
     }
 }
 
index 02c961d..811c53a 100644 (file)
@@ -2328,7 +2328,7 @@ void RenderBlock::paintColumnContents(PaintInfo& paintInfo, int tx, int ty, bool
         info.rect.intersect(colRect);
         
         if (!info.rect.isEmpty()) {
-            context->save();
+            GraphicsContextStateSaver stateSaver(*context);
             
             // Each strip pushes a clip, since column boxes are specified as being
             // like overflow:hidden.
@@ -2341,8 +2341,6 @@ void RenderBlock::paintColumnContents(PaintInfo& paintInfo, int tx, int ty, bool
                 paintFloats(info, finalX, finalY, paintInfo.phase == PaintPhaseSelection || paintInfo.phase == PaintPhaseTextClip);
             else
                 paintContents(info, finalX, finalY);
-
-            context->restore();
         }
 
         int blockDelta = (isHorizontalWritingMode() ? colRect.height() : colRect.width());
@@ -2730,7 +2728,8 @@ void RenderBlock::paintSelection(PaintInfo& paintInfo, int tx, int ty)
         int lastTop = 0;
         int lastLeft = logicalLeftSelectionOffset(this, lastTop);
         int lastRight = logicalRightSelectionOffset(this, lastTop);
-        paintInfo.context->save();
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
+
         IntRect gapRectsBounds = selectionGaps(this, IntPoint(tx, ty), IntSize(), lastTop, lastLeft, lastRight, &paintInfo);
         if (!gapRectsBounds.isEmpty()) {
             if (RenderLayer* layer = enclosingLayer()) {
@@ -2744,7 +2743,6 @@ void RenderBlock::paintSelection(PaintInfo& paintInfo, int tx, int ty)
                 layer->addBlockSelectionGapsBounds(gapRectsBounds);
             }
         }
-        paintInfo.context->restore();
     }
 }
 
index 0ec7c42..d1dc18a 100644 (file)
@@ -847,12 +847,14 @@ void RenderBox::paintBoxDecorationsWithSize(PaintInfo& paintInfo, int tx, int ty
     paintBoxShadow(paintInfo.context, tx, ty, width, height, style(), Normal);
 
     BackgroundBleedAvoidance bleedAvoidance = determineBackgroundBleedAvoidance(paintInfo.context);
+
+    GraphicsContextStateSaver stateSaver(*paintInfo.context, false);
     if (bleedAvoidance == BackgroundBleedUseTransparencyLayer) {
         // To avoid the background color bleeding out behind the border, we'll render background and border
         // into a transparency layer, and then clip that in one go (which requires setting up the clip before
         // beginning the layer).
         RoundedIntRect border = style()->getRoundedBorderFor(IntRect(tx, ty, width, height));
-        paintInfo.context->save();
+        stateSaver.save();
         paintInfo.context->addRoundedRectClip(border);
         paintInfo.context->beginTransparencyLayer(1);
     }
@@ -877,10 +879,8 @@ void RenderBox::paintBoxDecorationsWithSize(PaintInfo& paintInfo, int tx, int ty
     if ((!style()->hasAppearance() || (!themePainted && theme()->paintBorderOnly(this, paintInfo, IntRect(tx, ty, width, height)))) && style()->hasBorder())
         paintBorder(paintInfo.context, tx, ty, width, height, style(), bleedAvoidance);
 
-    if (bleedAvoidance == BackgroundBleedUseTransparencyLayer) {
+    if (bleedAvoidance == BackgroundBleedUseTransparencyLayer)
         paintInfo.context->endTransparencyLayer();
-        paintInfo.context->restore();
-    }
 }
 
 void RenderBox::paintMask(PaintInfo& paintInfo, int tx, int ty)
index efe0d42..f4e7218 100644 (file)
@@ -666,7 +666,7 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co
         int y = ty + borderTop() + (includePadding ? paddingTop() : 0);
         int width = w - bLeft - bRight - (includePadding ? pLeft + pRight : 0);
         int height = h - borderTop() - borderBottom() - (includePadding ? paddingTop() + paddingBottom() : 0);
-        backgroundClipStateSaver.saveState();
+        backgroundClipStateSaver.save();
         context->clip(IntRect(x, y, width, height));
     } else if (bgLayer->clip() == TextFillBox) {
         // We have to draw our text into a mask that can then be used to clip background drawing.
@@ -696,7 +696,7 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co
         }
         
         // The mask has been created.  Now we just need to clip to it.
-        backgroundClipStateSaver.saveState();
+        backgroundClipStateSaver.save();
         context->clipToImageBuffer(maskImage.get(), maskRect);
     }
     
@@ -1618,7 +1618,7 @@ void RenderBoxModelObject::paintBorder(GraphicsContext* graphicsContext, int tx,
         border.includeLogicalEdges(style->getRoundedBorderFor(border.rect()).radii(),
                                    horizontal, includeLogicalLeftEdge, includeLogicalRightEdge);
         if (border.isRounded()) {
-            stateSaver.saveState();
+            stateSaver.save();
             graphicsContext->addRoundedRectClip(border);
         }
     }
index 3561fe0..3c9a697 100644 (file)
@@ -166,7 +166,7 @@ void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, int tx, int ty)
     if (!getReplacementTextGeometry(tx, ty, contentRect, path, replacementTextRect, font, run, textWidth))
         return;
     
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     context->clip(contentRect);
     context->setAlpha(m_missingPluginIndicatorIsPressed ? replacementTextPressedRoundedRectOpacity : replacementTextRoundedRectOpacity);
     context->setFillColor(m_missingPluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : Color::white, style()->colorSpace());
@@ -178,7 +178,6 @@ void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, int tx, int ty)
     context->setAlpha(m_missingPluginIndicatorIsPressed ? replacementTextPressedTextOpacity : replacementTextTextOpacity);
     context->setFillColor(Color::black, style()->colorSpace());
     context->drawBidiText(font, run, FloatPoint(labelX, labelY));
-    context->restore();
 }
 
 bool RenderEmbeddedObject::getReplacementTextGeometry(int tx, int ty, FloatRect& contentRect, Path& path, FloatRect& replacementTextRect, Font& font, TextRun& run, float& textWidth)
index e13da3f..b3b84ae 100644 (file)
@@ -162,7 +162,7 @@ void RenderFieldset::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty)
     
     // Create a clipping region around the legend and paint the border as normal
     GraphicsContext* graphicsContext = paintInfo.context;
-    graphicsContext->save();
+    GraphicsContextStateSaver stateSaver(*graphicsContext);
 
     // FIXME: We need to work with "rl" and "bt" block flow directions.  In those
     // cases the legend is embedded in the right and bottom borders respectively.
@@ -178,8 +178,6 @@ void RenderFieldset::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty)
     }
 
     paintBorder(paintInfo.context, tx, ty, w, h, style());
-
-    graphicsContext->restore();
 }
 
 void RenderFieldset::paintMask(PaintInfo& paintInfo, int tx, int ty)
index 8056662..67d20b9 100644 (file)
@@ -209,12 +209,13 @@ void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, int tx, int ty)
     ASSERT(m_fileChooser);
     
     // Push a clip.
+    GraphicsContextStateSaver stateSaver(*paintInfo.context, false);
     if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds) {
         IntRect clipRect(tx + borderLeft(), ty + borderTop(),
                          width() - borderLeft() - borderRight(), height() - borderBottom() - borderTop() + buttonShadowHeight);
         if (clipRect.isEmpty())
             return;
-        paintInfo.context->save();
+        stateSaver.save();
         paintInfo.context->clip(clipRect);
     }
 
@@ -260,10 +261,6 @@ void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, int tx, int ty)
 
     // Paint the children.
     RenderBlock::paintObject(paintInfo, tx, ty);
-
-    // Pop the clip.
-    if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds)
-        paintInfo.context->restore();
 }
 
 void RenderFileUploadControl::computePreferredLogicalWidths()
index 3e6afaa..e493f3c 100644 (file)
@@ -2345,7 +2345,7 @@ void RenderLayer::paintResizer(GraphicsContext* context, int tx, int ty, const I
     // Draw a frame around the resizer (1px grey line) if there are any scrollbars present.
     // Clipping will exclude the right and bottom edges of this frame.
     if (!hasOverlayScrollbars() && (m_vBar || m_hBar)) {
-        context->save();
+        GraphicsContextStateSaver stateSaver(*context);
         context->clip(absRect);
         IntRect largerCorner = absRect;
         largerCorner.setSize(IntSize(largerCorner.width() + 1, largerCorner.height() + 1));
@@ -2353,7 +2353,6 @@ void RenderLayer::paintResizer(GraphicsContext* context, int tx, int ty, const I
         context->setStrokeThickness(1.0f);
         context->setFillColor(Color::transparent, ColorSpaceDeviceRGB);
         context->drawRect(largerCorner);
-        context->restore();
     }
 }
 
@@ -2541,14 +2540,14 @@ void RenderLayer::paintLayer(RenderLayer* rootLayer, GraphicsContext* p,
         transform.translateRight(x, y);
         
         // Apply the transform.
-        p->save();
-        p->concatCTM(transform.toAffineTransform());
+        {
+            GraphicsContextStateSaver stateSaver(*p);
+            p->concatCTM(transform.toAffineTransform());
 
-        // Now do a paint with the root layer shifted to be us.
-        paintLayer(this, p, transform.inverse().mapRect(paintDirtyRect), paintBehavior, paintingRoot, overlapTestRequests, paintFlags | PaintLayerAppliedTransform);
+            // Now do a paint with the root layer shifted to be us.
+            paintLayer(this, p, transform.inverse().mapRect(paintDirtyRect), paintBehavior, paintingRoot, overlapTestRequests, paintFlags | PaintLayerAppliedTransform);
+        }        
 
-        p->restore();
-        
         // Restore the clip.
         restoreClip(p, paintDirtyRect, clipRect);
         
@@ -2750,7 +2749,7 @@ void RenderLayer::paintChildLayerIntoColumns(RenderLayer* childLayer, RenderLaye
         localDirtyRect.intersect(colRect);
         
         if (!localDirtyRect.isEmpty()) {
-            context->save();
+            GraphicsContextStateSaver stateSaver(*context);
             
             // Each strip pushes a clip, since column boxes are specified as being
             // like overflow:hidden.
@@ -2788,8 +2787,6 @@ void RenderLayer::paintChildLayerIntoColumns(RenderLayer* childLayer, RenderLaye
                                            paintingRoot, overlapTestRequests, paintFlags, 
                                            columnLayers, colIndex - 1);
             }
-
-            context->restore();
         }
 
         // Move to the next position.
index c1c7245..4d3b660 100644 (file)
@@ -1255,11 +1255,12 @@ void RenderListMarker::paint(PaintInfo& paintInfo, int tx, int ty)
 
     TextRun textRun(m_text);
 
+    GraphicsContextStateSaver stateSaver(*context, false);
     if (!style()->isHorizontalWritingMode()) {
         marker.move(-boxOrigin.x(), -boxOrigin.y());
         marker = marker.transposedRect();
         marker.move(box.x(), box.y() - logicalHeight());
-        context->save();
+        stateSaver.save();
         context->translate(marker.x(), marker.maxY());
         context->rotate(static_cast<float>(deg2rad(90.)));
         context->translate(-marker.x(), -marker.maxY());
@@ -1297,9 +1298,6 @@ void RenderListMarker::paint(PaintInfo& paintInfo, int tx, int ty)
             context->drawText(style()->font(), textRun, textOrigin + IntSize(width, 0));
         }
     }
-    
-    if (!style()->isHorizontalWritingMode())
-        context->restore();
 }
 
 void RenderListMarker::layout()
index 928b5b8..eebaa7d 100644 (file)
@@ -106,7 +106,8 @@ void RenderMediaControls::adjustMediaSliderThumbSize(RenderObject* o)
 bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
 {
     static const int themeStyle = WKMediaControllerThemeQuickTime;
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
+
     switch (part) {
         case MediaFullscreenButton:
             wkDrawMediaUIPart(WKMediaUIPartFullscreenButton, themeStyle, paintInfo.context->platformContext(), r, determineState(o));
@@ -173,7 +174,6 @@ bool RenderMediaControls::paintMediaControlsPart(MediaControlElementType part, R
             ASSERT_NOT_REACHED();
             break;
     }
-    paintInfo.context->restore();
 
     return false;
 }
index f8a3899..4635642 100644 (file)
@@ -988,15 +988,13 @@ void RenderTableCell::paintBackgroundsBehindCell(PaintInfo& paintInfo, int tx, i
         // We have to clip here because the background would paint
         // on top of the borders otherwise.  This only matters for cells and rows.
         bool shouldClip = backgroundObject->hasLayer() && (backgroundObject == this || backgroundObject == parent()) && tableElt->collapseBorders();
+        GraphicsContextStateSaver stateSaver(*paintInfo.context, shouldClip);
         if (shouldClip) {
             IntRect clipRect(tx + borderLeft(), ty + borderTop(),
                 w - borderLeft() - borderRight(), h - borderTop() - borderBottom());
-            paintInfo.context->save();
             paintInfo.context->clip(clipRect);
         }
         paintFillLayers(paintInfo, c, bgLayer, tx, ty, w, h, BackgroundBleedNone, CompositeSourceOver, backgroundObject);
-        if (shouldClip)
-            paintInfo.context->restore();
     }
 }
 
index 8149f6c..212e71e 100644 (file)
@@ -626,8 +626,7 @@ void RenderTextControl::paintPlaceholder(PaintInfo& paintInfo, int tx, int ty)
     if (clipRect.isEmpty())
         return;
     
-    paintInfo.context->save();
-    
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     paintInfo.context->clip(clipRect);
     
     RefPtr<RenderStyle> placeholderStyle = getCachedPseudoStyle(INPUT_PLACEHOLDER);
@@ -650,7 +649,6 @@ void RenderTextControl::paintPlaceholder(PaintInfo& paintInfo, int tx, int ty)
         
         paintInfo.context->drawBidiText(placeholderStyle->font(), textRun, textPoint);
     }
-    paintInfo.context->restore();    
 }
 
 void RenderTextControl::paintObject(PaintInfo& paintInfo, int tx, int ty)
index a6f999a..fb5b930 100644 (file)
@@ -786,7 +786,7 @@ bool RenderThemeMac::paintMenuList(RenderObject* o, const PaintInfo& paintInfo,
     if (r.width() >= minimumMenuListSize(o->style()))
         inflatedRect = inflateRect(inflatedRect, size, popupButtonMargins(), zoomLevel);
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     
 #ifndef BUILDING_ON_TIGER
     // On Leopard, the cell will draw outside of the given rect, so we have to clip to the rect
@@ -804,8 +804,6 @@ bool RenderThemeMac::paintMenuList(RenderObject* o, const PaintInfo& paintInfo,
     [popupButton drawWithFrame:inflatedRect inView:documentViewFor(o)];
     [popupButton setControlView:nil];
 
-    paintInfo.context->restore();
-
     return false;
 }
 
@@ -831,11 +829,10 @@ bool RenderThemeMac::paintMeter(RenderObject* renderObject, const PaintInfo& pai
     LocalCurrentGraphicsContext localContext(paintInfo.context);
 
     NSLevelIndicatorCell* cell = levelIndicatorFor(toRenderMeter(renderObject));
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
+
     [cell drawWithFrame:rect inView:documentViewFor(renderObject)];
     [cell setControlView:nil];
-    paintInfo.context->restore();
-
     return false;
 }
 
@@ -955,7 +952,7 @@ bool RenderThemeMac::paintProgressBar(RenderObject* renderObject, const PaintInf
 
     HIThemeDrawTrack(&trackInfo, 0, imageBuffer->context()->platformContext(), kHIThemeOrientationNormal);
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
     if (!renderProgress->style()->isLeftToRightDirection()) {
         paintInfo.context->translate(2 * rect.x() + rect.width(), 0);
@@ -963,8 +960,6 @@ bool RenderThemeMac::paintProgressBar(RenderObject* renderObject, const PaintInf
     }
     
     paintInfo.context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, rect.location());
-
-    paintInfo.context->restore();
     return false;
 }    
 #endif
@@ -1028,7 +1023,7 @@ void RenderThemeMac::paintMenuListButtonGradients(RenderObject* o, const PaintIn
 
     CGContextRef context = paintInfo.context->platformContext();
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
     RoundedIntRect border = o->style()->getRoundedBorderFor(r);
     int radius = border.radii().topLeft().width();
@@ -1052,34 +1047,35 @@ void RenderThemeMac::paintMenuListButtonGradients(RenderObject* o, const PaintIn
     RetainPtr<CGShadingRef> leftShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(r.x(),  r.y()), CGPointMake(r.x() + radius, r.y()), mainFunction.get(), false, false));
 
     RetainPtr<CGShadingRef> rightShading(AdoptCF, CGShadingCreateAxial(cspace, CGPointMake(r.maxX(),  r.y()), CGPointMake(r.maxX() - radius, r.y()), mainFunction.get(), false, false));
-    paintInfo.context->save();
-    CGContextClipToRect(context, r);
-    paintInfo.context->addRoundedRectClip(border);
-    CGContextDrawShading(context, mainShading.get());
-    paintInfo.context->restore();
-
-    paintInfo.context->save();
-    CGContextClipToRect(context, topGradient);
-    paintInfo.context->addRoundedRectClip(RoundedIntRect(enclosingIntRect(topGradient), border.radii().topLeft(), border.radii().topRight(), IntSize(), IntSize()));
-    CGContextDrawShading(context, topShading.get());
-    paintInfo.context->restore();
 
+    {
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
+        CGContextClipToRect(context, r);
+        paintInfo.context->addRoundedRectClip(border);
+        CGContextDrawShading(context, mainShading.get());
+    }
+    
+    {
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
+        CGContextClipToRect(context, topGradient);
+        paintInfo.context->addRoundedRectClip(RoundedIntRect(enclosingIntRect(topGradient), border.radii().topLeft(), border.radii().topRight(), IntSize(), IntSize()));
+        CGContextDrawShading(context, topShading.get());
+    }
+    
     if (!bottomGradient.isEmpty()) {
-        paintInfo.context->save();
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
         CGContextClipToRect(context, bottomGradient);
         paintInfo.context->addRoundedRectClip(RoundedIntRect(enclosingIntRect(bottomGradient), IntSize(), IntSize(), border.radii().bottomLeft(), border.radii().bottomRight()));
         CGContextDrawShading(context, bottomShading.get());
-        paintInfo.context->restore();
     }
 
-    paintInfo.context->save();
-    CGContextClipToRect(context, r);
-    paintInfo.context->addRoundedRectClip(border);
-    CGContextDrawShading(context, leftShading.get());
-    CGContextDrawShading(context, rightShading.get());
-    paintInfo.context->restore();
-
-    paintInfo.context->restore();
+    {
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
+        CGContextClipToRect(context, r);
+        paintInfo.context->addRoundedRectClip(border);
+        CGContextDrawShading(context, leftShading.get());
+        CGContextDrawShading(context, rightShading.get());
+    }
 }
 
 bool RenderThemeMac::paintMenuListButton(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
@@ -1102,7 +1098,7 @@ bool RenderThemeMac::paintMenuListButton(RenderObject* o, const PaintInfo& paint
     if (bounds.width() < arrowWidth + arrowPaddingLeft * o->style()->effectiveZoom())
         return false;
     
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
     paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), o->style()->colorSpace());
     paintInfo.context->setStrokeStyle(NoStroke);
@@ -1140,8 +1136,6 @@ bool RenderThemeMac::paintMenuListButton(RenderObject* o, const PaintInfo& paint
     paintInfo.context->setStrokeColor(rightSeparatorColor, ColorSpaceDeviceRGB);
     paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()),
                                 IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.maxY()));
-
-    paintInfo.context->restore();
     return false;
 }
 
@@ -1283,7 +1277,7 @@ bool RenderThemeMac::paintSliderTrack(RenderObject* o, const PaintInfo& paintInf
     CGContextRef context = paintInfo.context->platformContext();
     CGColorSpaceRef cspace = deviceRGBColorSpaceRef();
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     CGContextClipToRect(context, bounds);
 
     struct CGFunctionCallbacks mainCallbacks = { 0, TrackGradientInterpolate, NULL };
@@ -1297,7 +1291,6 @@ bool RenderThemeMac::paintSliderTrack(RenderObject* o, const PaintInfo& paintInf
     IntSize radius(trackRadius, trackRadius);
     paintInfo.context->addRoundedRectClip(RoundedIntRect(bounds, radius, radius, radius, radius));
     CGContextDrawShading(context, mainShading.get());
-    paintInfo.context->restore();
     
     return false;
 }
@@ -1350,7 +1343,7 @@ bool RenderThemeMac::paintSliderThumb(RenderObject* o, const PaintInfo& paintInf
     if (o->style()->appearance() == SliderThumbVerticalPart)
         bounds.setHeight(bounds.height() + verticalSliderHeightPadding * o->style()->effectiveZoom());
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     float zoomLevel = o->style()->effectiveZoom();
     
     FloatRect unzoomedRect = bounds;
@@ -1365,8 +1358,6 @@ bool RenderThemeMac::paintSliderThumb(RenderObject* o, const PaintInfo& paintInf
     [sliderThumbCell drawWithFrame:unzoomedRect inView:documentViewFor(o)];
     [sliderThumbCell setControlView:nil];
 
-    paintInfo.context->restore();
-
     return false;
 }
 
@@ -1377,7 +1368,7 @@ bool RenderThemeMac::paintSearchField(RenderObject* o, const PaintInfo& paintInf
 
     setSearchCellState(o, r);
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
     float zoomLevel = o->style()->effectiveZoom();
 
@@ -1403,8 +1394,6 @@ bool RenderThemeMac::paintSearchField(RenderObject* o, const PaintInfo& paintInf
     [search setControlView:nil];
     [search resetSearchButtonCell];
 
-    paintInfo.context->restore();
-
     return false;
 }
 
@@ -1481,7 +1470,7 @@ bool RenderThemeMac::paintSearchFieldCancelButton(RenderObject* o, const PaintIn
     updateActiveState([search cancelButtonCell], o);
     updatePressedState([search cancelButtonCell], o);
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
 
     float zoomLevel = o->style()->effectiveZoom();
 
@@ -1509,8 +1498,6 @@ bool RenderThemeMac::paintSearchFieldCancelButton(RenderObject* o, const PaintIn
 
     [[search cancelButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(o)];
     [[search cancelButtonCell] setControlView:nil];
-
-    paintInfo.context->restore();
     return false;
 }
 
@@ -1605,8 +1592,7 @@ bool RenderThemeMac::paintSearchFieldResultsButton(RenderObject* o, const PaintI
     if (![search searchMenuTemplate])
         [search setSearchMenuTemplate:searchMenuTemplate()];
 
-    paintInfo.context->save();
-
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     float zoomLevel = o->style()->effectiveZoom();
 
     FloatRect localBounds = [search searchButtonRectForBounds:NSRect(input->renderBox()->borderBoxRect())];
@@ -1624,8 +1610,6 @@ bool RenderThemeMac::paintSearchFieldResultsButton(RenderObject* o, const PaintI
     [[search searchButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(o)];
     [[search searchButtonCell] setControlView:nil];
     
-    paintInfo.context->restore();
-
     return false;
 }
 
@@ -1816,12 +1800,10 @@ bool RenderThemeMac::paintMediaSliderTrack(RenderObject* o, const PaintInfo& pai
     if (isnan(duration))
         duration = 0;
  
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
     wkDrawMediaSliderTrack(mediaControllerTheme(), paintInfo.context->platformContext(), unzoomedRect, 
         timeLoaded, currentTime, duration, getMediaUIPartStateFlags(node));
-    
-    paintInfo.context->restore();
     return false;
 }
 
@@ -1891,10 +1873,9 @@ bool RenderThemeMac::paintMediaCurrentTime(RenderObject* o, const PaintInfo& pai
     if (!node)
         return false;
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
     wkDrawMediaUIPart(MediaCurrentTimeDisplay, mediaControllerTheme(), paintInfo.context->platformContext(), unzoomedRect, getMediaUIPartStateFlags(node));
-    paintInfo.context->restore();
     return false;
 }
 
@@ -1904,10 +1885,9 @@ bool RenderThemeMac::paintMediaTimeRemaining(RenderObject* o, const PaintInfo& p
     if (!node)
         return false;
 
-    paintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*paintInfo.context);
     FloatRect unzoomedRect = getUnzoomedRectAndAdjustCurrentContext(o, paintInfo, r);
     wkDrawMediaUIPart(MediaTimeRemainingDisplay, mediaControllerTheme(), paintInfo.context->platformContext(), unzoomedRect, getMediaUIPartStateFlags(node));
-    paintInfo.context->restore();
     return false;
 }
 
index 14e7656..0440d7c 100644 (file)
@@ -85,7 +85,7 @@ void RenderMathMLBlock::paint(PaintInfo& info, int tx, int ty)
     tx += x();
     ty += y();
     
-    info.context->save();
+    GraphicsContextStateSaver stateSaver(*info.context);
     
     info.context->setStrokeThickness(1.0f);
     info.context->setStrokeStyle(SolidStroke);
@@ -107,9 +107,6 @@ void RenderMathMLBlock::paint(PaintInfo& info, int tx, int ty)
     info.context->setStrokeColor(Color(255, 0, 0), ColorSpaceSRGB);
     
     info.context->drawLine(IntPoint(tx, ty + baseline), IntPoint(tx + offsetWidth(), ty + baseline));
-    
-    info.context->restore();
-    
 }
 #endif // ENABLE(DEBUG_MATH_LAYOUT)
 
index 48d3f39..1f52a12 100644 (file)
@@ -156,15 +156,13 @@ void RenderMathMLFraction::paint(PaintInfo& info, int tx, int ty)
     tx += x();
     ty += y() + verticalOffset;
     
-    info.context->save();
+    GraphicsContextStateSaver stateSaver(*info.context);
     
     info.context->setStrokeThickness(m_lineThickness);
     info.context->setStrokeStyle(SolidStroke);
     info.context->setStrokeColor(style()->visitedDependentColor(CSSPropertyColor), ColorSpaceSRGB);
     
     info.context->drawLine(IntPoint(tx, ty), IntPoint(tx + offsetWidth(), ty));
-    
-    info.context->restore();
 }
 
 int RenderMathMLFraction::baselinePosition(FontBaseline, bool firstLine, LineDirectionMode lineDirection, LinePositionMode linePositionMode) const
index 51046f8..60bd69b 100644 (file)
@@ -148,7 +148,7 @@ void RenderMathMLRoot::paint(PaintInfo& info, int tx, int ty)
     FloatPoint topLeft(start - gRadicalTopLeftPointXPos * frontWidth , ty + gRadicalTopLeftPointYPos * maxHeight);
     FloatPoint leftEnd(start - frontWidth , topLeft.y() + gRadicalLeftEndYShift * style()->fontSize());
     
-    info.context->save();
+    GraphicsContextStateSaver stateSaver(*info.context);
     
     info.context->setStrokeThickness(gRadicalLineThickness * style()->fontSize());
     info.context->setStrokeStyle(SolidStroke);
@@ -170,7 +170,7 @@ void RenderMathMLRoot::paint(PaintInfo& info, int tx, int ty)
     
     info.context->strokePath(root);
     
-    info.context->save();
+    GraphicsContextStateSaver maskStateSaver(*info.context);
     
     // Build a mask to draw the thick part of the root.
     Path mask;
@@ -191,11 +191,6 @@ void RenderMathMLRoot::paint(PaintInfo& info, int tx, int ty)
     line.addLineTo(topLeft);
 
     info.context->strokePath(line);
-    
-    info.context->restore();
-    
-    info.context->restore();
-
 }
 
 void RenderMathMLRoot::layout()
index 3f99e6d..8f69019 100644 (file)
@@ -114,7 +114,7 @@ void RenderMathMLSquareRoot::paint(PaintInfo& info, int tx, int ty)
     FloatPoint topLeft(tx + frontWidth * gRadicalTopLeftPointXPos , ty + gRadicalTopLeftPointYPos * maxHeight);
     FloatPoint leftEnd(tx , topLeft.y() + gRadicalLeftEndYShift * style()->fontSize());
     
-    info.context->save();
+    GraphicsContextStateSaver stateSaver(*info.context);
     
     info.context->setStrokeThickness(gRadicalLineThickness * style()->fontSize());
     info.context->setStrokeStyle(SolidStroke);
@@ -136,7 +136,7 @@ void RenderMathMLSquareRoot::paint(PaintInfo& info, int tx, int ty)
 
     info.context->strokePath(root);
     
-    info.context->save();
+    GraphicsContextStateSaver maskStateSaver(*info.context);
     
     // Build a mask to draw the thick part of the root.
     Path mask;
@@ -157,10 +157,6 @@ void RenderMathMLSquareRoot::paint(PaintInfo& info, int tx, int ty)
     line.addLineTo(topLeft);
     
     info.context->strokePath(line);
-    
-    info.context->restore();
-    
-    info.context->restore();
 }
 
 void RenderMathMLSquareRoot::layout()
index 1897f53..d3c481e 100644 (file)
@@ -105,28 +105,28 @@ void RenderSVGContainer::paint(PaintInfo& paintInfo, int, int)
         return;
 
     PaintInfo childPaintInfo(paintInfo);
-    childPaintInfo.context->save();
+    {
+        GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
 
-    // Let the RenderSVGViewportContainer subclass clip if necessary
-    applyViewportClip(childPaintInfo);
+        // Let the RenderSVGViewportContainer subclass clip if necessary
+        applyViewportClip(childPaintInfo);
 
-    childPaintInfo.applyTransform(localToParentTransform());
+        childPaintInfo.applyTransform(localToParentTransform());
 
-    bool continueRendering = true;
-    if (childPaintInfo.phase == PaintPhaseForeground)
-        continueRendering = SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo);
+        bool continueRendering = true;
+        if (childPaintInfo.phase == PaintPhaseForeground)
+            continueRendering = SVGRenderSupport::prepareToRenderSVGContent(this, childPaintInfo);
 
-    if (continueRendering) {
-        childPaintInfo.updatePaintingRootForChildren(this);
-        for (RenderObject* child = firstChild(); child; child = child->nextSibling())
-            child->paint(childPaintInfo, 0, 0);
-    }
-
-    if (paintInfo.phase == PaintPhaseForeground)
-        SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, paintInfo.context);
-
-    childPaintInfo.context->restore();
+        if (continueRendering) {
+            childPaintInfo.updatePaintingRootForChildren(this);
+            for (RenderObject* child = firstChild(); child; child = child->nextSibling())
+                child->paint(childPaintInfo, 0, 0);
+        }
 
+        if (paintInfo.phase == PaintPhaseForeground)
+            SVGRenderSupport::finishRenderSVGContent(this, childPaintInfo, paintInfo.context);
+    }
+    
     // FIXME: This really should be drawn from local coordinates, but currently we hack it
     // to avoid our clip killing our outline rect.  Thus we translate our
     // outline rect into parent coords before drawing.
index 200fab2..6f32bd4 100644 (file)
@@ -50,7 +50,7 @@ void RenderSVGForeignObject::paint(PaintInfo& paintInfo, int, int)
         return;
 
     PaintInfo childPaintInfo(paintInfo);
-    childPaintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
     childPaintInfo.applyTransform(localTransform());
 
     if (SVGRenderSupport::isOverflowHidden(this))
@@ -64,8 +64,6 @@ void RenderSVGForeignObject::paint(PaintInfo& paintInfo, int, int)
 
     if (opacity < 1.0f)
         childPaintInfo.context->endTransparencyLayer();
-
-    childPaintInfo.context->restore();
 }
 
 IntRect RenderSVGForeignObject::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer)
index 81a5cea..5fff7f7 100644 (file)
@@ -115,7 +115,7 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, int, int)
     PaintInfo childPaintInfo(paintInfo);
     bool drawsOutline = style()->outlineWidth() && (childPaintInfo.phase == PaintPhaseOutline || childPaintInfo.phase == PaintPhaseSelfOutline);
     if (drawsOutline || childPaintInfo.phase == PaintPhaseForeground) {
-        childPaintInfo.context->save();
+        GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
         childPaintInfo.applyTransform(m_localTransform);
 
         if (childPaintInfo.phase == PaintPhaseForeground) {
@@ -139,8 +139,6 @@ void RenderSVGImage::paint(PaintInfo& paintInfo, int, int)
         if (drawsOutline)
             paintOutline(childPaintInfo.context, static_cast<int>(boundingBox.x()), static_cast<int>(boundingBox.y()),
                 static_cast<int>(boundingBox.width()), static_cast<int>(boundingBox.height()));
-        
-        childPaintInfo.context->restore();
     }
 }
 
index cc7c86e..6216de8 100644 (file)
@@ -172,7 +172,8 @@ void RenderSVGPath::fillAndStrokePath(GraphicsContext* context)
     Path path;
 
     bool nonScalingStroke = style->svgStyle()->vectorEffect() == VE_NON_SCALING_STROKE;
-    bool restoreContext = false;
+
+    GraphicsContextStateSaver stateSaver(*context, false);
     if (nonScalingStroke) {
         SVGStyledTransformableElement* element = static_cast<SVGStyledTransformableElement*>(node());
         AffineTransform nonScalingStrokeTransform = element->getScreenCTM(SVGLocatable::DisallowStyleUpdate);
@@ -182,9 +183,8 @@ void RenderSVGPath::fillAndStrokePath(GraphicsContext* context)
         path = m_path;
         path.transform(nonScalingStrokeTransform);
 
-        context->save();
+        stateSaver.save();
         context->concatCTM(nonScalingStrokeTransform.inverse());
-        restoreContext = true;
     }
 
     if (strokePaintingResource->applyResource(this, style, context, ApplyToStrokeMode))
@@ -195,9 +195,6 @@ void RenderSVGPath::fillAndStrokePath(GraphicsContext* context)
         if (fallbackResource->applyResource(this, style, context, ApplyToStrokeMode))
             fallbackResource->postApplyResource(this, context, ApplyToStrokeMode, nonScalingStroke ? &path : &m_path);
     }
-
-    if (restoreContext)
-        context->restore();
 }
 
 void RenderSVGPath::paint(PaintInfo& paintInfo, int, int)
@@ -212,7 +209,7 @@ void RenderSVGPath::paint(PaintInfo& paintInfo, int, int)
     PaintInfo childPaintInfo(paintInfo);
     bool drawsOutline = style()->outlineWidth() && (childPaintInfo.phase == PaintPhaseOutline || childPaintInfo.phase == PaintPhaseSelfOutline);
     if (drawsOutline || childPaintInfo.phase == PaintPhaseForeground) {
-        childPaintInfo.context->save();
+        GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
         childPaintInfo.applyTransform(m_localTransform);
 
         if (childPaintInfo.phase == PaintPhaseForeground) {
@@ -235,8 +232,6 @@ void RenderSVGPath::paint(PaintInfo& paintInfo, int, int)
         if (drawsOutline)
             paintOutline(childPaintInfo.context, static_cast<int>(boundingBox.x()), static_cast<int>(boundingBox.y()),
                 static_cast<int>(boundingBox.width()), static_cast<int>(boundingBox.height()));
-        
-        childPaintInfo.context->restore();
     }
 }
 
index 245a859..238c096 100644 (file)
@@ -183,22 +183,19 @@ bool RenderSVGResourceClipper::applyClippingToContext(RenderObject* object, cons
         ASSERT(maskContext);
 
         // The save/restore pair is needed for clipToImageBuffer - it doesn't work without it on non-Cg platforms.
-        maskContext->save();
+        GraphicsContextStateSaver stateSaver(*maskContext);
         maskContext->translate(-clampedAbsoluteTargetRect.x(), -clampedAbsoluteTargetRect.y());
         maskContext->concatCTM(absoluteTransform);
 
         // clipPath can also be clipped by another clipPath.
         if (SVGResources* resources = SVGResourcesCache::cachedResourcesForRenderObject(this)) {
             if (RenderSVGResourceClipper* clipper = resources->clipper()) {
-                if (!clipper->applyClippingToContext(this, objectBoundingBox, repaintRect, maskContext)) {
-                    maskContext->restore();
+                if (!clipper->applyClippingToContext(this, objectBoundingBox, repaintRect, maskContext))
                     return false;
-                }
             }
         }
 
         drawContentIntoMaskImage(clipperData, objectBoundingBox);
-        maskContext->restore();
     }
 
     if (!clipperData->clipMaskImage)
index fcad27f..57f8e3c 100644 (file)
@@ -130,10 +130,9 @@ AffineTransform RenderSVGResourceMarker::markerTransformation(const FloatPoint&
 void RenderSVGResourceMarker::draw(PaintInfo& paintInfo, const AffineTransform& transform)
 {
     PaintInfo info(paintInfo);
-    info.context->save();
+    GraphicsContextStateSaver stateSaver(*info.context);
     info.applyTransform(transform);
     RenderSVGContainer::paint(info, 0, 0);
-    info.context->restore();
 }
 
 AffineTransform RenderSVGResourceMarker::markerContentTransformation(const AffineTransform& contentTransformation, const FloatPoint& origin, float strokeWidth) const
index 7af6cc6..1b8cbe3 100644 (file)
@@ -240,10 +240,9 @@ void RenderSVGText::paint(PaintInfo& paintInfo, int, int)
          return;
 
     PaintInfo blockInfo(paintInfo);
-    blockInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*blockInfo.context);
     blockInfo.applyTransform(localToParentTransform());
     RenderBlock::paint(blockInfo, 0, 0);
-    blockInfo.context->restore();
 }
 
 FloatRect RenderSVGText::strokeBoundingBox() const
index 85707da..1d0043b 100644 (file)
@@ -57,7 +57,7 @@ void SVGInlineFlowBox::paint(PaintInfo& paintInfo, int, int, int, int)
     ASSERT(boxRenderer);
 
     PaintInfo childPaintInfo(paintInfo);
-    childPaintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
 
     if (SVGRenderSupport::prepareToRenderSVGContent(boxRenderer, childPaintInfo)) {
         for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
@@ -69,7 +69,6 @@ void SVGInlineFlowBox::paint(PaintInfo& paintInfo, int, int, int, int)
     }
 
     SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
-    childPaintInfo.context->restore();
 }
 
 IntRect SVGInlineFlowBox::calculateBoundaries() const
index bc550a6..dbdef07 100644 (file)
@@ -226,7 +226,7 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
         if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
             continue;
 
-        paintInfo.context->save();
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
         fragment.buildFragmentTransform(fragmentTransform);
         if (!fragmentTransform.isIdentity())
             paintInfo.context->concatCTM(fragmentTransform);
@@ -235,7 +235,6 @@ void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
         paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor, style->colorSpace());
 
         m_paintingResourceMode = ApplyToDefaultMode;
-        paintInfo.context->restore();
     }
 
     ASSERT(!m_paintingResource);
@@ -296,7 +295,7 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, int, int, int, int)
         SVGTextFragment& fragment = m_textFragments.at(i);
         ASSERT(!m_paintingResource);
 
-        paintInfo.context->save();
+        GraphicsContextStateSaver stateSaver(*paintInfo.context);
         fragment.buildFragmentTransform(fragmentTransform);
         if (!fragmentTransform.isIdentity())
             paintInfo.context->concatCTM(fragmentTransform);
@@ -325,7 +324,6 @@ void SVGInlineTextBox::paint(PaintInfo& paintInfo, int, int, int, int)
             paintDecoration(paintInfo.context, LINE_THROUGH, fragment);
 
         m_paintingResourceMode = ApplyToDefaultMode;
-        paintInfo.context->restore();
     }
 
     ASSERT(!m_paintingResource);
@@ -568,7 +566,7 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextD
     float width = fragment.width;
     const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     if (scalingFactor != 1) {
         width *= scalingFactor;
         decorationOrigin.scale(scalingFactor, scalingFactor);
@@ -587,8 +585,6 @@ void SVGInlineTextBox::paintDecorationWithStyle(GraphicsContext* context, ETextD
 
     if (acquirePaintingResource(context, scalingFactor, decorationRenderer, decorationStyle))
         releasePaintingResource(context, &path);
-
-    context->restore();
 }
 
 void SVGInlineTextBox::paintTextWithShadows(GraphicsContext* context, RenderStyle* style, TextRun& textRun, const SVGTextFragment& fragment, int startPosition, int endPosition)
index cc6cb75..5727511 100644 (file)
@@ -56,7 +56,7 @@ void SVGRootInlineBox::paint(PaintInfo& paintInfo, int, int, int, int)
         }
     }
 
-    childPaintInfo.context->save();
+    GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
 
     if (SVGRenderSupport::prepareToRenderSVGContent(boxRenderer, childPaintInfo)) {
         for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
@@ -68,7 +68,6 @@ void SVGRootInlineBox::paint(PaintInfo& paintInfo, int, int, int, int)
     }
 
     SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
-    childPaintInfo.context->restore();
 }
 
 void SVGRootInlineBox::computePerCharacterLayoutInformation()
index f3a0dab..06095fe 100644 (file)
@@ -380,7 +380,7 @@ void Font::drawTextUsingSVGFont(GraphicsContext* context, const TextRun& run,
             if (identifier.isValid) {
                 // FIXME: Support arbitary SVG content as glyph (currently limited to <glyph d="..."> situations).
                 if (!identifier.pathData.isEmpty()) {
-                    context->save();
+                    GraphicsContextStateSaver stateSaver(*context);
 
                     if (isVerticalText) {
                         glyphOrigin.setX(identifier.verticalOriginX * scale);
@@ -401,8 +401,6 @@ void Font::drawTextUsingSVGFont(GraphicsContext* context, const TextRun& run,
                         }
                         activePaintingResource->postApplyResource(referencingRenderObjectParent, context, resourceMode, &glyphPath);
                     }
-
-                    context->restore();
                 }
 
                 if (isVerticalText)
index 85c00f3..71806f3 100644 (file)
@@ -182,7 +182,7 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
 
     FrameView* view = m_page->mainFrame()->view();
 
-    context->save();
+    GraphicsContextStateSaver stateSaver(*context);
     context->setCompositeOperation(compositeOp);
     context->clip(enclosingIntRect(dstRect));
     if (compositeOp != CompositeSourceOver)
@@ -208,7 +208,7 @@ void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const Fl
     if (compositeOp != CompositeSourceOver)
         context->endTransparencyLayer();
 
-    context->restore();
+    stateSaver.restore();
 
     if (imageObserver())
         imageObserver()->didDraw(this);