diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (patch) | |
tree | d49911209b132da58d838efa852daf28d516df21 /WebCore/platform/graphics/cg | |
parent | 87eb0cb35bad8784770ebc807e6c982432e47107 (diff) | |
download | external_webkit-9364f22aed35e1a1e9d07c121510f80be3ab0502.zip external_webkit-9364f22aed35e1a1e9d07c121510f80be3ab0502.tar.gz external_webkit-9364f22aed35e1a1e9d07c121510f80be3ab0502.tar.bz2 |
Initial Contribution
Diffstat (limited to 'WebCore/platform/graphics/cg')
-rw-r--r-- | WebCore/platform/graphics/cg/GraphicsContextCG.cpp | 49 | ||||
-rw-r--r-- | WebCore/platform/graphics/cg/ImageBufferCG.cpp | 112 | ||||
-rw-r--r-- | WebCore/platform/graphics/cg/ImageSourceCG.cpp | 27 |
3 files changed, 8 insertions, 180 deletions
diff --git a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp index de546ac..c490dcb 100644 --- a/WebCore/platform/graphics/cg/GraphicsContextCG.cpp +++ b/WebCore/platform/graphics/cg/GraphicsContextCG.cpp @@ -30,14 +30,10 @@ #include "AffineTransform.h" #include "FloatConversion.h" #include "GraphicsContextPlatformPrivateCG.h" -#include "ImageBuffer.h" #include "KURL.h" #include "Path.h" -#include <CoreGraphics/CGBitmapContext.h> #include <CoreGraphics/CGPDFContext.h> #include <wtf/MathExtras.h> -#include <wtf/OwnArrayPtr.h> -#include <wtf/RetainPtr.h> using namespace std; @@ -928,49 +924,6 @@ void GraphicsContext::setCompositeOperation(CompositeOperator mode) CGContextSetBlendMode(platformContext(), target); } #endif - -void GraphicsContext::paintBuffer(ImageBuffer* buffer, const IntRect& r) -{ - CGContextRef context = buffer->context()->platformContext(); - if (!context) - return; - CGContextFlush(context); - if (CGImageRef image = CGBitmapContextCreateImage(context)) { - CGContextDrawImage(platformContext(), roundToDevicePixels(r), image); - CGImageRelease(image); - } -} - -void GraphicsContext::drawImage(ImageBuffer* buffer, const FloatRect& srcRect, const FloatRect& destRect) -{ - CGContextRef context = buffer->context()->platformContext(); - CGContextFlush(context); - RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(context)); - float iw = CGImageGetWidth(image.get()); - float ih = CGImageGetHeight(image.get()); - if (srcRect.x() == 0 && srcRect.y() == 0 && iw == srcRect.width() && ih == srcRect.height()) { - // Fast path, yay! - CGContextDrawImage(platformContext(), destRect, image.get()); - } else { - // Slow path, boo! - // FIXME: We can do this without creating a separate image - - size_t csw = static_cast<size_t>(ceilf(srcRect.width())); - size_t csh = static_cast<size_t>(ceilf(srcRect.height())); - - RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); - size_t bytesPerRow = csw * 4; - OwnArrayPtr<char> buffer(new char[csh * bytesPerRow]); - RetainPtr<CGContextRef> clippedSourceContext(AdoptCF, CGBitmapContextCreate(buffer.get(), csw, csh, - 8, bytesPerRow, colorSpace.get(), kCGImageAlphaPremultipliedLast)); - CGContextTranslateCTM(clippedSourceContext.get(), -srcRect.x(), -srcRect.y()); - CGContextDrawImage(clippedSourceContext.get(), CGRectMake(0, 0, iw, ih), image.get()); - - RetainPtr<CGImageRef> clippedSourceImage(AdoptCF, CGBitmapContextCreateImage(clippedSourceContext.get())); - - CGContextDrawImage(platformContext(), destRect, clippedSourceImage.get()); - } -} - + } diff --git a/WebCore/platform/graphics/cg/ImageBufferCG.cpp b/WebCore/platform/graphics/cg/ImageBufferCG.cpp index 7cb28e3..2d1ac01 100644 --- a/WebCore/platform/graphics/cg/ImageBufferCG.cpp +++ b/WebCore/platform/graphics/cg/ImageBufferCG.cpp @@ -1,6 +1,5 @@ /* * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> - * Copyright (C) 2008 Apple, Inc * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,7 +27,6 @@ #include "ImageBuffer.h" #include "GraphicsContext.h" -#include "ImageData.h" #include <ApplicationServices/ApplicationServices.h> #include <wtf/Assertions.h> @@ -75,7 +73,6 @@ ImageBuffer::ImageBuffer(void* imageData, const IntSize& size, auto_ptr<Graphics , m_context(context.release()) , m_cgImage(0) { - ASSERT((reinterpret_cast<size_t>(imageData) & 2) == 0); } ImageBuffer::~ImageBuffer() @@ -101,113 +98,4 @@ CGImageRef ImageBuffer::cgImage() const return m_cgImage; } -PassRefPtr<ImageData> ImageBuffer::getImageData(const IntRect& rect) const -{ - if (!m_data) - return 0; - - PassRefPtr<ImageData> result = ImageData::create(rect.width(), rect.height()); - unsigned char* data = result->data()->data().data(); - - if (rect.x() < 0 || rect.y() < 0 || (rect.x() + rect.width()) > m_size.width() || (rect.y() + rect.height()) > m_size.height()) - memset(data, 0, result->data()->length()); - - int originx = rect.x(); - int destx = 0; - if (originx < 0) { - destx = -originx; - originx = 0; - } - int endx = rect.x() + rect.width(); - if (endx > m_size.width()) - endx = m_size.width(); - int numColumns = endx - originx; - - int originy = rect.y(); - int desty = 0; - if (originy < 0) { - desty = -originy; - originy = 0; - } - int endy = rect.y() + rect.height(); - if (endy > m_size.height()) - endy = m_size.height(); - int numRows = endy - originy; - - unsigned srcBytesPerRow = 4 * m_size.width(); - unsigned destBytesPerRow = 4 * rect.width(); - - // m_size.height() - originy to handle the accursed flipped y axis in CG backing store - unsigned char* srcRows = reinterpret_cast<unsigned char*>(m_data) + (m_size.height() - originy - 1) * srcBytesPerRow + originx * 4; - unsigned char* destRows = data + desty * destBytesPerRow + destx * 4; - for (int y = 0; y < numRows; ++y) { - for (int x = 0; x < numColumns; x++) { - int basex = x * 4; - if (unsigned char alpha = srcRows[basex + 3]) { - destRows[0] = (srcRows[basex] * 255) / alpha; - destRows[1] = (srcRows[basex + 1] * 255) / alpha; - destRows[2] = (srcRows[basex + 2] * 255) / alpha; - destRows[3] = alpha; - } else { - reinterpret_cast<uint32_t*>(destRows)[0] = reinterpret_cast<uint32_t*>(srcRows)[0]; - } - destRows += 4; - } - srcRows -= srcBytesPerRow; - } - return result; -} - -void ImageBuffer::putImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint) -{ - ASSERT(sourceRect.width() > 0); - ASSERT(sourceRect.height() > 0); - - int originx = sourceRect.x(); - int destx = destPoint.x() + sourceRect.x(); - ASSERT(destx >= 0); - ASSERT(destx < m_size.width()); - ASSERT(originx >= 0); - ASSERT(originx <= sourceRect.right()); - - int endx = destPoint.x() + sourceRect.right(); - ASSERT(endx <= m_size.width()); - - int numColumns = endx - destx; - - int originy = sourceRect.y(); - int desty = destPoint.y() + sourceRect.y(); - ASSERT(desty >= 0); - ASSERT(desty < m_size.height()); - ASSERT(originy >= 0); - ASSERT(originy <= sourceRect.bottom()); - - int endy = destPoint.y() + sourceRect.bottom(); - ASSERT(endy <= m_size.height()); - int numRows = endy - desty; - - unsigned srcBytesPerRow = 4 * source->width(); - unsigned destBytesPerRow = 4 * m_size.width(); - - unsigned char* srcRows = source->data()->data().data() + originy * srcBytesPerRow + originx * 4; - - // -desty to handle the accursed flipped y axis - unsigned char* destRows = reinterpret_cast<unsigned char*>(m_data) + (m_size.height() - desty - 1) * destBytesPerRow + destx * 4; - for (int y = 0; y < numRows; ++y) { - for (int x = 0; x < numColumns; x++) { - unsigned char alpha = srcRows[x * 4 + 3]; - if (alpha != 255) { - destRows[x * 4 + 0] = (srcRows[0] * alpha) / 255; - destRows[x * 4 + 1] = (srcRows[1] * alpha) / 255; - destRows[x * 4 + 2] = (srcRows[2] * alpha) / 255; - destRows[x * 4 + 3] = alpha; - } else { - reinterpret_cast<uint32_t*>(destRows + x * 4)[0] = reinterpret_cast<uint32_t*>(srcRows + x * 4)[0]; - } - } - destRows -= destBytesPerRow; - srcRows += srcBytesPerRow; - } -} - } diff --git a/WebCore/platform/graphics/cg/ImageSourceCG.cpp b/WebCore/platform/graphics/cg/ImageSourceCG.cpp index 08e8172..2bfc204 100644 --- a/WebCore/platform/graphics/cg/ImageSourceCG.cpp +++ b/WebCore/platform/graphics/cg/ImageSourceCG.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -25,17 +25,15 @@ #include "config.h" #include "ImageSource.h" +#include "SharedBuffer.h" #if PLATFORM(CG) #include "IntSize.h" -#include "SharedBuffer.h" #include <ApplicationServices/ApplicationServices.h> namespace WebCore { -static const CFStringRef kCGImageSourceShouldPreferRGB32 = CFSTR("kCGImageSourceShouldPreferRGB32"); - ImageSource::ImageSource() : m_decoder(0) { @@ -54,13 +52,15 @@ void ImageSource::clear() } } +const CFStringRef kCGImageSourceShouldPreferRGB32 = CFSTR("kCGImageSourceShouldPreferRGB32"); + CFDictionaryRef imageSourceOptions() { static CFDictionaryRef options; if (!options) { - const void* keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 }; - const void* values[2] = { kCFBooleanTrue, kCFBooleanTrue }; + const void *keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 }; + const void *values[2] = { kCFBooleanTrue, kCFBooleanTrue }; options = CFDictionaryCreate(NULL, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } @@ -154,20 +154,7 @@ size_t ImageSource::frameCount() const CGImageRef ImageSource::createFrameAtIndex(size_t index) { - CGImageRef image = CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions()); - CFStringRef imageUTI = CGImageSourceGetType(m_decoder); - static const CFStringRef xbmUTI = CFSTR("public.xbitmap-image"); - if (!imageUTI || !CFEqual(imageUTI, xbmUTI)) - return image; - - // If it is an xbm image, mask out all the white areas to render them transparent. - const CGFloat maskingColors[6] = {255, 255, 255, 255, 255, 255}; - CGImageRef maskedImage = CGImageCreateWithMaskingColors(image, maskingColors); - if (!maskedImage) - return image; - - CGImageRelease(image); - return maskedImage; + return CGImageSourceCreateImageAtIndex(m_decoder, index, imageSourceOptions()); } bool ImageSource::frameIsCompleteAtIndex(size_t index) |