2010-12-10 Andreas Kling <kling@webkit.org>

        Reviewed by Eric Seidel.

        Don't do GraphicsContext save/restore just to preserve the CompositeOperator
        https://bugs.webkit.org/show_bug.cgi?id=50070

        Add GraphicsContext::compositeOperation() so we don't have to do a full
        save/restore if the only context-tainting call is setCompositeOperation().

        GraphicsContext::setCompositeOperation() now stores the op in its state
        and calls a port-specific setPlatformCompositeOperation().

        No new tests, this is an optimization.

        * platform/graphics/GraphicsContext.cpp:
        (WebCore::GraphicsContext::setCompositeOperation):
        (WebCore::GraphicsContext::compositeOperation):
        * platform/graphics/GraphicsContext.h:
        * platform/graphics/GraphicsContextPrivate.h:
        (WebCore::GraphicsContextState::GraphicsContextState):
        * platform/graphics/Image.cpp:
        (WebCore::Image::fillWithSolidColor):
        * platform/graphics/cairo/GraphicsContextCairo.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/haiku/GraphicsContextHaiku.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/mac/GraphicsContextMac.mm:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/openvg/GraphicsContextOpenVG.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/qt/GraphicsContextQt.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/skia/GraphicsContextSkia.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/skia/SkiaUtils.cpp:
        (WebCore::WebCoreCompositeToSkiaComposite):
        * platform/graphics/wince/GraphicsContextWinCE.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * platform/graphics/wx/GraphicsContextWx.cpp:
        (WebCore::GraphicsContext::setPlatformCompositeOperation):
        * rendering/RenderBoxModelObject.cpp:
        (WebCore::RenderBoxModelObject::paintFillLayerExtended):
        * rendering/RenderView.cpp:
        (WebCore::RenderView::paintBoxDecorations):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73729 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a1db5cff
