summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/graphics/cg/ImageSourceCG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/graphics/cg/ImageSourceCG.cpp')
-rw-r--r--WebCore/platform/graphics/cg/ImageSourceCG.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/WebCore/platform/graphics/cg/ImageSourceCG.cpp b/WebCore/platform/graphics/cg/ImageSourceCG.cpp
index c059985..7cb8799 100644
--- a/WebCore/platform/graphics/cg/ImageSourceCG.cpp
+++ b/WebCore/platform/graphics/cg/ImageSourceCG.cpp
@@ -33,10 +33,12 @@
#include "MIMETypeRegistry.h"
#include "SharedBuffer.h"
#include <ApplicationServices/ApplicationServices.h>
+#include <wtf/UnusedParam.h>
namespace WebCore {
static const CFStringRef kCGImageSourceShouldPreferRGB32 = CFSTR("kCGImageSourceShouldPreferRGB32");
+static const CFStringRef kCGImageSourceDoNotCacheImageBlocks = CFSTR("kCGImageSourceDoNotCacheImageBlocks");
ImageSource::ImageSource()
: m_decoder(0)
@@ -48,11 +50,24 @@ ImageSource::~ImageSource()
clear(true);
}
-void ImageSource::clear(bool, size_t, SharedBuffer* data, bool allDataReceived)
+void ImageSource::clear(bool destroyAllFrames, size_t, SharedBuffer* data, bool allDataReceived)
{
- // We always destroy the decoder, because there is no API to get it to
- // selectively release some of the frames it's holding, and if we don't
- // release any of them, we use too much memory on large images.
+#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+ // Recent versions of ImageIO discard previously decoded image frames if the client
+ // application no longer holds references to them, so there's no need to throw away
+ // the decoder unless we're explicitly asked to destroy all of the frames.
+
+ if (!destroyAllFrames)
+ return;
+#else
+ // Older versions of ImageIO hold references to previously decoded image frames.
+ // There is no API to selectively release some of the frames it is holding, and
+ // if we don't release the frames we use too much memory on large images.
+ // Destroying the decoder is the only way to release previous frames.
+
+ UNUSED_PARAM(destroyAllFrames);
+#endif
+
if (m_decoder) {
CFRelease(m_decoder);
m_decoder = 0;
@@ -66,9 +81,9 @@ static CFDictionaryRef imageSourceOptions()
static CFDictionaryRef options;
if (!options) {
- const void* keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 };
- const void* values[2] = { kCFBooleanTrue, kCFBooleanTrue };
- options = CFDictionaryCreate(NULL, keys, values, 2,
+ const void* keys[3] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32, kCGImageSourceDoNotCacheImageBlocks };
+ const void* values[3] = { kCFBooleanTrue, kCFBooleanTrue, kCFBooleanTrue };
+ options = CFDictionaryCreate(NULL, keys, values, 3,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
}
return options;
@@ -227,9 +242,17 @@ float ImageSource::frameDurationAtIndex(size_t index)
bool ImageSource::frameHasAlphaAtIndex(size_t)
{
- // Might be interesting to do this optimization on Mac some day, but for now we're just using this
- // for the Cairo source, since it uses our decoders, and our decoders can answer this question.
- // FIXME: Could return false for JPEG and other non-transparent image formats.
+ if (!m_decoder)
+ return false;
+
+ CFStringRef imageType = CGImageSourceGetType(m_decoder);
+
+ // Return false if there is no image type or the image type is JPEG, because
+ // JPEG does not support alpha transparency.
+ if (!imageType || CFEqual(imageType, CFSTR("public.jpeg")))
+ return false;
+
+ // FIXME: Could return false for other non-transparent image formats.
// FIXME: Could maybe return false for a GIF Frame if we have enough info in the GIF properties dictionary
// to determine whether or not a transparent color was defined.
return true;