Files
palemoon27/image/Image.cpp
T
roytam1 6b6341f075 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1102048 (Part 20, imgLoader) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (0a8270ba4)
- Bug 1102048 (Part 23, encoders) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (6625ca535)
- Bug 1102048 (Part 39, decoders/icon) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (55956f847)
- Bug 1102048 (Part 24, decoders) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (cf2b002a7)
- Bug 1102048 (Part 04, ClippedImage) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (c9f1451ad)
- Bug 1102048 (Part 30, imgTools) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (2e3378d34)
- Bug 1082837 - Track insecure redirects on imgRequest. r=? (466a14e22)
- Bug 1139225 (Part 3) - Make OnDataAvailable threadsafe. r=tn (d10208a8b)
- Bug 1139225 (Part 1) - Remove unused imgRequest::mBlockingOnload flag. r=tn (c0d80facd)
- Bug 1102048 (Part 11, imgRequest) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (63ee15eb8)
- Bug 1102048 (Part 38, ShutdownTracker) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (a58d515ed)
- Bug 1102048 (Part 37, ProgressTracker) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (04b07cb06)
- Bug 1102048 (Part 14, NotificationObserver) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (ca32242a4)
- Bug 1102048 (Part 13, RasterImage) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (8f3931f31)
- Bug 1102048 (Part 10, imgFrame) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (2f2b22e70)
- Bug 1102048 (Part 36, DynamicImage) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (2cce04d2b)
- Bug 1102048 (Part 09, Image) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (2f3743d2e)
- Bug 1102048 (Part 29, imgRequestProxy) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (bf2824c08)
- Bug 1102048 (Part 31, SurfaceCache) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (c6849f4d9)
- Bug 1102048 (Part 25, header guards) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (bde0a4979)
- Bug 1102048 (Part 33, SVGDocument) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (71f5f960c)
- Bug 1102048 (Part 05, Decoder) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (48b1d5a80)
- Bug 1102048 (Part 34, Multipart) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (fb65aa069)
- Bug 1102048 (Part 35, Downscaler) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (2eb0be1f7)
- Bug 1102048 (Part 19, ImageMetadata) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (749305ddd)
- Bug 1102048 (Part 32, FrameAnimator) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (1df4850d6)
- Bug 1102048 (Part 26) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (52550fb88)
- Bug 1102048 (Part 03) - Make image/src files comply with the Mozilla Coding Style Guide. r=seth (438e52a57)
2020-12-29 11:56:14 +08:00

166 lines
4.0 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsMimeTypes.h"
#include "Image.h"
#include "nsRefreshDriver.h"
#include "mozilla/TimeStamp.h"
namespace mozilla {
namespace image {
// Constructor
ImageResource::ImageResource(ImageURL* aURI) :
mURI(aURI),
mInnerWindowId(0),
mAnimationConsumers(0),
mAnimationMode(kNormalAnimMode),
mInitialized(false),
mAnimating(false),
mError(false)
{ }
// 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;
#ifdef MOZ_JXR
// JXR (JPEG XR)
} else if (
!strcmp(aMimeType, IMAGE_JXR) || !strcmp(aMimeType, IMAGE_MS_PHOTO)
) {
if (gfxPrefs::MediaJXREnabled()) {
rv = eDecoderType_jxr;
}
#endif
// WEBP
} else if (!strcmp(aMimeType, IMAGE_WEBP)) {
rv = eDecoderType_webp;
// BMP
} else if (!strcmp(aMimeType, IMAGE_BMP)) {
rv = eDecoderType_bmp;
} else if (!strcmp(aMimeType, IMAGE_BMP_MS)) {
rv = eDecoderType_bmp;
// ICO
} else if (!strcmp(aMimeType, IMAGE_ICO)) {
rv = eDecoderType_ico;
} else if (!strcmp(aMimeType, IMAGE_ICO_MS)) {
rv = eDecoderType_ico;
// Icon
} else if (!strcmp(aMimeType, IMAGE_ICON_MS)) {
rv = eDecoderType_icon;
}
return rv;
}
void
ImageResource::IncrementAnimationConsumers()
{
MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
"with DecrementAnimationConsumers");
mAnimationConsumers++;
}
void
ImageResource::DecrementAnimationConsumers()
{
MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
"with IncrementAnimationConsumers");
MOZ_ASSERT(mAnimationConsumers >= 1,
"Invalid no. of animation consumers!");
mAnimationConsumers--;
}
nsresult
ImageResource::GetAnimationModeInternal(uint16_t* aAnimationMode)
{
if (mError) {
return NS_ERROR_FAILURE;
}
NS_ENSURE_ARG_POINTER(aAnimationMode);
*aAnimationMode = mAnimationMode;
return NS_OK;
}
nsresult
ImageResource::SetAnimationModeInternal(uint16_t aAnimationMode)
{
if (mError) {
return NS_ERROR_FAILURE;
}
NS_ASSERTION(aAnimationMode == kNormalAnimMode ||
aAnimationMode == kDontAnimMode ||
aAnimationMode == kLoopOnceAnimMode,
"Wrong Animation Mode is being set!");
mAnimationMode = aAnimationMode;
return NS_OK;
}
bool
ImageResource::HadRecentRefresh(const TimeStamp& aTime)
{
// Our threshold for "recent" is 1/2 of the default refresh-driver interval.
// This ensures that we allow for frame rates at least as fast as the
// refresh driver's default rate.
static TimeDuration recentThreshold =
TimeDuration::FromMilliseconds(nsRefreshDriver::DefaultInterval() / 2.0);
if (!mLastRefreshTime.IsNull() &&
aTime - mLastRefreshTime < recentThreshold) {
return true;
}
// else, we can proceed with a refresh.
// But first, update our last refresh time:
mLastRefreshTime = aTime;
return false;
}
void
ImageResource::EvaluateAnimation()
{
if (!mAnimating && ShouldAnimate()) {
nsresult rv = StartAnimation();
mAnimating = NS_SUCCEEDED(rv);
} else if (mAnimating && !ShouldAnimate()) {
StopAnimation();
}
}
} // namespace image
} // namespace mozilla