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

Side by Side Diff: skia/ext/skia_utils_mac.mm

Issue 149173: A null CGImageRef should be treated as a "null" SkBitmap,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698