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/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 fromRect:NSZeroRect | 160 fromRect:NSZeroRect |
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* SkBitmapToNSImageWithColorSpace(const SkBitmap& skiaBitmap, |
171 CGColorSpaceRef colorSpace) { | |
171 if (skiaBitmap.isNull()) | 172 if (skiaBitmap.isNull()) |
172 return nil; | 173 return nil; |
173 | 174 |
174 // First convert SkBitmap to CGImageRef. | 175 // First convert SkBitmap to CGImageRef. |
175 CGImageRef cgimage = SkCreateCGImageRef(skiaBitmap); | 176 CGImageRef cgimage = SkCreateCGImageRefWithColorspace( |
177 skiaBitmap, colorSpace); | |
viettrungluu
2011/01/12 19:02:11
I believe you can format this more nicely.
| |
176 | 178 |
177 // Now convert to NSImage. | 179 // Now convert to NSImage. |
178 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] | 180 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] |
179 initWithCGImage:cgimage] autorelease]; | 181 initWithCGImage:cgimage] autorelease]; |
180 CFRelease(cgimage); | 182 CFRelease(cgimage); |
181 NSImage* image = [[[NSImage alloc] init] autorelease]; | 183 NSImage* image = [[[NSImage alloc] init] autorelease]; |
182 [image addRepresentation:bitmap]; | 184 [image addRepresentation:bitmap]; |
183 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; | 185 [image setSize:NSMakeSize(skiaBitmap.width(), skiaBitmap.height())]; |
184 return image; | 186 return image; |
185 } | 187 } |
186 | 188 |
189 NSImage* SkBitmapToNSImage(const SkBitmap& skiaBitmap) { | |
viettrungluu
2011/01/12 19:02:11
Do you put implementations in random order just to
| |
190 base::mac::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( | |
191 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | |
192 return SkBitmapToNSImageWithColorSpace(skiaBitmap, colorSpace.get()); | |
193 } | |
194 | |
187 SkBitmap AppplicationIconAtSize(int size) { | 195 SkBitmap AppplicationIconAtSize(int size) { |
188 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; | 196 NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"]; |
189 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); | 197 return NSImageToSkBitmap(image, NSMakeSize(size, size), /* is_opaque=*/true); |
190 } | 198 } |
191 | 199 |
192 } // namespace gfx | 200 } // namespace gfx |
OLD | NEW |