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
+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.
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
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
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;
// 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
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());
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,
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;
if (!m_layerImage)
return;
- graphicsContext->save();
+ GraphicsContextStateSaver stateSaver(*graphicsContext);
IntSize bufferSize = m_layerImage->size();
if (bufferSize != m_layerSize) {
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)
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));
}
blurShadowBuffer(expandedIntSize(m_layerSize));
-
- shadowContext->restore();
ScratchBuffer::shared().setLastShadowValues(m_blurRadius, Color::black, ColorSpaceDeviceRGB, bufferRelativeShadowedRect, radii);
}
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));
blurShadowBuffer(expandedIntSize(m_layerSize));
- shadowContext->restore();
-
ScratchBuffer::shared().setLastInsetShadowValues(m_blurRadius, Color::black, ColorSpaceDeviceRGB, bufferRelativeRect, bufferRelativeHoleRect, holeRadii);
}
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);
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);
shadowContext->fillPath(path);
blurAndColorShadowBuffer(templateSize);
- shadowContext->restore();
ScratchBuffer::shared().setLastInsetShadowValues(m_blurRadius, m_color, m_colorSpace, templateBounds, templateHole, radii);
}
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);
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);
}
blurAndColorShadowBuffer(templateSize);
- shadowContext->restore();
ScratchBuffer::shared().setLastShadowValues(m_blurRadius, m_color, m_colorSpace, templateShadow, radii);
}
drawLayerPieces(graphicsContext, shadowBounds, radii, roundedRadius, templateSize, OuterShadow);
- graphicsContext->restore();
-
m_layerImage = 0;
ScratchBuffer::shared().scheduleScratchBufferPurge();
}
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();
}
}
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;
}
return;
CGContextRef context = ctxt->platformContext();
- ctxt->save();
+ GraphicsContextStateSaver stateSaver(*ctxt);
bool shouldUseSubimage = false;
// Draw the image.
CGContextDrawImage(context, adjustedDestRect, image.get());
- ctxt->restore();
+ stateSaver.restore();
if (imageObserver())
imageObserver()->didDraw(this);
return;
CGContextRef context = ctxt->platformContext();
- ctxt->save();
+ GraphicsContextStateSaver stateSaver(*ctxt);
CGContextClipToRect(context, destRect);
ctxt->setCompositeOperation(op);
CGContextTranslateCTM(context, destRect.x(), destRect.y() + destRect.height());
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));
}
#endif
- ctxt->restore();
+ stateSaver.restore();
if (imageObserver())
imageObserver()->didDraw(this);
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);
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);
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()
[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);
}
#endif
- context->restore();
END_BLOCK_OBJC_EXCEPTIONS;
[m_objcObserver.get() setDelayCallbacks:NO];
}
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);
scrollbar->frameRect());
scrollAnimator->setIsDrawingIntoLayer(false);
-
- context->restore();
return true;
#endif
NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor);
LocalCurrentGraphicsContext localContext(context);
- context->save();
+ GraphicsContextStateSaver stateSaver(*context);
NSControlSize controlSize = [checkboxCell controlSize];
IntSize zoomedSize = checkboxSizes()[controlSize];
[checkboxCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
[checkboxCell setControlView:nil];
-
- context->restore();
END_BLOCK_OBJC_EXCEPTIONS
}
NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor);
LocalCurrentGraphicsContext localContext(context);
- context->save();
+ GraphicsContextStateSaver stateSaver(*context);
NSControlSize controlSize = [radioCell controlSize];
IntSize zoomedSize = radioSizes()[controlSize];
[radioCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
[radioCell setControlView:nil];
END_BLOCK_OBJC_EXCEPTIONS
-
- context->restore();
}
// Buttons
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);
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.
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)
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();
}
}
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();
}
}
}
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)
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) {
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());
if (combinedText)
context->concatCTM(rotation(boxRect, Counterclockwise));
}
- if (selectionStrokeWidth > 0)
- context->restore();
}
// Paint decorations
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
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)
if (sPos >= ePos)
return;
- context->save();
+ GraphicsContextStateSaver stateSaver(*context);
Color c = Color(225, 221, 85);
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)
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));
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();
}
}
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.
paintFloats(info, finalX, finalY, paintInfo.phase == PaintPhaseSelection || paintInfo.phase == PaintPhaseTextClip);
else
paintContents(info, finalX, finalY);
-
- context->restore();
}
int blockDelta = (isHorizontalWritingMode() ? colRect.height() : colRect.width());
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()) {
layer->addBlockSelectionGapsBounds(gapRectsBounds);
}
}
- paintInfo.context->restore();
}
}
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);
}
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)
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.
}
// The mask has been created. Now we just need to clip to it.
- backgroundClipStateSaver.saveState();
+ backgroundClipStateSaver.save();
context->clipToImageBuffer(maskImage.get(), maskRect);
}
border.includeLogicalEdges(style->getRoundedBorderFor(border.rect()).radii(),
horizontal, includeLogicalLeftEdge, includeLogicalRightEdge);
if (border.isRounded()) {
- stateSaver.saveState();
+ stateSaver.save();
graphicsContext->addRoundedRectClip(border);
}
}
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());
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)
// 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.
}
paintBorder(paintInfo.context, tx, ty, w, h, style());
-
- graphicsContext->restore();
}
void RenderFieldset::paintMask(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);
}
// Paint the children.
RenderBlock::paintObject(paintInfo, tx, ty);
-
- // Pop the clip.
- if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds)
- paintInfo.context->restore();
}
void RenderFileUploadControl::computePreferredLogicalWidths()
// 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));
context->setStrokeThickness(1.0f);
context->setFillColor(Color::transparent, ColorSpaceDeviceRGB);
context->drawRect(largerCorner);
- context->restore();
}
}
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);
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.
paintingRoot, overlapTestRequests, paintFlags,
columnLayers, colIndex - 1);
}
-
- context->restore();
}
// Move to the next position.
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());
context->drawText(style()->font(), textRun, textOrigin + IntSize(width, 0));
}
}
-
- if (!style()->isHorizontalWritingMode())
- context->restore();
}
void RenderListMarker::layout()
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));
ASSERT_NOT_REACHED();
break;
}
- paintInfo.context->restore();
return false;
}
// 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();
}
}
if (clipRect.isEmpty())
return;
- paintInfo.context->save();
-
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
paintInfo.context->clip(clipRect);
RefPtr<RenderStyle> placeholderStyle = getCachedPseudoStyle(INPUT_PLACEHOLDER);
paintInfo.context->drawBidiText(placeholderStyle->font(), textRun, textPoint);
}
- paintInfo.context->restore();
}
void RenderTextControl::paintObject(PaintInfo& paintInfo, int tx, int ty)
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
[popupButton drawWithFrame:inflatedRect inView:documentViewFor(o)];
[popupButton setControlView:nil];
- paintInfo.context->restore();
-
return false;
}
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;
}
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);
}
paintInfo.context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, rect.location());
-
- paintInfo.context->restore();
return false;
}
#endif
CGContextRef context = paintInfo.context->platformContext();
- paintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
RoundedIntRect border = o->style()->getRoundedBorderFor(r);
int radius = border.radii().topLeft().width();
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)
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);
paintInfo.context->setStrokeColor(rightSeparatorColor, ColorSpaceDeviceRGB);
paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()),
IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.maxY()));
-
- paintInfo.context->restore();
return false;
}
CGContextRef context = paintInfo.context->platformContext();
CGColorSpaceRef cspace = deviceRGBColorSpaceRef();
- paintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
CGContextClipToRect(context, bounds);
struct CGFunctionCallbacks mainCallbacks = { 0, TrackGradientInterpolate, NULL };
IntSize radius(trackRadius, trackRadius);
paintInfo.context->addRoundedRectClip(RoundedIntRect(bounds, radius, radius, radius, radius));
CGContextDrawShading(context, mainShading.get());
- paintInfo.context->restore();
return false;
}
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;
[sliderThumbCell drawWithFrame:unzoomedRect inView:documentViewFor(o)];
[sliderThumbCell setControlView:nil];
- paintInfo.context->restore();
-
return false;
}
setSearchCellState(o, r);
- paintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
float zoomLevel = o->style()->effectiveZoom();
[search setControlView:nil];
[search resetSearchButtonCell];
- paintInfo.context->restore();
-
return false;
}
updateActiveState([search cancelButtonCell], o);
updatePressedState([search cancelButtonCell], o);
- paintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
float zoomLevel = o->style()->effectiveZoom();
[[search cancelButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(o)];
[[search cancelButtonCell] setControlView:nil];
-
- paintInfo.context->restore();
return false;
}
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())];
[[search searchButtonCell] drawWithFrame:unzoomedRect inView:documentViewFor(o)];
[[search searchButtonCell] setControlView:nil];
- paintInfo.context->restore();
-
return false;
}
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;
}
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;
}
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;
}
tx += x();
ty += y();
- info.context->save();
+ GraphicsContextStateSaver stateSaver(*info.context);
info.context->setStrokeThickness(1.0f);
info.context->setStrokeStyle(SolidStroke);
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)
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
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);
info.context->strokePath(root);
- info.context->save();
+ GraphicsContextStateSaver maskStateSaver(*info.context);
// Build a mask to draw the thick part of the root.
Path mask;
line.addLineTo(topLeft);
info.context->strokePath(line);
-
- info.context->restore();
-
- info.context->restore();
-
}
void RenderMathMLRoot::layout()
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);
info.context->strokePath(root);
- info.context->save();
+ GraphicsContextStateSaver maskStateSaver(*info.context);
// Build a mask to draw the thick part of the root.
Path mask;
line.addLineTo(topLeft);
info.context->strokePath(line);
-
- info.context->restore();
-
- info.context->restore();
}
void RenderMathMLSquareRoot::layout()
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.
return;
PaintInfo childPaintInfo(paintInfo);
- childPaintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
childPaintInfo.applyTransform(localTransform());
if (SVGRenderSupport::isOverflowHidden(this))
if (opacity < 1.0f)
childPaintInfo.context->endTransparencyLayer();
-
- childPaintInfo.context->restore();
}
IntRect RenderSVGForeignObject::clippedOverflowRectForRepaint(RenderBoxModelObject* repaintContainer)
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) {
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();
}
}
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);
path = m_path;
path.transform(nonScalingStrokeTransform);
- context->save();
+ stateSaver.save();
context->concatCTM(nonScalingStrokeTransform.inverse());
- restoreContext = true;
}
if (strokePaintingResource->applyResource(this, style, context, ApplyToStrokeMode))
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)
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) {
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();
}
}
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)
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
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
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()) {
}
SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
- childPaintInfo.context->restore();
}
IntRect SVGInlineFlowBox::calculateBoundaries() const
if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
continue;
- paintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*paintInfo.context);
fragment.buildFragmentTransform(fragmentTransform);
if (!fragmentTransform.isIdentity())
paintInfo.context->concatCTM(fragmentTransform);
paintInfo.context->fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style), backgroundColor, style->colorSpace());
m_paintingResourceMode = ApplyToDefaultMode;
- paintInfo.context->restore();
}
ASSERT(!m_paintingResource);
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);
paintDecoration(paintInfo.context, LINE_THROUGH, fragment);
m_paintingResourceMode = ApplyToDefaultMode;
- paintInfo.context->restore();
}
ASSERT(!m_paintingResource);
float width = fragment.width;
const FontMetrics& scaledFontMetrics = scaledFont.fontMetrics();
- context->save();
+ GraphicsContextStateSaver stateSaver(*context);
if (scalingFactor != 1) {
width *= scalingFactor;
decorationOrigin.scale(scalingFactor, scalingFactor);
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)
}
}
- childPaintInfo.context->save();
+ GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
if (SVGRenderSupport::prepareToRenderSVGContent(boxRenderer, childPaintInfo)) {
for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
}
SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
- childPaintInfo.context->restore();
}
void SVGRootInlineBox::computePerCharacterLayoutInformation()
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);
}
activePaintingResource->postApplyResource(referencingRenderObjectParent, context, resourceMode, &glyphPath);
}
-
- context->restore();
}
if (isVerticalText)
FrameView* view = m_page->mainFrame()->view();
- context->save();
+ GraphicsContextStateSaver stateSaver(*context);
context->setCompositeOperation(compositeOp);
context->clip(enclosingIntRect(dstRect));
if (compositeOp != CompositeSourceOver)
if (compositeOp != CompositeSourceOver)
context->endTransparencyLayer();
- context->restore();
+ stateSaver.restore();
if (imageObserver())
imageObserver()->didDraw(this);