Commit 4bc83c31 authored by darin's avatar darin

Reviewed and significantly tweaked by Darin.

        - fix http://bugs.webkit.org/show_bug.cgi?id=12103
          LEAK: Fix the leaking ImageBuffer buffers on TOT

        * ksvg2/svg/SVGMaskElement.h:
        * ksvg2/svg/SVGMaskElement.cpp:
        (WebCore::SVGMaskElement::drawMaskerContent):
        Changed to return auto_ptr since it returns a newly-created ImageBuffer.

        * ksvg2/svg/SVGPatternElement.cpp:
        (WebCore::SVGPatternElement::buildPattern):
        Changed to use auto_ptr since ImageBuffer::create now returns one.

        * platform/graphics/GraphicsContext.h: Removed the include of ImageBuffer.h,
        which was never needed, and the declaration of createImageBuffer, which is
        now a class member function of ImageBuffer.

        * platform/graphics/ImageBuffer.h: Replaced the constructor with a create
        function. Added a comment about the need to move renderSubtreeToImage
        elsewhere. Added an m_data member to store the data so it can be deleted
        when the object is done, made the m_size member non-platform-specific.
        Added a private constructor for use to create the CG version.

        * platform/graphics/cg/GraphicsContextCG.cpp: Removed
        GraphicsContext::createImageBuffer.

        * platform/graphics/cg/ImageBufferCG.cpp:
        (WebCore::ImageBuffer::create): Added. Replaces the old
        GraphicsContext::createImageBuffer function.
        (WebCore::ImageBuffer::ImageBuffer): Added m_data and m_context.
        (WebCore::ImageBuffer::~ImageBuffer): Added a fastFree of the data and got
        rid of the unneeded null check before calling CGImageRelease.

        * platform/graphics/svg/SVGPaintServerGradient.h: Removed the include of
        ImageBuffer.h and declared the ImageBuffer class instead.

        * platform/graphics/svg/SVGPaintServerPattern.h: Removed the include of
        ImageBuffer.h and declared the ImageBuffer class instead, and changed setTile
        to take an auto_ptr since it takes ownership of the ImageBuffer.
        * platform/graphics/svg/SVGPaintServerPattern.cpp:
        (WebCore::SVGPaintServerPattern::setTile): Ditto.

        * platform/graphics/svg/SVGResourceMasker.h: Removed the include of
        ImageBuffer.h and declared the ImageBuffer class instead, and changed setMask
        to take an auto_ptr since it takes ownership of the ImageBuffer.
        * platform/graphics/svg/SVGResourceMasker.cpp:
        (WebCore::SVGResourceMasker::setMask): Ditto.

        * platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp:
        (WebCore::SVGPaintServerGradient::setup): Updated to use auto_ptr.

        * platform/graphics/svg/cg/SVGPaintServerPatternCg.cpp: Updated includes.

        * platform/graphics/svg/cg/SVGResourceMaskerCg.mm:
        (WebCore::SVGResourceMasker::applyMask): Updated to use auto_ptr.

        - other changes

        * ksvg2/svg/SVGAnimateTransformElement.cpp:
        (WebCore::SVGAnimateTransformElement::handleStartCondition):
        Remove unused variables.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@18641 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 71ce147f
