| 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 "skia/ext/skia_utils_mac.h" | 5 #include "skia/ext/skia_utils_mac.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/scoped_cftyperef.h" | 10 #include "base/scoped_cftyperef.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 operation:NSCompositeCopy | 161 operation:NSCompositeCopy |
| 162 fraction:1.0]; | 162 fraction:1.0]; |
| 163 | 163 |
| 164 // Done drawing, restore context. | 164 // Done drawing, restore context. |
| 165 [NSGraphicsContext restoreGraphicsState]; | 165 [NSGraphicsContext restoreGraphicsState]; |
| 166 | 166 |
| 167 return bitmap; | 167 return bitmap; |
| 168 } | 168 } |
| 169 | 169 |
| 170 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { | 170 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { |
| 171 if (skiaBitmap.isNull()) |
| 172 return nil; |
| 173 |
| 171 // First convert SkBitmap to CGImageRef. | 174 // First convert SkBitmap to CGImageRef. |
| 172 CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap); | 175 CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap); |
| 173 | 176 |
| 174 // Now convert to NSImage. | 177 // Now convert to NSImage. |
| 175 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] | 178 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] |
| 176 initWithCGImage:cgimage] autorelease]; | 179 initWithCGImage:cgimage] autorelease]; |
| 177 CFRelease(cgimage); | 180 CFRelease(cgimage); |
| 178 NSImage* image = [[[NSImage alloc] init] autorelease]; | 181 NSImage* image = [[[NSImage alloc] init] autorelease]; |
| 179 [image addRepresentation:bitmap]; | 182 [image addRepresentation:bitmap]; |
| 180 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; | 183 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; |
| 181 return image; | 184 return image; |
| 182 } | 185 } |
| 183 | 186 |
| 184 SkBitmap AppplicationIconAtSize(int size) { | 187 SkBitmap AppplicationIconAtSize(int size) { |
| 185 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 188 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
| 186 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); | 189 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace gfx | 192 } // namespace gfx |
| OLD | NEW |