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
|
|
|
|
2013-01-08 13:40:47 -08:00
|
|
|
#include "nsMimeTypes.h"
|
|
|
|
|
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
|
2013-09-28 11:28:44 -07:00
|
|
|
ImageResource::ImageResource(ImageURL* aURI) :
|
2013-09-28 11:28:42 -07:00
|
|
|
mURI(aURI),
|
2012-12-19 14:24:32 -08: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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-12-19 14:24:32 -08:00
|
|
|
ImageResource::SizeOfData()
|
2010-10-06 08:37:12 -07:00
|
|
|
{
|
|
|
|
if (mError)
|
|
|
|
return 0;
|
2013-03-29 13:14:19 -07:00
|
|
|
|
2012-02-19 19:51:48 -08:00
|
|
|
// This is not used by memory reporters, but for sizing the cache, which is
|
2013-12-07 21:38:32 -08:00
|
|
|
// why it uses |moz_malloc_size_of| rather than a
|
|
|
|
// |MOZ_DEFINE_MALLOC_SIZE_OF|.
|
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
|
2013-01-08 13:40:47 -08:00
|
|
|
if (!strcmp(aMimeType, IMAGE_PNG))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_png;
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_X_PNG))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_png;
|
|
|
|
|
|
|
|
// GIF
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_GIF))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_gif;
|
|
|
|
|
|
|
|
|
|
|
|
// JPEG
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_JPEG))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_jpeg;
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_PJPEG))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_jpeg;
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_JPG))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_jpeg;
|
|
|
|
|
|
|
|
// BMP
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_BMP))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_bmp;
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_BMP_MS))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_bmp;
|
|
|
|
|
|
|
|
|
|
|
|
// ICO
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_ICO))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_ico;
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_ICO_MS))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_ico;
|
|
|
|
|
|
|
|
// Icon
|
2013-01-08 13:40:47 -08:00
|
|
|
else if (!strcmp(aMimeType, IMAGE_ICON_MS))
|
2010-08-22 19:30:45 -07:00
|
|
|
rv = eDecoderType_icon;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
void
|
2012-12-19 14:24:32 -08:00
|
|
|
ImageResource::IncrementAnimationConsumers()
|
2010-09-07 17:33:02 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
|
|
|
|
"with DecrementAnimationConsumers");
|
2010-09-07 17:33:02 -07:00
|
|
|
mAnimationConsumers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-19 14:24:32 -08:00
|
|
|
ImageResource::DecrementAnimationConsumers()
|
2010-09-07 17:33:02 -07:00
|
|
|
{
|
2013-09-28 11:28:43 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
|
|
|
|
"with IncrementAnimationConsumers");
|
2010-09-07 17:33:02 -07:00
|
|
|
NS_ABORT_IF_FALSE(mAnimationConsumers >= 1, "Invalid no. of animation consumers!");
|
|
|
|
mAnimationConsumers--;
|
|
|
|
}
|
|
|
|
|
2012-10-19 13:27:11 -07:00
|
|
|
nsresult
|
2012-12-19 14:24:32 -08:00
|
|
|
ImageResource::GetAnimationModeInternal(uint16_t* aAnimationMode)
|
2010-11-17 12:39:23 -08:00
|
|
|
{
|
|
|
|
if (mError)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aAnimationMode);
|
2012-10-19 13:27:11 -07:00
|
|
|
|
2010-11-17 12:39:23 -08:00
|
|
|
*aAnimationMode = mAnimationMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-19 13:27:11 -07:00
|
|
|
nsresult
|
2012-12-19 14:24:32 -08:00
|
|
|
ImageResource::SetAnimationModeInternal(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!");
|
2012-10-19 13:27:11 -07:00
|
|
|
|
2010-11-17 12:39:23 -08:00
|
|
|
mAnimationMode = aAnimationMode;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
void
|
2012-12-19 14:24:32 -08:00
|
|
|
ImageResource::EvaluateAnimation()
|
2010-09-07 17:33:02 -07:00
|
|
|
{
|
|
|
|
if (!mAnimating && ShouldAnimate()) {
|
|
|
|
nsresult rv = StartAnimation();
|
|
|
|
mAnimating = NS_SUCCEEDED(rv);
|
|
|
|
} else if (mAnimating && !ShouldAnimate()) {
|
|
|
|
StopAnimation();
|
|
|
|
}
|
|
|
|
}
|
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
|