Bug 717872 - Make blending functions take const source parameters so it's a little less likely that we modify things in mFrames again. r=seth
authorJoe Drew <joe@drew.ca>
Fri, 28 Jun 2013 15:01:32 -0400
changeset 137467 77c0bebf47edc45b2788610af83a8fa0edea8711
parent 137466 233906d2c528364165871b7a32d347c7f647d35d
child 137468 454706720bbcfb0bc2f926424be9dea042076303
child 137502 5796c661ad878c61f6eb3ec18bf8dab6e82e38df
push id30551
push userjdrew@mozilla.com
push dateThu, 04 Jul 2013 18:47:15 +0000
treeherdermozilla-inbound@77c0bebf47ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs717872
milestone25.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 717872 - Make blending functions take const source parameters so it's a little less likely that we modify things in mFrames again. r=seth
image/src/FrameBlender.cpp
image/src/FrameBlender.h
--- a/image/src/FrameBlender.cpp
+++ b/image/src/FrameBlender.cpp
@@ -133,18 +133,18 @@ bool
 FrameBlender::DoBlend(nsIntRect* aDirtyRect,
                       uint32_t aPrevFrameIndex,
                       uint32_t aNextFrameIndex)
 {
   if (!aDirtyRect) {
     return false;
   }
 
-  FrameDataPair& prevFrame = mFrames[aPrevFrameIndex];
-  FrameDataPair& nextFrame = mFrames[aNextFrameIndex];
+  const FrameDataPair& prevFrame = mFrames[aPrevFrameIndex];
+  const FrameDataPair& nextFrame = mFrames[aNextFrameIndex];
   if (!prevFrame.HasFrameData() || !nextFrame.HasFrameData()) {
     return false;
   }
 
   int32_t prevFrameDisposalMethod = prevFrame->GetFrameDisposalMethod();
   if (prevFrameDisposalMethod == FrameBlender::kDisposeRestorePrevious &&
       !mAnim->compositingPrevFrame)
     prevFrameDisposalMethod = FrameBlender::kDisposeClear;
@@ -428,33 +428,33 @@ FrameBlender::ClearFrame(uint8_t* aFrame
     memset(aFrameData + toClear.x * 4 + row * bytesPerRow, 0, toClear.width * 4);
   }
 }
 
 //******************************************************************************
 // Whether we succeed or fail will not cause a crash, and there's not much
 // we can do about a failure, so there we don't return a nsresult
 bool
