Commit f5ef91cf authored by eric@webkit.org's avatar eric@webkit.org

Reviewed by Simon Fraser.

        Add SVGRenderBase to share logic between SVG renderers
        https://bugs.webkit.org/show_bug.cgi?id=25532

        I've added an SVGRenderBase base class which is shared by
        all of the SVG renders now.  This patch is just moving code
        there are no functional changes in this patch.

        Currently I've left these functions in SVGRenderSupport.h
        In a later patch I will rename SVGRenderSupport.* to SVGRenderBase.*

        clampImageBufferSizeToViewport now takes a FrameView* which makes some code easier to read.

        * rendering/RenderSVGBlock.h:
        * rendering/RenderSVGImage.h:
        * rendering/RenderSVGModelObject.h:
        * rendering/RenderSVGRoot.h:
        * rendering/SVGRenderSupport.cpp:
        (WebCore::SVGRenderBase::prepareToRenderSVGContent):
        (WebCore::SVGRenderBase::finishRenderSVGContent):
        (WebCore::clampImageBufferSizeToViewport):
        (WebCore::SVGRenderBase::computeContainerBoundingBox):
        (WebCore::SVGRenderBase::filterBoundingBoxForRenderer):
        * rendering/SVGRenderSupport.h:
        * rendering/SVGRootInlineBox.cpp:
        (WebCore::SVGRootInlineBoxPaintWalker::chunkStartCallback):
        (WebCore::SVGRootInlineBoxPaintWalker::chunkEndCallback):
        (WebCore::SVGRootInlineBox::paint):
        * svg/SVGMaskElement.cpp:
        (WebCore::SVGMaskElement::drawMaskerContent):
        * svg/SVGPatternElement.cpp:
        (WebCore::SVGPatternElement::buildPattern):
        * svg/graphics/SVGPaintServerGradient.cpp:
        (WebCore::createMaskAndSwapContextForTextGradient):
        (WebCore::clipToTextMask):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@43209 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 18ae0b0b
