Bug 1102048 - Make image/src files comply with the Mozilla Coding Style Guide. r=seth

This commit is contained in:
Glenn Randers-Pehrson 2014-12-05 17:17:00 -08:00
parent 769737166d
commit 8f980a0f12
2 changed files with 65 additions and 50 deletions

View File

@ -66,9 +66,9 @@ FrameBlender::GetTimeoutForFrame(uint32_t aFrameNum)
const int32_t timeout = frame->GetRawTimeout();
// Ensure a minimal time between updates so we don't throttle the UI thread.
// consider 0 == unspecified and make it fast but not too fast. Unless we have
// a single loop GIF. See bug 890743, bug 125137, bug 139677, and bug 207059.
// The behavior of recent IE and Opera versions seems to be:
// consider 0 == unspecified and make it fast but not too fast. Unless we
// have a single loop GIF. See bug 890743, bug 125137, bug 139677, and bug
// 207059. The behavior of recent IE and Opera versions seems to be:
// IE 6/Win:
// 10 - 50ms go 100ms
// >50ms go correct speed
@ -258,8 +258,10 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
} else {
if ((prevFrameRect.x >= nextFrameRect.x) &&
(prevFrameRect.y >= nextFrameRect.y) &&
(prevFrameRect.x + prevFrameRect.width <= nextFrameRect.x + nextFrameRect.width) &&
(prevFrameRect.y + prevFrameRect.height <= nextFrameRect.y + nextFrameRect.height)) {
(prevFrameRect.x + prevFrameRect.width <=
nextFrameRect.x + nextFrameRect.width) &&
(prevFrameRect.y + prevFrameRect.height <=
nextFrameRect.y + nextFrameRect.height)) {
// Optimization: No need to dispose prev.frame when
// next frame fully overlaps previous frame.
doDisposal = false;
@ -299,8 +301,10 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
mAnim->compositingFrame->GetRect());
// destroy only if we don't need it for this frame's disposal
if (nextFrameDisposalMethod != FrameBlender::kDisposeRestorePrevious)
if (nextFrameDisposalMethod !=
FrameBlender::kDisposeRestorePrevious) {
mAnim->compositingPrevFrame.reset();
}
} else {
ClearFrame(mAnim->compositingFrame->GetRawData(),
mAnim->compositingFrame->GetRect());
@ -308,12 +312,13 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
break;
default:
// Copy previous frame into compositingFrame before we put the new frame on top
// Copy previous frame into compositingFrame before we put the new
// frame on top
// Assumes that the previous frame represents a full frame (it could be
// smaller in size than the container, as long as the frame before it erased
// itself)
// Note: Frame 1 never gets into DoBlend(), so (aNextFrameIndex - 1) will
// always be a valid frame number.
// smaller in size than the container, as long as the frame before it
// erased itself)
// Note: Frame 1 never gets into DoBlend(), so (aNextFrameIndex - 1)
// will always be a valid frame number.
if (mAnim->lastCompositedFrameIndex != int32_t(aNextFrameIndex - 1)) {
if (isFullPrevFrame && !prevFrame->GetIsPaletted()) {
// Just copy the bits
@ -339,13 +344,13 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
}
}
} else if (needToBlankComposite) {
// If we just created the composite, it could have anything in it's
// If we just created the composite, it could have anything in its
// buffers. Clear them
ClearFrame(mAnim->compositingFrame->GetRawData(),
mAnim->compositingFrame->GetRect());
}
// Check if the frame we are composing wants the previous image restored afer
// Check if the frame we are composing wants the previous image restored after
// it is done. Don't store it (again) if last frame wanted its image restored
// too
if ((nextFrameDisposalMethod == FrameBlender::kDisposeRestorePrevious) &&
@ -400,15 +405,17 @@ FrameBlender::DoBlend(nsIntRect* aDirtyRect,
void
FrameBlender::ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect)
{
if (!aFrameData)
if (!aFrameData) {
return;
}
memset(aFrameData, 0, aFrameRect.width * aFrameRect.height * 4);
}
//******************************************************************************
void
FrameBlender::ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect, const nsIntRect& aRectToClear)
FrameBlender::ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect,
const nsIntRect& aRectToClear)
{
if (!aFrameData || aFrameRect.width <= 0 || aFrameRect.height <= 0 ||
aRectToClear.width <= 0 || aRectToClear.height <= 0) {
@ -422,7 +429,8 @@ FrameBlender::ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect, const
uint32_t bytesPerRow = aFrameRect.width * 4;
for (int row = toClear.y; row < toClear.y + toClear.height; ++row) {
memset(aFrameData + toClear.x * 4 + row * bytesPerRow, 0, toClear.width * 4);
memset(aFrameData + toClear.x * 4 + row * bytesPerRow, 0,
toClear.width * 4);
}
}
@ -430,8 +438,8 @@ FrameBlender::ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect, const
// 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(const uint8_t *aDataSrc, const nsIntRect& aRectSrc,
uint8_t *aDataDest, const nsIntRect& aRectDest)
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;
@ -446,9 +454,9 @@ FrameBlender::CopyFrameImage(const uint8_t *aDataSrc, const nsIntRect& aRectSrc,
}
nsresult
FrameBlender::DrawFrameTo(const 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,
uint8_t* aDstPixels, const nsIntRect& aDstRect,
FrameBlender::FrameBlendMethod aBlendMethod)
{
NS_ENSURE_ARG_POINTER(aSrcData);
@ -480,9 +488,9 @@ FrameBlender::DrawFrameTo(const uint8_t *aSrcData, const nsIntRect& aSrcRect,
"FrameBlender::DrawFrameTo: source must be smaller than dest");
// Get pointers to image data
const uint8_t *srcPixels = aSrcData + aSrcPaletteLength;
uint32_t *dstPixels = reinterpret_cast<uint32_t*>(aDstPixels);
const uint32_t *colormap = reinterpret_cast<const uint32_t*>(aSrcData);
const uint8_t* srcPixels = aSrcData + aSrcPaletteLength;
uint32_t* dstPixels = reinterpret_cast<uint32_t*>(aDstPixels);
const uint32_t* colormap = reinterpret_cast<const uint32_t*>(aSrcData);
// Skip to the right offset
dstPixels += aSrcRect.x + (aSrcRect.y * aDstRect.width);
@ -499,8 +507,9 @@ FrameBlender::DrawFrameTo(const uint8_t *aSrcData, const nsIntRect& aSrcRect,
for (int32_t r = height; r > 0; --r) {
for (int32_t c = 0; c < width; c++) {
const uint32_t color = colormap[srcPixels[c]];
if (color)
if (color) {
dstPixels[c] = color;
}
}
// Go to the next row in the source resp. destination image
srcPixels += aSrcRect.width;
@ -508,18 +517,22 @@ FrameBlender::DrawFrameTo(const uint8_t *aSrcData, const nsIntRect& aSrcRect,
}
}
} else {
pixman_image_t* src = pixman_image_create_bits(aSrcHasAlpha ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
aSrcRect.width,
aSrcRect.height,
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_t* src =
pixman_image_create_bits(
aSrcHasAlpha ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
aSrcRect.width, aSrcRect.height,
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,
auto op = aBlendMethod == FrameBlender::kBlendSource ? PIXMAN_OP_SRC
: PIXMAN_OP_OVER;
pixman_image_composite32(op,
src,
nullptr,
dst,

View File

@ -55,9 +55,10 @@ public:
uint32_t GetNumFrames() const;
/*
* Returns the frame's adjusted timeout. If the animation loops and the timeout
* falls in between a certain range then the timeout is adjusted so that
* it's never 0. If the animation does not loop then no adjustments are made.
* Returns the frame's adjusted timeout. If the animation loops and the
* timeout falls in between a certain range then the timeout is adjusted so
* that it's never 0. If the animation does not loop then no adjustments are
* made.
*/
int32_t GetTimeoutForFrame(uint32_t aFrameNum);
@ -130,9 +131,7 @@ private:
*/
RawAccessFrameRef compositingPrevFrame;
Anim() :
lastCompositedFrameIndex(-1)
{}
Anim() : lastCompositedFrameIndex(-1) { }
};
/** Clears an area of <aFrame> with transparent black.
@ -140,19 +139,20 @@ private:
* @param aFrameData Target Frame data
* @param aFrameRect The rectangle of the data pointed ot by aFrameData
*
* @note Does also clears the transparancy mask
* @note Does also clears the transparency mask
*/
static void ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect);
//! @overload
static void ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect, const nsIntRect &aRectToClear);
static void ClearFrame(uint8_t* aFrameData, const nsIntRect& aFrameRect,
const nsIntRect& aRectToClear);
//! Copy one frames's image and mask into another
static bool CopyFrameImage(const uint8_t *aDataSrc, const nsIntRect& aRectSrc,
uint8_t *aDataDest, const nsIntRect& aRectDest);
//! Copy one frame's image and mask into another
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
* Draws one frame's image to into another, at the position specified by
* aSrcRect.
*
* @aSrcData the raw data of the current frame being drawn
@ -164,11 +164,13 @@ private:
* @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.
* @aBlendMethod the blend method for how to blend src on the composition
* frame.
*/
static nsresult DrawFrameTo(const 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,
uint8_t* aDstPixels, const nsIntRect& aDstRect,
FrameBlendMethod aBlendMethod);
private: // data