summaryrefslogtreecommitdiffstats
path: root/skia/ext
diff options
context:
space:
mode:
authornoyau@chromium.org <noyau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-09 12:35:55 +0000
committernoyau@chromium.org <noyau@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-09 12:35:55 +0000
commit566b237aa2b38ecb5bdcde187db4215af154991c (patch)
treee2857d8e640f3341ef37241366ace5a369353d1f /skia/ext
parent0571e2283aa25db8e27c79caed8b63cc3c8a8baf (diff)
downloadchromium_src-566b237aa2b38ecb5bdcde187db4215af154991c.zip
chromium_src-566b237aa2b38ecb5bdcde187db4215af154991c.tar.gz
chromium_src-566b237aa2b38ecb5bdcde187db4215af154991c.tar.bz2
Use CGImage for conversion to SkBitmap.
This has two advantages: we can convert a CGImage without building an UIImage first and the convertion can happen on any thread, not just the main thread. BUG= Review URL: https://chromiumcodereview.appspot.com/11362164 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166900 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext')
-rw-r--r--skia/ext/skia_utils_ios.h6
-rw-r--r--skia/ext/skia_utils_ios.mm19
2 files changed, 7 insertions, 18 deletions
diff --git a/skia/ext/skia_utils_ios.h b/skia/ext/skia_utils_ios.h
index 7b49baa..f213cf0 100644
--- a/skia/ext/skia_utils_ios.h
+++ b/skia/ext/skia_utils_ios.h
@@ -18,8 +18,10 @@ class UIImage;
namespace gfx {
-// Draws a UIImage with a given size into a SkBitmap.
-SK_API SkBitmap UIImageToSkBitmap(UIImage* image, CGSize size, bool is_opaque);
+// Draws a CGImage into an SkBitmap of the given size.
+SK_API SkBitmap CGImageToSkBitmap(CGImageRef image,
+ CGSize size,
+ bool is_opaque);
// Given an SkBitmap and a color space, return an autoreleased UIImage.
SK_API UIImage* SkBitmapToUIImageWithColorSpace(const SkBitmap& skia_bitmap,
diff --git a/skia/ext/skia_utils_ios.mm b/skia/ext/skia_utils_ios.mm
index 686f30e..fba12df 100644
--- a/skia/ext/skia_utils_ios.mm
+++ b/skia/ext/skia_utils_ios.mm
@@ -12,7 +12,7 @@
namespace gfx {
-SkBitmap UIImageToSkBitmap(UIImage* image, CGSize size, bool is_opaque) {
+SkBitmap CGImageToSkBitmap(CGImageRef image, CGSize size, bool is_opaque) {
SkBitmap bitmap;
if (!image)
return bitmap;
@@ -47,21 +47,8 @@ SkBitmap UIImageToSkBitmap(UIImage* image, CGSize size, bool is_opaque) {
if (!context)
return bitmap;
- // We need to invert the y-axis of the canvas so that Core Graphics drawing
- // happens right-side up. Skia has an upper-left origin and CG has a lower-
- // left one.
- CGContextScaleCTM(context, 1.0, -1.0);
- CGContextTranslateCTM(context, 0, -size.height);
-
- // UIGraphicsPushContext be called from the main thread.
- // TODO(rohitrao): We can use CG to make this thread safe, but the mac code
- // calls setCurrentContext, so it's similarly limited to the main thread.
- DCHECK([NSThread isMainThread]);
- UIGraphicsPushContext(context);
- [image drawInRect:CGRectMake(0, 0, size.width, size.height)
- blendMode:kCGBlendModeCopy
- alpha:1.0];
- UIGraphicsPopContext();
+ CGRect imageRect = CGRectMake(0.0, 0.0, size.width, size.height);
+ CGContextDrawImage(context, imageRect, image);
return bitmap;
}