Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: ui/gfx/image/image_mac.mm

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_mac_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7ac0abeb833b52a4a09c54f56da6dbfbdf180165 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];
+ 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
« no previous file with comments | « ui/gfx/image/image.cc ('k') | ui/gfx/image/image_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698