2010-12-10 Andreas Kling <kling@webkit.org>
Reviewed by Eric Seidel.
Don't do GraphicsContext save/restore just to preserve the CompositeOperator
https://bugs.webkit.org/show_bug.cgi?id=50070
Add GraphicsContext::compositeOperation() so we don't have to do a full
save/restore if the only context-tainting call is setCompositeOperation().
GraphicsContext::setCompositeOperation() now stores the op in its state
and calls a port-specific setPlatformCompositeOperation().
No new tests, this is an optimization.
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::setCompositeOperation):
(WebCore::GraphicsContext::compositeOperation):
* platform/graphics/GraphicsContext.h:
* platform/graphics/GraphicsContextPrivate.h:
(WebCore::GraphicsContextState::GraphicsContextState):
* platform/graphics/Image.cpp:
(WebCore::Image::fillWithSolidColor):
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/haiku/GraphicsContextHaiku.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/mac/GraphicsContextMac.mm:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/openvg/GraphicsContextOpenVG.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/qt/GraphicsContextQt.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/skia/GraphicsContextSkia.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/skia/SkiaUtils.cpp:
(WebCore::WebCoreCompositeToSkiaComposite):
* platform/graphics/wince/GraphicsContextWinCE.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* platform/graphics/wx/GraphicsContextWx.cpp:
(WebCore::GraphicsContext::setPlatformCompositeOperation):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended):
* rendering/RenderView.cpp:
(WebCore::RenderView::paintBoxDecorations):
2010-12-10 Renata Hodovan <reni@webkit.org> 2010-12-10 Renata Hodovan <reni@webkit.org>
Reviewed by Andreas Kling. Reviewed by Andreas Kling.
......
...@@ -551,6 +551,17 @@ void GraphicsContext::fillRect(const FloatRect& rect, Generator& generator) ...@@ -551,6 +551,17 @@ void GraphicsContext::fillRect(const FloatRect& rect, Generator& generator)
generator.fill(this, rect); generator.fill(this, rect);
} }
void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation)
{
m_state.compositeOperator = compositeOperation;
setPlatformCompositeOperation(compositeOperation);
}
CompositeOperator GraphicsContext::compositeOperation() const
{
return m_state.compositeOperator;
}
#if !PLATFORM(SKIA) #if !PLATFORM(SKIA)
void GraphicsContext::setPlatformFillGradient(Gradient*) void GraphicsContext::setPlatformFillGradient(Gradient*)
{ {
......
...@@ -162,6 +162,7 @@ namespace WebCore { ...@@ -162,6 +162,7 @@ namespace WebCore {
, fillRule(RULE_NONZERO) , fillRule(RULE_NONZERO)
, strokeColorSpace(ColorSpaceDeviceRGB) , strokeColorSpace(ColorSpaceDeviceRGB)
, fillColorSpace(ColorSpaceDeviceRGB) , fillColorSpace(ColorSpaceDeviceRGB)
, compositeOperator(CompositeSourceOver)
, shouldAntialias(true) , shouldAntialias(true)
, paintingDisabled(false) , paintingDisabled(false)
, shadowsIgnoreTransforms(false) , shadowsIgnoreTransforms(false)
...@@ -194,6 +195,8 @@ namespace WebCore { ...@@ -194,6 +195,8 @@ namespace WebCore {
ColorSpace strokeColorSpace; ColorSpace strokeColorSpace;
ColorSpace fillColorSpace; ColorSpace fillColorSpace;
CompositeOperator compositeOperator;
bool shouldAntialias; bool shouldAntialias;
bool paintingDisabled; bool paintingDisabled;
bool shadowsIgnoreTransforms; bool shadowsIgnoreTransforms;
...@@ -352,6 +355,7 @@ namespace WebCore { ...@@ -352,6 +355,7 @@ namespace WebCore {
#endif #endif
void setCompositeOperation(CompositeOperator); void setCompositeOperation(CompositeOperator);
CompositeOperator compositeOperation() const;
#if PLATFORM(SKIA) #if PLATFORM(SKIA)
void beginPath(); void beginPath();
...@@ -498,6 +502,8 @@ namespace WebCore { ...@@ -498,6 +502,8 @@ namespace WebCore {
void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace); void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace);
void clearPlatformShadow(); void clearPlatformShadow();
void setPlatformCompositeOperation(CompositeOperator);
static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle&); static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle&);
GraphicsContextPlatformPrivate* m_data; GraphicsContextPlatformPrivate* m_data;
......
...@@ -81,10 +81,10 @@ void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, ...@@ -81,10 +81,10 @@ void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect,
if (color.alpha() <= 0) if (color.alpha() <= 0)
return; return;
ctxt->save(); CompositeOperator previousOperator = ctxt->compositeOperation();
ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op); ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
ctxt->fillRect(dstRect, color, styleColorSpace); ctxt->fillRect(dstRect, color, styleColorSpace);
ctxt->restore(); ctxt->setCompositeOperation(previousOperator);
} }
static inline FloatSize calculatePatternScale(const FloatRect& dstRect, const FloatRect& srcRect, Image::TileRule hRule, Image::TileRule vRule) static inline FloatSize calculatePatternScale(const FloatRect& dstRect, const FloatRect& srcRect, Image::TileRule hRule, Image::TileRule vRule)
......
...@@ -997,7 +997,7 @@ float GraphicsContext::getAlpha() ...@@ -997,7 +997,7 @@ float GraphicsContext::getAlpha()
return m_state.globalAlpha; return m_state.globalAlpha;
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
......
...@@ -1188,8 +1188,8 @@ void GraphicsContext::setPlatformShouldAntialias(bool enable) ...@@ -1188,8 +1188,8 @@ void GraphicsContext::setPlatformShouldAntialias(bool enable)
CGContextSetShouldAntialias(platformContext(), enable); CGContextSetShouldAntialias(platformContext(), enable);
} }
#ifndef BUILDING_ON_TIGER // Tiger's setCompositeOperation() is defined in GraphicsContextMac.mm. #ifndef BUILDING_ON_TIGER // Tiger's setPlatformCompositeOperation() is defined in GraphicsContextMac.mm.
void GraphicsContext::setCompositeOperation(CompositeOperator mode) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator mode)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
......
...@@ -343,7 +343,7 @@ void GraphicsContext::setAlpha(float opacity) ...@@ -343,7 +343,7 @@ void GraphicsContext::setAlpha(float opacity)
notImplemented(); notImplemented();
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
...@@ -358,7 +358,7 @@ void GraphicsContext::setCompositeOperation(CompositeOperator op) ...@@ -358,7 +358,7 @@ void GraphicsContext::setCompositeOperation(CompositeOperator op)
mode = B_OP_OVER; mode = B_OP_OVER;
break; break;
default: default:
printf("GraphicsContext::setCompositeOperation: Unsupported composite operation %s\n", printf("GraphicsContext::setPlatformCompositeOperation: Unsupported composite operation %s\n",
compositeOperatorName(op).utf8().data()); compositeOperatorName(op).utf8().data());
} }
m_data->m_view->SetDrawingMode(mode); m_data->m_view->SetDrawingMode(mode);
......
...@@ -87,8 +87,8 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int ...@@ -87,8 +87,8 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
drawFocusRingToContext(platformContext(), focusRingPath.get(), colorRef, radius); drawFocusRingToContext(platformContext(), focusRingPath.get(), colorRef, radius);
} }
#ifdef BUILDING_ON_TIGER // Post-Tiger's setCompositeOperation() is defined in GraphicsContextCG.cpp. #ifdef BUILDING_ON_TIGER // Post-Tiger's setPlatformCompositeOperation() is defined in GraphicsContextCG.cpp.
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
......
...@@ -364,7 +364,7 @@ void GraphicsContext::setAlpha(float opacity) ...@@ -364,7 +364,7 @@ void GraphicsContext::setAlpha(float opacity)
m_data->setOpacity(opacity); m_data->setOpacity(opacity);
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
......
...@@ -1130,13 +1130,17 @@ void GraphicsContext::setAlpha(float opacity) ...@@ -1130,13 +1130,17 @@ void GraphicsContext::setAlpha(float opacity)
p->setOpacity(opacity); p->setOpacity(opacity);
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
if (m_data->p()->paintEngine()->hasFeature(QPaintEngine::PorterDuff)) QPainter* painter = m_data->p();
m_data->p()->setCompositionMode(toQtCompositionMode(op));
if (!painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff))
return;
painter->setCompositionMode(toQtCompositionMode(op));
} }
void GraphicsContext::clip(const Path& path) void GraphicsContext::clip(const Path& path)
......
...@@ -926,7 +926,7 @@ void GraphicsContext::setAlpha(float alpha) ...@@ -926,7 +926,7 @@ void GraphicsContext::setAlpha(float alpha)
platformContext()->setAlpha(alpha); platformContext()->setAlpha(alpha);
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (paintingDisabled()) if (paintingDisabled())
return; return;
......
...@@ -70,7 +70,7 @@ SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op) ...@@ -70,7 +70,7 @@ SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op)
return (SkXfermode::Mode)table[i].m_xfermodeMode; return (SkXfermode::Mode)table[i].m_xfermodeMode;
} }
SkDEBUGF(("GraphicsContext::setCompositeOperation uknown CompositeOperator %d\n", op)); SkDEBUGF(("GraphicsContext::setPlatformCompositeOperation unknown CompositeOperator %d\n", op));
return SkXfermode::kSrcOver_Mode; // fall-back return SkXfermode::kSrcOver_Mode; // fall-back
} }
......
...@@ -1173,7 +1173,7 @@ void GraphicsContext::setAlpha(float alpha) ...@@ -1173,7 +1173,7 @@ void GraphicsContext::setAlpha(float alpha)
m_data->m_opacity = alpha; m_data->m_opacity = alpha;
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
notImplemented(); notImplemented();
} }
......
...@@ -442,7 +442,7 @@ void GraphicsContext::setURLForRect(const KURL&, const IntRect&) ...@@ -442,7 +442,7 @@ void GraphicsContext::setURLForRect(const KURL&, const IntRect&)
notImplemented(); notImplemented();
} }
void GraphicsContext::setCompositeOperation(CompositeOperator op) void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{ {
if (m_data->context) if (m_data->context)
{ {
......
...@@ -671,10 +671,10 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co ...@@ -671,10 +671,10 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co
if (isOpaqueRoot) { if (isOpaqueRoot) {
Color baseColor = view()->frameView()->baseBackgroundColor(); Color baseColor = view()->frameView()->baseBackgroundColor();
if (baseColor.alpha() > 0) { if (baseColor.alpha() > 0) {
context->save(); CompositeOperator previousOperator = context->compositeOperation();
context->setCompositeOperation(CompositeCopy); context->setCompositeOperation(CompositeCopy);
context->fillRect(rect, baseColor, style()->colorSpace()); context->fillRect(rect, baseColor, style()->colorSpace());
context->restore(); context->setCompositeOperation(previousOperator);
} else } else
context->clearRect(rect); context->clearRect(rect);
} }
......
...@@ -221,10 +221,10 @@ void RenderView::paintBoxDecorations(PaintInfo& paintInfo, int, int) ...@@ -221,10 +221,10 @@ void RenderView::paintBoxDecorations(PaintInfo& paintInfo, int, int)
else { else {
Color baseColor = frameView()->baseBackgroundColor(); Color baseColor = frameView()->baseBackgroundColor();
if (baseColor.alpha() > 0) { if (baseColor.alpha() > 0) {
paintInfo.context->save(); CompositeOperator previousOperator = paintInfo.context->compositeOperation();
paintInfo.context->setCompositeOperation(CompositeCopy); paintInfo.context->setCompositeOperation(CompositeCopy);
paintInfo.context->fillRect(paintInfo.rect, baseColor, style()->colorSpace()); paintInfo.context->fillRect(paintInfo.rect, baseColor, style()->colorSpace());
paintInfo.context->restore(); paintInfo.context->setCompositeOperation(previousOperator);
} else } else
paintInfo.context->clearRect(paintInfo.rect); paintInfo.context->clearRect(paintInfo.rect);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment