Bug 1102048 (Part 10, imgFrame) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth

This commit is contained in:
Glenn Randers-Pehrson 2015-03-31 10:48:00 -07:00
parent c051fd5cb8
commit d308a1d6f2
2 changed files with 107 additions and 66 deletions

View File

@ -75,14 +75,16 @@ AllocateBufferForImage(const IntSize& size, SurfaceFormat format)
int32_t stride = VolatileSurfaceStride(size, format);
RefPtr<VolatileBuffer> buf = new VolatileBuffer();
if (buf->Init(stride * size.height,
1 << gfxAlphaRecovery::GoodAlignmentLog2()))
1 << gfxAlphaRecovery::GoodAlignmentLog2())) {
return buf;
}
return nullptr;
}
// Returns true if an image of aWidth x aHeight is allowed and legal.
static bool AllowedImageSize(int32_t aWidth, int32_t aHeight)
static bool
AllowedImageSize(int32_t aWidth, int32_t aHeight)
{
// reject over-wide or over-tall images
const int32_t k64KLimit = 0x0000FFFF;
@ -103,7 +105,8 @@ static bool AllowedImageSize(int32_t aWidth, int32_t aHeight)
return false;
}
#if defined(XP_MACOSX)
// CoreGraphics is limited to images < 32K in *height*, so clamp all surfaces on the Mac to that height
// CoreGraphics is limited to images < 32K in *height*, so clamp all surfaces
// on the Mac to that height
if (MOZ_UNLIKELY(aHeight > SHRT_MAX)) {
NS_WARNING("image too big");
return false;
@ -128,7 +131,6 @@ static bool AllowedImageAndFrameDimensions(const nsIntSize& aImageSize,
return true;
}
imgFrame::imgFrame()
: mMonitor("imgFrame")
, mDecoded(0, 0, 0, 0)
@ -276,8 +278,9 @@ imgFrame::InitForDecoder(const nsIntSize& aImageSize,
mPalettedImageData =
static_cast<uint8_t*>(malloc(PaletteDataLength() +
(mSize.width * mSize.height)));
if (!mPalettedImageData)
if (!mPalettedImageData) {
NS_WARNING("malloc for paletted image data should succeed");
}
NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY);
} else {
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitForDecoder() twice?");
@ -397,7 +400,8 @@ imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
return NS_OK;
}
nsresult imgFrame::Optimize()
nsresult
imgFrame::Optimize()
{
MOZ_ASSERT(NS_IsMainThread());
mMonitor.AssertCurrentThreadOwns();
@ -405,19 +409,23 @@ nsresult imgFrame::Optimize()
"Should only optimize when holding the lock exclusively");
// Don't optimize during shutdown because gfxPlatform may not be available.
if (ShutdownTracker::ShutdownHasStarted())
if (ShutdownTracker::ShutdownHasStarted()) {
return NS_OK;
}
if (!mOptimizable || gDisableOptimize)
if (!mOptimizable || gDisableOptimize) {
return NS_OK;
}
if (mPalettedImageData || mOptSurface || mSinglePixel)
if (mPalettedImageData || mOptSurface || mSinglePixel) {
return NS_OK;
}
// Don't do single-color opts on non-premult data.
// Cairo doesn't support non-premult single-colors.
if (mNonPremult)
if (mNonPremult) {
return NS_OK;
}
/* Figure out if the entire image is a constant color */
@ -453,24 +461,27 @@ nsresult imgFrame::Optimize()
}
}
// if it's not RGB24/ARGB32, don't optimize, but we never hit this at the moment
// if it's not RGB24/ARGB32, don't optimize, but we never hit this at the
// moment
}
#ifdef ANDROID
SurfaceFormat optFormat =
gfxPlatform::GetPlatform()->Optimal2DFormatForContent(gfxContentType::COLOR);
SurfaceFormat optFormat = gfxPlatform::GetPlatform()
->Optimal2DFormatForContent(gfxContentType::COLOR);
if (mFormat != SurfaceFormat::B8G8R8A8 &&
optFormat == SurfaceFormat::R5G6B5) {
RefPtr<VolatileBuffer> buf =
AllocateBufferForImage(mSize, optFormat);
if (!buf)
if (!buf) {
return NS_OK;
}
RefPtr<DataSourceSurface> surf =
CreateLockedSurface(buf, mSize, optFormat);
if (!surf)
if (!surf) {
return NS_ERROR_OUT_OF_MEMORY;
}
DataSourceSurface::MappedSurface mapping;
DebugOnly<bool> success =
@ -497,9 +508,11 @@ nsresult imgFrame::Optimize()
mFormat = optFormat;
}
#else
mOptSurface = gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget()->OptimizeSourceSurface(mImageSurface);
if (mOptSurface == mImageSurface)
mOptSurface = gfxPlatform::GetPlatform()
->ScreenReferenceDrawTarget()->OptimizeSourceSurface(mImageSurface);
if (mOptSurface == mImageSurface) {
mOptSurface = nullptr;
}
#endif
if (mOptSurface) {
@ -560,7 +573,8 @@ imgFrame::SurfaceForDrawing(bool aDoPadding,
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, size), mFormat);
}
gfxRect available = gfxRect(mDecoded.x, mDecoded.y, mDecoded.width, mDecoded.height);
gfxRect available = gfxRect(mDecoded.x, mDecoded.y, mDecoded.width,
mDecoded.height);
if (aDoTile || mSinglePixel) {
// Create a temporary surface.
@ -569,8 +583,9 @@ imgFrame::SurfaceForDrawing(bool aDoPadding,
RefPtr<DrawTarget> target =
gfxPlatform::GetPlatform()->
CreateOffscreenContentDrawTarget(size, SurfaceFormat::B8G8R8A8);
if (!target)
if (!target) {
return SurfaceWithFormat();
}
// Fill 'available' with whatever we've got
if (mSinglePixel) {
@ -585,7 +600,8 @@ imgFrame::SurfaceForDrawing(bool aDoPadding,
}
RefPtr<SourceSurface> newsurf = target->Snapshot();
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, size), target->GetFormat());
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, size),
target->GetFormat());
}
// Not tiling, and we have a surface, so we can account for
@ -709,7 +725,8 @@ imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */,
ImageUpdatedInternal(GetRect());
}
nsIntRect imgFrame::GetRect() const
nsIntRect
imgFrame::GetRect() const
{
return nsIntRect(mOffset, nsIntSize(mSize.width, mSize.height));
}
@ -726,26 +743,31 @@ imgFrame::GetStride() const
return VolatileSurfaceStride(mSize, mFormat);
}
SurfaceFormat imgFrame::GetFormat() const
SurfaceFormat
imgFrame::GetFormat() const
{
MonitorAutoLock lock(mMonitor);
return mFormat;
}
uint32_t imgFrame::GetImageBytesPerRow() const
uint32_t
imgFrame::GetImageBytesPerRow() const
{
mMonitor.AssertCurrentThreadOwns();
if (mVBuf)
if (mVBuf) {
return mSize.width * BytesPerPixel(mFormat);
}
if (mPaletteDepth)
if (mPaletteDepth) {
return mSize.width;
}
return 0;
}
uint32_t imgFrame::GetImageDataLength() const
uint32_t
imgFrame::GetImageDataLength() const
{
return GetImageBytesPerRow() * mSize.height;
}
@ -765,19 +787,23 @@ imgFrame::GetImageDataInternal(uint8_t** aData, uint32_t* aLength) const
if (mImageSurface) {
*aData = mVBufPtr;
MOZ_ASSERT(*aData, "mImageSurface is non-null, but mVBufPtr is null in GetImageData");
MOZ_ASSERT(*aData,
"mImageSurface is non-null, but mVBufPtr is null in GetImageData");
} else if (mPalettedImageData) {
*aData = mPalettedImageData + PaletteDataLength();
MOZ_ASSERT(*aData, "mPalettedImageData is non-null, but result is null in GetImageData");
MOZ_ASSERT(*aData,
"mPalettedImageData is non-null, but result is null in GetImageData");
} else {
MOZ_ASSERT(false, "Have neither mImageSurface nor mPalettedImageData in GetImageData");
MOZ_ASSERT(false,
"Have neither mImageSurface nor mPalettedImageData in GetImageData");
*aData = nullptr;
}
*aLength = GetImageDataLength();
}
uint8_t* imgFrame::GetImageData() const
uint8_t*
imgFrame::GetImageData() const
{
uint8_t* data;
uint32_t length;
@ -785,12 +811,14 @@ uint8_t* imgFrame::GetImageData() const
return data;
}
bool imgFrame::GetIsPaletted() const
bool
imgFrame::GetIsPaletted() const
{
return mPalettedImageData != nullptr;
}
void imgFrame::GetPaletteData(uint32_t **aPalette, uint32_t *length) const
void
imgFrame::GetPaletteData(uint32_t** aPalette, uint32_t* length) const
{
AssertImageDataLocked();
@ -803,7 +831,8 @@ void imgFrame::GetPaletteData(uint32_t **aPalette, uint32_t *length) const
}
}
uint32_t* imgFrame::GetPaletteData() const
uint32_t*
imgFrame::GetPaletteData() const
{
uint32_t* data;
uint32_t length;
@ -852,17 +881,20 @@ imgFrame::Deoptimize()
if (!mImageSurface) {
if (mVBuf) {
VolatileBufferPtr<uint8_t> ref(mVBuf);
if (ref.WasBufferPurged())
if (ref.WasBufferPurged()) {
return NS_ERROR_FAILURE;
}
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
if (!mImageSurface)
if (!mImageSurface) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
if (mOptSurface || mSinglePixel || mFormat == SurfaceFormat::R5G6B5) {
SurfaceFormat format = mFormat;
if (mFormat == SurfaceFormat::R5G6B5)
if (mFormat == SurfaceFormat::R5G6B5) {
format = SurfaceFormat::B8G8R8A8;
}
// Recover the pixels
RefPtr<VolatileBuffer> buf =
@ -873,8 +905,9 @@ imgFrame::Deoptimize()
RefPtr<DataSourceSurface> surf =
CreateLockedSurface(buf, mSize, format);
if (!surf)
if (!surf) {
return NS_ERROR_OUT_OF_MEMORY;
}
DataSourceSurface::MappedSurface mapping;
DebugOnly<bool> success =
@ -887,20 +920,22 @@ imgFrame::Deoptimize()
mapping.mStride,
format);
if (!target) {
gfxWarning() << "imgFrame::Deoptimize failed in CreateDrawTargetForData";
gfxWarning() <<
"imgFrame::Deoptimize failed in CreateDrawTargetForData";
return NS_ERROR_OUT_OF_MEMORY;
}
Rect rect(0, 0, mSize.width, mSize.height);
if (mSinglePixel)
if (mSinglePixel) {
target->FillRect(rect, ColorPattern(mSinglePixelColor),
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
else if (mFormat == SurfaceFormat::R5G6B5)
} else if (mFormat == SurfaceFormat::R5G6B5) {
target->DrawSurface(mImageSurface, rect, rect);
else
} else {
target->DrawSurface(mOptSurface, rect, rect,
DrawSurfaceOptions(),
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
}
target->Flush();
surf->Unmap();
@ -1019,21 +1054,25 @@ imgFrame::GetSurfaceInternal()
mMonitor.AssertCurrentThreadOwns();
if (mOptSurface) {
if (mOptSurface->IsValid())
if (mOptSurface->IsValid()) {
return mOptSurface;
else
} else {
mOptSurface = nullptr;
}
}
if (mImageSurface)
if (mImageSurface) {
return mImageSurface;
}
if (!mVBuf)
if (!mVBuf) {
return nullptr;
}
VolatileBufferPtr<char> buf(mVBuf);
if (buf.WasBufferPurged())
if (buf.WasBufferPurged()) {
return nullptr;
}
return CreateLockedSurface(mVBuf, mSize, mFormat);
}
@ -1137,7 +1176,8 @@ bool imgFrame::GetCompositingFailed() const
return mCompositingFailed;
}
void imgFrame::SetCompositingFailed(bool val)
void
imgFrame::SetCompositingFailed(bool val)
{
MOZ_ASSERT(NS_IsMainThread());
mCompositingFailed = val;
@ -1149,7 +1189,8 @@ imgFrame::SizeOfExcludingThis(gfxMemoryLocation aLocation,
{
MonitorAutoLock lock(mMonitor);
// aMallocSizeOf is only used if aLocation==gfxMemoryLocation::IN_PROCESS_HEAP. It
// aMallocSizeOf is only used if aLocation is
// gfxMemoryLocation::IN_PROCESS_HEAP. It
// should be nullptr otherwise.
MOZ_ASSERT(
(aLocation == gfxMemoryLocation::IN_PROCESS_HEAP && aMallocSizeOf) ||

View File

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef imgFrame_h
#define imgFrame_h
#ifndef mozilla_image_src_imgFrame_h
#define mozilla_image_src_imgFrame_h
#include "mozilla/MemoryReporting.h"
#include "mozilla/Monitor.h"
@ -45,7 +45,6 @@ enum class Opacity : uint8_t {
SOME_TRANSPARENCY
};
/**
* AnimationData contains all of the information necessary for using an imgFrame
* as part of an animation.
@ -303,7 +302,8 @@ private: // methods
SurfaceFormat mFormat;
SurfaceWithFormat() { }
SurfaceWithFormat(gfxDrawable* aDrawable, SurfaceFormat aFormat)
: mDrawable(aDrawable), mFormat(aFormat) {}
: mDrawable(aDrawable), mFormat(aFormat)
{ }
bool IsValid() { return !!mDrawable; }
};
@ -524,4 +524,4 @@ private:
} // namespace image
} // namespace mozilla
#endif /* imgFrame_h */
#endif // mozilla_image_src_imgFrame_h