check to see if CGImage already knows if we're opaque
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 7 Nov 2012 22:06:55 +0000 (22:06 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 7 Nov 2012 22:06:55 +0000 (22:06 +0000)
Review URL: https://codereview.appspot.com/6838043

git-svn-id: http://skia.googlecode.com/svn/trunk@6340 2bbb7eff-a529-9590-31e7-b0007b416f81

src/ports/SkImageDecoder_CG.cpp

index ba7a89c91e26e7b42a4d701e68d0ad4525f48047..c1b63ea7a8d258835ca8872e3502812a8f389175 100644 (file)
@@ -87,8 +87,18 @@ bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
     CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image);
     CGContextRelease(cg);
 
-    // since CGImage won't tell us if it is opaque, we have to compute it.
-    bm->computeAndSetOpaquePredicate();
+    CGImageAlphaInfo info = CGImageGetAlphaInfo(image);
+    switch (info) {
+        case kCGImageAlphaNone:
+        case kCGImageAlphaNoneSkipLast:
+        case kCGImageAlphaNoneSkipFirst:
+            SkASSERT(SkBitmap::ComputeIsOpaque(*bm));
+            bm->setIsOpaque(true);
+            break;
+        default:
+            // we don't know if we're opaque or not, so compute it.
+            bm->computeAndSetOpaquePredicate();
+    }
     bm->unlockPixels();
     return true;
 }