Chromium Code Reviews| Index: ui/gfx/image/image_mac.mm |
| diff --git a/ui/gfx/image/image_mac.mm b/ui/gfx/image/image_mac.mm |
| index 55b4aa4338d23413207c2b66a1da26f1806cac60..3ea4766c6ab9314751a520c0ca994f5e866cf25e 100644 |
| --- a/ui/gfx/image/image_mac.mm |
| +++ b/ui/gfx/image/image_mac.mm |
| @@ -3,23 +3,44 @@ |
| // found in the LICENSE file. |
| #import <AppKit/AppKit.h> |
| +#import <vector> |
| +#include "base/memory/scoped_nsobject.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "skia/ext/skia_utils_mac.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/gfx/image/image_skia.h" |
| namespace gfx { |
| namespace internal { |
| -bool NSImageToSkBitmaps(NSImage* image, std::vector<const SkBitmap*>* bitmaps) { |
| +gfx::ImageSkia NSImageToImageSkia(NSImage* image) { |
| + gfx::ImageSkia image_skia; |
| for (NSImageRep* imageRep in [image representations]) { |
| - scoped_ptr<SkBitmap> bitmap(new SkBitmap( |
| - gfx::NSImageRepToSkBitmap(imageRep, [imageRep size], false))); |
| - if (bitmap->isNull()) |
| - return false; |
| - bitmaps->push_back(bitmap.release()); |
| + NSSize imageRepSize = [imageRep size]; |
|
Robert Sesek
2012/05/08 23:30:47
naming: in C++ context, use image_rep_size
|
| + SkBitmap bitmap(gfx::NSImageRepToSkBitmap(imageRep, imageRepSize, false)); |
| + if (!bitmap.isNull() && !bitmap.empty()) { |
| + float scaleFactor = imageRepSize.width / [image size].width; |
| + image_skia->AddBitmapForScale(bitmap, scaleFactor); |
| + } |
| } |
| - return true; |
| + return image_skia; |
| +} |
| + |
| +NSImage* ImageSkiaToNSImage(const gfx::ImageSkia* image_skia) { |
| + if (image_skia->empty()) |
| + return nil; |
| + |
| + scoped_nsobject<NSImage> image([[NSImage alloc] init]); |
| + |
| + const std::vector<SkBitmap>& bitmaps = image_skia->bitmaps(); |
| + for (std::vector<SkBitmap>::const_iterator it = bitmaps.begin(); |
| + it != bitmaps.end(); ++it) { |
| + [image addRepresentation:gfx::SkBitmapToNSBitmapImageRep(*it)]; |
| + } |
| + |
| + [image setSize:NSMakeSize(image_skia->width(), image_skia->height())]; |
| + return [image.release() autorelease]; |
| } |
| } // namespace internal |