Commit 46464f35 authored by mitz@apple.com's avatar mitz@apple.com
Browse files

Replace many manually-released CFTypeRefs with RetainPtrs

https://bugs.webkit.org/show_bug.cgi?id=28498

Reviewed by Geoffrey Garen.

* platform/graphics/cg/ColorCG.cpp:
(WebCore::createCGColor):
* platform/graphics/cg/GradientCG.cpp:
(WebCore::Gradient::platformGradient):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::platformContext):
(WebCore::GraphicsContext::applyStrokePattern):
(WebCore::GraphicsContext::applyFillPattern):
(WebCore::GraphicsContext::setPlatformShadow):
(WebCore::GraphicsContext::setURLForRect):
* platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
(WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::ImageBuffer):
* platform/graphics/cg/ImageCG.cpp:
(WebCore::BitmapImage::checkForSolidColor):
(WebCore::Image::drawPattern):
* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::ImageSource::setData):
(WebCore::ImageSource::isSizeAvailable):
(WebCore::ImageSource::frameSizeAtIndex):
(WebCore::ImageSource::repetitionCount):
(WebCore::ImageSource::createFrameAtIndex):
(WebCore::ImageSource::frameDurationAtIndex):
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::dataChanged):
* platform/graphics/cg/PathCG.cpp:
(WebCore::createScratchContext):
(WebCore::Path::contains):
* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/mac/GraphicsContextMac.mm:
(WebCore::GraphicsContext::drawFocusRing):
* platform/graphics/mac/ImageMac.mm:
(WebCore::BitmapImage::getTIFFRepresentation):
* platform/mac/ClipboardMac.mm:
(WebCore::cocoaTypeFromMIMEType):
(WebCore::MIMETypeFromCocoaType):
* platform/mac/WebCoreNSStringExtras.mm:
(stringEncodingForResource):
* platform/network/mac/FormDataStreamMac.mm:
(WebCore::advanceCurrentStream):
(WebCore::setHTTPBody):
* platform/text/mac/TextCodecMac.cpp:
(WebCore::TextCodecMac::encode):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47585 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b7aceb57
2009-08-20 Dan Bernstein <mitz@apple.com>
Reviewed by Geoffrey Garen.
Replace many manually-released CFTypeRefs with RetainPtrs
https://bugs.webkit.org/show_bug.cgi?id=28498
* platform/graphics/cg/ColorCG.cpp:
(WebCore::createCGColor):
* platform/graphics/cg/GradientCG.cpp:
(WebCore::Gradient::platformGradient):
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::platformContext):
(WebCore::GraphicsContext::applyStrokePattern):
(WebCore::GraphicsContext::applyFillPattern):
(WebCore::GraphicsContext::setPlatformShadow):
(WebCore::GraphicsContext::setURLForRect):
* platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
(WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::ImageBuffer):
* platform/graphics/cg/ImageCG.cpp:
(WebCore::BitmapImage::checkForSolidColor):
(WebCore::Image::drawPattern):
* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::ImageSource::setData):
(WebCore::ImageSource::isSizeAvailable):
(WebCore::ImageSource::frameSizeAtIndex):
(WebCore::ImageSource::repetitionCount):
(WebCore::ImageSource::createFrameAtIndex):
(WebCore::ImageSource::frameDurationAtIndex):
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::dataChanged):
* platform/graphics/cg/PathCG.cpp:
(WebCore::createScratchContext):
(WebCore::Path::contains):
* platform/graphics/mac/FontCustomPlatformData.cpp:
(WebCore::createFontCustomPlatformData):
* platform/graphics/mac/GraphicsContextMac.mm:
(WebCore::GraphicsContext::drawFocusRing):
* platform/graphics/mac/ImageMac.mm:
(WebCore::BitmapImage::getTIFFRepresentation):
* platform/mac/ClipboardMac.mm:
(WebCore::cocoaTypeFromMIMEType):
(WebCore::MIMETypeFromCocoaType):
* platform/mac/WebCoreNSStringExtras.mm:
(stringEncodingForResource):
* platform/network/mac/FormDataStreamMac.mm:
(WebCore::advanceCurrentStream):
(WebCore::setHTTPBody):
* platform/text/mac/TextCodecMac.cpp:
(WebCore::TextCodecMac::encode):
2009-08-20 Shinichiro Hamaji <hamaji@chromium.org>
 
