Bug 1131446. mFrameHasNoAlpha is mostly pointless. r=seth
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 10 Feb 2015 13:26:14 +0800
changeset 255788 b24f9a3b47a6f1bb6bc3b74932d07dc783719e0b
parent 255787 d2717f1bd34872b5be255f2c0d4bed9c34a4cf3b
child 255789 bf710daef92bcad49f883e4dd6cbe02c9e6cc62b
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs1131446, 391583
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1131446. mFrameHasNoAlpha is mostly pointless. r=seth Starting with bug 391583 we detect whether a png image has any transparency during decode. I don't think this is worth doing anymore. We choose the format of image based on the png header, that should be sufficient for the performance improvement we desire from opaque images. This gets us faster image decoding.
image/decoders/nsPNGDecoder.cpp
image/decoders/nsPNGDecoder.h
--- a/image/decoders/nsPNGDecoder.cpp
+++ b/image/decoders/nsPNGDecoder.cpp
@@ -164,17 +164,16 @@ void nsPNGDecoder::CreateFrame(png_uint_
     }
 
     NeedNewFrame(mNumFrames, x_offset, y_offset, width, height, format);
   } else if (mNumFrames != 0) {
     NeedNewFrame(mNumFrames, x_offset, y_offset, width, height, format);
   }
 
   mFrameRect = neededRect;
-  mFrameHasNoAlpha = true;
 
   PR_LOG(GetPNGDecoderAccountingLog(), PR_LOG_DEBUG,
          ("PNGDecoderAccounting: nsPNGDecoder::CreateFrame -- created "
           "image frame with %dx%d pixels in container %p",
           width, height,
           &mImage));
 
 #ifdef PNG_APNG_SUPPORTED
@@ -196,17 +195,17 @@ nsPNGDecoder::EndImageFrame()
 {
   if (mFrameIsHidden) {
     return;
   }
 
   mNumFrames++;
 
   Opacity opacity = Opacity::SOME_TRANSPARENCY;
-  if (format == gfx::SurfaceFormat::B8G8R8X8 || mFrameHasNoAlpha) {
+  if (format == gfx::SurfaceFormat::B8G8R8X8) {
     opacity = Opacity::OPAQUE;
   }
 
 #ifdef PNG_APNG_SUPPORTED
   uint32_t numFrames = GetFrameCount();
 
   // We can't use mPNG->num_frames_read as it may be one ahead.
   if (numFrames > 1) {
@@ -734,17 +733,16 @@ nsPNGDecoder::row_callback(png_structp p
     png_bytep line = new_row;
     if (decoder->interlacebuf) {
       line = decoder->interlacebuf + (row_num * decoder->mChannels * width);
       png_progressive_combine_row(png_ptr, line, new_row);
     }
 
     uint32_t bpr = width * sizeof(uint32_t);
     uint32_t* cptr32 = (uint32_t*)(decoder->mImageData + (row_num*bpr));
-    bool rowHasNoAlpha = true;
 
     if (decoder->mTransform) {
       if (decoder->mCMSLine) {
         qcms_transform_data(decoder->mTransform, line, decoder->mCMSLine,
                             iwidth);
         // copy alpha over
         uint32_t channels = decoder->mChannels;
         if (channels == 2 || channels == 4) {
@@ -783,41 +781,31 @@ nsPNGDecoder::row_callback(png_structp p
           line += 3;
         }
       }
       break;
       case gfx::SurfaceFormat::B8G8R8A8: {
         if (!decoder->mDisablePremultipliedAlpha) {
           for (uint32_t x=width; x>0; --x) {
             *cptr32++ = gfxPackedPixel(line[3], line[0], line[1], line[2]);
-            if (line[3] != 0xff) {
-              rowHasNoAlpha = false;
-            }
             line += 4;
           }
         } else {
           for (uint32_t x=width; x>0; --x) {
             *cptr32++ = gfxPackedPixelNoPreMultiply(line[3], line[0], line[1],
                                                     line[2]);
-            if (line[3] != 0xff) {
-              rowHasNoAlpha = false;
-            }
             line += 4;
           }
         }
       }
       break;
       default:
         png_longjmp(decoder->mPNG, 1);
     }
 
-    if (!rowHasNoAlpha) {
-      decoder->mFrameHasNoAlpha = false;
-    }
-
     if (decoder->mNumFrames <= 1) {
       // Only do incremental image display for the first frame
       // XXXbholley - this check should be handled in the superclass
       nsIntRect r(0, row_num, width, 1);
       decoder->PostInvalidation(r);
     }
   }
 }
--- a/image/decoders/nsPNGDecoder.h
+++ b/image/decoders/nsPNGDecoder.h
@@ -81,17 +81,16 @@ public:
   // For size decodes
   uint8_t mSizeBytes[8]; // Space for width and height, both 4 bytes
   uint32_t mHeaderBytesRead;
 
   // whether CMS or premultiplied alpha are forced off
   uint32_t mCMSMode;
 
   uint8_t mChannels;
-  bool mFrameHasNoAlpha;
   bool mFrameIsHidden;
   bool mDisablePremultipliedAlpha;
 
   struct AnimFrameInfo
   {
     AnimFrameInfo();
 #ifdef PNG_APNG_SUPPORTED
     AnimFrameInfo(png_structp aPNG, png_infop aInfo);