diff options
author | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-17 14:07:08 +0000 |
---|---|---|
committer | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-17 14:07:08 +0000 |
commit | 2fb5bbd13a4599e024028bf16e35e49de119e80a (patch) | |
tree | 0511185a0b459553f8a84ade635c12ebd0536ba4 /webkit/glue/image_decoder.cc | |
parent | d632798e22600557d9bb2c84450dd110cb9d6230 (diff) | |
download | chromium_src-2fb5bbd13a4599e024028bf16e35e49de119e80a.zip chromium_src-2fb5bbd13a4599e024028bf16e35e49de119e80a.tar.gz chromium_src-2fb5bbd13a4599e024028bf16e35e49de119e80a.tar.bz2 |
Convert CG images to Skia to draw.
Review URL: http://codereview.chromium.org/3088
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2304 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/image_decoder.cc')
-rw-r--r-- | webkit/glue/image_decoder.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/webkit/glue/image_decoder.cc b/webkit/glue/image_decoder.cc index e6c448b..577b3183 100644 --- a/webkit/glue/image_decoder.cc +++ b/webkit/glue/image_decoder.cc @@ -6,7 +6,12 @@ #include "webkit/glue/image_decoder.h" #pragma warning(push, 0) +#if defined(OS_WIN) #include "ImageSourceSkia.h" +#elif defined(OS_MACOSX) +#include "ImageSource.h" +#include "RetainPtr.h" +#endif #include "IntSize.h" #include "RefPtr.h" #include "SharedBuffer.h" @@ -27,12 +32,28 @@ ImageDecoder::~ImageDecoder() { } SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) { + + // What's going on here? ImageDecoder is only used by ImageResourceFetcher, + // which is only used (but extensively) by WebViewImpl. On the Mac we're using + // CoreGraphics, but right now WebViewImpl uses SkBitmaps everywhere. For now, + // this is a convenient bottleneck to convert from CGImageRefs to SkBitmaps, + // but in the future we will need to replumb to get CGImageRefs (or whatever + // the native type is) everywhere, directly. + +#if defined(OS_WIN) WebCore::ImageSourceSkia source; +#elif defined(OS_MACOSX) + WebCore::ImageSource source; +#endif WTF::RefPtr<WebCore::SharedBuffer> buffer(new WebCore::SharedBuffer( data, static_cast<int>(size))); +#if defined(OS_WIN) source.setData(buffer.get(), true, WebCore::IntSize(desired_icon_size_.width(), desired_icon_size_.height())); +#elif defined(OS_MACOSX) + source.setData(buffer.get(), true); +#endif if (!source.isSizeAvailable()) return SkBitmap(); @@ -41,7 +62,38 @@ SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) { if (!frame0) return SkBitmap(); +#if defined(OS_WIN) return *reinterpret_cast<SkBitmap*>(frame0); +#elif defined(OS_MACOSX) + // BitmapImage releases automatically, but we're bypassing it so we'll need + // to do the releasing. + RetainPtr<CGImageRef> image(AdoptCF, frame0); + + SkBitmap result; + result.setConfig(SkBitmap::kARGB_8888_Config, CGImageGetWidth(image.get()), + CGImageGetHeight(image.get())); + + RetainPtr<CGColorSpace> cg_color(AdoptCF, CGColorSpaceCreateDeviceRGB()); + // The last parameter is a total guess. Feel free to adjust it if images draw + // incorrectly. TODO(avi): Verify byte ordering; it should be possible to + // swizzle bytes with various combinations of the byte order and alpha + // constants. + RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate( + result.getPixels(), + result.width(), + result.height(), + result.bytesPerPixel() * 8 / 4, + result.rowBytes(), + cg_color.get(), + kCGImageAlphaPremultipliedFirst | + kCGBitmapByteOrder32Host)); + CGRect rect = CGRectMake(0, 0, + CGImageGetWidth(image.get()), + CGImageGetHeight(image.get())); + CGContextDrawImage(context.get(), rect, image.get()); + + return result; +#endif } } // namespace webkit_glue |