Changeset 47585 in webkit


Ignore:
Timestamp:
Aug 20, 2009, 12:24:38 PM (16 years ago)
Author:
mitz@apple.com
Message:

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):

Location:
trunk/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/WebCore/ChangeLog

    r47583 r47585  
     12009-08-20  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        Replace many manually-released CFTypeRefs with RetainPtrs
     6        https://bugs.webkit.org/show_bug.cgi?id=28498
     7
     8        * platform/graphics/cg/ColorCG.cpp:
     9        (WebCore::createCGColor):
     10        * platform/graphics/cg/GradientCG.cpp:
     11        (WebCore::Gradient::platformGradient):
     12        * platform/graphics/cg/GraphicsContextCG.cpp:
     13        (WebCore::GraphicsContext::platformContext):
     14        (WebCore::GraphicsContext::applyStrokePattern):
     15        (WebCore::GraphicsContext::applyFillPattern):
     16        (WebCore::GraphicsContext::setPlatformShadow):
     17        (WebCore::GraphicsContext::setURLForRect):
     18        * platform/graphics/cg/GraphicsContextPlatformPrivateCG.h:
     19        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate):
     20        (WebCore::GraphicsContextPlatformPrivate::~GraphicsContextPlatformPrivate):
     21        * platform/graphics/cg/ImageBufferCG.cpp:
     22        (WebCore::ImageBuffer::ImageBuffer):
     23        * platform/graphics/cg/ImageCG.cpp:
     24        (WebCore::BitmapImage::checkForSolidColor):
     25        (WebCore::Image::drawPattern):
     26        * platform/graphics/cg/ImageSourceCG.cpp:
     27        (WebCore::ImageSource::setData):
     28        (WebCore::ImageSource::isSizeAvailable):
     29        (WebCore::ImageSource::frameSizeAtIndex):
     30        (WebCore::ImageSource::repetitionCount):
     31        (WebCore::ImageSource::createFrameAtIndex):
     32        (WebCore::ImageSource::frameDurationAtIndex):
     33        * platform/graphics/cg/PDFDocumentImage.cpp:
     34        (WebCore::PDFDocumentImage::dataChanged):
     35        * platform/graphics/cg/PathCG.cpp:
     36        (WebCore::createScratchContext):
     37        (WebCore::Path::contains):
     38        * platform/graphics/mac/FontCustomPlatformData.cpp:
     39        (WebCore::createFontCustomPlatformData):
     40        * platform/graphics/mac/GraphicsContextMac.mm:
     41        (WebCore::GraphicsContext::drawFocusRing):
     42        * platform/graphics/mac/ImageMac.mm:
     43        (WebCore::BitmapImage::getTIFFRepresentation):
     44        * platform/mac/ClipboardMac.mm:
     45        (WebCore::cocoaTypeFromMIMEType):
     46        (WebCore::MIMETypeFromCocoaType):
     47        * platform/mac/WebCoreNSStringExtras.mm:
     48        (stringEncodingForResource):
     49        * platform/network/mac/FormDataStreamMac.mm:
     50        (WebCore::advanceCurrentStream):
     51        (WebCore::setHTTPBody):
     52        * platform/text/mac/TextCodecMac.cpp:
     53        (WebCore::TextCodecMac::encode):
     54
    1552009-08-20  Shinichiro Hamaji  <hamaji@chromium.org>
    256
  • TabularUnified trunk/WebCore/platform/graphics/cg/ColorCG.cpp

    r41345 r47585  
    3030
    3131#include <wtf/Assertions.h>
     32#include <wtf/RetainPtr.h>
    3233#include <ApplicationServices/ApplicationServices.h>
    3334
     
    7677    CMGetSystemProfile(&prof);
    7778
    78     CGColorSpaceRef rgbSpace = CGColorSpaceCreateWithPlatformColorSpace(prof);
     79    RetainPtr<CGColorSpaceRef> rgbSpace(AdoptCF, CGColorSpaceCreateWithPlatformColorSpace(prof));
    7980
    80     if (rgbSpace != NULL)
    81     {
    82         float components[4] = {c.red() / 255.0f, c.green() / 255.0f, c.blue() / 255.0f, c.alpha() / 255.0f};
    83         color = CGColorCreate(rgbSpace, components);
    84         CGColorSpaceRelease(rgbSpace);
     81    if (rgbSpace) {
     82        CGFloat components[4] = { static_cast<CGFloat>(c.red()) / 255, static_cast<CGFloat>(c.green()) / 255,
     83                                  static_cast<CGFloat>(c.blue()) / 255, static_cast<CGFloat>(c.alpha()) / 255 };
     84        color = CGColorCreate(rgbSpace.get(), components);
    8585    }
    8686
  • TabularUnified trunk/WebCore/platform/graphics/cg/GradientCG.cpp

    r31830 r47585  
    5959    const CGFloat colorComponentRanges[4 * 2] = { 0, 1, 0, 1, 0, 1, 0, 1 };
    6060    const CGFunctionCallbacks gradientCallbacks = { 0, gradientCallback, 0 };
    61     CGFunctionRef colorFunction = CGFunctionCreate(this, 1, intervalRanges, 4, colorComponentRanges, &gradientCallbacks);
     61    RetainPtr<CGFunctionRef> colorFunction(AdoptCF, CGFunctionCreate(this, 1, intervalRanges, 4, colorComponentRanges, &gradientCallbacks));
    6262
    63     CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
     63    static CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    6464
    6565    if (m_radial)
    66         m_gradient = CGShadingCreateRadial(colorSpace, m_p0, m_r0, m_p1, m_r1, colorFunction, true, true);
     66        m_gradient = CGShadingCreateRadial(colorSpace, m_p0, m_r0, m_p1, m_r1, colorFunction.get(), true, true);
    6767    else
    68         m_gradient = CGShadingCreateAxial(colorSpace, m_p0, m_p1, colorFunction, true, true);
    69 
    70     CGColorSpaceRelease(colorSpace);
    71     CGFunctionRelease(colorFunction);
     68        m_gradient = CGShadingCreateAxial(colorSpace, m_p0, m_p1, colorFunction.get(), true, true);
    7269
    7370    return m_gradient;
  • TabularUnified trunk/WebCore/platform/graphics/cg/GraphicsContextCG.cpp

    r47360 r47585  
    8888    ASSERT(!paintingDisabled());
    8989    ASSERT(m_data->m_cgContext);
    90     return m_data->m_cgContext;
     90    return m_data->m_cgContext.get();
    9191}
    9292
     
    393393    CGContextRef cgContext = platformContext();
    394394
    395     CGPatternRef platformPattern = m_common->state.strokePattern.get()->createPlatformPattern(getCTM());
     395    RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_common->state.strokePattern.get()->createPlatformPattern(getCTM()));
    396396    if (!platformPattern)
    397397        return;
    398398
    399     CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(0);
    400     CGContextSetStrokeColorSpace(cgContext, patternSpace);
    401     CGColorSpaceRelease(patternSpace);
     399    RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
     400    CGContextSetStrokeColorSpace(cgContext, patternSpace.get());
    402401
    403402    const CGFloat patternAlpha = 1;
    404     CGContextSetStrokePattern(cgContext, platformPattern, &patternAlpha);
    405     CGPatternRelease(platformPattern);
     403    CGContextSetStrokePattern(cgContext, platformPattern.get(), &patternAlpha);
    406404}
    407405
     
    410408    CGContextRef cgContext = platformContext();
    411409
    412     CGPatternRef platformPattern = m_common->state.fillPattern.get()->createPlatformPattern(getCTM());
     410    RetainPtr<CGPatternRef> platformPattern(AdoptCF, m_common->state.fillPattern.get()->createPlatformPattern(getCTM()));
    413411    if (!platformPattern)
    414412        return;
    415413
    416     CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(0);
    417     CGContextSetFillColorSpace(cgContext, patternSpace);
    418     CGColorSpaceRelease(patternSpace);
     414    RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
     415    CGContextSetFillColorSpace(cgContext, patternSpace.get());
    419416
    420417    const CGFloat patternAlpha = 1;
    421     CGContextSetFillPattern(cgContext, platformPattern, &patternAlpha);
    422     CGPatternRelease(platformPattern);
     418    CGContextSetFillPattern(cgContext, platformPattern.get(), &patternAlpha);
    423419}
    424420
     
    732728        CGContextSetShadow(context, CGSizeMake(width, height), blurRadius);
    733729    else {
    734         CGColorRef colorCG = createCGColor(color);
     730        RetainPtr<CGColorRef> colorCG(AdoptCF, createCGColor(color));
    735731        CGContextSetShadowWithColor(context,
    736732                                    CGSizeMake(width, height),
    737733                                    blurRadius,
    738                                     colorCG);
    739         CGColorRelease(colorCG);
     734                                    colorCG.get());
    740735    }
    741736}
     
    1001996        return;
    1002997
    1003     CFURLRef urlRef = link.createCFURL();
    1004     if (urlRef) {
    1005         CGContextRef context = platformContext();
    1006 
    1007         // Get the bounding box to handle clipping.
    1008         CGRect box = CGContextGetClipBoundingBox(context);
    1009 
    1010         IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
    1011         IntRect rect = destRect;
    1012         rect.intersect(intBox);
    1013 
    1014         CGPDFContextSetURLForRect(context, urlRef,
    1015             CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
    1016 
    1017         CFRelease(urlRef);
    1018     }
     998    RetainPtr<CFURLRef> urlRef(AdoptCF, link.createCFURL());
     999    if (!urlRef)
     1000        return;
     1001
     1002    CGContextRef context = platformContext();
     1003
     1004    // Get the bounding box to handle clipping.
     1005    CGRect box = CGContextGetClipBoundingBox(context);
     1006
     1007    IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
     1008    IntRect rect = destRect;
     1009    rect.intersect(intBox);
     1010
     1011    CGPDFContextSetURLForRect(context, urlRef.get(),
     1012        CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
    10191013}
    10201014
  • TabularUnified trunk/WebCore/platform/graphics/cg/GraphicsContextPlatformPrivateCG.h

    r44821 r47585  
    3939        , m_userToDeviceTransformKnownToBeIdentity(false)
    4040    {
    41         CGContextRetain(m_cgContext);
    4241    }
    4342   
    4443    ~GraphicsContextPlatformPrivate()
    4544    {
    46         CGContextRelease(m_cgContext);
    4745    }
    4846
     
    8179#endif
    8280
    83     CGContextRef m_cgContext;
     81    RetainPtr<CGContextRef> m_cgContext;
    8482    bool m_userToDeviceTransformKnownToBeIdentity;
    8583};
  • TabularUnified trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r47099 r47585  
    7171    ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0);
    7272
    73     CGColorSpaceRef colorSpace;
     73    RetainPtr<CGColorSpaceRef> colorSpace;
    7474    switch(imageColorSpace) {
    7575        case DeviceRGB:
    76             colorSpace = CGColorSpaceCreateDeviceRGB();
     76            colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB());
    7777            break;
    7878        case GrayScale:
    79             colorSpace = CGColorSpaceCreateDeviceGray();
     79            colorSpace.adoptCF(CGColorSpaceCreateDeviceGray());
    8080            break;
    8181#if PLATFORM(MAC) && !defined(BUILDING_ON_TIGER)
    8282        case LinearRGB:
    83             colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
     83            colorSpace.adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear));
    8484            break;
    8585#endif
    8686        default:
    87             colorSpace = CGColorSpaceCreateDeviceRGB();
     87            colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB());
    8888            break;
    8989    }
    9090
    91     CGContextRef cgContext = CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow,
    92         colorSpace, (imageColorSpace == GrayScale) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast);
    93     CGColorSpaceRelease(colorSpace);
     91    RetainPtr<CGContextRef> cgContext(AdoptCF, CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow,
     92        colorSpace.get(), (imageColorSpace == GrayScale) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast));
    9493    if (!cgContext)
    9594        return;
    9695
    97     m_context.set(new GraphicsContext(cgContext));
     96    m_context.set(new GraphicsContext(cgContext.get()));
    9897    m_context->scale(FloatSize(1, -1));
    9998    m_context->translate(0, -size.height());
    100     CGContextRelease(cgContext);
    10199    success = true;
    102100}
  • TabularUnified trunk/WebCore/platform/graphics/cg/ImageCG.cpp

    r46002 r47585  
    102102{
    103103    m_checkedForSolidColor = true;
    104     if (frameCount() > 1)
     104    if (frameCount() > 1) {
    105105        m_isSolidColor = false;
    106     else {
    107         CGImageRef image = frameAtIndex(0);
    108        
    109         // Currently we only check for solid color in the important special case of a 1x1 image.
    110         if (image && CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
    111             unsigned char pixel[4]; // RGBA
    112             CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    113             CGContextRef bmap = CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), space,
    114                 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
    115             if (bmap) {
    116                 GraphicsContext(bmap).setCompositeOperation(CompositeCopy);
    117                 CGRect dst = { {0, 0}, {1, 1} };
    118                 CGContextDrawImage(bmap, dst, image);
    119                 if (pixel[3] == 0)
    120                     m_solidColor = Color(0, 0, 0, 0);
    121                 else
    122                     m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
    123                 m_isSolidColor = true;
    124                 CFRelease(bmap);
    125             }
    126             CFRelease(space);
    127         }
     106        return;
     107    }
     108
     109    CGImageRef image = frameAtIndex(0);
     110   
     111    // Currently we only check for solid color in the important special case of a 1x1 image.
     112    if (image && CGImageGetWidth(image) == 1 && CGImageGetHeight(image) == 1) {
     113        unsigned char pixel[4]; // RGBA
     114        static CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
     115        RetainPtr<CGContextRef> bmap(AdoptCF, CGBitmapContextCreate(pixel, 1, 1, 8, sizeof(pixel), space,
     116            kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big));
     117        if (!bmap)
     118            return;
     119        GraphicsContext(bmap.get()).setCompositeOperation(CompositeCopy);
     120        CGRect dst = { {0, 0}, {1, 1} };
     121        CGContextDrawImage(bmap.get(), dst, image);
     122        if (pixel[3] == 0)
     123            m_solidColor = Color(0, 0, 0, 0);
     124        else
     125            m_solidColor = Color(pixel[0] * 255 / pixel[3], pixel[1] * 255 / pixel[3], pixel[2] * 255 / pixel[3], pixel[3]);
     126        m_isSolidColor = true;
    128127    }
    129128}
     
    253252    float h = CGImageGetHeight(tileImage);
    254253
    255     CGImageRef subImage;
     254    RetainPtr<CGImageRef> subImage;
    256255    if (tileRect.size() == size())
    257256        subImage = tileImage;
     
    260259        // because sub-images are only used for border-image, which only renders when the image is fully decoded.
    261260        ASSERT(h == height());
    262         subImage = CGImageCreateWithImageInRect(tileImage, tileRect);
     261        subImage.adoptCF(CGImageCreateWithImageInRect(tileImage, tileRect));
    263262    }
    264263   
     
    276275    if (w == size().width() && h == size().height())
    277276#endif
    278         CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage);
     277        CGContextDrawTiledImage(context, FloatRect(adjustedX, adjustedY, scaledTileWidth, scaledTileHeight), subImage.get());
    279278    else {
    280279#endif
     
    289288    // The top of a partially-decoded image is drawn at the bottom of the tile. Map it to the top.
    290289    matrix = CGAffineTransformTranslate(matrix, 0, size().height() - h);
    291     CGPatternRef pattern = CGPatternCreate(subImage, CGRectMake(0, 0, tileRect.width(), tileRect.height()),
    292                                            matrix, tileRect.width(), tileRect.height(),
    293                                            kCGPatternTilingConstantSpacing, true, &patternCallbacks);
    294     if (pattern == NULL) {
    295         if (subImage != tileImage)
    296             CGImageRelease(subImage);
     290    RetainPtr<CGPatternRef> pattern(AdoptCF, CGPatternCreate(subImage.get(), CGRectMake(0, 0, tileRect.width(), tileRect.height()),
     291                                             matrix, tileRect.width(), tileRect.height(),
     292                                             kCGPatternTilingConstantSpacing, true, &patternCallbacks));
     293    if (!pattern) {
    297294        ctxt->restore();
    298295        return;
    299296    }
    300297
    301     CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
     298    RetainPtr<CGColorSpaceRef> patternSpace(AdoptCF, CGColorSpaceCreatePattern(0));
    302299   
    303300    CGFloat alpha = 1;
    304     CGColorRef color = CGColorCreateWithPattern(patternSpace, pattern, &alpha);
    305     CGContextSetFillColorSpace(context, patternSpace);
    306     CGColorSpaceRelease(patternSpace);
    307     CGPatternRelease(pattern);
     301    RetainPtr<CGColorRef> color(AdoptCF, CGColorCreateWithPattern(patternSpace.get(), pattern.get(), &alpha));
     302    CGContextSetFillColorSpace(context, patternSpace.get());
    308303
    309304    // FIXME: Really want a public API for this.  It is just CGContextSetBaseCTM(context, CGAffineTransformIdentiy).
     
    311306    CGContextSetPatternPhase(context, CGSizeZero);
    312307
    313     CGContextSetFillColorWithColor(context, color);
     308    CGContextSetFillColorWithColor(context, color.get());
    314309    CGContextFillRect(context, CGContextGetClipBoundingBox(context));
    315    
    316     CGColorRelease(color);
    317    
     310
    318311#ifndef BUILDING_ON_TIGER
    319312    }
    320313#endif
    321314
    322     if (subImage != tileImage)
    323         CGImageRelease(subImage);
    324315    ctxt->restore();
    325316
  • TabularUnified trunk/WebCore/platform/graphics/cg/ImageSourceCG.cpp

    r46527 r47585  
    110110    // On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.  We use SharedBuffer's ability
    111111    // to wrap itself inside CFData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
    112     CFDataRef cfData = data->createCFData();
     112    RetainPtr<CFDataRef> cfData(AdoptCF, data->createCFData());
    113113#else
    114114    // 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
     
    116116    data->ref();
    117117    CFAllocatorContext context = {0, data, 0, 0, 0, 0, 0, &sharedBufferDerefCallback, 0};
    118     CFAllocatorRef derefAllocator = CFAllocatorCreate(kCFAllocatorDefault, &context);
    119     CFDataRef cfData = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data->data()), data->size(), derefAllocator);
    120     CFRelease(derefAllocator);
     118    RetainPtr<CFAllocatorRef> derefAllocator(AdoptCF, CFAllocatorCreate(kCFAllocatorDefault, &context));
     119    RetainPtr<CFDataRef> cfData(AdoptCF, CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(data->data()), data->size(), derefAllocator.get()));
    121120#endif
    122     CGImageSourceUpdateData(m_decoder, cfData, allDataReceived);
    123     CFRelease(cfData);
     121    CGImageSourceUpdateData(m_decoder, cfData.get(), allDataReceived);
    124122}
    125123
     
    139137    // Ragnaros yells: TOO SOON! You have awakened me TOO SOON, Executus!
    140138    if (imageSourceStatus >= kCGImageStatusIncomplete) {
    141         CFDictionaryRef image0Properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions());
     139        RetainPtr<CFDictionaryRef> image0Properties(AdoptCF, CGImageSourceCopyPropertiesAtIndex(m_decoder, 0, imageSourceOptions()));
    142140        if (image0Properties) {
    143             CFNumberRef widthNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties, kCGImagePropertyPixelWidth);
    144             CFNumberRef heightNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties, kCGImagePropertyPixelHeight);
     141            CFNumberRef widthNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelWidth);
     142            CFNumberRef heightNumber = (CFNumberRef)CFDictionaryGetValue(image0Properties.get(), kCGImagePropertyPixelHeight);
    145143            result = widthNumber && heightNumber;
    146             CFRelease(image0Properties);
    147144        }
    148145    }
     
    154151{
    155152    IntSize result;
    156     CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
     153    RetainPtr<CFDictionaryRef> properties(AdoptCF, CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions()));
    157154    if (properties) {
    158155        int w = 0, h = 0;
    159         CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelWidth);
     156        CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelWidth);
    160157        if (num)
    161158            CFNumberGetValue(num, kCFNumberIntType, &w);
    162         num = (CFNumberRef)CFDictionaryGetValue(properties, kCGImagePropertyPixelHeight);
     159        num = (CFNumberRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyPixelHeight);
    163160        if (num)
    164161            CFNumberGetValue(num, kCFNumberIntType, &h);
    165162        result = IntSize(w, h);
    166         CFRelease(properties);
    167163    }
    168164    return result;
     
    181177
    182178    // A property with value 0 means loop forever.
    183     CFDictionaryRef properties = CGImageSourceCopyProperties(m_decoder, imageSourceOptions());
     179    RetainPtr<CFDictionaryRef> properties(AdoptCF, CGImageSourceCopyProperties(m_decoder, imageSourceOptions()));
    184180    if (properties) {
    185         CFDictionaryRef gifProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary);
     181        CFDictionaryRef gifProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyGIFDictionary);
    186182        if (gifProperties) {
    187183            CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(gifProperties, kCGImagePropertyGIFLoopCount);
     
    190186        } else
    191187            result = cAnimationNone; // Turns out we're not a GIF after all, so we don't animate.
    192        
    193         CFRelease(properties);
    194188    }
    195189   
     
    207201        return 0;
    208202
    209     CGImageRef image = CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions());
     203    RetainPtr<CGImageRef> image(AdoptCF, CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions()));
    210204    CFStringRef imageUTI = CGImageSourceGetType(m_decoder);
    211205    static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image");
    212206    if (!imageUTI || !CFEqual(imageUTI, xbmUTI))
    213         return image;
     207        return image.releaseRef();
    214208   
    215209    // If it is an xbm image, mask out all the white areas to render them transparent.
    216210    const CGFloat maskingColors[6] = {255, 255,  255, 255, 255, 255};
    217     CGImageRef maskedImage = CGImageCreateWithMaskingColors(image, maskingColors);
     211    RetainPtr<CGImageRef> maskedImage(AdoptCF, CGImageCreateWithMaskingColors(image.get(), maskingColors));
    218212    if (!maskedImage)
    219         return image;
    220        
    221     CGImageRelease(image);
    222     return maskedImage;
     213        return image.releaseRef();
     214
     215    return maskedImage.releaseRef();
    223216}
    224217
     
    234227
    235228    float duration = 0;
    236     CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions());
     229    RetainPtr<CFDictionaryRef> properties(AdoptCF, CGImageSourceCopyPropertiesAtIndex(m_decoder, index, imageSourceOptions()));
    237230    if (properties) {
    238         CFDictionaryRef typeProperties = (CFDictionaryRef)CFDictionaryGetValue(properties, kCGImagePropertyGIFDictionary);
     231        CFDictionaryRef typeProperties = (CFDictionaryRef)CFDictionaryGetValue(properties.get(), kCGImagePropertyGIFDictionary);
    239232        if (typeProperties) {
    240233            CFNumberRef num = (CFNumberRef)CFDictionaryGetValue(typeProperties, kCGImagePropertyGIFDelayTime);
     
    242235                CFNumberGetValue(num, kCFNumberFloatType, &duration);
    243236        }
    244         CFRelease(properties);
    245237    }
    246238
  • TabularUnified trunk/WebCore/platform/graphics/cg/PDFDocumentImage.cpp

    r45781 r47585  
    6969        // On Mac the NSData inside the SharedBuffer can be secretly appended to without the SharedBuffer's knowledge.  We use SharedBuffer's ability
    7070        // to wrap itself inside CFData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
    71         CFDataRef data = this->data()->createCFData();
     71        RetainPtr<CFDataRef> data(AdoptCF, this->data()->createCFData());
    7272#else
    7373        // 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
    7474        // scenes.  We use CFDataCreateWithBytesNoCopy in that case.
    75         CFDataRef data = CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(this->data()->data()), this->data()->size(), kCFAllocatorNull);
     75        RetainPtr<CFDataRef> data(AdoptCF, CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(this->data()->data()), this->data()->size(), kCFAllocatorNull));
    7676#endif
    77         CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData(data);
    78         CFRelease(data);
    79         m_document = CGPDFDocumentCreateWithProvider(dataProvider);
    80         CGDataProviderRelease(dataProvider);
     77        RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
     78        m_document = CGPDFDocumentCreateWithProvider(dataProvider.get());
    8179        setCurrentPage(0);
    8280    }
  • TabularUnified trunk/WebCore/platform/graphics/cg/PathCG.cpp

    r45873 r47585  
    5050{
    5151    CGDataConsumerCallbacks callbacks = { putBytesNowhere, 0 };
    52     CGDataConsumerRef consumer = CGDataConsumerCreate(0, &callbacks);
    53     CGContextRef context = CGPDFContextCreate(consumer, 0, 0);
    54     CGDataConsumerRelease(consumer);
     52    RetainPtr<CGDataConsumerRef> consumer(AdoptCF, CGDataConsumerCreate(0, &callbacks));
     53    CGContextRef context = CGPDFContextCreate(consumer.get(), 0, 0);
    5554
    5655    CGFloat black[4] = { 0, 0, 0, 1 };
     
    130129
    131130    // 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
    132     CGMutablePathRef path = copyCGPathClosingSubpaths(m_path);
    133     bool ret = CGPathContainsPoint(path, 0, point, rule == RULE_EVENODD ? true : false);
    134     CGPathRelease(path);
     131    RetainPtr<CGMutablePathRef> path(AdoptCF, copyCGPathClosingSubpaths(m_path));
     132    bool ret = CGPathContainsPoint(path.get(), 0, point, rule == RULE_EVENODD ? true : false);
    135133    return ret;
    136134}
  • TabularUnified trunk/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp

    r40375 r47585  
    4747    ATSFontRef fontRef = 0;
    4848
     49    RetainPtr<CGFontRef> cgFontRef;
     50
    4951#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    5052    RetainPtr<CFDataRef> bufferData(AdoptCF, buffer->createCFData());
    5153    RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(bufferData.get()));
    5254   
    53     CGFontRef cgFontRef = CGFontCreateWithDataProvider(dataProvider.get());
     55    cgFontRef.adoptCF(CGFontCreateWithDataProvider(dataProvider.get()));
    5456    if (!cgFontRef)
    5557        return 0;
     
    7678    }
    7779   
    78     CGFontRef cgFontRef = CGFontCreateWithPlatformFont(&fontRef);
     80    cgFontRef.adoptCF(CGFontCreateWithPlatformFont(&fontRef));
    7981#ifndef BUILDING_ON_TIGER
    8082    // Workaround for <rdar://problem/5675504>.
    81     if (cgFontRef && !CGFontGetNumberOfGlyphs(cgFontRef)) {
    82         CFRelease(cgFontRef);
     83    if (cgFontRef && !CGFontGetNumberOfGlyphs(cgFontRef.get()))
    8384        cgFontRef = 0;
    84     }
    8585#endif
    8686    if (!cgFontRef) {
     
    9090#endif // !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
    9191
    92     return new FontCustomPlatformData(containerRef, fontRef, cgFontRef);
     92    return new FontCustomPlatformData(containerRef, fontRef, cgFontRef.releaseRef());
    9393}
    9494
  • TabularUnified trunk/WebCore/platform/graphics/mac/GraphicsContextMac.mm

    r43389 r47585  
    5151    int radius = (focusRingWidth() - 1) / 2;
    5252    int offset = radius + focusRingOffset();
    53     CGColorRef colorRef = color.isValid() ? createCGColor(color) : 0;
     53    RetainPtr<CGColorRef> colorRef;
     54    if (color.isValid())
     55        colorRef.adoptCF(createCGColor(color));
    5456
    55     CGMutablePathRef focusRingPath = CGPathCreateMutable();
     57    RetainPtr<CGMutablePathRef> focusRingPath(AdoptCF, CGPathCreateMutable());
    5658    const Vector<IntRect>& rects = focusRingRects();
    5759    unsigned rectCount = rects.size();
    5860    for (unsigned i = 0; i < rectCount; i++)
    59         CGPathAddRect(focusRingPath, 0, CGRectInset(rects[i], -offset, -offset));
     61        CGPathAddRect(focusRingPath.get(), 0, CGRectInset(rects[i], -offset, -offset));
    6062
    6163    CGContextRef context = platformContext();
     
    6466#endif
    6567    CGContextBeginPath(context);
    66     CGContextAddPath(context, focusRingPath);
    67     wkDrawFocusRing(context, colorRef, radius);
     68    CGContextAddPath(context, focusRingPath.get());
     69    wkDrawFocusRing(context, colorRef.get(), radius);
    6870#ifdef BUILDING_ON_TIGER
    6971    CGContextEndTransparencyLayer(context);
    7072#endif
    71     CGColorRelease(colorRef);
    72 
    73     CGPathRelease(focusRingPath);
    7473}
    7574
  • TabularUnified trunk/WebCore/platform/graphics/mac/ImageMac.mm

    r35731 r47585  
    9595    RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(0, 0));
    9696    // FIXME:  Use type kCGImageTypeIdentifierTIFF constant once is becomes available in the API
    97     CGImageDestinationRef destination = CGImageDestinationCreateWithData(data.get(), CFSTR("public.tiff"), numValidFrames, 0);
    98    
     97    RetainPtr<CGImageDestinationRef> destination(AdoptCF, CGImageDestinationCreateWithData(data.get(), CFSTR("public.tiff"), numValidFrames, 0));
     98
    9999    if (!destination)
    100100        return 0;
    101101   
    102102    for (unsigned i = 0; i < numValidFrames; ++i)
    103         CGImageDestinationAddImage(destination, images[i], 0);
     103        CGImageDestinationAddImage(destination.get(), images[i], 0);
    104104
    105     CGImageDestinationFinalize(destination);
    106     CFRelease(destination);
     105    CGImageDestinationFinalize(destination.get());
    107106
    108107    m_tiffRep = data;
  • TabularUnified trunk/WebCore/platform/mac/ClipboardMac.mm

    r45168 r47585  
    8383    // Try UTI now
    8484    NSString *mimeType = qType;
    85     CFStringRef UTIType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL);
    86     if (UTIType) {
    87         CFStringRef pbType = UTTypeCopyPreferredTagWithClass(UTIType, kUTTagClassNSPboardType);
    88         CFRelease(UTIType);
     85    RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (CFStringRef)mimeType, NULL));
     86    if (utiType) {
     87        CFStringRef pbType = UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassNSPboardType);
    8988        if (pbType)
    9089            return HardAutorelease(pbType);
     
    104103   
    105104    // Now try the general UTI mechanism
    106     CFStringRef UTIType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL);
    107     if (UTIType) {
    108         CFStringRef mimeType = UTTypeCopyPreferredTagWithClass(UTIType, kUTTagClassMIMEType);
    109         CFRelease(UTIType);
    110         if (mimeType) {
    111             String result = mimeType;
    112             CFRelease(mimeType);
    113             return result;
    114         }
     105    RetainPtr<CFStringRef> utiType(AdoptCF, UTTypeCreatePreferredIdentifierForTag(kUTTagClassNSPboardType, (CFStringRef)type, NULL));
     106    if (utiType) {
     107        RetainPtr<CFStringRef> mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(utiType.get(), kUTTagClassMIMEType));
     108        if (mimeType)
     109            return String(mimeType.get());
    115110    }
    116111
  • TabularUnified trunk/WebCore/platform/mac/WebCoreNSStringExtras.mm

    r38333 r47585  
    2929#import "config.h"
    3030#import "WebCoreNSStringExtras.h"
     31
     32#import <wtf/RetainPtr.h>
    3133
    3234BOOL stringIsCaseInsensitiveEqualToString(NSString *first, NSString *second)
     
    7072{
    7173    short resRef = HomeResFile(resource);
    72     if (ResError() != noErr) {
     74    if (ResError() != noErr)
    7375        return NSMacOSRomanStringEncoding;
    74     }
    7576   
    7677    // Get the FSRef for the current resource file
    7778    FSRef fref;
    7879    OSStatus error = FSGetForkCBInfo(resRef, 0, NULL, NULL, NULL, &fref, NULL);
    79     if (error != noErr) {
     80    if (error != noErr)
    8081        return NSMacOSRomanStringEncoding;
    81     }
    8282   
    83     CFURLRef URL = CFURLCreateFromFSRef(NULL, &fref);
    84     if (URL == NULL) {
     83    RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateFromFSRef(NULL, &fref));
     84    if (!url)
    8585        return NSMacOSRomanStringEncoding;
    86     }
    87    
    88     NSString *path = [(NSURL *)URL path];
    89     CFRelease(URL);
    90    
     86
     87    NSString *path = [(NSURL *)url.get() path];
     88
    9189    // Get the lproj directory name
    9290    path = [path stringByDeletingLastPathComponent];
    93     if (!stringIsCaseInsensitiveEqualToString([path pathExtension], @"lproj")) {
     91    if (!stringIsCaseInsensitiveEqualToString([path pathExtension], @"lproj"))
    9492        return NSMacOSRomanStringEncoding;
    95     }
    9693   
    9794    NSString *directoryName = [[path stringByDeletingPathExtension] lastPathComponent];
    98     CFStringRef locale = CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName);
    99     if (locale == NULL) {
     95    RetainPtr<CFStringRef> locale(AdoptCF, CFLocaleCreateCanonicalLocaleIdentifierFromString(NULL, (CFStringRef)directoryName));
     96    if (!locale)
    10097        return NSMacOSRomanStringEncoding;
    101     }
    102            
     98
    10399    LangCode lang;
    104100    RegionCode region;
    105     error = LocaleStringToLangAndRegionCodes([(NSString *)locale UTF8String], &lang, &region);
    106     CFRelease(locale);
    107     if (error != noErr) {
     101    error = LocaleStringToLangAndRegionCodes([(NSString *)locale.get() UTF8String], &lang, &region);
     102    if (error != noErr)
    108103        return NSMacOSRomanStringEncoding;
    109     }
    110    
     104
    111105    TextEncoding encoding;
    112106    error = UpgradeScriptInfoToTextEncoding(kTextScriptDontCare, lang, region, NULL, &encoding);
    113     if (error != noErr) {
     107    if (error != noErr)
    114108        return NSMacOSRomanStringEncoding;
    115     }
    116109   
    117110    return encoding;
  • TabularUnified trunk/WebCore/platform/network/mac/FormDataStreamMac.mm

    r46822 r47585  
    162162    } else {
    163163        const String& path = nextInput.m_shouldGenerateFile ? nextInput.m_generatedFilename : nextInput.m_filename;
    164         CFStringRef filename = path.createCFString();
    165         CFURLRef fileURL = CFURLCreateWithFileSystemPath(0, filename, kCFURLPOSIXPathStyle, FALSE);
    166         CFRelease(filename);
    167         form->currentStream = CFReadStreamCreateWithFile(0, fileURL);
    168         CFRelease(fileURL);
     164        RetainPtr<CFStringRef> filename(AdoptCF, path.createCFString());
     165        RetainPtr<CFURLRef> fileURL(AdoptCF, CFURLCreateWithFileSystemPath(0, filename.get(), kCFURLPOSIXPathStyle, FALSE));
     166        form->currentStream = CFReadStreamCreateWithFile(0, fileURL.get());
    169167    }
    170168    form->remainingElements.removeLast();
     
    376374    FormContext formContext = { formData.releaseRef(), length };
    377375
    378     CFReadStreamRef stream = wkCreateCustomCFReadStream(formCreate, formFinalize,
     376    RetainPtr<CFReadStreamRef> stream(AdoptCF, wkCreateCustomCFReadStream(formCreate, formFinalize,
    379377        formOpen, formRead, formCanRead, formClose, formSchedule, formUnschedule,
    380         &formContext);
    381     [request setHTTPBodyStream:(NSInputStream *)stream];
    382     CFRelease(stream);
     378        &formContext));
     379    [request setHTTPBodyStream:(NSInputStream *)stream.get()];
    383380}
    384381
  • TabularUnified trunk/WebCore/platform/text/mac/TextCodecMac.cpp

    r47341 r47585  
    284284    String copy(characters, length);
    285285    copy.replace('\\', m_backslashAsCurrencySymbol);
    286     CFStringRef cfs = copy.createCFString();
     286    RetainPtr<CFStringRef> cfs(AdoptCF, copy.createCFString());
    287287
    288288    CFIndex startPos = 0;
    289     CFIndex charactersLeft = CFStringGetLength(cfs);
     289    CFIndex charactersLeft = CFStringGetLength(cfs.get());
    290290    Vector<char> result;
    291291    size_t size = 0;
     
    294294        CFRange range = CFRangeMake(startPos, charactersLeft);
    295295        CFIndex bufferLength;
    296         CFStringGetBytes(cfs, range, m_encoding, lossByte, false, NULL, 0x7FFFFFFF, &bufferLength);
     296        CFStringGetBytes(cfs.get(), range, m_encoding, lossByte, false, NULL, 0x7FFFFFFF, &bufferLength);
    297297
    298298        result.grow(size + bufferLength);
    299299        unsigned char* buffer = reinterpret_cast<unsigned char*>(result.data() + size);
    300         CFIndex charactersConverted = CFStringGetBytes(cfs, range, m_encoding, lossByte, false, buffer, bufferLength, &bufferLength);
     300        CFIndex charactersConverted = CFStringGetBytes(cfs.get(), range, m_encoding, lossByte, false, buffer, bufferLength, &bufferLength);
    301301        size += bufferLength;
    302302
    303303        if (charactersConverted != charactersLeft) {
    304             unsigned badChar = CFStringGetCharacterAtIndex(cfs, startPos + charactersConverted);
     304            unsigned badChar = CFStringGetCharacterAtIndex(cfs.get(), startPos + charactersConverted);
    305305            ++charactersConverted;
    306306            if ((badChar & 0xFC00) == 0xD800 && charactersConverted != charactersLeft) { // is high surrogate
    307                 UniChar low = CFStringGetCharacterAtIndex(cfs, startPos + charactersConverted);
     307                UniChar low = CFStringGetCharacterAtIndex(cfs.get(), startPos + charactersConverted);
    308308                if ((low & 0xFC00) == 0xDC00) { // is low surrogate
    309309                    badChar <<= 10;
     
    323323        charactersLeft -= charactersConverted;
    324324    }
    325     CFRelease(cfs);
    326325    return CString(result.data(), size);
    327326}
Note: See TracChangeset for help on using the changeset viewer.