Commit 01907fa0 authored by Andrew Osmond's avatar Andrew Osmond
Browse files

Bug 1462355 - Part 1c. Make individual image decoders to use updated...

Bug 1462355 - Part 1c. Make individual image decoders to use updated Decoder/SurfacePipe methods. r=tnikkel
parent 6c32a5f9
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -685,8 +685,7 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
  }

  MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
  nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
                              FullOutputFrame(),
  nsresult rv = AllocateFrame(OutputSize(), FullOutputFrame(),
                              mMayHaveTransparency ? SurfaceFormat::B8G8R8A8
                                                   : SurfaceFormat::B8G8R8X8);
  if (NS_FAILED(rv)) {
+15 −9
Original line number Diff line number Diff line
@@ -182,6 +182,14 @@ nsGIFDecoder2::BeginImageFrame(const IntRect& aFrameRect,
  // Make sure there's no animation if we're downscaling.
  MOZ_ASSERT_IF(Size() != OutputSize(), !GetImageMetadata().HasAnimation());

  AnimationParams animParams {
    aFrameRect,
    FrameTimeout::FromRawMilliseconds(mGIFStruct.delay_time),
    uint32_t(mGIFStruct.images_decoded),
    BlendMethod::OVER,
    DisposalMethod(mGIFStruct.disposal_method)
  };

  SurfacePipeFlags pipeFlags = aIsInterlaced
                             ? SurfacePipeFlags::DEINTERLACE
                             : SurfacePipeFlags();
@@ -196,9 +204,9 @@ nsGIFDecoder2::BeginImageFrame(const IntRect& aFrameRect,

    // The first frame is always decoded into an RGB surface.
    pipe =
      SurfacePipeFactory::CreateSurfacePipe(this, mGIFStruct.images_decoded,
                                            Size(), OutputSize(),
                                            aFrameRect, format, pipeFlags);
      SurfacePipeFactory::CreateSurfacePipe(this, Size(), OutputSize(),
                                            aFrameRect, format,
                                            Some(animParams), pipeFlags);
  } else {
    // This is an animation frame (and not the first). To minimize the memory
    // usage of animations, the image data is stored in paletted form.
@@ -210,10 +218,10 @@ nsGIFDecoder2::BeginImageFrame(const IntRect& aFrameRect,
    // historically.
    MOZ_ASSERT(Size() == OutputSize());
    pipe =
      SurfacePipeFactory::CreatePalettedSurfacePipe(this, mGIFStruct.images_decoded,
                                                    Size(), aFrameRect,
      SurfacePipeFactory::CreatePalettedSurfacePipe(this, Size(), aFrameRect,
                                                    SurfaceFormat::B8G8R8A8,
                                                    aDepth, pipeFlags);
                                                    aDepth, Some(animParams),
                                                    pipeFlags);
  }

  mCurrentFrameIndex = mGIFStruct.images_decoded;
@@ -254,9 +262,7 @@ nsGIFDecoder2::EndImageFrame()
  mGIFStruct.images_decoded++;

  // Tell the superclass we finished a frame
  PostFrameStop(opacity,
                DisposalMethod(mGIFStruct.disposal_method),
                FrameTimeout::FromRawMilliseconds(mGIFStruct.delay_time));
  PostFrameStop(opacity);

  // Reset the transparent pixel
  if (mOldColor) {
+2 −1
Original line number Diff line number Diff line
@@ -70,8 +70,9 @@ nsIconDecoder::ReadHeader(const char* aData)

  MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
  Maybe<SurfacePipe> pipe =
    SurfacePipeFactory::CreateSurfacePipe(this, 0, Size(), OutputSize(),
    SurfacePipeFactory::CreateSurfacePipe(this, Size(), OutputSize(),
                                          FullFrame(), SurfaceFormat::B8G8R8A8,
                                          /* aAnimParams */ Nothing(),
                                          SurfacePipeFlags());
  if (!pipe) {
    return Transition::TerminateFailure();
+2 −2
Original line number Diff line number Diff line
@@ -385,8 +385,8 @@ nsJPEGDecoder::ReadJPEGData(const char* aData, size_t aLength)
    jpeg_calc_output_dimensions(&mInfo);

    MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
    nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
                                FullOutputFrame(), SurfaceFormat::B8G8R8X8);
    nsresult rv = AllocateFrame(OutputSize(), FullOutputFrame(),
                                SurfaceFormat::B8G8R8X8);
    if (NS_FAILED(rv)) {
      mState = JPEG_ERROR;
      MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,
+23 −18
Original line number Diff line number Diff line
@@ -203,6 +203,25 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
  MOZ_ASSERT_IF(Size() != OutputSize(),
                transparency != TransparencyType::eFrameRect);

  Maybe<AnimationParams> animParams;
#ifdef PNG_APNG_SUPPORTED
  if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) {
    mAnimInfo = AnimFrameInfo(mPNG, mInfo);

    if (mAnimInfo.mDispose == DisposalMethod::CLEAR) {
      // We may have to display the background under this image during
      // animation playback, so we regard it as transparent.
      PostHasTransparency();
    }

    animParams.emplace(AnimationParams {
      aFrameInfo.mFrameRect,
      FrameTimeout::FromRawMilliseconds(mAnimInfo.mTimeout),
      mNumFrames, mAnimInfo.mBlend, mAnimInfo.mDispose
    });
  }
#endif

  // If this image is interlaced, we can display better quality intermediate
  // results to the user by post processing them with ADAM7InterpolatingFilter.
  SurfacePipeFlags pipeFlags = aFrameInfo.mIsInterlaced
@@ -215,9 +234,9 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
  }

  Maybe<SurfacePipe> pipe =
    SurfacePipeFactory::CreateSurfacePipe(this, mNumFrames, Size(),
                                          OutputSize(), aFrameInfo.mFrameRect,
                                          mFormat, pipeFlags);
    SurfacePipeFactory::CreateSurfacePipe(this, Size(), OutputSize(),
                                          aFrameInfo.mFrameRect, mFormat,
                                          animParams, pipeFlags);

  if (!pipe) {
    mPipe = SurfacePipe();
@@ -234,18 +253,6 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
          "image frame with %dx%d pixels for decoder %p",
          mFrameRect.Width(), mFrameRect.Height(), this));

#ifdef PNG_APNG_SUPPORTED
  if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) {
    mAnimInfo = AnimFrameInfo(mPNG, mInfo);

    if (mAnimInfo.mDispose == DisposalMethod::CLEAR) {
      // We may have to display the background under this image during
      // animation playback, so we regard it as transparent.
      PostHasTransparency();
    }
  }
#endif

  return NS_OK;
}

@@ -263,9 +270,7 @@ nsPNGDecoder::EndImageFrame()
                  ? Opacity::FULLY_OPAQUE
                  : Opacity::SOME_TRANSPARENCY;

  PostFrameStop(opacity, mAnimInfo.mDispose,
                FrameTimeout::FromRawMilliseconds(mAnimInfo.mTimeout),
                mAnimInfo.mBlend, Some(mFrameRect));
  PostFrameStop(opacity);
}

nsresult