зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1102048 (Part 13, RasterImage) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth
This commit is contained in:
Родитель
d308a1d6f2
Коммит
34d6cb6f43
|
@ -3,7 +3,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/. */
|
||||
|
||||
// Must #include ImageLogging.h before any IPDL-generated files or other files that #include prlog.h
|
||||
// Must #include ImageLogging.h before any IPDL-generated files or other files
|
||||
// that #include prlog.h
|
||||
#include "ImageLogging.h"
|
||||
|
||||
#include "RasterImage.h"
|
||||
|
@ -295,12 +296,14 @@ RasterImage::Init(const char* aMimeType,
|
|||
uint32_t aFlags)
|
||||
{
|
||||
// We don't support re-initialization
|
||||
if (mInitialized)
|
||||
if (mInitialized) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
// Not sure an error can happen before init, but be safe
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aMimeType);
|
||||
|
||||
|
@ -382,7 +385,7 @@ RasterImage::RequestRefresh(const TimeStamp& aTime)
|
|||
//******************************************************************************
|
||||
/* readonly attribute int32_t width; */
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetWidth(int32_t *aWidth)
|
||||
RasterImage::GetWidth(int32_t* aWidth)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aWidth);
|
||||
|
||||
|
@ -398,7 +401,7 @@ RasterImage::GetWidth(int32_t *aWidth)
|
|||
//******************************************************************************
|
||||
/* readonly attribute int32_t height; */
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetHeight(int32_t *aHeight)
|
||||
RasterImage::GetHeight(int32_t* aHeight)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHeight);
|
||||
|
||||
|
@ -416,8 +419,9 @@ RasterImage::GetHeight(int32_t *aHeight)
|
|||
NS_IMETHODIMP
|
||||
RasterImage::GetIntrinsicSize(nsSize* aSize)
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
|
||||
nsPresContext::CSSPixelsToAppUnits(mSize.height));
|
||||
|
@ -429,8 +433,9 @@ RasterImage::GetIntrinsicSize(nsSize* aSize)
|
|||
NS_IMETHODIMP
|
||||
RasterImage::GetIntrinsicRatio(nsSize* aRatio)
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aRatio = nsSize(mSize.width, mSize.height);
|
||||
return NS_OK;
|
||||
|
@ -445,7 +450,7 @@ RasterImage::GetOrientation()
|
|||
//******************************************************************************
|
||||
/* unsigned short GetType(); */
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetType(uint16_t *aType)
|
||||
RasterImage::GetType(uint16_t* aType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aType);
|
||||
|
||||
|
@ -604,10 +609,11 @@ RasterImage::OnSurfaceDiscarded()
|
|||
//******************************************************************************
|
||||
/* readonly attribute boolean animated; */
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetAnimated(bool *aAnimated)
|
||||
RasterImage::GetAnimated(bool* aAnimated)
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_ENSURE_ARG_POINTER(aAnimated);
|
||||
|
||||
|
@ -619,8 +625,9 @@ RasterImage::GetAnimated(bool *aAnimated)
|
|||
|
||||
// Otherwise, we need to have been decoded to know for sure, since if we were
|
||||
// decoded at least once mAnim would have been created for animated images
|
||||
if (!mHasBeenDecoded)
|
||||
if (!mHasBeenDecoded) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
// We know for sure
|
||||
*aAnimated = false;
|
||||
|
@ -633,12 +640,14 @@ RasterImage::GetAnimated(bool *aAnimated)
|
|||
NS_IMETHODIMP_(int32_t)
|
||||
RasterImage::GetFirstFrameDelay()
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool animated = false;
|
||||
if (NS_FAILED(GetAnimated(&animated)) || !animated)
|
||||
if (NS_FAILED(GetAnimated(&animated)) || !animated) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mAnim, "Animated images should have a FrameAnimator");
|
||||
return mAnim->GetTimeoutForFrame(0);
|
||||
|
@ -647,11 +656,13 @@ RasterImage::GetFirstFrameDelay()
|
|||
TemporaryRef<SourceSurface>
|
||||
RasterImage::CopyFrame(uint32_t aWhichFrame, uint32_t aFlags)
|
||||
{
|
||||
if (aWhichFrame > FRAME_MAX_VALUE)
|
||||
if (aWhichFrame > FRAME_MAX_VALUE) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get the frame. If it's not there, it's probably the caller's fault for
|
||||
// not waiting for the data to be loaded from the network or not passing
|
||||
|
@ -939,11 +950,12 @@ RasterImage::OnAddedFrame(uint32_t aNewFrameCount,
|
|||
// We don't support discarding animated images (See bug 414259).
|
||||
// Lock the image and throw away the key.
|
||||
//
|
||||
// Note that this is inefficient, since we could get rid of the source data
|
||||
// too. However, doing this is actually hard, because we're probably
|
||||
// mid-decode, and thus we're decoding out of the source buffer. Since we're
|
||||
// going to fix this anyway later, and since we didn't kill the source data
|
||||
// in the old world either, locking is acceptable for the moment.
|
||||
// Note that this is inefficient, since we could get rid of the source
|
||||
// data too. However, doing this is actually hard, because we're probably
|
||||
// mid-decode, and thus we're decoding out of the source buffer. Since
|
||||
// we're going to fix this anyway later, and since we didn't kill the
|
||||
// source data in the old world either, locking is acceptable for the
|
||||
// moment.
|
||||
LockImage();
|
||||
|
||||
if (mPendingAnimation && ShouldAnimate()) {
|
||||
|
@ -961,13 +973,15 @@ RasterImage::SetSize(int32_t aWidth, int32_t aHeight, Orientation aOrientation)
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Ensure that we have positive values
|
||||
// XXX - Why isn't the size unsigned? Should this be changed?
|
||||
if ((aWidth < 0) || (aHeight < 0))
|
||||
if ((aWidth < 0) || (aHeight < 0)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// if we already have a size, check the new size against the old one
|
||||
if (mHasSize &&
|
||||
|
@ -1019,8 +1033,9 @@ RasterImage::SetAnimationMode(uint16_t aAnimationMode)
|
|||
nsresult
|
||||
RasterImage::StartAnimation()
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(ShouldAnimate(), "Should not animate!");
|
||||
|
||||
|
@ -1068,8 +1083,9 @@ RasterImage::StopAnimation()
|
|||
NS_IMETHODIMP
|
||||
RasterImage::ResetAnimation()
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
mPendingAnimation = false;
|
||||
|
||||
|
@ -1080,8 +1096,9 @@ RasterImage::ResetAnimation()
|
|||
|
||||
mAnimationFinished = false;
|
||||
|
||||
if (mAnimating)
|
||||
if (mAnimating) {
|
||||
StopAnimation();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mAnim, "Should have a FrameAnimator");
|
||||
mAnim->ResetAnimation();
|
||||
|
@ -1100,8 +1117,9 @@ RasterImage::ResetAnimation()
|
|||
NS_IMETHODIMP_(void)
|
||||
RasterImage::SetAnimationStartTime(const TimeStamp& aTime)
|
||||
{
|
||||
if (mError || mAnimationMode == kDontAnimMode || mAnimating || !mAnim)
|
||||
if (mError || mAnimationMode == kDontAnimMode || mAnimating || !mAnim) {
|
||||
return;
|
||||
}
|
||||
|
||||
mAnim->SetAnimationFrameTime(aTime);
|
||||
}
|
||||
|
@ -1118,8 +1136,9 @@ RasterImage::GetFrameIndex(uint32_t aWhichFrame)
|
|||
void
|
||||
RasterImage::SetLoopCount(int32_t aLoopCount)
|
||||
{
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return;
|
||||
}
|
||||
|
||||
// No need to set this if we're not an animation.
|
||||
if (mAnim) {
|
||||
|
@ -1236,27 +1255,30 @@ RasterImage::SetSourceSizeHint(uint32_t aSizeHint)
|
|||
return mSourceBuffer->ExpectLength(aSizeHint);
|
||||
}
|
||||
|
||||
/********* Methods to implement lazy allocation of nsIProperties object *************/
|
||||
/********* Methods to implement lazy allocation of nsIProperties object *******/
|
||||
NS_IMETHODIMP
|
||||
RasterImage::Get(const char *prop, const nsIID & iid, void * *result)
|
||||
RasterImage::Get(const char* prop, const nsIID& iid, void** result)
|
||||
{
|
||||
if (!mProperties)
|
||||
if (!mProperties) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mProperties->Get(prop, iid, result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RasterImage::Set(const char *prop, nsISupports *value)
|
||||
RasterImage::Set(const char* prop, nsISupports* value)
|
||||
{
|
||||
if (!mProperties)
|
||||
if (!mProperties) {
|
||||
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
||||
if (!mProperties)
|
||||
}
|
||||
if (!mProperties) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return mProperties->Set(prop, value);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RasterImage::Has(const char *prop, bool *_retval)
|
||||
RasterImage::Has(const char* prop, bool* _retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
if (!mProperties) {
|
||||
|
@ -1267,15 +1289,16 @@ RasterImage::Has(const char *prop, bool *_retval)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RasterImage::Undefine(const char *prop)
|
||||
RasterImage::Undefine(const char* prop)
|
||||
{
|
||||
if (!mProperties)
|
||||
if (!mProperties) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return mProperties->Undefine(prop);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetKeys(uint32_t *count, char ***keys)
|
||||
RasterImage::GetKeys(uint32_t* count, char*** keys)
|
||||
{
|
||||
if (!mProperties) {
|
||||
*count = 0;
|
||||
|
@ -1400,18 +1423,22 @@ RasterImage::CreateDecoder(const Maybe<nsIntSize>& aSize, uint32_t aFlags)
|
|||
}
|
||||
|
||||
if (!aSize) {
|
||||
Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Subtract(mDecodeCount);
|
||||
Telemetry::GetHistogramById(
|
||||
Telemetry::IMAGE_DECODE_COUNT)->Subtract(mDecodeCount);
|
||||
mDecodeCount++;
|
||||
Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Add(mDecodeCount);
|
||||
Telemetry::GetHistogramById(
|
||||
Telemetry::IMAGE_DECODE_COUNT)->Add(mDecodeCount);
|
||||
|
||||
if (mDecodeCount > sMaxDecodeCount) {
|
||||
// Don't subtract out 0 from the histogram, because that causes its count
|
||||
// to go negative, which is not kosher.
|
||||
if (sMaxDecodeCount > 0) {
|
||||
Telemetry::GetHistogramById(Telemetry::IMAGE_MAX_DECODE_COUNT)->Subtract(sMaxDecodeCount);
|
||||
Telemetry::GetHistogramById(
|
||||
Telemetry::IMAGE_MAX_DECODE_COUNT)->Subtract(sMaxDecodeCount);
|
||||
}
|
||||
sMaxDecodeCount = mDecodeCount;
|
||||
Telemetry::GetHistogramById(Telemetry::IMAGE_MAX_DECODE_COUNT)->Add(sMaxDecodeCount);
|
||||
Telemetry::GetHistogramById(
|
||||
Telemetry::IMAGE_MAX_DECODE_COUNT)->Add(sMaxDecodeCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1784,17 +1811,20 @@ RasterImage::Draw(gfxContext* aContext,
|
|||
const Maybe<SVGImageContext>& /*aSVGContext - ignored*/,
|
||||
uint32_t aFlags)
|
||||
{
|
||||
if (aWhichFrame > FRAME_MAX_VALUE)
|
||||
if (aWhichFrame > FRAME_MAX_VALUE) {
|
||||
return DrawResult::BAD_ARGS;
|
||||
}
|
||||
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return DrawResult::BAD_IMAGE;
|
||||
}
|
||||
|
||||
// Illegal -- you can't draw with non-default decode flags.
|
||||
// (Disabling colorspace conversion might make sense to allow, but
|
||||
// we don't currently.)
|
||||
if (DecodeFlags(aFlags) != DECODE_FLAGS_DEFAULT)
|
||||
if (DecodeFlags(aFlags) != DECODE_FLAGS_DEFAULT) {
|
||||
return DrawResult::BAD_ARGS;
|
||||
}
|
||||
|
||||
if (!aContext) {
|
||||
return DrawResult::BAD_ARGS;
|
||||
|
@ -1843,8 +1873,9 @@ RasterImage::LockImage()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(),
|
||||
"Main thread to encourage serialization with UnlockImage");
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Increment the lock count
|
||||
mLockCount++;
|
||||
|
@ -1864,14 +1895,16 @@ RasterImage::UnlockImage()
|
|||
{
|
||||
MOZ_ASSERT(NS_IsMainThread(),
|
||||
"Main thread to encourage serialization with LockImage");
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// It's an error to call this function if the lock count is 0
|
||||
MOZ_ASSERT(mLockCount > 0,
|
||||
"Calling UnlockImage with mLockCount == 0!");
|
||||
if (mLockCount == 0)
|
||||
if (mLockCount == 0) {
|
||||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
// Decrement our lock count
|
||||
mLockCount--;
|
||||
|
@ -1903,10 +1936,12 @@ void
|
|||
RasterImage::DoError()
|
||||
{
|
||||
// If we've flagged an error before, we have nothing to do
|
||||
if (mError)
|
||||
if (mError) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We can't safely handle errors off-main-thread, so dispatch a worker to do it.
|
||||
// We can't safely handle errors off-main-thread, so dispatch a worker to
|
||||
// do it.
|
||||
if (!NS_IsMainThread()) {
|
||||
HandleErrorWorker::DispatchIfNeeded(this);
|
||||
return;
|
||||
|
@ -1980,7 +2015,7 @@ RasterImage::ShouldAnimate()
|
|||
/* readonly attribute uint32_t framesNotified; */
|
||||
#ifdef DEBUG
|
||||
NS_IMETHODIMP
|
||||
RasterImage::GetFramesNotified(uint32_t *aFramesNotified)
|
||||
RasterImage::GetFramesNotified(uint32_t* aFramesNotified)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFramesNotified);
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* @author Andrew Smith <asmith15@learn.senecac.on.ca>
|
||||
*/
|
||||
|
||||
#ifndef mozilla_imagelib_RasterImage_h_
|
||||
#define mozilla_imagelib_RasterImage_h_
|
||||
#ifndef mozilla_image_src_RasterImage_h
|
||||
#define mozilla_image_src_RasterImage_h
|
||||
|
||||
#include "Image.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -182,7 +182,8 @@ public:
|
|||
/* The total number of frames in this image. */
|
||||
uint32_t GetNumFrames() const { return mFrameCount; }
|
||||
|
||||
virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const override;
|
||||
virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf)
|
||||
const override;
|
||||
virtual size_t SizeOfDecoded(gfxMemoryLocation aLocation,
|
||||
MallocSizeOf aMallocSizeOf) const override;
|
||||
|
||||
|
@ -313,8 +314,9 @@ private:
|
|||
|
||||
nsIntRect GetFirstFrameRect();
|
||||
|
||||
size_t SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation,
|
||||
MallocSizeOf aMallocSizeOf) const;
|
||||
size_t
|
||||
SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation,
|
||||
MallocSizeOf aMallocSizeOf) const;
|
||||
|
||||
Pair<DrawResult, nsRefPtr<layers::Image>>
|
||||
GetCurrentImage(layers::ImageContainer* aContainer, uint32_t aFlags);
|
||||
|
@ -325,7 +327,9 @@ private:
|
|||
// that for animated images because in EnsureAnimExists we lock the image and
|
||||
// never unlock so that animated images always have their lock count >= 1. In
|
||||
// that case we use our animation consumers count as a proxy for lock count.
|
||||
bool IsUnlocked() { return (mLockCount == 0 || (mAnim && mAnimationConsumers == 0)); }
|
||||
bool IsUnlocked() {
|
||||
return (mLockCount == 0 || (mAnim && mAnimationConsumers == 0));
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -374,7 +378,8 @@ private: // data
|
|||
// This is currently only used for statistics
|
||||
int32_t mDecodeCount;
|
||||
|
||||
// If the image contains multiple resolutions, a hint as to which one should be used
|
||||
// If the image contains multiple resolutions, a hint as to which one
|
||||
// should be used
|
||||
nsIntSize mRequestedResolution;
|
||||
|
||||
// A hint for image decoder that directly scale the image to smaller buffer
|
||||
|
@ -434,9 +439,11 @@ private: // data
|
|||
void RequestScale(imgFrame* aFrame, uint32_t aFlags, const nsIntSize& aSize);
|
||||
|
||||
// Determines whether we can perform an HQ scale with the given parameters.
|
||||
bool CanScale(GraphicsFilter aFilter, const nsIntSize& aSize, uint32_t aFlags);
|
||||
bool CanScale(GraphicsFilter aFilter, const nsIntSize& aSize,
|
||||
uint32_t aFlags);
|
||||
|
||||
// Determines whether we can downscale during decode with the given parameters.
|
||||
// Determines whether we can downscale during decode with the given
|
||||
// parameters.
|
||||
bool CanDownscaleDuringDecode(const nsIntSize& aSize, uint32_t aFlags);
|
||||
|
||||
// Called by the HQ scaler when a new scaled frame is ready.
|
||||
|
@ -478,11 +485,12 @@ protected:
|
|||
friend class ImageFactory;
|
||||
};
|
||||
|
||||
inline NS_IMETHODIMP RasterImage::GetAnimationMode(uint16_t *aAnimationMode) {
|
||||
inline NS_IMETHODIMP
|
||||
RasterImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
||||
return GetAnimationModeInternal(aAnimationMode);
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_imagelib_RasterImage_h_ */
|
||||
#endif /* mozilla_image_src_RasterImage_h */
|
||||
|
|
Загрузка…
Ссылка в новой задаче