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>
Reviewed by Andreas Kling.
......
......@@ -551,6 +551,17 @@ void GraphicsContext::fillRect(const FloatRect& rect, Generator& generator)
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)
void GraphicsContext::setPlatformFillGradient(Gradient*)
{
......
......@@ -162,6 +162,7 @@ namespace WebCore {
, fillRule(RULE_NONZERO)
, strokeColorSpace(ColorSpaceDeviceRGB)
, fillColorSpace(ColorSpaceDeviceRGB)
, compositeOperator(CompositeSourceOver)
, shouldAntialias(true)
, paintingDisabled(false)
, shadowsIgnoreTransforms(false)
......@@ -194,6 +195,8 @@ namespace WebCore {
ColorSpace strokeColorSpace;
ColorSpace fillColorSpace;
CompositeOperator compositeOperator;
bool shouldAntialias;
bool paintingDisabled;
bool shadowsIgnoreTransforms;
......@@ -352,6 +355,7 @@ namespace WebCore {
#endif
void setCompositeOperation(CompositeOperator);
CompositeOperator compositeOperation() const;
#if PLATFORM(SKIA)
void beginPath();
......@@ -498,6 +502,8 @@ namespace WebCore {
void setPlatformShadow(const FloatSize&, float blur, const Color&, ColorSpace);
void clearPlatformShadow();
void setPlatformCompositeOperation(CompositeOperator);
static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle&);
GraphicsContextPlatformPrivate* m_data;
......
......@@ -81,10 +81,10 @@ void Image::fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect,
if (color.alpha() <= 0)
return;
ctxt->save();
CompositeOperator previousOperator = ctxt->compositeOperation();
ctxt->setCompositeOperation(!color.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
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)
......
......@@ -997,7 +997,7 @@ float GraphicsContext::getAlpha()
return m_state.globalAlpha;
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
......
......@@ -1188,8 +1188,8 @@ void GraphicsContext::setPlatformShouldAntialias(bool enable)
CGContextSetShouldAntialias(platformContext(), enable);
}
#ifndef BUILDING_ON_TIGER // Tiger's setCompositeOperation() is defined in GraphicsContextMac.mm.
void GraphicsContext::setCompositeOperation(CompositeOperator mode)
#ifndef BUILDING_ON_TIGER // Tiger's setPlatformCompositeOperation() is defined in GraphicsContextMac.mm.
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator mode)
{
if (paintingDisabled())
return;
......
......@@ -343,7 +343,7 @@ void GraphicsContext::setAlpha(float opacity)
notImplemented();
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
......@@ -358,7 +358,7 @@ void GraphicsContext::setCompositeOperation(CompositeOperator op)
mode = B_OP_OVER;
break;
default:
printf("GraphicsContext::setCompositeOperation: Unsupported composite operation %s\n",
printf("GraphicsContext::setPlatformCompositeOperation: Unsupported composite operation %s\n",
compositeOperatorName(op).utf8().data());
}
m_data->m_view->SetDrawingMode(mode);
......
......@@ -87,8 +87,8 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
drawFocusRingToContext(platformContext(), focusRingPath.get(), colorRef, radius);
}
#ifdef BUILDING_ON_TIGER // Post-Tiger's setCompositeOperation() is defined in GraphicsContextCG.cpp.
void GraphicsContext::setCompositeOperation(CompositeOperator op)
#ifdef BUILDING_ON_TIGER // Post-Tiger's setPlatformCompositeOperation() is defined in GraphicsContextCG.cpp.
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
......
......@@ -364,7 +364,7 @@ void GraphicsContext::setAlpha(float opacity)
m_data->setOpacity(opacity);
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
......
......@@ -1130,13 +1130,17 @@ void GraphicsContext::setAlpha(float opacity)
p->setOpacity(opacity);
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
if (m_data->p()->paintEngine()->hasFeature(QPaintEngine::PorterDuff))
m_data->p()->setCompositionMode(toQtCompositionMode(op));
QPainter* painter = m_data->p();
if (!painter->paintEngine()->hasFeature(QPaintEngine::PorterDuff))
return;
painter->setCompositionMode(toQtCompositionMode(op));
}
void GraphicsContext::clip(const Path& path)
......
......@@ -926,7 +926,7 @@ void GraphicsContext::setAlpha(float alpha)
platformContext()->setAlpha(alpha);
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (paintingDisabled())
return;
......
......@@ -70,7 +70,7 @@ SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op)
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
}
......
......@@ -1173,7 +1173,7 @@ void GraphicsContext::setAlpha(float alpha)
m_data->m_opacity = alpha;
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
notImplemented();
}
......
......@@ -442,7 +442,7 @@ void GraphicsContext::setURLForRect(const KURL&, const IntRect&)
notImplemented();
}
void GraphicsContext::setCompositeOperation(CompositeOperator op)
void GraphicsContext::setPlatformCompositeOperation(CompositeOperator op)
{
if (m_data->context)
{
......
......@@ -671,10 +671,10 @@ void RenderBoxModelObject::paintFillLayerExtended(const PaintInfo& paintInfo, co
if (isOpaqueRoot) {
Color baseColor = view()->frameView()->baseBackgroundColor();
if (baseColor.alpha() > 0) {
context->save();
CompositeOperator previousOperator = context->compositeOperation();
context->setCompositeOperation(CompositeCopy);
context->fillRect(rect, baseColor, style()->colorSpace());
context->restore();
context->setCompositeOperation(previousOperator);
} else
context->clearRect(rect);
}
......
......@@ -221,10 +221,10 @@ void RenderView::paintBoxDecorations(PaintInfo& paintInfo, int, int)
else {
Color baseColor = frameView()->baseBackgroundColor();
if (baseColor.alpha() > 0) {
paintInfo.context->save();
CompositeOperator previousOperator = paintInfo.context->compositeOperation();
paintInfo.context->setCompositeOperation(CompositeCopy);
paintInfo.context->fillRect(paintInfo.rect, baseColor, style()->colorSpace());
paintInfo.context->restore();
paintInfo.context->setCompositeOperation(previousOperator);
} else
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