2009-05-03 Eric Seidel <eric@webkit.org>
Reviewed by Simon Fraser.
Add SVGRenderBase to share logic between SVG renderers
https://bugs.webkit.org/show_bug.cgi?id=25532
I've added an SVGRenderBase base class which is shared by
all of the SVG renders now. This patch is just moving code
there are no functional changes in this patch.
Currently I've left these functions in SVGRenderSupport.h
In a later patch I will rename SVGRenderSupport.* to SVGRenderBase.*
clampImageBufferSizeToViewport now takes a FrameView* which makes some code easier to read.
* rendering/RenderSVGBlock.h:
* rendering/RenderSVGImage.h:
* rendering/RenderSVGModelObject.h:
* rendering/RenderSVGRoot.h:
* rendering/SVGRenderSupport.cpp:
(WebCore::SVGRenderBase::prepareToRenderSVGContent):
(WebCore::SVGRenderBase::finishRenderSVGContent):
(WebCore::clampImageBufferSizeToViewport):
(WebCore::SVGRenderBase::computeContainerBoundingBox):
(WebCore::SVGRenderBase::filterBoundingBoxForRenderer):
* rendering/SVGRenderSupport.h:
* rendering/SVGRootInlineBox.cpp:
(WebCore::SVGRootInlineBoxPaintWalker::chunkStartCallback):
(WebCore::SVGRootInlineBoxPaintWalker::chunkEndCallback):
(WebCore::SVGRootInlineBox::paint):
* svg/SVGMaskElement.cpp:
(WebCore::SVGMaskElement::drawMaskerContent):
* svg/SVGPatternElement.cpp:
(WebCore::SVGPatternElement::buildPattern):
* svg/graphics/SVGPaintServerGradient.cpp:
(WebCore::createMaskAndSwapContextForTextGradient):
(WebCore::clipToTextMask):
2009-05-05 Simon Hausmann <simon.hausmann@nokia.com>
Unreviewed SVG build fix.
......@@ -25,12 +25,13 @@
#if ENABLE(SVG)
#include "RenderBlock.h"
#include "SVGRenderSupport.h"
namespace WebCore {
class SVGElement;
class RenderSVGBlock : public RenderBlock {
class RenderSVGBlock : public RenderBlock, protected SVGRenderBase {
public:
RenderSVGBlock(SVGElement*);
virtual void setStyle(PassRefPtr<RenderStyle>);
......
......@@ -28,13 +28,14 @@
#include "TransformationMatrix.h"
#include "FloatRect.h"
#include "RenderImage.h"
#include "SVGRenderSupport.h"
namespace WebCore {
class SVGImageElement;
class SVGPreserveAspectRatio;
class RenderSVGImage : public RenderImage {
class RenderSVGImage : public RenderImage, SVGRenderBase {
public:
RenderSVGImage(SVGImageElement*);
virtual ~RenderSVGImage();
......
......@@ -34,17 +34,18 @@
#if ENABLE(SVG)
#include "RenderObject.h"
#include "SVGRenderSupport.h"
namespace WebCore {
// Most renderers in the SVG rendering tree will inherit from this class
// but not all. (e.g. RenderSVGForeignObject, RenderSVGBlock, RenderSVGImage) thus methods
// required by SVG renders need to be declared on RenderObject, but some shared
// logic can go in this class.
// required by SVG renders need to be declared on RenderObject, but shared
// logic can go in this class or in SVGRenderBase.
class SVGStyledElement;
class RenderSVGModelObject : public RenderObject {
class RenderSVGModelObject : public RenderObject, protected SVGRenderBase {
public:
RenderSVGModelObject(SVGStyledElement*);
......
......@@ -25,13 +25,14 @@
#if ENABLE(SVG)
#include "RenderBox.h"
#include "FloatRect.h"
#include "SVGRenderSupport.h"
namespace WebCore {
class SVGStyledElement;
class TransformationMatrix;
class RenderSVGRoot : public RenderBox {
class RenderSVGRoot : public RenderBox, SVGRenderBase {
public:
RenderSVGRoot(SVGStyledElement*);
~RenderSVGRoot();
......
......@@ -40,7 +40,7 @@
namespace WebCore {
void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
void SVGRenderBase::prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
{
#if !ENABLE(SVG_FILTERS)
UNUSED_PARAM(filter);
......@@ -109,7 +109,7 @@ void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& pa
svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);
}
void finishRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, GraphicsContext* savedContext)
void SVGRenderBase::finishRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, GraphicsContext* savedContext)
{
#if !ENABLE(SVG_FILTERS)
UNUSED_PARAM(boundingBox);
......@@ -156,17 +156,13 @@ void renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
svgContainer->setDrawsContents(false);
}
void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
void clampImageBufferSizeToViewport(FrameView* frameView, IntSize& size)
{
if (!object || !object->isRenderView())
if (!frameView)
return;
RenderView* view = toRenderView(object);
if (!view->frameView())
return;
int viewWidth = view->frameView()->visibleWidth();
int viewHeight = view->frameView()->visibleHeight();
int viewWidth = frameView->visibleWidth();
int viewHeight = frameView->visibleHeight();
if (size.width() > viewWidth)
size.setWidth(viewWidth);
......@@ -175,7 +171,7 @@ void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
size.setHeight(viewHeight);
}
FloatRect computeContainerBoundingBox(const RenderObject* container, bool includeAllPaintedContent)
FloatRect SVGRenderBase::computeContainerBoundingBox(const RenderObject* container, bool includeAllPaintedContent)
{
FloatRect boundingBox;
......@@ -189,7 +185,7 @@ FloatRect computeContainerBoundingBox(const RenderObject* container, bool includ
return boundingBox;
}
FloatRect filterBoundingBoxForRenderer(const RenderObject* object)
FloatRect SVGRenderBase::filterBoundingBoxForRenderer(const RenderObject* object)
{
#if ENABLE(SVG_FILTERS)
SVGResourceFilter* filter = getFilterById(object->document(), object->style()->svgStyle()->filter());
......
......@@ -21,34 +21,48 @@
*
*/
#ifndef SVGRenderBase_h
#define SVGRenderBase_h
#if ENABLE(SVG)
#include "RenderObject.h"
namespace WebCore {
// FIXME: Most of this code should move to RenderSVGModelObject once
// all SVG renderers inherit from RenderSVGModelObject
class SVGResourceFilter;
class ImageBuffer;
class SVGResourceFilter;
void prepareToRenderSVGContent(RenderObject*, RenderObject::PaintInfo&, const FloatRect& boundingBox, SVGResourceFilter*&, SVGResourceFilter* rootFilter = 0);
void finishRenderSVGContent(RenderObject*, RenderObject::PaintInfo&, const FloatRect& boundingBox, SVGResourceFilter*&, GraphicsContext* savedContext);
// SVGRendererBase is an abstract base class which all SVG renderers inherit
// from in order to share SVG renderer code.
// FIXME: This code can all move into RenderSVGModelObject once
// all SVG renderers inherit from RenderSVGModelObject.
class SVGRenderBase {
public:
// FIXME: These are only public for SVGRootInlineBox.
// It's unclear if these should be exposed or not. SVGRootInlineBox may
// pass the wrong RenderObject* and boundingBox to these functions.
static void prepareToRenderSVGContent(RenderObject*, RenderObject::PaintInfo&, const FloatRect& boundingBox, SVGResourceFilter*&, SVGResourceFilter* rootFilter = 0);
static void finishRenderSVGContent(RenderObject*, RenderObject::PaintInfo&, const FloatRect& boundingBox, SVGResourceFilter*&, GraphicsContext* savedContext);
// This offers a way to render parts of a WebKit rendering tree into a ImageBuffer.
class ImageBuffer;
void renderSubtreeToImage(ImageBuffer*, RenderObject*);
protected:
// Used to share the "walk all the children" logic between objectBoundingBox
// and repaintRectInLocalCoordinates in RenderSVGRoot and RenderSVGContainer
static FloatRect computeContainerBoundingBox(const RenderObject* container, bool includeAllPaintedContent);
void clampImageBufferSizeToViewport(RenderObject*, IntSize&);
// returns the filter bounding box (or the empty rect if no filter) in local coordinates
static FloatRect filterBoundingBoxForRenderer(const RenderObject*);
};
// Used to share the "walk all the children" logic between objectBoundingBox
// and repaintRectInLocalCoordinates in RenderSVGRoot and RenderSVGContainer
FloatRect computeContainerBoundingBox(const RenderObject* container, bool includeAllPaintedContent);
// FIXME: This should move to RenderObject or PaintInfo
// Used for transforming the GraphicsContext and damage rect before passing PaintInfo to child renderers.
void applyTransformToPaintInfo(RenderObject::PaintInfo&, const TransformationMatrix& localToChildTransform);
// returns the filter bounding box (or the empty rect if no filter) in local coordinates
FloatRect filterBoundingBoxForRenderer(const RenderObject*);
// This offers a way to render parts of a WebKit rendering tree into a ImageBuffer.
void renderSubtreeToImage(ImageBuffer*, RenderObject*);
// Used for transforming the GraphicsContext and damage rect before passing PaintInfo to child renderers.
void applyTransformToPaintInfo(RenderObject::PaintInfo& paintInfo, const TransformationMatrix& localToChildTransform);
void clampImageBufferSizeToViewport(FrameView*, IntSize& imageBufferSize);
} // namespace WebCore
}
#endif // ENABLE(SVG)
#endif
#endif // SVGRenderBase_h
......@@ -402,8 +402,9 @@ struct SVGRootInlineBoxPaintWalker {
m_savedInfo = m_paintInfo;
m_paintInfo.context->save();
// FIXME: Why is this done here instead of in RenderSVGText?
if (!flowBox->isRootInlineBox())
prepareToRenderSVGContent(object, m_paintInfo, m_boundingBox, m_filter, m_rootFilter);
SVGRenderBase::prepareToRenderSVGContent(object, m_paintInfo, m_boundingBox, m_filter, m_rootFilter);
}
void chunkEndCallback(InlineBox* box)
......@@ -422,7 +423,7 @@ struct SVGRootInlineBoxPaintWalker {
// Finalize text rendering
if (!flowBox->isRootInlineBox()) {
finishRenderSVGContent(object, m_paintInfo, m_boundingBox, m_filter, m_savedInfo.context);
SVGRenderBase::finishRenderSVGContent(object, m_paintInfo, m_boundingBox, m_filter, m_savedInfo.context);
m_filter = 0;
}
......@@ -577,7 +578,7 @@ void SVGRootInlineBox::paint(RenderObject::PaintInfo& paintInfo, int tx, int ty)
FloatRect boundingBox(tx + x(), ty + y(), width(), height());
// Initialize text rendering
prepareToRenderSVGContent(renderer(), paintInfo, boundingBox, filter);
SVGRenderBase::prepareToRenderSVGContent(renderer(), paintInfo, boundingBox, filter);
// Render text, chunk-by-chunk
SVGRootInlineBoxPaintWalker walkerCallback(this, filter, paintInfo, tx, ty);
......@@ -591,7 +592,7 @@ void SVGRootInlineBox::paint(RenderObject::PaintInfo& paintInfo, int tx, int ty)
walkTextChunks(&walker);
// Finalize text rendering
finishRenderSVGContent(renderer(), paintInfo, boundingBox, filter, savedInfo.context);
SVGRenderBase::finishRenderSVGContent(renderer(), paintInfo, boundingBox, filter, savedInfo.context);
paintInfo.context->restore();
}
......
......@@ -146,7 +146,7 @@ auto_ptr<ImageBuffer> SVGMaskElement::drawMaskerContent(const FloatRect& targetR
}
IntSize imageSize(lroundf(widthValue), lroundf(heightValue));
clampImageBufferSizeToViewport(document()->renderer(), imageSize);
clampImageBufferSizeToViewport(document()->view(), imageSize);
if (imageSize.width() < static_cast<int>(widthValue))
widthValue = imageSize.width();
......
......@@ -177,7 +177,7 @@ void SVGPatternElement::buildPattern(const FloatRect& targetRect) const
patternBoundaries.setHeight(targetRect.height());
IntSize patternSize(patternBoundaries.width(), patternBoundaries.height());
clampImageBufferSizeToViewport(document()->renderer(), patternSize);
clampImageBufferSizeToViewport(document()->view(), patternSize);
if (patternSize.width() < static_cast<int>(patternBoundaries.width()))
patternBoundaries.setWidth(patternSize.width());
......@@ -212,7 +212,7 @@ void SVGPatternElement::buildPattern(const FloatRect& targetRect) const
}
IntSize imageSize(lroundf(patternBoundariesIncludingOverflow.width()), lroundf(patternBoundariesIncludingOverflow.height()));
clampImageBufferSizeToViewport(document()->renderer(), imageSize);
clampImageBufferSizeToViewport(document()->view(), imageSize);
auto_ptr<ImageBuffer> patternImage = ImageBuffer::create(imageSize, false);
......
......@@ -34,6 +34,7 @@
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "RenderObject.h"
#include "RenderView.h"
#include "SVGGradientElement.h"
#include "SVGPaintServerLinearGradient.h"
#include "SVGPaintServerRadialGradient.h"
......@@ -134,7 +135,7 @@ static inline bool createMaskAndSwapContextForTextGradient(
IntRect maskRect = enclosingIntRect(object->absoluteTransform().mapRect(maskBBox));
IntSize maskSize(maskRect.width(), maskRect.height());
clampImageBufferSizeToViewport(object->document()->renderer(), maskSize);
clampImageBufferSizeToViewport(object->view()->frameView(), maskSize);
auto_ptr<ImageBuffer> maskImage = ImageBuffer::create(maskSize, false);
......@@ -166,7 +167,7 @@ static inline TransformationMatrix clipToTextMask(GraphicsContext* context,
FloatRect textBoundary = transform.mapRect(maskBBox);
IntSize maskSize(lroundf(textBoundary.width()), lroundf(textBoundary.height()));
clampImageBufferSizeToViewport(object->document()->renderer(), maskSize);
clampImageBufferSizeToViewport(object->view()->frameView(), maskSize);
textBoundary.setSize(textBoundary.size().shrunkTo(maskSize));
// Clip current context to mask image (gradient)
......
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