Changeset 51207 in webkit


Ignore:
Timestamp:
Nov 19, 2009 3:12:56 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-19 Avi Drissman <avi@chromium.org>

Reviewed by Darin Adler.

Properly create a CGImageRef on non-PLATFORM(MAC).
https://bugs.webkit.org/show_bug.cgi?id=27777

  • platform/graphics/cg/ImageSourceCG.cpp: (WebCore::sharedBufferGetBytesAtPosition): (WebCore::sharedBufferRelease): (WebCore::ImageSource::setData):
  • platform/graphics/cg/ImageSourceCG.h:
  • platform/graphics/cg/PDFDocumentImage.cpp: (WebCore::PDFDocumentImage::dataChanged):
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r51205 r51207  
     12009-11-19  Avi Drissman  <avi@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Properly create a CGImageRef on non-PLATFORM(MAC).
     6        https://bugs.webkit.org/show_bug.cgi?id=27777
     7
     8        * platform/graphics/cg/ImageSourceCG.cpp:
     9        (WebCore::sharedBufferGetBytesAtPosition):
     10        (WebCore::sharedBufferRelease):
     11        (WebCore::ImageSource::setData):
     12        * platform/graphics/cg/ImageSourceCG.h:
     13        * platform/graphics/cg/PDFDocumentImage.cpp:
     14        (WebCore::PDFDocumentImage::dataChanged):
     15
    1162009-11-19  Oliver Hunt  <oliver@apple.com>
    217
  • trunk/WebCore/platform/graphics/cg/ImageSourceCG.cpp

    r47585 r51207  
    3636#include <wtf/UnusedParam.h>
    3737
     38using namespace std;
     39
    3840namespace WebCore {
    3941
     
    4143
    4244#if !PLATFORM(MAC)
    43 static void sharedBufferDerefCallback(void*, void* info)
     45size_t sharedBufferGetBytesAtPosition(void* info, void* buffer, off_t position, size_t count)
     46{
     47    SharedBuffer* sharedBuffer = static_cast<SharedBuffer*>(info);
     48    size_t sourceSize = sharedBuffer->size();
     49    if (position >= sourceSize)
     50        return 0;
     51
     52    const char* source = sharedBuffer->data() + position;
     53    size_t amount = min<size_t>(count, sourceSize - position);
     54    memcpy(buffer, source, amount);
     55    return amount;
     56}
     57
     58void sharedBufferRelease(void* info)
    4459{
    4560    SharedBuffer* sharedBuffer = static_cast<SharedBuffer*>(info);
     
    111126    // to wrap itself inside CFData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
    112127    RetainPtr<CFDataRef> cfData(AdoptCF, data->createCFData());
     128    CGImageSourceUpdateData(m_decoder, cfData.get(), allDataReceived);
    113129#else
    114     // 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
    115     // scenes.  We use CFDataCreateWithBytesNoCopy in that case. Ensure that the SharedBuffer lives as long as the CFDataRef.
     130    // Create a CGDataProvider to wrap the SharedBuffer.
    116131    data->ref();
    117     CFAllocatorContext context = {0, data, 0, 0, 0, 0, 0, &sharedBufferDerefCallback, 0};
    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()));
     132    // We use the GetBytesAtPosition callback rather than the GetBytePointer one because SharedBuffer
     133    // does not provide a way to lock down the byte pointer and guarantee that it won't move, which
     134    // is a requirement for using the GetBytePointer callback.
     135    CGDataProviderDirectCallbacks providerCallbacks = { 0, 0, 0, sharedBufferGetBytesAtPosition, sharedBufferRelease };
     136    RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateDirect(data, data->size(), &providerCallbacks));
     137    CGImageSourceUpdateDataProvider(m_decoder, dataProvider.get(), allDataReceived);
    120138#endif
    121     CGImageSourceUpdateData(m_decoder, cfData.get(), allDataReceived);
    122139}
    123140
  • trunk/WebCore/platform/graphics/cg/ImageSourceCG.h

    r39185 r51207  
    3737String MIMETypeForImageSourceType(const String& type);
    3838
     39#if !PLATFORM(MAC)
     40size_t sharedBufferGetBytesAtPosition(void* info, void* buffer, off_t position, size_t count);
     41#endif
     42
    3943}
    4044
  • trunk/WebCore/platform/graphics/cg/PDFDocumentImage.cpp

    r47585 r51207  
    3232#include "GraphicsContext.h"
    3333#include "ImageObserver.h"
     34#if !PLATFORM(MAC)
     35#include "ImageSourceCG.h"
     36#endif
    3437#include <wtf/MathExtras.h>
    3538
     
    7073        // to wrap itself inside CFData to get around this, ensuring that ImageIO is really looking at the SharedBuffer.
    7174        RetainPtr<CFDataRef> data(AdoptCF, this->data()->createCFData());
     75        RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
    7276#else
    73         // 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
    74         // scenes.  We use CFDataCreateWithBytesNoCopy in that case.
    75         RetainPtr<CFDataRef> data(AdoptCF, CFDataCreateWithBytesNoCopy(0, reinterpret_cast<const UInt8*>(this->data()->data()), this->data()->size(), kCFAllocatorNull));
     77        // Create a CGDataProvider to wrap the SharedBuffer.
     78        // We use the GetBytesAtPosition callback rather than the GetBytePointer one because SharedBuffer
     79        // does not provide a way to lock down the byte pointer and guarantee that it won't move, which
     80        // is a requirement for using the GetBytePointer callback.
     81        CGDataProviderDirectCallbacks providerCallbacks = { 0, 0, 0, sharedBufferGetBytesAtPosition, 0 };
     82        RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateDirect(this->data(), this->data()->size(), &providerCallbacks));
    7683#endif
    77         RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
    7884        m_document = CGPDFDocumentCreateWithProvider(dataProvider.get());
    7985        setCurrentPage(0);
Note: See TracChangeset for help on using the changeset viewer.