Bug 795722 - Clear our cached ImageContainer when the imgFrame changes. r=joe
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 02 Oct 2012 17:01:25 +1300
changeset 108907 b0fc903a074955d3b33ee75761001465c50796f1
parent 108906 396630ce4035872fe4a1d03258343e7405bbf18b
child 108915 85dd8e346102a3839fcab5f89420f708a9b6cb6d
child 108979 7f3d9233b236a347174bb6f917f288fd571609ea
child 111104 8d1ffa2548af2bb99e74add6c78297610edf4cd0
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjoe
bugs795722
milestone18.0a1
Bug 795722 - Clear our cached ImageContainer when the imgFrame changes. r=joe
image/src/RasterImage.cpp
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -938,16 +938,20 @@ RasterImage::GetFrame(uint32_t aWhichFra
 
 already_AddRefed<layers::Image>
 RasterImage::GetCurrentImage()
 {
   nsRefPtr<gfxASurface> imageSurface;
   nsresult rv = GetFrame(FRAME_CURRENT, FLAG_SYNC_DECODE, getter_AddRefs(imageSurface));
   NS_ENSURE_SUCCESS(rv, nullptr);
 
+  if (!mImageContainer) {
+    mImageContainer = LayerManager::CreateImageContainer();
+  }
+
   CairoImage::Data cairoData;
   cairoData.mSurface = imageSurface;
   GetWidth(&cairoData.mSize.width);
   GetHeight(&cairoData.mSize.height);
 
   ImageFormat cairoFormat = CAIRO_SURFACE;
   nsRefPtr<layers::Image> image = mImageContainer->CreateImage(&cairoFormat, 1);
   NS_ASSERTION(image, "Failed to create Image");
@@ -963,18 +967,16 @@ NS_IMETHODIMP
 RasterImage::GetImageContainer(ImageContainer **_retval)
 {
   if (mImageContainer) {
     *_retval = mImageContainer;
     NS_ADDREF(*_retval);
     return NS_OK;
   }
   
-  mImageContainer = LayerManager::CreateImageContainer();
-  
   nsRefPtr<layers::Image> image = GetCurrentImage();
   if (!image) {
     return NS_ERROR_FAILURE;
   }
   mImageContainer->SetCurrentImageInTransaction(image);
 
   *_retval = mImageContainer;
   NS_ADDREF(*_retval);
@@ -1287,19 +1289,19 @@ RasterImage::FrameUpdated(uint32_t aFram
 {
   NS_ABORT_IF_FALSE(aFrameNum < mFrames.Length(), "Invalid frame index!");
 
   imgFrame *frame = GetImgFrameNoDecode(aFrameNum);
   NS_ABORT_IF_FALSE(frame, "Calling FrameUpdated on frame that doesn't exist!");
 
   frame->ImageUpdated(aUpdatedRect);
     
-  if (aFrameNum == GetCurrentImgFrameIndex()) {
-    // The image has changed, so we need to invalidate our cached ImageContainer.
-    UpdateImageContainer();
+  if (aFrameNum == GetCurrentImgFrameIndex() &&
+      !IsInUpdateImageContainer()) {
+    mImageContainer = nullptr;
   }
 }
 
 nsresult
 RasterImage::SetFrameDisposalMethod(uint32_t aFrameNum,
                                     int32_t aDisposalMethod)
 {
   if (mError)