2007-01-06 Eric Seidel <eric@webkit.org>
Reviewed and significantly tweaked by Darin.
- fix http://bugs.webkit.org/show_bug.cgi?id=12103
LEAK: Fix the leaking ImageBuffer buffers on TOT
* ksvg2/svg/SVGMaskElement.h:
* ksvg2/svg/SVGMaskElement.cpp:
(WebCore::SVGMaskElement::drawMaskerContent):
Changed to return auto_ptr since it returns a newly-created ImageBuffer.
* ksvg2/svg/SVGPatternElement.cpp:
(WebCore::SVGPatternElement::buildPattern):
Changed to use auto_ptr since ImageBuffer::create now returns one.
* platform/graphics/GraphicsContext.h: Removed the include of ImageBuffer.h,
which was never needed, and the declaration of createImageBuffer, which is
now a class member function of ImageBuffer.
* platform/graphics/ImageBuffer.h: Replaced the constructor with a create
function. Added a comment about the need to move renderSubtreeToImage
elsewhere. Added an m_data member to store the data so it can be deleted
when the object is done, made the m_size member non-platform-specific.
Added a private constructor for use to create the CG version.
* platform/graphics/cg/GraphicsContextCG.cpp: Removed
GraphicsContext::createImageBuffer.
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::create): Added. Replaces the old
GraphicsContext::createImageBuffer function.
(WebCore::ImageBuffer::ImageBuffer): Added m_data and m_context.
(WebCore::ImageBuffer::~ImageBuffer): Added a fastFree of the data and got
rid of the unneeded null check before calling CGImageRelease.
* platform/graphics/svg/SVGPaintServerGradient.h: Removed the include of
ImageBuffer.h and declared the ImageBuffer class instead.
* platform/graphics/svg/SVGPaintServerPattern.h: Removed the include of
ImageBuffer.h and declared the ImageBuffer class instead, and changed setTile
to take an auto_ptr since it takes ownership of the ImageBuffer.
* platform/graphics/svg/SVGPaintServerPattern.cpp:
(WebCore::SVGPaintServerPattern::setTile): Ditto.
* platform/graphics/svg/SVGResourceMasker.h: Removed the include of
ImageBuffer.h and declared the ImageBuffer class instead, and changed setMask
to take an auto_ptr since it takes ownership of the ImageBuffer.
* platform/graphics/svg/SVGResourceMasker.cpp:
(WebCore::SVGResourceMasker::setMask): Ditto.
* platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp:
(WebCore::SVGPaintServerGradient::setup): Updated to use auto_ptr.
* platform/graphics/svg/cg/SVGPaintServerPatternCg.cpp: Updated includes.
* platform/graphics/svg/cg/SVGResourceMaskerCg.mm:
(WebCore::SVGResourceMasker::applyMask): Updated to use auto_ptr.
- other changes
* ksvg2/svg/SVGAnimateTransformElement.cpp:
(WebCore::SVGAnimateTransformElement::handleStartCondition):
Remove unused variables.
2007-01-06 Mitz Pettel <mitz@webkit.org>
Reviewed by Maciej.
......
......@@ -265,12 +265,6 @@ bool SVGAnimateTransformElement::handleStartCondition()
if (!m_fromTransform)
m_fromTransform = new SVGTransform();
AffineTransform byMatrix = m_toTransform->matrix();
AffineTransform fromMatrix = m_fromTransform->matrix();
byMatrix *= fromMatrix;
break;
}
case VALUES_ANIMATION:
......
......@@ -27,13 +27,16 @@
#include "SVGMaskElement.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "RenderSVGContainer.h"
#include "SVGLength.h"
#include "SVGNames.h"
#include "cssstyleselector.h"
#include <wtf/OwnPtr.h>
#include <math.h>
#include <wtf/MathExtras.h>
#include <wtf/OwnPtr.h>
using namespace std;
namespace WebCore {
......@@ -106,13 +109,13 @@ void SVGMaskElement::parseMappedAttribute(MappedAttribute* attr)
}
}
ImageBuffer* SVGMaskElement::drawMaskerContent()
auto_ptr<ImageBuffer> SVGMaskElement::drawMaskerContent()
{
IntSize size = IntSize(lroundf(width().value()), lroundf(height().value()));
ImageBuffer* maskImage(GraphicsContext::createImageBuffer(size, false));
if (!maskImage)
return 0;
auto_ptr<ImageBuffer> maskImage = ImageBuffer::create(size, false);
if (!maskImage.get())
return maskImage;
GraphicsContext* maskImageContext = maskImage->context();
ASSERT(maskImageContext);
......@@ -120,7 +123,7 @@ ImageBuffer* SVGMaskElement::drawMaskerContent()
maskImageContext->save();
maskImageContext->translate(-x().value(), -y().value());
ImageBuffer::renderSubtreeToImage(maskImage, renderer());
ImageBuffer::renderSubtreeToImage(maskImage.get(), renderer());
maskImageContext->restore();
return maskImage;
......
......@@ -56,7 +56,7 @@ namespace WebCore
virtual SVGResource* canvasResource();
protected:
ImageBuffer* drawMaskerContent();
std::auto_ptr<ImageBuffer> drawMaskerContent();
ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGURIReference, String, Href, href)
ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired)
......
......@@ -28,6 +28,7 @@
#include "AffineTransform.h"
#include "Document.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "PatternAttributes.h"
#include "RenderSVGContainer.h"
#include "SVGLength.h"
......@@ -42,6 +43,8 @@
#include <wtf/OwnPtr.h>
#include <wtf/MathExtras.h>
using namespace std;
namespace WebCore {
SVGPatternElement::SVGPatternElement(const QualifiedName& tagName, Document* doc)
......@@ -144,8 +147,8 @@ void SVGPatternElement::buildPattern(const FloatRect& targetRect) const
if (heightValue > targetRect.height())
heightValue = targetRect.height();
ImageBuffer* patternImage = GraphicsContext::createImageBuffer(IntSize(lroundf(widthValue), lroundf(heightValue)), false);
if (!patternImage)
auto_ptr<ImageBuffer> patternImage = ImageBuffer::create(IntSize(lroundf(widthValue), lroundf(heightValue)), false);
if (!patternImage.get())
return;
GraphicsContext* context = patternImage->context();
......@@ -167,7 +170,7 @@ void SVGPatternElement::buildPattern(const FloatRect& targetRect) const
if (!item)
continue;
ImageBuffer::renderSubtreeToImage(patternImage, item);
ImageBuffer::renderSubtreeToImage(patternImage.get(), item);
}
if (attributes.boundingBoxModeContent())
......
......@@ -28,7 +28,6 @@
#include "FloatRect.h"
#include "Image.h"
#include "ImageBuffer.h"
#include "IntRect.h"
#include "Path.h"
#include "TextDirection.h"
......@@ -198,8 +197,6 @@ namespace WebCore {
PlatformPath* currentPath();
#endif
static ImageBuffer* createImageBuffer(const IntSize&, bool grayScale);
private:
void savePlatformState();
void restorePlatformState();
......
......@@ -35,6 +35,11 @@
namespace WebCore {
IntSize ImageBuffer::size() const
{
return m_size;
}
void ImageBuffer::renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
{
ASSERT(item && image && image->context());
......
/*
* Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2007 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -38,26 +39,32 @@ namespace WebCore {
class GraphicsContext;
class RenderObject;
class ImageBuffer {
class ImageBuffer : Noncopyable {
public:
ImageBuffer(const IntSize&, GraphicsContext*);
static std::auto_ptr<ImageBuffer> create(const IntSize&, bool grayScale);
~ImageBuffer();
IntSize size() const;
GraphicsContext* context() const;
// This offers a way to render parts of a WebKit rendering tree into this ImageBuffer class.
static void renderSubtreeToImage(ImageBuffer*, RenderObject* item);
// FIXME: This doesn't belong in the platform directory.
// Bad layering that this knows about the render tree.
// We need to move it into RenderObject or somewhere in the SVG world.
static void renderSubtreeToImage(ImageBuffer*, RenderObject*);
#if PLATFORM(CG)
CGImageRef cgImage() const;
#endif
private:
void* m_data;
IntSize m_size;
OwnPtr<GraphicsContext> m_context;
#if PLATFORM(CG)
IntSize m_size;
#if PLATFORM(CG)
ImageBuffer(void* imageData, const IntSize&, std::auto_ptr<GraphicsContext>);
mutable CGImageRef m_cgImage;
#endif
};
......
......@@ -771,27 +771,6 @@ void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
}
}
ImageBuffer* GraphicsContext::createImageBuffer(const IntSize& size, bool grayScale)
{
unsigned int bytesPerRow = size.width();
if (!grayScale)
bytesPerRow *= 4;
void* imageBuffer = fastMalloc(bytesPerRow * size.height());
if (!imageBuffer)
return 0;
memset(imageBuffer, 0, bytesPerRow * size.height());
CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(imageBuffer, size.width(), size.height(), 8, bytesPerRow,
colorSpace, grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
GraphicsContext *graphicsContext = new GraphicsContext(context);
CGContextRelease(context);
return new ImageBuffer(size, graphicsContext);
}
void GraphicsContext::setPlatformTextDrawingMode(int mode)
{
if (paintingDisabled())
......
......@@ -31,24 +31,46 @@
#include <ApplicationServices/ApplicationServices.h>
#include <wtf/Assertions.h>
using namespace std;
namespace WebCore {
ImageBuffer::ImageBuffer(const IntSize& size, GraphicsContext* context)
: m_context(context)
, m_size(size)
, m_cgImage(0)
auto_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, bool grayScale)
{
unsigned int bytesPerRow = size.width();
if (!grayScale)
bytesPerRow *= 4;
void* imageBuffer = fastCalloc(size.height(), bytesPerRow);
if (!imageBuffer)
return auto_ptr<ImageBuffer>();
CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
CGContextRef cgContext = CGBitmapContextCreate(imageBuffer, size.width(), size.height(), 8, bytesPerRow,
colorSpace, grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
if (!cgContext)
return auto_ptr<ImageBuffer>();
auto_ptr<GraphicsContext> context(new GraphicsContext(cgContext));
CGContextRelease(cgContext);
return auto_ptr<ImageBuffer>(new ImageBuffer(imageBuffer, size, context));
}
ImageBuffer::~ImageBuffer()
ImageBuffer::ImageBuffer(void* imageData, const IntSize& size, auto_ptr<GraphicsContext> context)
: m_data(imageData)
, m_size(size)
, m_context(context.release())
, m_cgImage(0)
{
if (m_cgImage)
CGImageRelease(m_cgImage);
}
IntSize ImageBuffer::size() const
ImageBuffer::~ImageBuffer()
{
return m_size;
fastFree(m_data);
CGImageRelease(m_cgImage);
}
GraphicsContext* ImageBuffer::context() const
......
......@@ -36,12 +36,9 @@
class QGradient;
#endif
#if PLATFORM(CG)
#include "ImageBuffer.h"
#endif
namespace WebCore {
class ImageBuffer;
class SVGGradientElement;
// FIXME: Remove the spread method enum in SVGGradientElement
......
......@@ -28,14 +28,16 @@
#ifdef SVG_SUPPORT
#include "SVGPaintServerPattern.h"
#include "ImageBuffer.h"
#include "SVGPatternElement.h"
#include "SVGRenderTreeAsText.h"
using namespace std;
namespace WebCore {
SVGPaintServerPattern::SVGPaintServerPattern(const SVGPatternElement* owner)
: m_ownerElement(owner)
#if PLATFORM(CG)
, m_patternSpace(0)
, m_pattern(0)
......@@ -67,9 +69,9 @@ ImageBuffer* SVGPaintServerPattern::tile() const
return m_tile.get();
}
void SVGPaintServerPattern::setTile(ImageBuffer* tile)
void SVGPaintServerPattern::setTile(auto_ptr<ImageBuffer> tile)
{
m_tile.set(tile);
m_tile.set(tile.release());
}
AffineTransform SVGPaintServerPattern::patternTransform() const
......
......@@ -30,13 +30,14 @@
#include "AffineTransform.h"
#include "FloatRect.h"
#include "GraphicsContext.h"
#include "SVGPaintServer.h"
#include <wtf/OwnPtr.h>
namespace WebCore {
class GraphicsContext;
class ImageBuffer;
class SVGPatternElement;
class SVGPaintServerPattern : public SVGPaintServer {
......@@ -51,7 +52,7 @@ namespace WebCore {
FloatRect patternBoundaries() const;
ImageBuffer* tile() const;
void setTile(ImageBuffer*);
void setTile(std::auto_ptr<ImageBuffer>);
AffineTransform patternTransform() const;
void setPatternTransform(const AffineTransform&);
......
......@@ -28,8 +28,11 @@
#ifdef SVG_SUPPORT
#include "SVGResourceMasker.h"
#include "ImageBuffer.h"
#include "TextStream.h"
using namespace std;
namespace WebCore {
SVGResourceMasker::SVGResourceMasker()
......@@ -41,9 +44,9 @@ SVGResourceMasker::~SVGResourceMasker()
{
}
void SVGResourceMasker::setMask(ImageBuffer* mask)
void SVGResourceMasker::setMask(auto_ptr<ImageBuffer> mask)
{
m_mask.set(mask);
m_mask.set(mask.release());
}
ImageBuffer* SVGResourceMasker::mask() const
......
......@@ -36,13 +36,14 @@
namespace WebCore {
class FloatRect;
class ImageBuffer;
class SVGResourceMasker : public SVGResource {
public:
SVGResourceMasker();
virtual ~SVGResourceMasker();
void setMask(ImageBuffer* mask);
void setMask(std::auto_ptr<ImageBuffer> mask);
ImageBuffer* mask() const;
virtual bool isMasker() const { return true; }
......
......@@ -24,12 +24,15 @@
#ifdef SVG_SUPPORT
#include "SVGPaintServerGradient.h"
#include "CgSupport.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "RenderPath.h"
#include "SVGGradientElement.h"
#include "SVGPaintServerLinearGradient.h"
#include "SVGPaintServerRadialGradient.h"
#include "RenderPath.h"
#include "CgSupport.h"
using namespace std;
namespace WebCore {
......@@ -272,7 +275,7 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject
IntRect maskRect = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
maskRect = object->absoluteTransform().inverse().mapRect(maskRect);
ImageBuffer* maskImage = GraphicsContext::createImageBuffer(IntSize(maskRect.width(), maskRect.height()), false);
auto_ptr<ImageBuffer> maskImage = ImageBuffer::create(IntSize(maskRect.width(), maskRect.height()), false);
// FIXME: maskImage could be NULL
GraphicsContext* maskImageContext = maskImage->context();
......@@ -283,7 +286,7 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject
const_cast<RenderObject*>(object)->style()->setColor(Color(255, 255, 255));
maskImageContext->setTextDrawingMode(cTextStroke);
m_imageBuffer = maskImage;
m_imageBuffer = maskImage.release();
m_savedContext = context;
context = maskImageContext;
}
......
......@@ -24,10 +24,11 @@
#ifdef SVG_SUPPORT
#include "SVGPaintServerPattern.h"
#include "CgSupport.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "RenderObject.h"
#include "SVGPatternElement.h"
#include "CgSupport.h"
namespace WebCore {
......
......@@ -27,15 +27,17 @@
#include "config.h"
#ifdef SVG_SUPPORT
#import "SVGResourceFilter.h"
#import "SVGResourceMasker.h"
#import "SVGRenderStyle.h"
#import "GraphicsContext.h"
#import "CgSupport.h"
#import <QuartzCore/CoreImage.h>
#import "GraphicsContext.h"
#import "ImageBuffer.h"
#import "SVGRenderStyle.h"
#import "SVGResourceFilter.h"
#import <QuartzCore/CIFilter.h>
#import <QuartzCore/CoreImage.h>
using namespace std;
namespace WebCore {
......@@ -100,8 +102,8 @@ void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& bou
maskSize.width(), maskSize.height());
// Create new graphics context in gray scale mode for image rendering
OwnPtr<ImageBuffer> grayScaleImage(GraphicsContext::createImageBuffer(maskSize, true));
if (!grayScaleImage)
auto_ptr<ImageBuffer> grayScaleImage(ImageBuffer::create(maskSize, true));
if (!grayScaleImage.get())
return;
CGContextRef grayScaleContext = grayScaleImage->context()->platformContext();
......
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