OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "webkit/glue/image_decoder.h" | 6 #include "webkit/glue/image_decoder.h" |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "webkit/api/public/WebData.h" |
| 9 #include "webkit/api/public/WebImage.h" |
| 10 #include "webkit/api/public/WebSize.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
10 | 12 |
11 MSVC_PUSH_WARNING_LEVEL(0); | 13 #if WEBKIT_USING_CG |
12 #if defined(OS_WIN) || defined(OS_LINUX) | |
13 #include "ImageSourceSkia.h" | |
14 #include "NativeImageSkia.h" | |
15 #elif defined(OS_MACOSX) | |
16 #include "ImageSource.h" | |
17 #include "RetainPtr.h" | |
18 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
19 #endif | 15 #endif |
20 #include "IntSize.h" | 16 |
21 #include "RefPtr.h" | 17 using WebKit::WebData; |
22 #include "SharedBuffer.h" | 18 using WebKit::WebImage; |
23 MSVC_POP_WARNING(); | |
24 | 19 |
25 namespace webkit_glue { | 20 namespace webkit_glue { |
26 | 21 |
27 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) { | 22 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) { |
28 } | 23 } |
29 | 24 |
30 ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size) | 25 ImageDecoder::ImageDecoder(const gfx::Size& desired_icon_size) |
31 : desired_icon_size_(desired_icon_size) { | 26 : desired_icon_size_(desired_icon_size) { |
32 } | 27 } |
33 | 28 |
34 ImageDecoder::~ImageDecoder() { | 29 ImageDecoder::~ImageDecoder() { |
35 } | 30 } |
36 | 31 |
37 SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const { | 32 SkBitmap ImageDecoder::Decode(const unsigned char* data, size_t size) const { |
38 | 33 const WebImage& image = WebImage::fromData( |
39 // What's going on here? ImageDecoder is only used by ImageResourceFetcher, | 34 WebData(reinterpret_cast<const char*>(data), size), desired_icon_size_); |
40 // which is only used (but extensively) by WebViewImpl. On the Mac we're using | 35 #if WEBKIT_USING_SKIA |
41 // CoreGraphics, but right now WebViewImpl uses SkBitmaps everywhere. For now, | 36 return image.getSkBitmap(); |
42 // this is a convenient bottleneck to convert from CGImageRefs to SkBitmaps, | 37 #elif WEBKIT_USING_CG |
43 // but in the future we will need to replumb to get CGImageRefs (or whatever | 38 return gfx::CGImageToSkBitmap(image.getCGImageRef()); |
44 // the native type is) everywhere, directly. | |
45 | |
46 #if defined(OS_WIN) || defined(OS_LINUX) | |
47 WebCore::ImageSourceSkia source; | |
48 #elif defined(OS_MACOSX) | |
49 WebCore::ImageSource source; | |
50 #endif | |
51 WTF::RefPtr<WebCore::SharedBuffer> buffer(WebCore::SharedBuffer::create( | |
52 data, static_cast<int>(size))); | |
53 #if defined(OS_WIN) || defined(OS_LINUX) | |
54 source.setData(buffer.get(), true, | |
55 WebCore::IntSize(desired_icon_size_.width(), | |
56 desired_icon_size_.height())); | |
57 #elif defined(OS_MACOSX) | |
58 source.setData(buffer.get(), true); | |
59 #endif | |
60 | |
61 if (!source.isSizeAvailable()) | |
62 return SkBitmap(); | |
63 | |
64 WebCore::NativeImagePtr frame0 = source.createFrameAtIndex(0); | |
65 if (!frame0) | |
66 return SkBitmap(); | |
67 | |
68 #if defined(OS_WIN) || defined(OS_LINUX) | |
69 SkBitmap retval = *reinterpret_cast<SkBitmap*>(frame0); | |
70 delete frame0; | |
71 return retval; | |
72 #elif defined(OS_MACOSX) | |
73 // TODO(port): should we delete frame0 like Linux/Windows do above? | |
74 // BitmapImage releases automatically, but we're bypassing it so we'll need | |
75 // to do the releasing. | |
76 RetainPtr<CGImageRef> image(AdoptCF, frame0); | |
77 return gfx::CGImageToSkBitmap(image.get()); | |
78 #endif | 39 #endif |
79 } | 40 } |
80 | 41 |
81 } // namespace webkit_glue | 42 } // namespace webkit_glue |
OLD | NEW |