-FrameBlender::CopyFrameImage(uint8_t *aDataSrc, const nsIntRect& aRectSrc,
+FrameBlender::CopyFrameImage(const uint8_t *aDataSrc, const nsIntRect& aRectSrc,
                              uint8_t *aDataDest, const nsIntRect& aRectDest)
 {
   uint32_t dataLengthSrc = aRectSrc.width * aRectSrc.height * 4;
   uint32_t dataLengthDest = aRectDest.width * aRectDest.height * 4;
 
   if (!aDataDest || !aDataSrc || dataLengthSrc != dataLengthDest) {
     return false;
   }
 
   memcpy(aDataDest, aDataSrc, dataLengthDest);
 
   return true;
 }
 
 nsresult
-FrameBlender::DrawFrameTo(uint8_t *aSrcData, const nsIntRect& aSrcRect,
+FrameBlender::DrawFrameTo(const uint8_t *aSrcData, const nsIntRect& aSrcRect,
                           uint32_t aSrcPaletteLength, bool aSrcHasAlpha,
                           uint8_t *aDstPixels, const nsIntRect& aDstRect,
                           FrameBlender::FrameBlendMethod aBlendMethod)
 {
   NS_ENSURE_ARG_POINTER(aSrcData);
   NS_ENSURE_ARG_POINTER(aDstPixels);
 
   // According to both AGIF and APNG specs, offsets are unsigned
@@ -478,19 +478,19 @@ FrameBlender::DrawFrameTo(uint8_t *aSrcD
                  (aSrcRect.y + height <= aDstRect.height),
                 "FrameBlender::DrawFrameTo: Invalid aSrcRect");
 
     // clipped image size may be smaller than source, but not larger
     NS_ASSERTION((width <= aSrcRect.width) && (height <= aSrcRect.height),
                  "FrameBlender::DrawFrameTo: source must be smaller than dest");
 
     // Get pointers to image data
-    uint8_t *srcPixels = aSrcData + aSrcPaletteLength;
+    const uint8_t *srcPixels = aSrcData + aSrcPaletteLength;
     uint32_t *dstPixels = reinterpret_cast<uint32_t*>(aDstPixels);
-    uint32_t *colormap = reinterpret_cast<uint32_t*>(aSrcData);
+    const uint32_t *colormap = reinterpret_cast<const uint32_t*>(aSrcData);
 
     // Skip to the right offset
     dstPixels += aSrcRect.x + (aSrcRect.y * aDstRect.width);
     if (!aSrcHasAlpha) {
       for (int32_t r = height; r > 0; --r) {
         for (int32_t c = 0; c < width; c++) {
           dstPixels[c] = colormap[srcPixels[c]];
         }
@@ -509,17 +509,17 @@ FrameBlender::DrawFrameTo(uint8_t *aSrcD
         srcPixels += aSrcRect.width;
         dstPixels += aDstRect.width;
       }
     }
   } else {
     pixman_image_t* src = pixman_image_create_bits(aSrcHasAlpha ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
                                                    aSrcRect.width,
                                                    aSrcRect.height,
-                                                   reinterpret_cast<uint32_t*>(aSrcData),
+                                                   reinterpret_cast<uint32_t*>(const_cast<uint8_t*>(aSrcData)),
                                                    aSrcRect.width * 4);
     pixman_image_t* dst = pixman_image_create_bits(PIXMAN_a8r8g8b8,
                                                    aDstRect.width,
                                                    aDstRect.height,
                                                    reinterpret_cast<uint32_t*>(aDstPixels),
                                                    aDstRect.width * 4);
 
     pixman_image_composite32(aBlendMethod == FrameBlender::kBlendSource ? PIXMAN_OP_SRC : PIXMAN_OP_OVER,
--- a/image/src/FrameBlender.h
+++ b/image/src/FrameBlender.h
@@ -245,17 +245,17 @@ private:
    * @note Does also clears the transparancy mask
    */
   static void ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect);
 
   //! @overload
   static void ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect, const nsIntRect &aRectToClear);
 
   //! Copy one frames's image and mask into another
-  static bool CopyFrameImage(uint8_t *aDataSrc, const nsIntRect& aRectSrc,
+  static bool CopyFrameImage(const uint8_t *aDataSrc, const nsIntRect& aRectSrc,
                              uint8_t *aDataDest, const nsIntRect& aRectDest);
 
   /**
    * Draws one frames's image to into another, at the position specified by
    * aSrcRect.
    *
    * @aSrcData the raw data of the current frame being drawn
    * @aSrcRect the size of the source frame, and the position of that frame in
@@ -263,17 +263,17 @@ private:
    * @aSrcPaletteLength the length (in bytes) of the palette at the beginning
    *                    of the source data (0 if image is not paletted)
    * @aSrcHasAlpha whether the source data represents an image with alpha
    * @aDstPixels the raw data of the composition frame where the current frame
    *             is drawn into (32-bit ARGB)
    * @aDstRect the size of the composition frame
    * @aBlendMethod the blend method for how to blend src on the composition frame.
    */
-  static nsresult DrawFrameTo(uint8_t *aSrcData, const nsIntRect& aSrcRect,
+  static nsresult DrawFrameTo(const uint8_t *aSrcData, const nsIntRect& aSrcRect,
                               uint32_t aSrcPaletteLength, bool aSrcHasAlpha,
                               uint8_t *aDstPixels, const nsIntRect& aDstRect,
                               FrameBlendMethod aBlendMethod);
 
 private: // data
   //! All the frames of the image
   nsTArray<FrameDataPair> mFrames;
   nsIntSize mSize;