diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp')
-rw-r--r-- | Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp b/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp index 28ba7ea..6bcc108 100644 --- a/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp +++ b/Source/WebKit2/Shared/cg/ShareableBitmapCG.cpp @@ -34,14 +34,26 @@ using namespace WebCore; namespace WebKit { +static CGBitmapInfo bitmapInfo(ShareableBitmap::Flags flags) +{ + CGBitmapInfo info = kCGBitmapByteOrder32Host; + if (flags & ShareableBitmap::SupportsAlpha) + info |= kCGImageAlphaPremultipliedFirst; + else + info |= kCGImageAlphaNoneSkipFirst; + + return info; +} + PassOwnPtr<GraphicsContext> ShareableBitmap::createGraphicsContext() { RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); - ref(); // Balanced by deref in releaseData. + + ref(); // Balanced by deref in releaseBitmapContextData. RetainPtr<CGContextRef> bitmapContext(AdoptCF, CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), 8, m_size.width() * 4, colorSpace.get(), - kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, releaseData, this)); + bitmapInfo(m_flags), releaseBitmapContextData, this)); // We want the origin to be in the top left corner so we flip the backing store context. CGContextTranslateCTM(bitmapContext.get(), 0, m_size.height()); @@ -52,14 +64,38 @@ PassOwnPtr<GraphicsContext> ShareableBitmap::createGraphicsContext() void ShareableBitmap::paint(WebCore::GraphicsContext& context, const IntPoint& dstPoint, const IntRect& srcRect) { - paintBitmapContext(context.platformContext(), createGraphicsContext()->platformContext(), dstPoint, srcRect); + paintImage(context.platformContext(), makeCGImageCopy().get(), dstPoint, srcRect); +} + +RetainPtr<CGImageRef> ShareableBitmap::makeCGImageCopy() +{ + OwnPtr<GraphicsContext> graphicsContext = createGraphicsContext(); + RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(graphicsContext->platformContext())); + return image; +} + +RetainPtr<CGImageRef> ShareableBitmap::makeCGImage() +{ + ref(); // Balanced by deref in releaseDataProviderData. + RetainPtr<CGDataProvider> dataProvider(AdoptCF, CGDataProviderCreateWithData(this, data(), sizeInBytes(), releaseDataProviderData)); + + RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); + RetainPtr<CGImageRef> image(AdoptCF, CGImageCreate(m_size.width(), m_size.height(), 8, 32, m_size.width() * 4, colorSpace.get(), bitmapInfo(m_flags), dataProvider.get(), 0, false, kCGRenderingIntentDefault)); + return image; } -void ShareableBitmap::releaseData(void* typelessBitmap, void* typelessData) +void ShareableBitmap::releaseBitmapContextData(void* typelessBitmap, void* typelessData) { ShareableBitmap* bitmap = static_cast<ShareableBitmap*>(typelessBitmap); ASSERT_UNUSED(typelessData, bitmap->data() == typelessData); bitmap->deref(); // Balanced by ref in createGraphicsContext. } +void ShareableBitmap::releaseDataProviderData(void* typelessBitmap, const void* typelessData, size_t) +{ + ShareableBitmap* bitmap = static_cast<ShareableBitmap*>(typelessBitmap); + ASSERT_UNUSED(typelessData, bitmap->data() == typelessData); + bitmap->deref(); // Balanced by ref in createCGImage. +} + } // namespace WebKit |