diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 05:58:45 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-03 05:58:45 +0000 |
commit | 8973f52efb98f531369f0b9daba397b1bf26d07b (patch) | |
tree | 297ec596fbaa2dc38af4c980d1a82b6dc49157ec /webkit/glue/image_decoder.cc | |
parent | c505de2b23a6a9b1c38d84cdc301dd6e2a71a9b4 (diff) | |
download | chromium_src-8973f52efb98f531369f0b9daba397b1bf26d07b.zip chromium_src-8973f52efb98f531369f0b9daba397b1bf26d07b.tar.gz chromium_src-8973f52efb98f531369f0b9daba397b1bf26d07b.tar.bz2 |
Port WebImage to CG and rework the Skia version so that WebImage just has a
SkBitmap member (avoiding a level of indirection).
This CL makes it so that Mac Chrome will now write bitmap data to the clipboard
when requested by WebKit. I also simplified the ImageDecoder class that lives
in glue.
BUG=15648
TEST=none
R=dglazkov
Review URL: http://codereview.chromium.org/155010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/image_decoder.cc')
-rw-r--r-- | webkit/glue/image_decoder.cc | 65 |
1 files changed, 13 insertions, 52 deletions
diff --git a/webkit/glue/image_decoder.cc b/webkit/glue/image_decoder.cc index 73c3f9b..2a7084b 100644 --- a/webkit/glue/image_decoder.cc +++ b/webkit/glue/image_decoder.cc @@ -5,22 +5,17 @@ #include "config.h" #include "webkit/glue/image_decoder.h" -#include "base/compiler_specific.h" +#include "webkit/api/public/WebData.h" +#include "webkit/api/public/WebImage.h" +#include "webkit/api/public/WebSize.h" #include "third_party/skia/include/core/SkBitmap.h" -MSVC_PUSH_WARNING_LEVEL(0); -#if defined(OS_WIN) || defined(OS_LINUX) -#include "ImageSourceSkia.h" -#include "NativeImageSkia.h" -#elif defined(OS_MACOSX) -#include "ImageSource.h" -#include "RetainPtr.h" +#if WEBKIT_USING_CG #include "skia/ext/skia_utils_mac.h" #endif -#include "IntSize.h" -#include "RefPtr.h" -#include "SharedBuffer.h" -MSVC_POP_WARNING(); + +using WebKit::WebData; +using WebKit::WebImage; namespace webkit_glue { @@ -35,46 +30,12 @@ ImageDecoder::~ImageDecoder() { } SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const { - - // 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) || defined(OS_LINUX) - WebCore::ImageSourceSkia source; -#elif defined(OS_MACOSX) - WebCore::ImageSource source; -#endif - WTF::RefPtr<WebCore::SharedBuffer> buffer(WebCore::SharedBuffer::create( - data, static_cast<int>(size))); -#if defined(OS_WIN) || defined(OS_LINUX) - 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(); - - WebCore::NativeImagePtr frame0 = source.createFrameAtIndex(0); - if (!frame0) - return SkBitmap(); - -#if defined(OS_WIN) || defined(OS_LINUX) - SkBitmap retval = *reinterpret_cast<SkBitmap*>(frame0); - delete frame0; - return retval; -#elif defined(OS_MACOSX) - // TODO(port): should we delete frame0 like Linux/Windows do above? - // BitmapImage releases automatically, but we're bypassing it so we'll need - // to do the releasing. - RetainPtr<CGImageRef> image(AdoptCF, frame0); - return gfx::CGImageToSkBitmap(image.get()); + const WebImage& image = WebImage::fromData( + WebData(reinterpret_cast<const char*>(data), size), desired_icon_size_); +#if WEBKIT_USING_SKIA + return image.getSkBitmap(); +#elif WEBKIT_USING_CG + return gfx::CGImageToSkBitmap(image.getCGImageRef()); #endif } |