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

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

Issue 10963064: Properly flip the CGContext during UIImage->SkBitmap conversions. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review. Created 8 years, 3 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
« no previous file with comments | « no previous file | ui/gfx/image/image_unittest.cc » ('j') | ui/gfx/image/image_unittest_util_ios.mm » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_ios.h" 5 #include "skia/ext/skia_utils_ios.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.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 29 matching lines...) Expand all
40 #else 40 #else
41 #error We require that Skia's and CoreGraphics's recommended \ 41 #error We require that Skia's and CoreGraphics's recommended \
42 image memory layout match. 42 image memory layout match.
43 #endif 43 #endif
44 #undef HAS_ARGB_SHIFTS 44 #undef HAS_ARGB_SHIFTS
45 45
46 DCHECK(context); 46 DCHECK(context);
47 if (!context) 47 if (!context)
48 return bitmap; 48 return bitmap;
49 49
50 // We need to invert the y-axis of the canvas so that Core Graphics drawing
51 // happens right-side up. Skia has an upper-left origin and CG has a lower-
52 // left one.
53 CGContextScaleCTM(context, 1.0, -1.0);
54 CGContextTranslateCTM(context, 0, -size.height);
55
50 // UIGraphicsPushContext be called from the main thread. 56 // UIGraphicsPushContext be called from the main thread.
51 // TODO(rohitrao): We can use CG to make this thread safe, but the mac code 57 // TODO(rohitrao): We can use CG to make this thread safe, but the mac code
52 // calls setCurrentContext, so it's similarly limited to the main thread. 58 // calls setCurrentContext, so it's similarly limited to the main thread.
53 DCHECK([NSThread isMainThread]); 59 DCHECK([NSThread isMainThread]);
54 UIGraphicsPushContext(context); 60 UIGraphicsPushContext(context);
55 [image drawInRect:CGRectMake(0, 0, size.width, size.height) 61 [image drawInRect:CGRectMake(0, 0, size.width, size.height)
56 blendMode:kCGBlendModeCopy 62 blendMode:kCGBlendModeCopy
57 alpha:1.0]; 63 alpha:1.0];
58 UIGraphicsPopContext(); 64 UIGraphicsPopContext();
59 65
60 return bitmap; 66 return bitmap;
61 } 67 }
62 68
63 UIImage* SkBitmapToUIImageWithColorSpace(const SkBitmap& skia_bitmap, 69 UIImage* SkBitmapToUIImageWithColorSpace(const SkBitmap& skia_bitmap,
64 CGColorSpaceRef color_space) { 70 CGColorSpaceRef color_space) {
65 if (skia_bitmap.isNull()) 71 if (skia_bitmap.isNull())
66 return nil; 72 return nil;
67 73
68 // First convert SkBitmap to CGImageRef. 74 // First convert SkBitmap to CGImageRef.
69 base::mac::ScopedCFTypeRef<CGImageRef> cg_image( 75 base::mac::ScopedCFTypeRef<CGImageRef> cg_image(
70 SkCreateCGImageRefWithColorspace(skia_bitmap, color_space)); 76 SkCreateCGImageRefWithColorspace(skia_bitmap, color_space));
71 77
72 // Now convert to UIImage. 78 // Now convert to UIImage.
73 // TODO(rohitrao): Gotta incorporate the scale factor somewhere! 79 // TODO(rohitrao): Gotta incorporate the scale factor somewhere!
74 return [UIImage imageWithCGImage:cg_image.get()]; 80 return [UIImage imageWithCGImage:cg_image.get()];
75 } 81 }
76 82
77 } // namespace gfx 83 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/image/image_unittest.cc » ('j') | ui/gfx/image/image_unittest_util_ios.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698