Commit 18d8fbf3 authored by hyatt@apple.com's avatar hyatt@apple.com
Browse files

2008-04-12 David Hyatt <hyatt@apple.com>

        Memory management cleanup for the new StyleCachedImage and StyleGeneratedImage classes.  Make the back end
        values hold refptrs to cached front end values.  This will avoid malloc churn as RenderStyles get
        re-resolved.

        Reviewed by olliej

        * css/CSSCursorImageValue.cpp:
        (WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed):
        (WebCore::CSSCursorImageValue::cachedImage):
        * css/CSSCursorImageValue.h:
        * css/CSSImageGeneratorValue.cpp:
        (WebCore::CSSImageGeneratorValue::CSSImageGeneratorValue):
        (WebCore::CSSImageGeneratorValue::generatedImage):
        * css/CSSImageGeneratorValue.h:
        * css/CSSImageValue.cpp:
        (WebCore::CSSImageValue::CSSImageValue):
        (WebCore::CSSImageValue::~CSSImageValue):
        (WebCore::CSSImageValue::cachedImage):
        * css/CSSImageValue.h:
        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::applyProperty):
        (WebCore::CSSStyleSelector::createStyleImage):
        * css/CSSStyleSelector.h:
        * rendering/RenderStyle.h:
        (WebCore::StyleCachedImage::cachedImage):
        (WebCore::StyleGeneratedImage::StyleGeneratedImage):
        (WebCore::StyleGeneratedImage::data):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31849 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 28586b65
2008-04-12 David Hyatt <hyatt@apple.com>
Memory management cleanup for the new StyleCachedImage and StyleGeneratedImage classes. Make the back end
values hold refptrs to cached front end values. This will avoid malloc churn as RenderStyles get
re-resolved.
Reviewed by olliej
* css/CSSCursorImageValue.cpp:
(WebCore::CSSCursorImageValue::updateIfSVGCursorIsUsed):
(WebCore::CSSCursorImageValue::cachedImage):
* css/CSSCursorImageValue.h:
* css/CSSImageGeneratorValue.cpp:
(WebCore::CSSImageGeneratorValue::CSSImageGeneratorValue):
(WebCore::CSSImageGeneratorValue::generatedImage):
* css/CSSImageGeneratorValue.h:
* css/CSSImageValue.cpp:
(WebCore::CSSImageValue::CSSImageValue):
(WebCore::CSSImageValue::~CSSImageValue):
(WebCore::CSSImageValue::cachedImage):
* css/CSSImageValue.h:
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
(WebCore::CSSStyleSelector::createStyleImage):
* css/CSSStyleSelector.h:
* rendering/RenderStyle.h:
(WebCore::StyleCachedImage::cachedImage):
(WebCore::StyleGeneratedImage::StyleGeneratedImage):
(WebCore::StyleGeneratedImage::data):
2008-04-12 Julien Chaffraix <jchaffraix@webkit.org>
 
Not reviewed, Qt build fix.
 
