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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 // Converts ARGB to CGColorRef. | 78 // Converts ARGB to CGColorRef. |
79 CGColorRef SkColorToCGColorRef(SkColor color) { | 79 CGColorRef SkColorToCGColorRef(SkColor color) { |
80 return CGColorCreateGenericRGB(SkColorGetR(color) / 255.0, | 80 return CGColorCreateGenericRGB(SkColorGetR(color) / 255.0, |
81 SkColorGetG(color) / 255.0, | 81 SkColorGetG(color) / 255.0, |
82 SkColorGetB(color) / 255.0, | 82 SkColorGetB(color) / 255.0, |
83 SkColorGetA(color) / 255.0); | 83 SkColorGetA(color) / 255.0); |
84 } | 84 } |
85 | 85 |
86 SkBitmap CGImageToSkBitmap(CGImageRef image) { | 86 SkBitmap CGImageToSkBitmap(CGImageRef image) { |
87 DCHECK(image != NULL); | 87 if (!image) |
| 88 return SkBitmap(); |
88 | 89 |
89 int width = CGImageGetWidth(image); | 90 int width = CGImageGetWidth(image); |
90 int height = CGImageGetHeight(image); | 91 int height = CGImageGetHeight(image); |
91 | 92 |
92 scoped_ptr<skia::BitmapPlatformDevice> device( | 93 scoped_ptr<skia::BitmapPlatformDevice> device( |
93 skia::BitmapPlatformDevice::Create(NULL, width, height, false)); | 94 skia::BitmapPlatformDevice::Create(NULL, width, height, false)); |
94 | 95 |
95 CGContextRef context = device->GetBitmapContext(); | 96 CGContextRef context = device->GetBitmapContext(); |
96 | 97 |
97 // We need to invert the y-axis of the canvas so that Core Graphics drawing | 98 // We need to invert the y-axis of the canvas so that Core Graphics drawing |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Now convert to NSImage. | 174 // Now convert to NSImage. |
174 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] | 175 NSBitmapImageRep* bitmap = [[[NSBitmapImageRep alloc] |
175 initWithCGImage:cgimage] autorelease]; | 176 initWithCGImage:cgimage] autorelease]; |
176 CFRelease(cgimage); | 177 CFRelease(cgimage); |
177 NSImage* image = [[[NSImage alloc] init] autorelease]; | 178 NSImage* image = [[[NSImage alloc] init] autorelease]; |
178 [image addRepresentation:bitmap]; | 179 [image addRepresentation:bitmap]; |
179 return image; | 180 return image; |
180 } | 181 } |
181 | 182 |
182 } // namespace gfx | 183 } // namespace gfx |
OLD | NEW |