2010-08-13 21:09:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2010-08-13 21:09:48 -07:00
|
|
|
|
|
|
|
#include "Image.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-13 21:09:48 -07:00
|
|
|
|
|
|
|
// Constructor
|
2010-08-23 15:44:07 -07:00
|
|
|
Image::Image(imgStatusTracker* aStatusTracker) :
|
2011-08-24 13:44:35 -07:00
|
|
|
mInnerWindowId(0),
|
2010-09-07 17:33:02 -07:00
|
|
|
mAnimationConsumers(0),
|
2010-11-17 12:39:23 -08:00
|
|
|
mAnimationMode(kNormalAnimMode),
|
2011-10-17 07:59:28 -07:00
|
|
|
mInitialized(false),
|
|
|
|
mAnimating(false),
|
|
|
|
mError(false)
|
2010-08-13 21:09:48 -07:00
|
|
|
{
|
2010-08-23 15:44:07 -07:00
|
|
|
if (aStatusTracker) {
|
|
|
|
mStatusTracker = aStatusTracker;
|
|
|
|
mStatusTracker->SetImage(this);
|
|
|
|
} else {
|
2012-10-12 09:11:20 -07:00
|
|
|
mStatusTracker = new imgStatusTracker(this, nullptr);
|
2010-08-23 15:44:07 -07:00
|
|
|
}
|
2010-08-13 21:09:48 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-02-19 19:51:48 -08:00
|
|
|
Image::SizeOfData()
|
2010-10-06 08:37:12 -07:00
|
|
|
{
|
|
|
|
if (mError)
|
|
|
|
return 0;
|
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
// This is not used by memory reporters, but for sizing the cache, which is
|
|
|
|
// why it uses |moz_malloc_size_of| rather than an
|
|
|
|
// |NS_MEMORY_REPORTER_MALLOC_SIZEOF_FUN|.
|
2012-08-22 08:56:38 -07:00
|
|
|
return uint32_t(HeapSizeOfSourceWithComputedFallback(moz_malloc_size_of) +
|
2012-02-19 19:51:48 -08:00
|
|
|
HeapSizeOfDecodedWithComputedFallback(moz_malloc_size_of) +
|
|
|
|
NonHeapSizeOfDecoded() +
|
|
|
|
OutOfProcessSizeOfDecoded());
|
2010-10-06 08:37:12 -07:00
|
|
|
}
|
|
|
|
|
2010-08-22 19:30:45 -07:00
|
|
|
// Translates a mimetype into a concrete decoder
|
|
|
|
Image::eDecoderType
|
|
|
|
Image::GetDecoderType(const char *aMimeType)
|
|
|
|
{
|
|
|
|
// By default we don't know
|
|
|
|
eDecoderType rv = eDecoderType_unknown;
|
|
|
|
|
|
|
|
// PNG
|
|
|
|
if (!strcmp(aMimeType, "image/png"))
|
|
|
|
rv = eDecoderType_png;
|
|
|
|
else if (!strcmp(aMimeType, "image/x-png"))
|
|
|
|
rv = eDecoderType_png;
|
|
|
|
|
|
|
|
// GIF
|
|
|
|
else if (!strcmp(aMimeType, "image/gif"))
|
|
|
|
rv = eDecoderType_gif;
|
|
|
|
|
|
|
|
|
|
|
|
// JPEG
|
|
|
|
else if (!strcmp(aMimeType, "image/jpeg"))
|
|
|
|
rv = eDecoderType_jpeg;
|
|
|
|
else if (!strcmp(aMimeType, "image/pjpeg"))
|
|
|
|
rv = eDecoderType_jpeg;
|
|
|
|
else if (!strcmp(aMimeType, "image/jpg"))
|
|
|
|
rv = eDecoderType_jpeg;
|
|
|
|
|
|
|
|
// BMP
|
|
|
|
else if (!strcmp(aMimeType, "image/bmp"))
|
|
|
|
rv = eDecoderType_bmp;
|
|
|
|
else if (!strcmp(aMimeType, "image/x-ms-bmp"))
|
|
|
|
rv = eDecoderType_bmp;
|
|
|
|
|
|
|
|
|
|
|
|
// ICO
|
|
|
|
else if (!strcmp(aMimeType, "image/x-icon"))
|
|
|
|
rv = eDecoderType_ico;
|
|
|
|
else if (!strcmp(aMimeType, "image/vnd.microsoft.icon"))
|
|
|
|
rv = eDecoderType_ico;
|
|
|
|
|
|
|
|
// Icon
|
|
|
|
else if (!strcmp(aMimeType, "image/icon"))
|
|
|
|
rv = eDecoderType_icon;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
void
|
|
|
|
Image::IncrementAnimationConsumers()
|
|
|
|
{
|
|
|
|
mAnimationConsumers++;
|
|
|
|
EvaluateAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Image::DecrementAnimationConsumers()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mAnimationConsumers >= 1, "Invalid no. of animation consumers!");
|
|
|
|
mAnimationConsumers--;
|
|
|
|
EvaluateAnimation();
|
|
|
|
}
|
|
|
|
|
2010-11-17 12:39:23 -08:00
|
|
|
//******************************************************************************
|
|
|
|
/* attribute unsigned short animationMode; */
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
Image::GetAnimationMode(uint16_t* aAnimationMode)
|
2010-11-17 12:39:23 -08:00
|
|
|
{
|
|
|
|
if (mError)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aAnimationMode);
|
|
|
|
|
|
|
|
*aAnimationMode = mAnimationMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* attribute unsigned short animationMode; */
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
Image::SetAnimationMode(uint16_t aAnimationMode)
|
2010-11-17 12:39:23 -08:00
|
|
|
{
|
|
|
|
if (mError)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
|
|
|
|
aAnimationMode == kDontAnimMode ||
|
|
|
|
aAnimationMode == kLoopOnceAnimMode,
|
|
|
|
"Wrong Animation Mode is being set!");
|
|
|
|
|
|
|
|
mAnimationMode = aAnimationMode;
|
|
|
|
|
|
|
|
EvaluateAnimation();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
void
|
|
|
|
Image::EvaluateAnimation()
|
|
|
|
{
|
|
|
|
if (!mAnimating && ShouldAnimate()) {
|
|
|
|
nsresult rv = StartAnimation();
|
|
|
|
mAnimating = NS_SUCCEEDED(rv);
|
|
|
|
} else if (mAnimating && !ShouldAnimate()) {
|
|
|
|
StopAnimation();
|
2011-10-17 07:59:28 -07:00
|
|
|
mAnimating = false;
|
2010-09-07 17:33:02 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-22 19:30:45 -07:00
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-13 21:09:48 -07:00
|
|
|
} // namespace mozilla
|