FontCustomPlatformData::FontCustomPlatformData(FT_Face freeTypeFace, SharedBuffer& buffer)
    : m_freeTypeFace(freeTypeFace)
    , m_fontFace(cairo_ft_font_face_create_for_ft_face(freeTypeFace, 0))
{
    // FIXME Should we be setting some hinting options here?

    buffer.ref(); // This is balanced by the buffer->deref() in releaseCustomFontData.
    static cairo_user_data_key_t bufferKey;
    cairo_font_face_set_user_data(m_fontFace, &bufferKey, &buffer,
                                  static_cast<cairo_destroy_func_t>(releaseCustomFontData));

    // Cairo doesn't do FreeType reference counting, so we need to ensure that when
    // this cairo_font_face_t is destroyed, it cleans up the FreeType face as well.
    static cairo_user_data_key_t freeTypeFaceKey;
    cairo_font_face_set_user_data(m_fontFace, &freeTypeFaceKey, freeTypeFace,
                                  reinterpret_cast<cairo_destroy_func_t>(FT_Done_Face));
}
PassRefPtr<API::Data> WebIconDatabase::iconDataForPageURL(const String& pageURL)
{
    auto* image = imageForPageURL(pageURL);
    if (!image)
        return nullptr;

    SharedBuffer* sharedBuffer = image->data();
    if (!sharedBuffer)
        return nullptr;

    // Balanced by deref() below.
    sharedBuffer->ref();
    return API::Data::createWithoutCopying(reinterpret_cast<const unsigned char*>(sharedBuffer->data()), sharedBuffer->size(),
        [](unsigned char*, const void* untypedSharedBuffer) {
            // Balanced by ref() above.
            static_cast<SharedBuffer*>(const_cast<void*>(untypedSharedBuffer))->deref();
        }, sharedBuffer);
}
Exemple #3
0
void ImageDecoder::setData(SharedBuffer& data, bool allDataReceived)
{
    m_isAllDataReceived = allDataReceived;

#if PLATFORM(COCOA)
    // 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.
    CGImageSourceUpdateData(m_nativeDecoder.get(), data.createCFData().get(), allDataReceived);
#else
    // Create a CGDataProvider to wrap the SharedBuffer.
    data.ref();
    // We use the GetBytesAtPosition callback rather than the GetBytePointer one because SharedBuffer
    // does not provide a way to lock down the byte pointer and guarantee that it won't move, which
    // is a requirement for using the GetBytePointer callback.
    CGDataProviderDirectCallbacks providerCallbacks = { 0, 0, 0, sharedBufferGetBytesAtPosition, sharedBufferRelease };
    RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateDirect(&data, data.size(), &providerCallbacks));
    CGImageSourceUpdateDataProvider(m_nativeDecoder.get(), dataProvider.get(), allDataReceived);
#endif
}
const void* getData(void* info)
{
    SharedBuffer* buffer = static_cast<SharedBuffer*>(info);
    buffer->ref();
    return (void*)buffer->data();
}