| 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 "base/compiler_specific.h" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 10 | 10 |
| 11 MSVC_PUSH_WARNING_LEVEL(0); | 11 MSVC_PUSH_WARNING_LEVEL(0); |
| 12 #if defined(OS_WIN) || defined(OS_LINUX) | 12 #if defined(OS_WIN) || defined(OS_LINUX) |
| 13 #include "ImageSourceSkia.h" | 13 #include "ImageSourceSkia.h" |
| 14 #include "NativeImageSkia.h" | 14 #include "NativeImageSkia.h" |
| 15 #elif defined(OS_MACOSX) | 15 #elif defined(OS_MACOSX) |
| 16 #include "ImageSource.h" | 16 #include "ImageSource.h" |
| 17 #include "RetainPtr.h" | 17 #include "RetainPtr.h" |
| 18 #include "skia/ext/skia_utils_mac.h" |
| 18 #endif | 19 #endif |
| 19 #include "IntSize.h" | 20 #include "IntSize.h" |
| 20 #include "RefPtr.h" | 21 #include "RefPtr.h" |
| 21 #include "SharedBuffer.h" | 22 #include "SharedBuffer.h" |
| 22 MSVC_POP_WARNING(); | 23 MSVC_POP_WARNING(); |
| 23 | 24 |
| 24 namespace webkit_glue { | 25 namespace webkit_glue { |
| 25 | 26 |
| 26 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) { | 27 ImageDecoder::ImageDecoder() : desired_icon_size_(0, 0) { |
| 27 } | 28 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 67 |
| 67 #if defined(OS_WIN) || defined(OS_LINUX) | 68 #if defined(OS_WIN) || defined(OS_LINUX) |
| 68 SkBitmap retval = *reinterpret_cast<SkBitmap*>(frame0); | 69 SkBitmap retval = *reinterpret_cast<SkBitmap*>(frame0); |
| 69 delete frame0; | 70 delete frame0; |
| 70 return retval; | 71 return retval; |
| 71 #elif defined(OS_MACOSX) | 72 #elif defined(OS_MACOSX) |
| 72 // TODO(port): should we delete frame0 like Linux/Windows do above? | 73 // TODO(port): should we delete frame0 like Linux/Windows do above? |
| 73 // BitmapImage releases automatically, but we're bypassing it so we'll need | 74 // BitmapImage releases automatically, but we're bypassing it so we'll need |
| 74 // to do the releasing. | 75 // to do the releasing. |
| 75 RetainPtr<CGImageRef> image(AdoptCF, frame0); | 76 RetainPtr<CGImageRef> image(AdoptCF, frame0); |
| 76 | 77 return gfx::CGImageToSkBitmap(image.get()); |
| 77 SkBitmap result; | |
| 78 result.setConfig(SkBitmap::kARGB_8888_Config, CGImageGetWidth(image.get()), | |
| 79 CGImageGetHeight(image.get())); | |
| 80 | |
| 81 // TODO(port): | |
| 82 // This line is a waste, but is needed when the renderer sends a | |
| 83 // ViewHostMsg_DidDownloadImage and tries to pickle the SkBitmap. | |
| 84 // Presumably this will be removed when we (ImageDecoder::Decode()) | |
| 85 // are changed to not return a fake SkBitmap. | |
| 86 result.allocPixels(); | |
| 87 | |
| 88 RetainPtr<CGColorSpace> cg_color(AdoptCF, CGColorSpaceCreateDeviceRGB()); | |
| 89 // The last parameter is a total guess. Feel free to adjust it if images draw | |
| 90 // incorrectly. TODO(avi): Verify byte ordering; it should be possible to | |
| 91 // swizzle bytes with various combinations of the byte order and alpha | |
| 92 // constants. | |
| 93 RetainPtr<CGContextRef> context(AdoptCF, CGBitmapContextCreate( | |
| 94 result.getPixels(), | |
| 95 result.width(), | |
| 96 result.height(), | |
| 97 result.bytesPerPixel() * 8 / 4, | |
| 98 result.rowBytes(), | |
| 99 cg_color.get(), | |
| 100 kCGImageAlphaPremultipliedFirst | | |
| 101 kCGBitmapByteOrder32Host)); | |
| 102 CGRect rect = CGRectMake(0, 0, | |
| 103 CGImageGetWidth(image.get()), | |
| 104 CGImageGetHeight(image.get())); | |
| 105 | |
| 106 // We want to copy transparent pixels from |image| over to |result|, instead | |
| 107 // of blending |image| onto the uninitialized pixels of |result|. Since | |
| 108 // |context| is used only locally, there's no need to restore the blend mode. | |
| 109 CGContextSetBlendMode(context.get(), kCGBlendModeCopy); | |
| 110 | |
| 111 CGContextDrawImage(context.get(), rect, image.get()); | |
| 112 | |
| 113 return result; | |
| 114 #endif | 78 #endif |
| 115 } | 79 } |
| 116 | 80 |
| 117 } // namespace webkit_glue | 81 } // namespace webkit_glue |
| OLD | NEW |