diff options
author | Steve Block <steveblock@google.com> | 2010-08-24 07:50:47 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-08-24 07:50:47 -0700 |
commit | c570a147a94b126d4172c30914f53dea17b4c8f5 (patch) | |
tree | 99c11741887d21f65d67c5bbdab58b7ba2a5d4d5 /WebCore/platform/graphics/cg/ImageBufferCG.cpp | |
parent | c952714bc6809a5ad081baaf9fcc04107b92ea3f (diff) | |
parent | 6c65f16005b91786c2b7c0791b9ea1dd684d57f4 (diff) | |
download | external_webkit-c570a147a94b126d4172c30914f53dea17b4c8f5.zip external_webkit-c570a147a94b126d4172c30914f53dea17b4c8f5.tar.gz external_webkit-c570a147a94b126d4172c30914f53dea17b4c8f5.tar.bz2 |
Merge changes I2e7e2317,Ie6ccde3a,I3e89f231,Id06ff339,I268dfe7d,Icaf70d9f,Ie234f1a0,Iff5c7aaa,I69b75bf0,Ifbf384f4
* changes:
Merge WebKit at r65615 : Update WebKit revision number
Merge WebKit at r65615 : Ignore http/tests/appcache/origin-quota.html
Merge WebKit at r65615 : Android-specific results for Geolocation tests.
Merge WebKit at r65615 : Fix GraphicsContext and ImageBuffer.
Merge WebKit at r65615 : processingUserGesture() is now static.
Merge WebKit at r65615 : UTF8String() becomes utf8().
Merge WebKit at r65615 : Fix include paths for string headers.
Merge WebKit at r65615 : Fix Makefiles.
Merge WebKit at r65615 : Fix conflicts.
Merge WebKit at r65615 : Initial merge by git.
Diffstat (limited to 'WebCore/platform/graphics/cg/ImageBufferCG.cpp')
-rw-r--r-- | WebCore/platform/graphics/cg/ImageBufferCG.cpp | 89 |
1 files changed, 71 insertions, 18 deletions
diff --git a/WebCore/platform/graphics/cg/ImageBufferCG.cpp b/WebCore/platform/graphics/cg/ImageBufferCG.cpp index feb8cec..ecbcf60 100644 --- a/WebCore/platform/graphics/cg/ImageBufferCG.cpp +++ b/WebCore/platform/graphics/cg/ImageBufferCG.cpp @@ -46,6 +46,11 @@ using namespace std; namespace WebCore { +static void releaseImageData(void*, const void* data, size_t) +{ + fastFree(const_cast<void*>(data)); +} + ImageBufferData::ImageBufferData(const IntSize&) : m_data(0) { @@ -56,42 +61,46 @@ ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, b , m_size(size) { success = false; // Make early return mean failure. - unsigned bytesPerRow; if (size.width() < 0 || size.height() < 0) return; - bytesPerRow = size.width(); + + unsigned bytesPerRow = size.width(); if (imageColorSpace != GrayScale) { // Protect against overflow if (bytesPerRow > 0x3FFFFFFF) return; bytesPerRow *= 4; } + m_data.m_bytesPerRow = bytesPerRow; + size_t dataSize = size.height() * bytesPerRow; if (!tryFastCalloc(size.height(), bytesPerRow).getValue(m_data.m_data)) return; ASSERT((reinterpret_cast<size_t>(m_data.m_data) & 2) == 0); - RetainPtr<CGColorSpaceRef> colorSpace; switch(imageColorSpace) { case DeviceRGB: - colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB()); + m_data.m_colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB()); break; case GrayScale: - colorSpace.adoptCF(CGColorSpaceCreateDeviceGray()); + m_data.m_colorSpace.adoptCF(CGColorSpaceCreateDeviceGray()); break; #if ((PLATFORM(MAC) || PLATFORM(CHROMIUM)) && !defined(BUILDING_ON_TIGER)) case LinearRGB: - colorSpace.adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear)); + m_data.m_colorSpace.adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear)); break; + #endif default: - colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB()); + m_data.m_colorSpace.adoptCF(CGColorSpaceCreateDeviceRGB()); break; } + m_data.m_grayScale = imageColorSpace == GrayScale; + m_data.m_bitmapInfo = m_data.m_grayScale ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast; RetainPtr<CGContextRef> cgContext(AdoptCF, CGBitmapContextCreate(m_data.m_data, size.width(), size.height(), 8, bytesPerRow, - colorSpace.get(), (imageColorSpace == GrayScale) ? kCGImageAlphaNone : kCGImageAlphaPremultipliedLast)); + m_data.m_colorSpace.get(), m_data.m_bitmapInfo)); if (!cgContext) return; @@ -99,11 +108,13 @@ ImageBuffer::ImageBuffer(const IntSize& size, ImageColorSpace imageColorSpace, b m_context->scale(FloatSize(1, -1)); m_context->translate(0, -size.height()); success = true; + + // Create a live image that wraps the data. + m_data.m_dataProvider.adoptCF(CGDataProviderCreateWithData(0, m_data.m_data, dataSize, releaseImageData)); } ImageBuffer::~ImageBuffer() { - fastFree(m_data.m_data); } GraphicsContext* ImageBuffer::context() const @@ -111,17 +122,59 @@ GraphicsContext* ImageBuffer::context() const return m_context.get(); } -Image* ImageBuffer::image() const +bool ImageBuffer::drawsUsingCopy() const +{ + return false; +} + +PassRefPtr<Image> ImageBuffer::copyImage() const +{ + // BitmapImage will release the passed in CGImage on destruction + return BitmapImage::create(CGBitmapContextCreateImage(context()->platformContext())); +} + +static CGImageRef cgImage(const IntSize& size, const ImageBufferData& data) { - if (!m_image) { - // It's assumed that if image() is called, the actual rendering to the - // GraphicsContext must be done. - ASSERT(context()); - CGImageRef cgImage = CGBitmapContextCreateImage(context()->platformContext()); - // BitmapImage will release the passed in CGImage on destruction - m_image = BitmapImage::create(cgImage); + return CGImageCreate(size.width(), size.height(), 8, data.m_grayScale ? 8 : 32, data.m_bytesPerRow, + data.m_colorSpace.get(), data.m_bitmapInfo, data.m_dataProvider.get(), 0, true, kCGRenderingIntentDefault); +} + +void ImageBuffer::draw(GraphicsContext* destContext, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect, + CompositeOperator op, bool useLowQualityScale) +{ + if (destContext == context()) { + // We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first. + RefPtr<Image> copy = copyImage(); + destContext->drawImage(copy.get(), DeviceColorSpace, destRect, srcRect, op, useLowQualityScale); + } else { + RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data)); + destContext->drawImage(imageForRendering.get(), styleColorSpace, destRect, srcRect, op, useLowQualityScale); + } +} + +void ImageBuffer::drawPattern(GraphicsContext* destContext, const FloatRect& srcRect, const AffineTransform& patternTransform, + const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator op, const FloatRect& destRect) +{ + if (destContext == context()) { + // We're drawing into our own buffer. In order for this to work, we need to copy the source buffer first. + RefPtr<Image> copy = copyImage(); + copy->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect); + } else { + RefPtr<Image> imageForRendering = BitmapImage::create(cgImage(m_size, m_data)); + imageForRendering->drawPattern(destContext, srcRect, patternTransform, phase, styleColorSpace, op, destRect); } - return m_image.get(); +} + +void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const +{ + RetainPtr<CGImageRef> image(AdoptCF, cgImage(m_size, m_data)); + + CGContextRef platformContext = context->platformContext(); + CGContextTranslateCTM(platformContext, rect.x(), rect.y() + rect.height()); + CGContextScaleCTM(platformContext, 1, -1); + CGContextClipToMask(platformContext, FloatRect(FloatPoint(), rect.size()), image.get()); + CGContextScaleCTM(platformContext, 1, -1); + CGContextTranslateCTM(platformContext, -rect.x(), -rect.y() - rect.height()); } template <Multiply multiplied> |