* dom/XMLTokenizer.cpp:
(WebCore::XMLTokenizer::parseEndElement):
(WebCore::XMLTokenizer::parseEndElement):
* platform/graphics/qt/GraphicsContextQt.cpp:
(WebCore::GraphicsContext::clip):
* platform/qt/ClipboardQt.cpp:
......@@ -27,6 +27,8 @@
#include "DocLoader.h"
#include "PlatformString.h"
#include "RenderStyle.h"
#if ENABLE(SVG)
#include "SVGCursorElement.h"
#include "SVGURIReference.h"
......@@ -96,8 +98,8 @@ bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
if (y != m_hotspot.y())
m_hotspot.setY(y);
if (m_image && m_image->url() != element->document()->completeURL(cursorElement->href())) {
m_image->removeClient(this);
if (m_image && m_image->cachedImage()->url() != element->document()->completeURL(cursorElement->href())) {
m_image->cachedImage()->removeClient(this);
m_image = 0;
m_accessedImage = false;
......@@ -113,7 +115,7 @@ bool CSSCursorImageValue::updateIfSVGCursorIsUsed(Element* element)
return false;
}
CachedImage* CSSCursorImageValue::image(DocLoader* loader)
StyleCachedImage* CSSCursorImageValue::cachedImage(DocLoader* loader)
{
String url = getStringValue();
......@@ -124,7 +126,7 @@ CachedImage* CSSCursorImageValue::image(DocLoader* loader)
}
#endif
return CSSImageValue::image(loader, url);
return CSSImageValue::cachedImage(loader, url);
}
} // namespace WebCore
......@@ -40,7 +40,7 @@ public:
IntPoint hotspot() const { return m_hotspot; }
bool updateIfSVGCursorIsUsed(Element*);
virtual CachedImage* image(DocLoader*);
virtual StyleCachedImage* cachedImage(DocLoader*);
private:
IntPoint m_hotspot;
......
......@@ -34,6 +34,12 @@
namespace WebCore {
CSSImageGeneratorValue::CSSImageGeneratorValue()
: m_accessedImage(false)
{
}
CSSImageGeneratorValue::~CSSImageGeneratorValue()
{
deleteAllValues(m_images);
......@@ -78,4 +84,13 @@ void CSSImageGeneratorValue::putImage(const IntSize& size, Image* image)
m_images.add(size, image);
}
StyleGeneratedImage* CSSImageGeneratorValue::generatedImage()
{
if (!m_accessedImage) {
m_accessedImage = true;
m_image = new StyleGeneratedImage(this);
}
return m_image.get();
}
} // namespace WebCore
......@@ -32,6 +32,7 @@
#include "IntSizeHash.h"
#include <wtf/HashMap.h>
#include <wtf/HashCountedSet.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
......@@ -39,10 +40,12 @@ namespace WebCore {
class Image;
class IntSize;
class StyleGeneratedImage;
class RenderObject;
class CSSImageGeneratorValue : public CSSValue {
public:
CSSImageGeneratorValue();
virtual ~CSSImageGeneratorValue();
virtual bool isImageGeneratorValue() const { return true; }
......@@ -50,6 +53,8 @@ public:
void addClient(RenderObject*, const IntSize&);
void removeClient(RenderObject*);
virtual Image* image(RenderObject*, const IntSize&) = 0;
StyleGeneratedImage* generatedImage();
protected:
Image* getImage(RenderObject*, const IntSize&);
......@@ -59,6 +64,8 @@ protected:
HashMap<RenderObject*, IntSize> m_clients; // A map from RenderObjects to image sizes.
HashMap<IntSize, Image*> m_images; // A map from sizes to generated images.
RefPtr<StyleGeneratedImage> m_image;
bool m_accessedImage;
};
} // namespace WebCore
......
......@@ -25,19 +25,18 @@
#include "Cache.h"
#include "CachedImage.h"
#include "DocLoader.h"
#include "RenderStyle.h"
namespace WebCore {
CSSImageValue::CSSImageValue(const String& url, StyleBase* style)
: CSSPrimitiveValue(url, CSS_URI)
, m_image(0)
, m_accessedImage(false)
{
}
CSSImageValue::CSSImageValue()
: CSSPrimitiveValue(CSSValueNone)
, m_image(0)
, m_accessedImage(true)
{
}
......@@ -45,31 +44,34 @@ CSSImageValue::CSSImageValue()
CSSImageValue::~CSSImageValue()
{
if (m_image)
m_image->removeClient(this);
m_image->cachedImage()->removeClient(this);
}
CachedImage* CSSImageValue::image(DocLoader* loader)
StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader)
{
return image(loader, getStringValue());
return cachedImage(loader, getStringValue());
}
CachedImage* CSSImageValue::image(DocLoader* loader, const String& url)
StyleCachedImage* CSSImageValue::cachedImage(DocLoader* loader, const String& url)
{
if (!m_accessedImage) {
m_accessedImage = true;
CachedImage* cachedImage = 0;
if (loader)
m_image = loader->requestImage(url);
cachedImage = loader->requestImage(url);
else {
// FIXME: Should find a way to make these images sit in their own memory partition, since they are user agent images.
m_image = static_cast<CachedImage*>(cache()->requestResource(0, CachedResource::ImageResource, KURL(url), String()));
cachedImage = static_cast<CachedImage*>(cache()->requestResource(0, CachedResource::ImageResource, KURL(url), String()));
}
if (m_image)
m_image->addClient(this);
if (cachedImage) {
cachedImage->addClient(this);
m_image = new StyleCachedImage(cachedImage);
}
}
return m_image;
return m_image.get();
}
} // namespace WebCore
......@@ -25,10 +25,12 @@
#include "CSSPrimitiveValue.h"
#include "CachedResourceClient.h"
#include <wtf/RefPtr.h>
namespace WebCore {
class DocLoader;
class StyleCachedImage;
class CSSImageValue : public CSSPrimitiveValue,
public CachedResourceClient {
......@@ -37,14 +39,14 @@ public:
CSSImageValue(const String& url, StyleBase*);
virtual ~CSSImageValue();
virtual CachedImage* image(DocLoader*);
virtual StyleCachedImage* cachedImage(DocLoader*);
virtual bool isImageValue() const { return true; }
protected:
CachedImage* image(DocLoader*, const String& url);
StyleCachedImage* cachedImage(DocLoader*, const String& url);
CachedImage* m_image;
RefPtr<StyleCachedImage> m_image;
bool m_accessedImage;
};
......
......@@ -2662,7 +2662,11 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
CSSCursorImageValue* image = static_cast<CSSCursorImageValue*>(primitiveValue);
if (image->updateIfSVGCursorIsUsed(m_element)) // Elements with SVG cursors are not allowed to share style.
m_style->setUnique();
m_style->addCursor(image->image(m_element->document()->docLoader()), image->hotspot());
// FIXME: Temporary clumsiness to pass off a CachedImage to an API that will eventually convert to using
// StyleImage.
RefPtr<StyleCachedImage> styleCachedImage(image->cachedImage(m_element->document()->docLoader()));
if (styleCachedImage)
m_style->addCursor(styleCachedImage->cachedImage(), image->hotspot());
} else if (type == CSSPrimitiveValue::CSS_IDENT)
m_style->setCursor(*primitiveValue);
}
......@@ -3395,7 +3399,11 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
}
case CSSPrimitiveValue::CSS_URI: {
CSSImageValue *image = static_cast<CSSImageValue*>(val);
m_style->setContent(image->image(m_element->document()->docLoader()), didSet);
// FIXME: Temporary clumsiness to pass off a CachedImage to an API that will eventually convert to using
// StyleImage.
RefPtr<StyleCachedImage> styleCachedImage(image->cachedImage(m_element->document()->docLoader()));
if (styleCachedImage)
m_style->setContent(styleCachedImage->cachedImage(), didSet);
didSet = true;
break;
}
......@@ -4639,18 +4647,12 @@ void CSSStyleSelector::mapBackgroundOrigin(BackgroundLayer* layer, CSSValue* val
layer->setBackgroundOrigin(*primitiveValue);
}
StyleImage* CSSStyleSelector::createStyleImage(CSSValue* value)
PassRefPtr<StyleImage> CSSStyleSelector::createStyleImage(CSSValue* value)
{
// FIXME: There will be malloc churn here. We need to convert all accesses of CSSImageValue over to
// StyleImage, and once that is done, we can start caching that inside the values instead.
if (value->isImageValue()) {
CachedImage* image = static_cast<CSSImageValue*>(value)->image(m_element->document()->docLoader());
if (image)
return new StyleCachedImage(image);
return 0;
}
if (value->isImageValue())
return static_cast<CSSImageValue*>(value)->cachedImage(m_element->document()->docLoader());
if (value->isImageGeneratorValue())
return new StyleGeneratedImage(static_cast<CSSImageGeneratorValue*>(value));
return static_cast<CSSImageGeneratorValue*>(value)->generatedImage();
return 0;
}
......
......@@ -194,7 +194,7 @@ public:
void applySVGProperty(int id, CSSValue*);
#endif
StyleImage* createStyleImage(CSSValue* value);
PassRefPtr<StyleImage> createStyleImage(CSSValue* value);
PseudoState checkPseudoState(Element*, bool checkVisited = true);
......
......@@ -172,6 +172,8 @@ public:
virtual PassRefPtr<CSSValue> cssValue();
CachedImage* cachedImage() const { return m_image; }
virtual bool canRender(float multiplier) const;
virtual bool isLoaded() const;
virtual bool errorOccurred() const;
......@@ -188,11 +190,11 @@ private:
class StyleGeneratedImage : public StyleImage
{
public:
StyleGeneratedImage(PassRefPtr<CSSImageGeneratorValue> val)
StyleGeneratedImage(CSSImageGeneratorValue* val)
: m_generator(val)
{}
virtual void* data() const { return m_generator.get(); }
virtual void* data() const { return m_generator; }
virtual bool isGeneratedImage() const { return true; }
......@@ -205,7 +207,7 @@ public:
virtual Image* image(RenderObject*, const IntSize&) const;
private:
RefPtr<CSSImageGeneratorValue> m_generator;
CSSImageGeneratorValue* m_generator; // The generator holds a reference to us.
IntSize m_containerSize;
};
......
Supports Markdown
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