Reviewed by Eric Seidel.
......@@ -29,6 +29,7 @@
#if PLATFORM(CG)
#include <wtf/Assertions.h>
#include <wtf/RetainPtr.h>
#include <ApplicationServices/ApplicationServices.h>
namespace WebCore {
......@@ -75,13 +76,12 @@ CGColorRef createCGColor(const Color& c)
CMProfileRef prof = NULL;
CMGetSystemProfile(&prof);
CGColorSpaceRef rgbSpace = CGColorSpaceCreateWithPlatformColorSpace(prof);
RetainPtr<CGColorSpaceRef> rgbSpace(AdoptCF, CGColorSpaceCreateWithPlatformColorSpace(prof));
if (rgbSpace != NULL)
{
float components[4] = {c.red() / 255.0f, c.green() / 255.0f, c.blue() / 255.0f, c.alpha() / 255.0f};
color = CGColorCreate(rgbSpace, components);
CGColorSpaceRelease(rgbSpace);
if (rgbSpace) {
CGFloat components[4] = { static_cast<CGFloat>(c.red()) / 255, static_cast<CGFloat>(c.green()) / 255,
static_cast<CGFloat>(c.blue()) / 255, static_cast<CGFloat>(c.alpha()) / 255 };
color = CGColorCreate(rgbSpace.get(), components);
}
CMCloseProfile(prof);
......
......@@ -58,17 +58,14 @@ CGShadingRef Gradient::platformGradient()
const CGFloat intervalRanges[2] = { 0, 1 };
const CGFloat colorComponentRanges[4 * 2] = { 0, 1, 0, 1, 0, 1, 0, 1 };
const CGFunctionCallbacks gradientCallbacks = { 0, gradientCallback, 0 };
CGFunctionRef colorFunction = CGFunctionCreate(this, 1, intervalRanges, 4, colorComponentRanges, &gradientCallbacks);
RetainPtr<CGFunctionRef> colorFunction(AdoptCF, CGFunctionCreate(this, 1, intervalRanges, 4, colorComponentRanges, &gradientCallbacks));
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
static CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
if (m_radial)
m_gradient = CGShadingCreateRadial(colorSpace, m_p0, m_r0, m_p1, m_r1, colorFunction, true, true);
m_gradient = CGShadingCreateRadial(colorSpace, m_p0, m_r0, m_p1, m_r1, colorFunction.get(), true, true);
else
m_gradient = CGShadingCreateAxial(colorSpace, m_p0, m_p1, colorFunction, true, true);
CGColorSpaceRelease(colorSpace);
CGFunctionRelease(colorFunction);
m_gradient = CGShadingCreateAxial(colorSpace, m_p0, m_p1, colorFunction.get(), true, true);
return m_gradient;
}
......
......@@ -87,7 +87,7 @@ CGContextRef GraphicsContext::platformContext() const
{
ASSERT(!paintingDisabled());
ASSERT(m_data->m_cgContext);
return m_data->m_cgContext;
return m_data->m_cgContext.get();
}
void GraphicsContext::savePlatformState()
......@@ -392,34 +392,30 @@ void GraphicsContext::applyStrokePattern()
{
CGContextRef cgContext = platformContext();
CGPatternRef platformPattern = m_common->state.strokePattern.get()->createPlatformPattern(getCTM());
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_common->state.strokePattern.get()->createPlatformPattern(getCTM()));
if (!platformPattern)
return;
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(0);
CGContextSetStrokeColorSpace(cgContext, patternSpace);
CGColorSpaceRelease(patternSpace);
RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
CGContextSetStrokeColorSpace(cgContext, patternSpace.get());
const CGFloat patternAlpha = 1;
CGContextSetStrokePattern(cgContext, platformPattern, &patternAlpha);
CGPatternRelease(platformPattern);
CGContextSetStrokePattern(cgContext, platformPattern.get(), &patternAlpha);
}
void GraphicsContext::applyFillPattern()
{
CGContextRef cgContext = platformContext();
CGPatternRef platformPattern = m_common->state.fillPattern.get()->createPlatformPattern(getCTM());
RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_common->state.fillPattern.get()->createPlatformPattern(getCTM()));
if (!platformPattern)
return;
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(0);
CGContextSetFillColorSpace(cgContext, patternSpace);
CGColorSpaceRelease(patternSpace);
RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
CGContextSetFillColorSpace(cgContext, patternSpace.get());
const CGFloat patternAlpha = 1;
CGContextSetFillPattern(cgContext, platformPattern, &patternAlpha);
CGPatternRelease(platformPattern);
CGContextSetFillPattern(cgContext, platformPattern.get(), &patternAlpha);
}
static inline bool calculateDrawingMode(const GraphicsContextState& state, CGPathDrawingMode& mode)
......@@ -731,12 +727,11 @@ void GraphicsContext::setPlatformShadow(const IntSize& size, int blur, const Col
if (!color.isValid())
CGContextSetShadow(context, CGSizeMake(width, height), blurRadius);
else {
CGColorRef colorCG = createCGColor(color);
RetainPtr<CGColorRef> colorCG(AdoptCF, createCGColor(color));
CGContextSetShadowWithColor(context,
CGSizeMake(width, height),
blurRadius,
colorCG);
CGColorRelease(colorCG);
colorCG.get());
}
}
......@@ -1000,22 +995,21 @@ void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
if (paintingDisabled())
return;
CFURLRef urlRef = link.createCFURL();
if (urlRef) {
CGContextRef context = platformContext();
RetainPtr<CFURLRef> urlRef(AdoptCF, link.createCFURL());
if (!urlRef)
return;
// Get the bounding box to handle clipping.
CGRect box = CGContextGetClipBoundingBox(context);
CGContextRef context = platformContext();
IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
IntRect rect = destRect;
rect.intersect(intBox);
// Get the bounding box to handle clipping.
CGRect box = CGContextGetClipBoundingBox(context);
CGPDFContextSetURLForRect(context, urlRef,
CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
IntRect rect = destRect;
rect.intersect(intBox);
CFRelease(urlRef);
}
CGPDFContextSetURLForRect(context, urlRef.get(),
CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
}
void GraphicsContext::setImageInterpolationQuality(InterpolationQuality mode)
......
......@@ -38,12 +38,10 @@ public:
#endif
, m_userToDeviceTransformKnownToBeIdentity(false)
{
CGContextRetain(m_cgContext);
}
~GraphicsContextPlatformPrivate()
{
CGContextRelease(m_cgContext);
}
#if PLATFORM(MAC) || PLATFORM(CHROMIUM)
......@@ -80,7 +78,7 @@ public:
bool m_shouldIncludeChildWindows;
#endif
CGContextRef m_cgContext;
RetainPtr<CGContextRef> m_cgContext;
bool m_userToDeviceTransformKnownToBeIdentity;
};
......
......@@ -70,34 +70,32 @@ ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, b
ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0);
CGColorSpaceRef colorSpace;
RetainPtr<CGColorSpaceRef> colorSpace;
switch(imageColorSpace) {
case DeviceRGB:
colorSpace = CGColorSpaceCreateDeviceRGB();
colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB());
break;
case GrayScale:
colorSpace = CGColorSpaceCreateDeviceGray();
colorSpace.adoptCF(CGColorSpaceCreateDeviceGray());
break;
#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER)
case LinearRGB:
colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
colorSpace.adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear));
break;
#endif
default:
colorSpace = CGColorSpaceCreateDeviceRGB();
colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB());
break;
}
CGContextRef cgContext = CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow,
colorSpace, (imageColorSpace == GrayScale) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
RetainPtr<CGContextRef> cgContext(AdoptCF, CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow,
colorSpace.get(), (imageColorSpace == GrayScale) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast));
if (!cgContext)
return;
m_context.set(new GraphicsContext(cgContext));
m_context.set(new GraphicsContext(cgContext.get()));
m_context->scale(FloatSize(1, -1));
m_context->translate(0, -size.height());
CGContextRelease(cgContext);
success = true;
}
......
......@@ -101,30 +101,29 @@ BitmapImage::BitmapImage(CGImageRef cgImage, ImageObserver* observer)
void BitmapImage::checkForSolidColor()
{
m_checkedForSolidColor = true;
if (frameCount() > 1)
if (frameCount() > 1) {
m_isSolidColor = false;
else {
CGImageRef image = frameAtIndex(0);
// Currently we only check for solid color in the important special case of a 1x1 image.
if (image && CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
unsigned char pixel[4]; // RGBA
CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
CGContextRef bmap = CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), space,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
if (bmap) {
GraphicsContext(bmap).setCompositeOperation(CompositeCopy);
CGRect dst = { {0, 0}, {1, 1} };
CGContextDrawImage(bmap, dst, image);
if (pixel[3] == 0)
m_solidColor = Color(0, 0, 0, 0);
else
m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
m_isSolidColor = true;
CFRelease(bmap);
}
CFRelease(space);
}
return;
}
CGImageRef image = frameAtIndex(0);
// Currently we only check for solid color in the important special case of a 1x1 image.
if (image && CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
unsigned char pixel[4]; // RGBA
static CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
RetainPtr<CGContextRef> bmap(AdoptCF, CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), space,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
if (!bmap)
return;
GraphicsContext(bmap.get()).setCompositeOperation(CompositeCopy);
CGRect dst = { {0, 0}, {1, 1} };
CGContextDrawImage(bmap.get(), dst, image);
if (pixel[3] == 0)
m_solidColor = Color(0, 0, 0, 0);
else
m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
m_isSolidColor = true;
}
}
......@@ -252,14 +251,14 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const
CGImageRef tileImage = nativeImageForCurrentFrame();
float h = CGImageGetHeight(tileImage);
CGImageRef subImage;
RetainPtr<CGImageRef> subImage;
if (tileRect.size() == size())
subImage = tileImage;
else {
// Copying a sub-image out of a partially-decoded image stops the decoding of the original image. It should never happen
// because sub-images are only used for border-image, which only renders when the image is fully decoded.
ASSERT(h == height());
subImage = CGImageCreateWithImageInRect(tileImage, tileRect);
subImage.adoptCF(CGImageCreateWithImageInRect(tileImage, tileRect));
}
#ifndef BUILDING_ON_TIGER
......@@ -275,7 +274,7 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const
#else
if (w == size().width() && h == size().height())
#endif
CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage);
CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage.get());
else {
#endif
......@@ -288,39 +287,31 @@ void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const
matrix = CGAffineTransformConcat(matrix, CGContextGetCTM(context));
// The top of a partially-decoded image is drawn at the bottom of the tile. Map it to the top.
matrix = CGAffineTransformTranslate(matrix, 0, size().height() - h);
CGPatternRef pattern = CGPatternCreate(subImage, CGRectMake(0, 0, tileRect.width(), tileRect.height()),
matrix, tileRect.width(), tileRect.height(),
kCGPatternTilingConstantSpacing, true, &patternCallbacks);
if (pattern == NULL) {
if (subImage != tileImage)
CGImageRelease(subImage);
RetainPtr<CGPatternRef> pattern(AdoptCF, CGPatternCreate(subImage.get(), CGRectMake(0, 0, tileRect.width(), tileRect.height()),
matrix, tileRect.width(), tileRect.height(),
kCGPatternTilingConstantSpacing, true, &patternCallbacks));
if (!pattern) {
ctxt->restore();
return;
}
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
CGFloat alpha = 1;
CGColorRef color = CGColorCreateWithPattern(patternSpace, pattern, &alpha);
CGContextSetFillColorSpace(context, patternSpace);
CGColorSpaceRelease(patternSpace);
CGPatternRelease(pattern);
RetainPtr<CGColorRef> color(AdoptCF, CGColorCreateWithPattern(patternSpace.get(), pattern.get(), &alpha));
CGContextSetFillColorSpace(context, patternSpace.get());
// FIXME: Really want a public API for this. It is just CGContextSetBaseCTM(context, CGAffineTransformIdentiy).
wkSetPatternBaseCTM(context, CGAffineTransformIdentity);
CGContextSetPatternPhase(context, CGSizeZero);
CGContextSetFillColorWithColor(context, color);
CGContextSetFillColorWithColor(context, color.get());
CGContextFillRect(context, CGContextGetClipBoundingBox(context));
CGColorRelease(color);
#ifndef BUILDING_ON_TIGER
}
#endif
if (subImage != tileImage)
CGImageRelease(subImage);
ctxt->restore();
if (imageObserver())
......
......@@ -109,18 +109,16 @@ void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
#if PLATFORM(MAC)
// On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge. We use SharedBuffer's ability
// to wrap itself inside CFData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
CFDataRef cfData = data->createCFData();
RetainPtr<CFDataRef> cfData(AdoptCF, data->createCFData());
#else
// If no NSData is available, then we know SharedBuffer will always just be a vector. That means no secret changes can occur to it behind the
// scenes. We use CFDataCreateWithBytesNoCopy in that case. Ensure that the SharedBuffer lives as long as the CFDataRef.
data->ref();
CFAllocatorContext context = {0, data, 0, 0, 0, 0, 0, &sharedBufferDerefCallback, 0};
CFAllocatorRef derefAllocator = CFAllocatorCreate(kCFAllocatorDefault, &context);
CFDataRef cfData = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data->data()), data->size(), derefAllocator);
CFRelease(derefAllocator);
RetainPtr<CFAllocatorRef> derefAllocator(AdoptCF, CFAllocatorCreate(kCFAllocatorDefault, &context));
RetainPtr<CFDataRef> cfData(AdoptCF, CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data->data()), data->size(), derefAllocator.get()));
#endif
CGImageSourceUpdateData(m_decoder, cfData, allDataReceived);
CFRelease(cfData);
CGImageSourceUpdateData(m_decoder, cfData.get(), allDataReceived);
}
String ImageSource::filenameExtension() const
......@@ -138,12 +136,11 @@ bool ImageSource::isSizeAvailable()
// Ragnaros yells: TOO SOON! You have awakened me TOO SOON, Executus!
if (imageSourceStatus >= kCGImageStatusIncomplete) {
CFDictionaryRef image0Properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions());
RetainPtr<CFDictionaryRef> image0Properties(AdoptCF, CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions()));
if (image0Properties) {
CFNumberRef widthNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties, kCGImagePropertyPixelWidth);
CFNumberRef heightNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties, kCGImagePropertyPixelHeight);
CFNumberRef widthNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelWidth);
CFNumberRef heightNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelHeight);
result = widthNumber && heightNumber;
CFRelease(image0Properties);
}
}
......@@ -153,17 +150,16 @@ bool ImageSource::isSizeAvailable()
IntSize ImageSource::frameSizeAtIndex(size_t index) const
{
IntSize result;
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
RetainPtr<CFDictionaryRef> properties(AdoptCF, CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions()));
if (properties) {
int w = 0, h = 0;
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelWidth);
if (num)
CFNumberGetValue(num, kCFNumberIntType, &w);
num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
num = (CFNumberRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelHeight);
if (num)
CFNumberGetValue(num, kCFNumberIntType, &h);
result = IntSize(w, h);
CFRelease(properties);
}
return result;
}
......@@ -180,17 +176,15 @@ int ImageSource::repetitionCount()
return result;
// A property with value 0 means loop forever.
CFDictionaryRef properties = CGImageSourceCopyProperties(m_decoder, imageSourceOptions());
RetainPtr<CFDictionaryRef> properties(AdoptCF, CGImageSourceCopyProperties(m_decoder, imageSourceOptions()));
if (properties) {
CFDictionaryRef gifProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary);
CFDictionaryRef gifProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyGIFDictionary);
if (gifProperties) {
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFLoopCount);
if (num)
CFNumberGetValue(num, kCFNumberIntType, &result);
} else
result = cAnimationNone; // Turns out we're not a GIF after all, so we don't animate.
CFRelease(properties);
}
return result;
......@@ -206,20 +200,19 @@ CGImageRef ImageSource::createFrameAtIndex(size_t index)
if (!initialized())
return 0;
CGImageRef image = CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions());
RetainPtr<CGImageRef> image(AdoptCF, CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions()));
CFStringRef imageUTI = CGImageSourceGetType(m_decoder);
static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image");
if (!imageUTI || !CFEqual(imageUTI, xbmUTI))
return image;
return image.releaseRef();
// If it is an xbm image, mask out all the white areas to render them transparent.
const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255};
CGImageRef maskedImage = CGImageCreateWithMaskingColors(image, maskingColors);
RetainPtr<CGImageRef> maskedImage(AdoptCF, CGImageCreateWithMaskingColors(image.get(), maskingColors));
if (!maskedImage)
return image;
CGImageRelease(image);
return maskedImage;
return image.releaseRef();
return maskedImage.releaseRef();
}
bool ImageSource::frameIsCompleteAtIndex(size_t index)
......@@ -233,15 +226,14 @@ float ImageSource::frameDurationAtIndex(size_t index)
return 0;
float duration = 0;
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
RetainPtr<CFDictionaryRef> properties(AdoptCF, CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions()));
if (properties) {
CFDictionaryRef typeProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary);
CFDictionaryRef typeProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyGIFDictionary);
if (typeProperties) {
CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(typeProperties, kCGImagePropertyGIFDelayTime);
if (num)
CFNumberGetValue(num, kCFNumberFloatType, &duration);
}
CFRelease(properties);
}
// Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
......
......@@ -68,16 +68,14 @@ bool PDFDocumentImage::dataChanged(bool allDataReceived)
#if PLATFORM(MAC)
// On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge. We use SharedBuffer's ability
// to wrap itself inside CFData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
CFDataRef data = this->data()->createCFData();
RetainPtr<CFDataRef> data(AdoptCF, this->data()->createCFData());
#else
// If no NSData is available, then we know SharedBuffer will always just be a vector. That means no secret changes can occur to it behind the
// scenes. We use CFDataCreateWithBytesNoCopy in that case.
CFDataRef data = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(this->data()->data()), this->data()->size(), kCFAllocatorNull);
RetainPtr<CFDataRef> data(AdoptCF, CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(this->data()->data()), this->data()->size(), kCFAllocatorNull));
#endif
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
CFRelease(data);
m_document = CGPDFDocumentCreateWithProvider(dataProvider);
CGDataProviderRelease(dataProvider);
RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
m_document = CGPDFDocumentCreateWithProvider(dataProvider.get());
setCurrentPage(0);
}
return m_document; // return true if size is available
......
......@@ -49,9 +49,8 @@ static size_t putBytesNowhere(void*, const void*, size_t count)
static CGContextRef createScratchContext()
{
CGDataConsumerCallbacks callbacks = { putBytesNowhere, 0 };
CGDataConsumerRef consumer = CGDataConsumerCreate(0, &callbacks);
CGContextRef context = CGPDFContextCreate(consumer, 0, 0);
CGDataConsumerRelease(consumer);
RetainPtr<CGDataConsumerRef> consumer(AdoptCF, CGDataConsumerCreate(0, &callbacks));
CGContextRef context = CGPDFContextCreate(consumer.get(), 0, 0);
CGFloat black[4] = { 0, 0, 0, 1 };
CGContextSetFillColor(context, black);
......@@ -129,9 +128,8 @@ bool Path::contains(const FloatPoint &point, WindRule rule) const
return false;
// CGPathContainsPoint returns false for non-closed paths, as a work-around, we copy and close the path first. Radar 4758998 asks for a better CG API to use
CGMutablePathRef path = copyCGPathClosingSubpaths(m_path);
bool ret = CGPathContainsPoint(path, 0, point, rule == RULE_EVENODD ? true : false);
CGPathRelease(path);
RetainPtr<CGMutablePathRef> path(AdoptCF, copyCGPathClosingSubpaths(m_path));
bool ret = CGPathContainsPoint(path.get(), 0, point, rule == RULE_EVENODD ? true : false);
return ret;
}
......
......@@ -46,11 +46,13 @@ FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
ATSFontContainerRef containerRef = 0;
ATSFontRef fontRef = 0;
RetainPtr<CGFontRef> cgFontRef;
#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)