2001-03-10 01:11:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
// Must #include ImageLogging.h before any IPDL-generated files or other files
|
|
|
|
// that #include prlog.h
|
2012-04-03 21:57:22 +00:00
|
|
|
#include "ImageLogging.h"
|
2014-04-15 18:02:23 +00:00
|
|
|
|
|
|
|
#include "RasterImage.h"
|
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
2005-01-12 20:16:07 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2018-02-13 11:43:31 +00:00
|
|
|
#include "DecodePool.h"
|
2010-08-23 02:30:46 +00:00
|
|
|
#include "Decoder.h"
|
2007-10-19 00:36:34 +00:00
|
|
|
#include "prenv.h"
|
2013-03-01 23:17:24 +00:00
|
|
|
#include "prsystem.h"
|
2016-06-29 20:43:19 +00:00
|
|
|
#include "IDecodingTask.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageRegion.h"
|
2012-08-19 19:33:25 +00:00
|
|
|
#include "Layers.h"
|
2015-07-01 01:57:03 +00:00
|
|
|
#include "LookupResult.h"
|
2015-07-31 14:29:15 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2015-07-23 05:39:48 +00:00
|
|
|
#include "nsIInputStream.h"
|
2015-07-31 14:29:15 +00:00
|
|
|
#include "nsIScriptError.h"
|
2015-08-14 07:37:13 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2013-01-11 03:38:34 +00:00
|
|
|
#include "nsPresContext.h"
|
2015-01-15 23:11:36 +00:00
|
|
|
#include "SourceBuffer.h"
|
2014-09-19 21:53:29 +00:00
|
|
|
#include "SurfaceCache.h"
|
2013-07-15 18:38:59 +00:00
|
|
|
#include "FrameAnimator.h"
|
2007-03-20 23:56:50 +00:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2014-04-15 18:02:23 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-01-18 22:02:13 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-01-19 23:46:55 +00:00
|
|
|
#include "mozilla/Likely.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-09-12 08:12:55 +00:00
|
|
|
#include "mozilla/Move.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-03-01 23:17:24 +00:00
|
|
|
#include "mozilla/Services.h"
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
2012-01-11 08:23:07 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-08-12 06:50:33 +00:00
|
|
|
#include "mozilla/Tuple.h"
|
2012-02-09 20:04:30 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-04-03 21:57:22 +00:00
|
|
|
#include "mozilla/gfx/Scale.h"
|
|
|
|
|
2013-03-18 14:25:50 +00:00
|
|
|
#include "GeckoProfiler.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2014-09-22 21:30:20 +00:00
|
|
|
#include "gfxPrefs.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2012-10-03 20:36:26 +00:00
|
|
|
|
2014-07-10 15:00:31 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
using namespace layers;
|
|
|
|
|
|
|
|
namespace image {
|
2014-10-15 20:52:20 +00:00
|
|
|
|
2014-07-28 21:27:39 +00:00
|
|
|
using std::ceil;
|
2014-10-15 20:52:20 +00:00
|
|
|
using std::min;
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifndef DEBUG
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties)
|
2010-09-08 00:34:18 +00:00
|
|
|
#else
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties,
|
|
|
|
imgIContainerDebug)
|
2010-09-08 00:34:18 +00:00
|
|
|
#endif
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2001-03-24 02:44:26 +00:00
|
|
|
//******************************************************************************
|
2015-04-28 23:32:02 +00:00
|
|
|
RasterImage::RasterImage(ImageURL* aURI /* = nullptr */) :
|
2013-09-28 18:28:44 +00:00
|
|
|
ImageResource(aURI), // invoke superclass's constructor
|
2001-10-25 07:44:55 +00:00
|
|
|
mSize(0,0),
|
2010-05-12 21:41:47 +00:00
|
|
|
mLockCount(0),
|
2011-09-08 18:05:11 +00:00
|
|
|
mDecodeCount(0),
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesNotified(0),
|
|
|
|
#endif
|
2017-10-20 07:25:33 +00:00
|
|
|
mSourceBuffer(MakeNotNull<SourceBuffer*>()),
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasSize(false),
|
2015-01-07 09:37:20 +00:00
|
|
|
mTransient(false),
|
2015-06-30 09:37:58 +00:00
|
|
|
mSyncLoad(false),
|
2011-10-17 14:59:28 +00:00
|
|
|
mDiscardable(false),
|
2016-11-28 13:42:55 +00:00
|
|
|
mSomeSourceData(false),
|
|
|
|
mAllSourceData(false),
|
2011-10-17 14:59:28 +00:00
|
|
|
mHasBeenDecoded(false),
|
2014-11-26 21:22:10 +00:00
|
|
|
mPendingAnimation(false),
|
2012-09-18 01:53:37 +00:00
|
|
|
mAnimationFinished(false),
|
2015-01-15 23:11:36 +00:00
|
|
|
mWantFullDecode(false)
|
2009-09-12 22:44:18 +00:00
|
|
|
{
|
2001-03-10 01:11:54 +00:00
|
|
|
}
|
|
|
|
|
2001-03-24 02:44:26 +00:00
|
|
|
//******************************************************************************
|
2010-08-14 04:09:49 +00:00
|
|
|
RasterImage::~RasterImage()
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2015-01-15 23:11:36 +00:00
|
|
|
// Make sure our SourceBuffer is marked as complete. This will ensure that any
|
|
|
|
// outstanding decoders terminate.
|
|
|
|
if (!mSourceBuffer->IsComplete()) {
|
|
|
|
mSourceBuffer->Complete(NS_ERROR_ABORT);
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
// Release all frames from the surface cache.
|
2014-11-26 21:22:10 +00:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2016-05-03 16:07:45 +00:00
|
|
|
|
|
|
|
// Record Telemetry.
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_COUNT, mDecodeCount);
|
2017-03-23 05:02:54 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_ANIMATED_DECODE_COUNT, mDecodeCount);
|
|
|
|
}
|
2001-03-10 01:11:54 +00:00
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
nsresult
|
2013-02-13 03:00:03 +00:00
|
|
|
RasterImage::Init(const char* aMimeType,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
2009-09-12 22:44:18 +00:00
|
|
|
{
|
|
|
|
// We don't support re-initialization
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mInitialized) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
|
|
|
// Not sure an error can happen before init, but be safe
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2001-03-10 01:11:54 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2015-07-15 01:16:31 +00:00
|
|
|
// We want to avoid redecodes for transient images.
|
2015-09-19 23:21:05 +00:00
|
|
|
MOZ_ASSERT_IF(aFlags & INIT_FLAG_TRANSIENT,
|
|
|
|
!(aFlags & INIT_FLAG_DISCARDABLE));
|
2008-01-19 08:10:26 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// Store initialization data
|
2010-05-25 22:27:29 +00:00
|
|
|
mDiscardable = !!(aFlags & INIT_FLAG_DISCARDABLE);
|
2015-04-07 23:44:29 +00:00
|
|
|
mWantFullDecode = !!(aFlags & INIT_FLAG_DECODE_IMMEDIATELY);
|
2015-01-07 09:37:20 +00:00
|
|
|
mTransient = !!(aFlags & INIT_FLAG_TRANSIENT);
|
2015-06-30 09:37:58 +00:00
|
|
|
mSyncLoad = !!(aFlags & INIT_FLAG_SYNC_LOAD);
|
2015-01-18 22:02:13 +00:00
|
|
|
|
2015-07-21 16:42:30 +00:00
|
|
|
// Use the MIME type to select a decoder type, and make sure there *is* a
|
|
|
|
// decoder for this MIME type.
|
|
|
|
NS_ENSURE_ARG_POINTER(aMimeType);
|
2015-07-23 05:39:48 +00:00
|
|
|
mDecoderType = DecoderFactory::GetDecoderType(aMimeType);
|
|
|
|
if (mDecoderType == DecoderType::UNKNOWN) {
|
2015-07-21 16:42:30 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
// Lock this image's surfaces in the SurfaceCache if we're not discardable.
|
|
|
|
if (!mDiscardable) {
|
2015-03-18 02:40:17 +00:00
|
|
|
mLockCount++;
|
2014-11-26 21:22:10 +00:00
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// Mark us as initialized
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:39:15 +00:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-16 22:25:43 +00:00
|
|
|
RasterImage::RequestRefresh(const TimeStamp& aTime)
|
2011-11-09 21:39:15 +00:00
|
|
|
{
|
2014-05-08 18:37:39 +00:00
|
|
|
if (HadRecentRefresh(aTime)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-03 20:20:15 +00:00
|
|
|
EvaluateAnimation();
|
|
|
|
|
|
|
|
if (!mAnimating) {
|
2011-11-09 21:39:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-20 01:20:13 +00:00
|
|
|
RefreshResult res;
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
MOZ_ASSERT(mFrameAnimator);
|
2017-03-26 05:04:53 +00:00
|
|
|
res = mFrameAnimator->RequestRefresh(*mAnimationState, aTime, mAnimationFinished);
|
2011-11-09 21:39:16 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 01:20:13 +00:00
|
|
|
if (res.mFrameAdvanced) {
|
2011-11-09 21:39:16 +00:00
|
|
|
// Notify listeners that our frame has actually changed, but do this only
|
|
|
|
// once for all frames that we've now passed (if AdvanceFrame() was called
|
|
|
|
// more than once).
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesNotified++;
|
|
|
|
#endif
|
|
|
|
|
2016-07-20 01:20:13 +00:00
|
|
|
NotifyProgress(NoProgress, res.mDirtyRect);
|
2013-07-15 18:38:59 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 01:20:13 +00:00
|
|
|
if (res.mAnimationFinished) {
|
2013-07-15 18:38:59 +00:00
|
|
|
mAnimationFinished = true;
|
|
|
|
EvaluateAnimation();
|
2011-11-09 21:39:16 +00:00
|
|
|
}
|
2011-11-09 21:39:15 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 23:33:11 +00:00
|
|
|
//******************************************************************************
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::GetWidth(int32_t* aWidth)
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2008-03-20 05:54:30 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
2002-10-07 21:49:33 +00:00
|
|
|
|
2010-10-06 22:18:52 +00:00
|
|
|
if (mError) {
|
|
|
|
*aWidth = 0;
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-06 22:18:52 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
*aWidth = mSize.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-13 23:33:11 +00:00
|
|
|
//******************************************************************************
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::GetHeight(int32_t* aHeight)
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2008-03-20 05:54:30 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
2002-10-07 21:49:33 +00:00
|
|
|
|
2010-10-06 22:18:52 +00:00
|
|
|
if (mError) {
|
|
|
|
*aHeight = 0;
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-06 22:18:52 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
*aHeight = mSize.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-01 23:17:24 +00:00
|
|
|
|
2017-03-22 13:05:36 +00:00
|
|
|
//******************************************************************************
|
|
|
|
nsresult
|
|
|
|
RasterImage::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const
|
|
|
|
{
|
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNativeSizes.IsEmpty()) {
|
|
|
|
aNativeSizes.Clear();
|
|
|
|
aNativeSizes.AppendElement(mSize);
|
|
|
|
} else {
|
|
|
|
aNativeSizes = mNativeSizes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:38:34 +00:00
|
|
|
//******************************************************************************
|
2017-09-05 11:58:44 +00:00
|
|
|
size_t
|
|
|
|
RasterImage::GetNativeSizesLength() const
|
|
|
|
{
|
|
|
|
if (mError || !mHasSize) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNativeSizes.IsEmpty()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mNativeSizes.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
2013-01-11 03:38:34 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::GetIntrinsicSize(nsSize* aSize)
|
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2013-01-11 03:38:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2013-01-11 03:38:34 +00:00
|
|
|
|
|
|
|
*aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(mSize.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::GetIntrinsicRatio(nsSize* aRatio)
|
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2013-01-11 03:38:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2013-01-11 03:38:34 +00:00
|
|
|
|
|
|
|
*aRatio = nsSize(mSize.width, mSize.height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2013-08-25 07:19:42 +00:00
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
RasterImage::GetOrientation()
|
|
|
|
{
|
|
|
|
return mOrientation;
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::GetType(uint16_t* aType)
|
2010-08-14 04:09:49 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
|
|
|
|
2015-03-19 14:12:52 +00:00
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
2010-08-14 04:09:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-01 01:57:03 +00:00
|
|
|
LookupResult
|
2016-08-18 07:06:41 +00:00
|
|
|
RasterImage::LookupFrameInternal(const IntSize& aSize,
|
|
|
|
uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType)
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2016-08-18 07:06:41 +00:00
|
|
|
if (mAnimationState && aPlaybackType == PlaybackType::eAnimated) {
|
2016-07-19 06:26:58 +00:00
|
|
|
MOZ_ASSERT(mFrameAnimator);
|
2015-08-15 00:56:44 +00:00
|
|
|
MOZ_ASSERT(ToSurfaceFlags(aFlags) == DefaultSurfaceFlags(),
|
|
|
|
"Can't composite frames with non-default surface flags");
|
2016-11-29 07:01:43 +00:00
|
|
|
return mFrameAnimator->GetCompositedFrame(*mAnimationState);
|
2015-01-07 09:40:23 +00:00
|
|
|
}
|
2014-11-26 21:22:10 +00:00
|
|
|
|
2015-10-06 00:06:34 +00:00
|
|
|
SurfaceFlags surfaceFlags = ToSurfaceFlags(aFlags);
|
2015-01-18 22:02:14 +00:00
|
|
|
|
2016-03-08 01:17:16 +00:00
|
|
|
// We don't want any substitution for sync decodes, and substitution would be
|
|
|
|
// illegal when high quality downscaling is disabled, so we use
|
2015-10-06 00:06:34 +00:00
|
|
|
// SurfaceCache::Lookup in this case.
|
2016-03-08 01:17:16 +00:00
|
|
|
if ((aFlags & FLAG_SYNC_DECODE) || !(aFlags & FLAG_HIGH_QUALITY_SCALING)) {
|
2015-01-18 22:02:14 +00:00
|
|
|
return SurfaceCache::Lookup(ImageKey(this),
|
|
|
|
RasterSurfaceKey(aSize,
|
2015-10-06 00:06:34 +00:00
|
|
|
surfaceFlags,
|
2016-08-18 07:06:41 +00:00
|
|
|
PlaybackType::eStatic));
|
2015-01-18 22:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We'll return the best match we can find to the requested frame.
|
|
|
|
return SurfaceCache::LookupBestMatch(ImageKey(this),
|
|
|
|
RasterSurfaceKey(aSize,
|
2015-10-06 00:06:34 +00:00
|
|
|
surfaceFlags,
|
2016-08-18 07:06:41 +00:00
|
|
|
PlaybackType::eStatic));
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
LookupResult
|
2016-08-18 07:06:41 +00:00
|
|
|
RasterImage::LookupFrame(const IntSize& aSize,
|
|
|
|
uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType)
|
2011-07-21 18:14:41 +00:00
|
|
|
{
|
2014-11-26 21:22:10 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-10-06 00:06:34 +00:00
|
|
|
// If we're opaque, we don't need to care about premultiplied alpha, because
|
|
|
|
// that can only matter for frames with transparency.
|
|
|
|
if (IsOpaque()) {
|
|
|
|
aFlags &= ~FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:02:14 +00:00
|
|
|
IntSize requestedSize = CanDownscaleDuringDecode(aSize, aFlags)
|
2015-03-29 14:59:08 +00:00
|
|
|
? aSize : mSize;
|
2015-10-29 23:37:42 +00:00
|
|
|
if (requestedSize.IsEmpty()) {
|
2017-11-17 11:45:27 +00:00
|
|
|
// Can't decode to a surface of zero size.
|
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-10-29 23:37:42 +00:00
|
|
|
}
|
2014-09-13 01:29:27 +00:00
|
|
|
|
2016-08-18 07:06:41 +00:00
|
|
|
LookupResult result =
|
|
|
|
LookupFrameInternal(requestedSize, aFlags, aPlaybackType);
|
2014-11-28 03:56:00 +00:00
|
|
|
|
2015-07-01 01:57:03 +00:00
|
|
|
if (!result && !mHasSize) {
|
2015-01-18 22:02:13 +00:00
|
|
|
// We can't request a decode without knowing our intrinsic size. Give up.
|
2017-11-17 11:45:27 +00:00
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-01-18 22:02:13 +00:00
|
|
|
}
|
|
|
|
|
2015-07-20 01:39:44 +00:00
|
|
|
if (result.Type() == MatchType::NOT_FOUND ||
|
|
|
|
result.Type() == MatchType::SUBSTITUTE_BECAUSE_NOT_FOUND ||
|
|
|
|
((aFlags & FLAG_SYNC_DECODE) && !result)) {
|
2015-07-20 01:39:40 +00:00
|
|
|
// We don't have a copy of this frame, and there's no decoder working on
|
2015-07-20 01:39:44 +00:00
|
|
|
// one. (Or we're sync decoding and the existing decoder hasn't even started
|
|
|
|
// yet.) Trigger decoding so it'll be available next time.
|
2016-08-18 07:06:41 +00:00
|
|
|
MOZ_ASSERT(aPlaybackType != PlaybackType::eAnimated ||
|
2017-03-27 05:17:52 +00:00
|
|
|
gfxPrefs::ImageMemAnimatedDiscardable() ||
|
2016-08-18 07:06:41 +00:00
|
|
|
!mAnimationState || mAnimationState->KnownFrameCount() < 1,
|
2016-07-19 06:26:58 +00:00
|
|
|
"Animated frames should be locked");
|
2014-09-27 01:50:24 +00:00
|
|
|
|
2017-09-05 11:58:45 +00:00
|
|
|
// The surface cache may suggest the preferred size we are supposed to
|
|
|
|
// decode at. This should only happen if we accept substitutions.
|
|
|
|
if (!result.SuggestedSize().IsEmpty()) {
|
|
|
|
MOZ_ASSERT(!(aFlags & FLAG_SYNC_DECODE) &&
|
|
|
|
(aFlags & FLAG_HIGH_QUALITY_SCALING));
|
|
|
|
requestedSize = result.SuggestedSize();
|
|
|
|
}
|
|
|
|
|
2016-12-22 19:15:41 +00:00
|
|
|
bool ranSync = Decode(requestedSize, aFlags, aPlaybackType);
|
2014-09-27 01:50:24 +00:00
|
|
|
|
2016-12-22 19:15:41 +00:00
|
|
|
// If we can or did sync decode, we should already have the frame.
|
|
|
|
if (ranSync || (aFlags & FLAG_SYNC_DECODE)) {
|
2016-08-18 07:06:41 +00:00
|
|
|
result = LookupFrameInternal(requestedSize, aFlags, aPlaybackType);
|
2015-01-12 14:35:17 +00:00
|
|
|
}
|
2013-04-04 22:05:19 +00:00
|
|
|
}
|
2009-11-12 23:18:40 +00:00
|
|
|
|
2015-07-01 01:57:03 +00:00
|
|
|
if (!result) {
|
2015-01-18 22:02:14 +00:00
|
|
|
// We still weren't able to get a frame. Give up.
|
2017-11-17 11:45:27 +00:00
|
|
|
return result;
|
2015-01-18 22:02:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-18 00:50:31 +00:00
|
|
|
if (result.Surface()->GetCompositingFailed()) {
|
2017-11-17 11:45:27 +00:00
|
|
|
DrawableSurface tmp = Move(result.Surface());
|
|
|
|
return result;
|
2014-09-13 01:29:27 +00:00
|
|
|
}
|
2013-07-26 14:41:57 +00:00
|
|
|
|
2016-08-18 00:50:31 +00:00
|
|
|
MOZ_ASSERT(!result.Surface()->GetIsPaletted(),
|
2016-08-16 00:58:35 +00:00
|
|
|
"Should not have a paletted frame");
|
2015-01-07 09:40:23 +00:00
|
|
|
|
2015-01-12 03:28:02 +00:00
|
|
|
// Sync decoding guarantees that we got the frame, but if it's owned by an
|
|
|
|
// async decoder that's currently running, the contents of the frame may not
|
|
|
|
// be available yet. Make sure we get everything.
|
2016-11-28 13:42:55 +00:00
|
|
|
if (mAllSourceData && (aFlags & FLAG_SYNC_DECODE)) {
|
2016-08-18 00:50:31 +00:00
|
|
|
result.Surface()->WaitUntilFinished();
|
2015-01-12 03:28:02 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 17:44:17 +00:00
|
|
|
// If we could have done some decoding in this function we need to check if
|
|
|
|
// that decoding encountered an error and hence aborted the surface. We want
|
|
|
|
// to avoid calling IsAborted if we weren't passed any sync decode flag because
|
|
|
|
// IsAborted acquires the monitor for the imgFrame.
|
|
|
|
if (aFlags & (FLAG_SYNC_DECODE | FLAG_SYNC_DECODE_IF_FAST) &&
|
2016-08-18 00:50:31 +00:00
|
|
|
result.Surface()->IsAborted()) {
|
2017-11-17 11:45:27 +00:00
|
|
|
DrawableSurface tmp = Move(result.Surface());
|
|
|
|
return result;
|
2016-04-01 17:44:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
return result;
|
2009-11-12 23:18:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:15:38 +00:00
|
|
|
bool
|
2014-11-25 07:42:43 +00:00
|
|
|
RasterImage::IsOpaque()
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2014-11-25 07:42:43 +00:00
|
|
|
if (mError) {
|
2013-02-04 22:22:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
2014-11-25 07:42:43 +00:00
|
|
|
Progress progress = mProgressTracker->GetProgress();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
2014-11-25 07:42:43 +00:00
|
|
|
// If we haven't yet finished decoding, the safe answer is "not opaque".
|
|
|
|
if (!(progress & FLAG_DECODE_COMPLETE)) {
|
2013-02-04 22:22:30 +00:00
|
|
|
return false;
|
2014-11-25 07:42:43 +00:00
|
|
|
}
|
2007-03-20 23:56:50 +00:00
|
|
|
|
2014-11-25 07:42:43 +00:00
|
|
|
// Other, we're opaque if FLAG_HAS_TRANSPARENCY is not set.
|
|
|
|
return !(progress & FLAG_HAS_TRANSPARENCY);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 02:15:38 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::WillDrawOpaqueNow()
|
|
|
|
{
|
|
|
|
if (!IsOpaque()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-06 09:00:36 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
if (!gfxPrefs::ImageMemAnimatedDiscardable()) {
|
|
|
|
// We never discard frames of animated images.
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (mAnimationState->GetCompositedFrameInvalid()) {
|
|
|
|
// We're not going to draw anything at all.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-08-23 02:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we are not locked our decoded data could get discard at any time (ie
|
|
|
|
// between the call to this function and when we are asked to draw), so we
|
|
|
|
// have to return false if we are unlocked.
|
2017-06-30 01:09:44 +00:00
|
|
|
if (mLockCount == 0) {
|
2016-08-23 02:15:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LookupResult result =
|
|
|
|
SurfaceCache::LookupBestMatch(ImageKey(this),
|
|
|
|
RasterSurfaceKey(mSize,
|
|
|
|
DefaultSurfaceFlags(),
|
|
|
|
PlaybackType::eStatic));
|
|
|
|
MatchType matchType = result.Type();
|
|
|
|
if (matchType == MatchType::NOT_FOUND || matchType == MatchType::PENDING ||
|
|
|
|
!result.Surface()->IsFinished()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-28 03:55:57 +00:00
|
|
|
void
|
2017-03-16 08:06:06 +00:00
|
|
|
RasterImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey)
|
2014-11-28 03:55:57 +00:00
|
|
|
{
|
2015-01-31 23:29:48 +00:00
|
|
|
MOZ_ASSERT(mProgressTracker);
|
2015-01-08 08:04:31 +00:00
|
|
|
|
2017-03-25 07:16:21 +00:00
|
|
|
bool animatedFramesDiscarded =
|
|
|
|
mAnimationState && aSurfaceKey.Playback() == PlaybackType::eAnimated;
|
|
|
|
|
2017-08-15 00:26:40 +00:00
|
|
|
nsCOMPtr<nsIEventTarget> eventTarget;
|
|
|
|
if (mProgressTracker) {
|
|
|
|
eventTarget = mProgressTracker->GetEventTarget();
|
|
|
|
} else {
|
|
|
|
eventTarget = do_GetMainThread();
|
|
|
|
}
|
|
|
|
|
2017-03-25 07:16:21 +00:00
|
|
|
RefPtr<RasterImage> image = this;
|
2017-08-15 00:26:40 +00:00
|
|
|
nsCOMPtr<nsIRunnable> ev = NS_NewRunnableFunction(
|
2017-03-25 07:16:21 +00:00
|
|
|
"RasterImage::OnSurfaceDiscarded",
|
|
|
|
[=]() -> void {
|
|
|
|
image->OnSurfaceDiscardedInternal(animatedFramesDiscarded);
|
2017-08-15 00:26:40 +00:00
|
|
|
});
|
|
|
|
eventTarget->Dispatch(ev.forget(), NS_DISPATCH_NORMAL);
|
2017-03-25 07:16:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RasterImage::OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (aAnimatedFramesDiscarded && mAnimationState) {
|
2017-03-16 08:06:04 +00:00
|
|
|
MOZ_ASSERT(gfxPrefs::ImageMemAnimatedDiscardable());
|
2017-11-17 11:45:24 +00:00
|
|
|
ReleaseImageContainer();
|
2017-04-06 09:00:36 +00:00
|
|
|
gfx::IntRect rect =
|
|
|
|
mAnimationState->UpdateState(mAnimationFinished, this, mSize);
|
|
|
|
NotifyProgress(NoProgress, rect);
|
2017-03-16 08:06:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-25 07:16:21 +00:00
|
|
|
if (mProgressTracker) {
|
|
|
|
mProgressTracker->OnDiscard();
|
|
|
|
}
|
2014-11-28 03:55:57 +00:00
|
|
|
}
|
|
|
|
|
2001-03-13 23:33:11 +00:00
|
|
|
//******************************************************************************
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::GetAnimated(bool* aAnimated)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aAnimated);
|
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
// If we have an AnimationState, we can know for sure.
|
|
|
|
if (mAnimationState) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aAnimated = true;
|
2009-10-07 04:39:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we need to have been decoded to know for sure, since if we were
|
2016-07-19 06:26:58 +00:00
|
|
|
// decoded at least once mAnimationState would have been created for animated
|
|
|
|
// images. This is true even though we check for animation during the
|
|
|
|
// metadata decode, because we may still discover animation only during the
|
|
|
|
// full decode for corrupt images.
|
2015-03-31 17:49:00 +00:00
|
|
|
if (!mHasBeenDecoded) {
|
2009-10-07 04:39:30 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-10-07 04:39:30 +00:00
|
|
|
|
|
|
|
// We know for sure
|
2011-10-17 14:59:28 +00:00
|
|
|
*aAnimated = false;
|
2009-10-07 04:39:30 +00:00
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-17 17:42:20 +00:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(int32_t)
|
|
|
|
RasterImage::GetFirstFrameDelay()
|
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2013-05-17 17:42:20 +00:00
|
|
|
return -1;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2013-05-17 17:42:20 +00:00
|
|
|
|
|
|
|
bool animated = false;
|
2015-03-31 17:49:00 +00:00
|
|
|
if (NS_FAILED(GetAnimated(&animated)) || !animated) {
|
2013-05-17 17:42:20 +00:00
|
|
|
return -1;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2013-05-17 17:42:20 +00:00
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
MOZ_ASSERT(mAnimationState, "Animated images should have an AnimationState");
|
2016-07-19 20:51:01 +00:00
|
|
|
return mAnimationState->FirstFrameTimeout().AsEncodedValueDeprecated();
|
2013-05-17 17:42:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
2012-08-22 15:56:38 +00:00
|
|
|
RasterImage::GetFrame(uint32_t aWhichFrame,
|
2013-12-13 08:34:24 +00:00
|
|
|
uint32_t aFlags)
|
2014-09-27 01:50:24 +00:00
|
|
|
{
|
2017-02-08 20:48:59 +00:00
|
|
|
return GetFrameAtSize(mSize, aWhichFrame, aFlags);
|
2015-09-19 20:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
|
|
RasterImage::GetFrameAtSize(const IntSize& aSize,
|
|
|
|
uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-08-01 22:08:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NotifyDrawingObservers();
|
|
|
|
#endif
|
|
|
|
|
2017-11-17 19:08:52 +00:00
|
|
|
auto result = GetFrameInternal(aSize, Nothing(), aWhichFrame, aFlags);
|
2018-02-12 12:59:58 +00:00
|
|
|
return mozilla::Get<2>(result).forget();
|
2014-09-27 01:50:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 15:37:59 +00:00
|
|
|
Tuple<ImgDrawResult, IntSize, RefPtr<SourceSurface>>
|
2015-09-19 20:34:09 +00:00
|
|
|
RasterImage::GetFrameInternal(const IntSize& aSize,
|
2017-11-17 19:08:52 +00:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2015-09-19 20:34:09 +00:00
|
|
|
uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags)
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
{
|
2013-12-13 08:34:24 +00:00
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
|
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
if (aSize.IsEmpty() || aWhichFrame > FRAME_MAX_VALUE) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return MakeTuple(ImgDrawResult::BAD_ARGS, aSize,
|
2017-11-17 11:45:27 +00:00
|
|
|
RefPtr<SourceSurface>());
|
2015-03-18 02:40:16 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-03-18 02:40:16 +00:00
|
|
|
if (mError) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return MakeTuple(ImgDrawResult::BAD_IMAGE, aSize,
|
2017-11-17 11:45:27 +00:00
|
|
|
RefPtr<SourceSurface>());
|
2015-03-18 02:40:16 +00:00
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// 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
|
2016-08-18 07:06:41 +00:00
|
|
|
// FLAG_SYNC_DECODE.
|
2017-11-17 11:45:27 +00:00
|
|
|
LookupResult result =
|
2016-08-18 07:06:41 +00:00
|
|
|
LookupFrame(aSize, aFlags, ToPlaybackType(aWhichFrame));
|
2017-11-17 11:45:27 +00:00
|
|
|
|
|
|
|
// The surface cache may have suggested we use a different size than the
|
|
|
|
// given size in the future. This may or may not be accompanied by an
|
|
|
|
// actual surface, depending on what it has in its cache.
|
|
|
|
IntSize suggestedSize = result.SuggestedSize().IsEmpty()
|
|
|
|
? aSize : result.SuggestedSize();
|
|
|
|
MOZ_ASSERT_IF(result.Type() == MatchType::SUBSTITUTE_BECAUSE_BEST,
|
|
|
|
suggestedSize != aSize);
|
|
|
|
|
|
|
|
if (!result) {
|
2014-09-27 01:50:24 +00:00
|
|
|
// The OS threw this frame away and we couldn't redecode it.
|
2017-12-11 15:37:59 +00:00
|
|
|
return MakeTuple(ImgDrawResult::TEMPORARY_ERROR, suggestedSize,
|
2017-11-17 11:45:27 +00:00
|
|
|
RefPtr<SourceSurface>());
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
RefPtr<SourceSurface> surface = result.Surface()->GetSourceSurface();
|
|
|
|
if (!result.Surface()->IsFinished()) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return MakeTuple(ImgDrawResult::INCOMPLETE, suggestedSize, Move(surface));
|
2015-03-18 02:40:16 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 15:37:59 +00:00
|
|
|
return MakeTuple(ImgDrawResult::SUCCESS, suggestedSize, Move(surface));
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 11:45:26 +00:00
|
|
|
IntSize
|
|
|
|
RasterImage::GetImageContainerSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
|
|
|
if (!IsImageContainerAvailableAtSize(aManager, aSize, aFlags)) {
|
|
|
|
return IntSize(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CanDownscaleDuringDecode(aSize, aFlags)) {
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aSize;
|
|
|
|
}
|
|
|
|
|
2015-05-13 07:23:44 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
|
|
{
|
2017-11-17 11:45:26 +00:00
|
|
|
return IsImageContainerAvailableAtSize(aManager, mSize, aFlags);
|
2015-05-13 07:23:44 +00:00
|
|
|
}
|
2012-09-24 20:31:30 +00:00
|
|
|
|
2015-03-18 02:40:16 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
RasterImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
2012-09-24 20:31:30 +00:00
|
|
|
{
|
2017-11-17 19:08:52 +00:00
|
|
|
return GetImageContainerImpl(aManager, mSize, Nothing(), aFlags);
|
2012-09-24 20:31:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 11:45:26 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-11-17 11:45:26 +00:00
|
|
|
// We check the minimum size because while we support downscaling, we do not
|
|
|
|
// support upscaling. If aSize > mSize, we will never give a larger surface
|
|
|
|
// than mSize. If mSize > aSize, and mSize > maxTextureSize, we still want to
|
|
|
|
// use image containers if aSize <= maxTextureSize.
|
|
|
|
int32_t maxTextureSize = aManager->GetMaxTextureSize();
|
|
|
|
if (!mHasSize || aSize.IsEmpty() ||
|
|
|
|
min(mSize.width, aSize.width) > maxTextureSize ||
|
|
|
|
min(mSize.height, aSize.height) > maxTextureSize) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-11-17 11:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
RasterImage::GetImageContainerAtSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
2017-11-17 19:08:52 +00:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 11:45:26 +00:00
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-12-01 11:59:21 +00:00
|
|
|
// We do not pass in the given SVG context because in theory it could differ
|
|
|
|
// between calls, but actually have no impact on the actual contents of the
|
|
|
|
// image container.
|
|
|
|
return GetImageContainerImpl(aManager, aSize, Nothing(), aFlags);
|
2017-11-17 11:45:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 03:51:48 +00:00
|
|
|
size_t
|
2017-07-28 10:10:04 +00:00
|
|
|
RasterImage::SizeOfSourceWithComputedFallback(SizeOfState& aState) const
|
2012-02-20 03:51:48 +00:00
|
|
|
{
|
2017-07-28 10:10:04 +00:00
|
|
|
return mSourceBuffer->SizeOfIncludingThisWithComputedFallback(
|
|
|
|
aState.mMallocSizeOf);
|
2012-02-20 03:51:48 +00:00
|
|
|
}
|
2011-07-18 13:20:27 +00:00
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
void
|
|
|
|
RasterImage::CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const
|
2010-05-22 04:10:14 +00:00
|
|
|
{
|
2015-04-28 18:46:17 +00:00
|
|
|
SurfaceCache::CollectSizeOfSurfaces(ImageKey(this), aCounters, aMallocSizeOf);
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mFrameAnimator) {
|
|
|
|
mFrameAnimator->CollectSizeOfCompositingSurfaces(aCounters, aMallocSizeOf);
|
2014-11-26 21:22:11 +00:00
|
|
|
}
|
2011-07-18 13:20:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-23 23:53:40 +00:00
|
|
|
bool
|
2015-08-14 07:37:13 +00:00
|
|
|
RasterImage::SetMetadata(const ImageMetadata& aMetadata,
|
|
|
|
bool aFromMetadataDecode)
|
2009-09-12 22:44:18 +00:00
|
|
|
{
|
2013-03-01 23:17:24 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2015-09-23 23:53:40 +00:00
|
|
|
return true;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
if (aMetadata.HasSize()) {
|
|
|
|
IntSize size = aMetadata.GetSize();
|
|
|
|
if (size.width < 0 || size.height < 0) {
|
2015-08-18 17:19:28 +00:00
|
|
|
NS_WARNING("Image has negative intrinsic size");
|
|
|
|
DoError();
|
2015-09-23 23:53:40 +00:00
|
|
|
return true;
|
2015-08-14 07:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aMetadata.HasOrientation());
|
|
|
|
Orientation orientation = aMetadata.GetOrientation();
|
|
|
|
|
|
|
|
// If we already have a size, check the new size against the old one.
|
|
|
|
if (mHasSize && (size != mSize || orientation != mOrientation)) {
|
|
|
|
NS_WARNING("Image changed size or orientation on redecode! "
|
|
|
|
"This should not happen!");
|
|
|
|
DoError();
|
2015-09-23 23:53:40 +00:00
|
|
|
return true;
|
2015-08-14 07:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the size and flag that we have it.
|
|
|
|
mSize = size;
|
|
|
|
mOrientation = orientation;
|
2017-03-22 13:05:36 +00:00
|
|
|
mNativeSizes = aMetadata.GetNativeSizes();
|
2015-08-14 07:37:13 +00:00
|
|
|
mHasSize = true;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mHasSize && aMetadata.HasAnimation() && !mAnimationState) {
|
2015-08-14 07:37:13 +00:00
|
|
|
// We're becoming animated, so initialize animation stuff.
|
2016-07-19 06:26:58 +00:00
|
|
|
mAnimationState.emplace(mAnimationMode);
|
|
|
|
mFrameAnimator = MakeUnique<FrameAnimator>(this, mSize);
|
2015-08-14 07:37:13 +00:00
|
|
|
|
2017-03-27 05:17:52 +00:00
|
|
|
if (!gfxPrefs::ImageMemAnimatedDiscardable()) {
|
|
|
|
// We don't support discarding animated images (See bug 414259).
|
|
|
|
// Lock the image and throw away the key.
|
|
|
|
LockImage();
|
|
|
|
}
|
2015-08-14 07:37:13 +00:00
|
|
|
|
|
|
|
if (!aFromMetadataDecode) {
|
|
|
|
// The metadata decode reported that this image isn't animated, but we
|
|
|
|
// discovered that it actually was during the full decode. This is a
|
|
|
|
// rare failure that only occurs for corrupt images. To recover, we need
|
|
|
|
// to discard all existing surfaces and redecode.
|
2015-09-23 23:53:40 +00:00
|
|
|
return false;
|
2015-08-14 07:37:13 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
mAnimationState->SetLoopCount(aMetadata.GetLoopCount());
|
|
|
|
mAnimationState->SetFirstFrameTimeout(aMetadata.GetFirstFrameTimeout());
|
2016-07-20 00:14:30 +00:00
|
|
|
|
|
|
|
if (aMetadata.HasLoopLength()) {
|
|
|
|
mAnimationState->SetLoopLength(aMetadata.GetLoopLength());
|
|
|
|
}
|
2016-07-20 06:35:41 +00:00
|
|
|
if (aMetadata.HasFirstFrameRefreshArea()) {
|
|
|
|
mAnimationState
|
|
|
|
->SetFirstFrameRefreshArea(aMetadata.GetFirstFrameRefreshArea());
|
|
|
|
}
|
2015-08-14 07:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aMetadata.HasHotspot()) {
|
|
|
|
IntPoint hotspot = aMetadata.GetHotspot();
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsPRUint32> intwrapx =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID);
|
|
|
|
nsCOMPtr<nsISupportsPRUint32> intwrapy =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID);
|
|
|
|
intwrapx->SetData(hotspot.x);
|
|
|
|
intwrapy->SetData(hotspot.y);
|
|
|
|
|
|
|
|
Set("hotspotX", intwrapx);
|
|
|
|
Set("hotspotY", intwrapy);
|
|
|
|
}
|
2015-09-23 23:53:40 +00:00
|
|
|
|
|
|
|
return true;
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 18:38:59 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::SetAnimationMode(uint16_t aAnimationMode)
|
|
|
|
{
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
mAnimationState->SetAnimationMode(aAnimationMode);
|
2013-07-15 18:38:59 +00:00
|
|
|
}
|
|
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2001-04-26 07:11:52 +00:00
|
|
|
//******************************************************************************
|
2015-08-04 23:17:36 +00:00
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
nsresult
|
2010-08-14 04:09:49 +00:00
|
|
|
RasterImage::StartAnimation()
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(ShouldAnimate(), "Should not animate!");
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
// If we're not ready to animate, then set mPendingAnimation, which will cause
|
|
|
|
// us to start animating if and when we do become ready.
|
2016-07-28 00:12:25 +00:00
|
|
|
mPendingAnimation = !mAnimationState || mAnimationState->KnownFrameCount() < 1;
|
2014-11-26 21:22:10 +00:00
|
|
|
if (mPendingAnimation) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2016-07-19 23:22:34 +00:00
|
|
|
// Don't bother to animate if we're displaying the first frame forever.
|
2016-08-18 07:06:41 +00:00
|
|
|
if (mAnimationState->GetCurrentAnimationFrameIndex() == 0 &&
|
2016-07-19 20:51:01 +00:00
|
|
|
mAnimationState->FirstFrameTimeout() == FrameTimeout::Forever()) {
|
2013-09-20 12:12:10 +00:00
|
|
|
mAnimationFinished = true;
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
2011-11-09 21:39:16 +00:00
|
|
|
|
2015-01-07 21:07:23 +00:00
|
|
|
// We need to set the time that this initial frame was first displayed, as
|
|
|
|
// this is used in AdvanceFrame().
|
2016-07-19 06:26:58 +00:00
|
|
|
mAnimationState->InitAnimationFrameTimeIfNecessary();
|
2013-03-29 20:14:19 +00:00
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-13 23:33:11 +00:00
|
|
|
//******************************************************************************
|
2010-09-08 00:33:02 +00:00
|
|
|
nsresult
|
2010-08-14 04:09:49 +00:00
|
|
|
RasterImage::StopAnimation()
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mAnimating, "Should be animating!");
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2013-09-20 12:12:10 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mError) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2016-07-19 06:26:58 +00:00
|
|
|
mAnimationState->SetAnimationFrameTime(TimeStamp());
|
2013-09-20 12:12:10 +00:00
|
|
|
}
|
2013-09-03 20:20:15 +00:00
|
|
|
|
2013-09-20 12:12:10 +00:00
|
|
|
mAnimating = false;
|
|
|
|
return rv;
|
2001-03-10 01:11:54 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 23:56:50 +00:00
|
|
|
//******************************************************************************
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::ResetAnimation()
|
2007-03-20 23:56:50 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
mPendingAnimation = false;
|
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mAnimationMode == kDontAnimMode || !mAnimationState ||
|
|
|
|
mAnimationState->GetCurrentAnimationFrameIndex() == 0) {
|
2007-03-20 23:56:50 +00:00
|
|
|
return NS_OK;
|
2014-11-26 21:22:10 +00:00
|
|
|
}
|
2007-03-20 23:56:50 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mAnimationFinished = false;
|
2011-03-31 21:05:31 +00:00
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mAnimating) {
|
2010-09-08 00:33:02 +00:00
|
|
|
StopAnimation();
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2007-03-20 23:56:50 +00:00
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
MOZ_ASSERT(mAnimationState, "Should have AnimationState");
|
2018-02-28 18:34:52 +00:00
|
|
|
MOZ_ASSERT(mFrameAnimator, "Should have FrameAnimator");
|
|
|
|
mFrameAnimator->ResetAnimation(*mAnimationState);
|
2013-06-17 20:49:04 +00:00
|
|
|
|
2016-07-20 06:35:41 +00:00
|
|
|
NotifyProgress(NoProgress, mAnimationState->FirstFrameRefreshArea());
|
2007-03-20 23:56:50 +00:00
|
|
|
|
2013-09-20 12:12:10 +00:00
|
|
|
// Start the animation again. It may not have been running before, if
|
|
|
|
// mAnimationFinished was true before entering this function.
|
|
|
|
EvaluateAnimation();
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2008-03-20 05:54:30 +00:00
|
|
|
return NS_OK;
|
2007-03-20 23:56:50 +00:00
|
|
|
}
|
|
|
|
|
2013-05-17 20:57:20 +00:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-16 22:25:43 +00:00
|
|
|
RasterImage::SetAnimationStartTime(const TimeStamp& aTime)
|
2013-05-17 20:57:20 +00:00
|
|
|
{
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mError || mAnimationMode == kDontAnimMode || mAnimating || !mAnimationState) {
|
2013-05-17 20:57:20 +00:00
|
|
|
return;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2013-05-17 20:57:20 +00:00
|
|
|
|
2016-07-19 06:26:58 +00:00
|
|
|
mAnimationState->SetAnimationFrameTime(aTime);
|
2013-05-17 20:57:20 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 22:58:20 +00:00
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
RasterImage::GetFrameIndex(uint32_t aWhichFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
|
2016-07-19 06:26:58 +00:00
|
|
|
return (aWhichFrame == FRAME_FIRST || !mAnimationState)
|
2013-04-25 22:58:20 +00:00
|
|
|
? 0.0f
|
2016-07-19 06:26:58 +00:00
|
|
|
: mAnimationState->GetCurrentAnimationFrameIndex();
|
2013-04-25 22:58:20 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 15:04:57 +00:00
|
|
|
NS_IMETHODIMP_(IntRect)
|
|
|
|
RasterImage::GetImageSpaceInvalidationRect(const IntRect& aRect)
|
2014-06-26 23:02:04 +00:00
|
|
|
{
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
nsresult
|
2015-01-15 23:11:36 +00:00
|
|
|
RasterImage::OnImageDataComplete(nsIRequest*, nsISupports*, nsresult aStatus,
|
|
|
|
bool aLastPart)
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2013-03-01 23:17:24 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Record that we have all the data we're going to get now.
|
2016-11-28 13:42:55 +00:00
|
|
|
mAllSourceData = true;
|
2013-02-14 02:41:10 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Let decoders know that there won't be any more data coming.
|
|
|
|
mSourceBuffer->Complete(aStatus);
|
2015-01-11 19:43:32 +00:00
|
|
|
|
2015-07-23 05:39:51 +00:00
|
|
|
// Allow a synchronous metadata decode if mSyncLoad was set, or if we're
|
|
|
|
// running on a single thread (in which case waiting for the async metadata
|
|
|
|
// decoder could delay this image's load event quite a bit), or if this image
|
|
|
|
// is transient.
|
|
|
|
bool canSyncDecodeMetadata = mSyncLoad || mTransient ||
|
|
|
|
DecodePool::NumberOfCores() < 2;
|
2015-07-08 22:52:51 +00:00
|
|
|
|
2015-07-23 05:39:51 +00:00
|
|
|
if (canSyncDecodeMetadata && !mHasSize) {
|
2015-06-30 09:37:58 +00:00
|
|
|
// We're loading this image synchronously, so it needs to be usable after
|
|
|
|
// this call returns. Since we haven't gotten our size yet, we need to do a
|
2015-07-23 05:39:51 +00:00
|
|
|
// synchronous metadata decode here.
|
|
|
|
DecodeMetadata(FLAG_SYNC_DECODE);
|
2015-01-11 19:43:32 +00:00
|
|
|
}
|
2015-01-11 13:34:20 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Determine our final status, giving precedence to Necko failure codes. We
|
2015-07-23 05:39:51 +00:00
|
|
|
// check after running the metadata decode in case it triggered an error.
|
2015-01-15 23:11:36 +00:00
|
|
|
nsresult finalStatus = mError ? NS_ERROR_FAILURE : NS_OK;
|
|
|
|
if (NS_FAILED(aStatus)) {
|
2015-01-12 18:17:52 +00:00
|
|
|
finalStatus = aStatus;
|
2015-01-15 23:11:36 +00:00
|
|
|
}
|
2015-01-12 18:17:52 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// If loading failed, report an error.
|
|
|
|
if (NS_FAILED(finalStatus)) {
|
|
|
|
DoError();
|
2015-01-12 18:17:52 +00:00
|
|
|
}
|
2015-01-12 09:20:23 +00:00
|
|
|
|
2015-06-30 09:37:58 +00:00
|
|
|
Progress loadProgress = LoadCompleteProgress(aLastPart, mError, finalStatus);
|
|
|
|
|
|
|
|
if (!mHasSize && !mError) {
|
|
|
|
// We don't have our size yet, so we'll fire the load event in SetSize().
|
2015-07-23 05:39:51 +00:00
|
|
|
MOZ_ASSERT(!canSyncDecodeMetadata,
|
|
|
|
"Firing load async after metadata sync decode?");
|
2015-06-30 09:37:58 +00:00
|
|
|
mLoadProgress = Some(loadProgress);
|
|
|
|
return finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyForLoadEvent(loadProgress);
|
|
|
|
|
|
|
|
return finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RasterImage::NotifyForLoadEvent(Progress aProgress)
|
|
|
|
{
|
2015-01-15 23:11:36 +00:00
|
|
|
MOZ_ASSERT(mHasSize || mError, "Need to know size before firing load event");
|
|
|
|
MOZ_ASSERT(!mHasSize ||
|
|
|
|
(mProgressTracker->GetProgress() & FLAG_SIZE_AVAILABLE),
|
|
|
|
"Should have notified that the size is available if we have it");
|
2015-01-19 23:46:55 +00:00
|
|
|
|
2015-06-30 09:37:58 +00:00
|
|
|
// If we encountered an error, make sure we notify for that as well.
|
|
|
|
if (mError) {
|
|
|
|
aProgress |= FLAG_HAS_ERROR;
|
|
|
|
}
|
2015-06-26 02:57:00 +00:00
|
|
|
|
2015-06-30 09:37:58 +00:00
|
|
|
// Notify our listeners, which will fire this image's load event.
|
|
|
|
NotifyProgress(aProgress);
|
2013-02-14 02:41:10 +00:00
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
nsresult
|
2012-12-17 22:05:18 +00:00
|
|
|
RasterImage::OnImageDataAvailable(nsIRequest*,
|
|
|
|
nsISupports*,
|
2015-08-01 01:10:29 +00:00
|
|
|
nsIInputStream* aInputStream,
|
|
|
|
uint64_t,
|
2012-12-17 22:05:18 +00:00
|
|
|
uint32_t aCount)
|
|
|
|
{
|
2015-08-01 01:10:29 +00:00
|
|
|
nsresult rv = mSourceBuffer->AppendFromInputStream(aInputStream, aCount);
|
2016-11-28 13:42:55 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !mSomeSourceData) {
|
|
|
|
mSomeSourceData = true;
|
|
|
|
if (!mSyncLoad) {
|
|
|
|
// Create an async metadata decoder and verify we succeed in doing so.
|
|
|
|
rv = DecodeMetadata(DECODE_FLAGS_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 14:09:35 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2015-08-01 01:10:29 +00:00
|
|
|
DoError();
|
|
|
|
}
|
2012-12-17 22:05:18 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
nsresult
|
2015-01-15 23:11:36 +00:00
|
|
|
RasterImage::SetSourceSizeHint(uint32_t aSizeHint)
|
2010-06-25 18:21:40 +00:00
|
|
|
{
|
2015-01-15 23:11:36 +00:00
|
|
|
return mSourceBuffer->ExpectLength(aSizeHint);
|
2010-06-25 18:21:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
/********* Methods to implement lazy allocation of nsIProperties object *******/
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::Get(const char* prop, const nsIID& iid, void** result)
|
2007-06-21 20:45:49 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (!mProperties) {
|
2007-06-21 20:45:49 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2007-06-21 20:45:49 +00:00
|
|
|
return mProperties->Get(prop, iid, result);
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::Set(const char* prop, nsISupports* value)
|
2007-06-21 20:45:49 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (!mProperties) {
|
2007-06-21 20:45:49 +00:00
|
|
|
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
|
|
|
if (!mProperties) {
|
2007-06-21 20:45:49 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2007-06-21 20:45:49 +00:00
|
|
|
return mProperties->Set(prop, value);
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::Has(const char* prop, bool* _retval)
|
2007-06-21 20:45:49 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
if (!mProperties) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = false;
|
2007-06-21 20:45:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mProperties->Has(prop, _retval);
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::Undefine(const char* prop)
|
2007-06-21 20:45:49 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (!mProperties) {
|
2007-06-21 20:45:49 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2007-06-21 20:45:49 +00:00
|
|
|
return mProperties->Undefine(prop);
|
|
|
|
}
|
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::GetKeys(uint32_t* count, char*** keys)
|
2007-06-21 20:45:49 +00:00
|
|
|
{
|
|
|
|
if (!mProperties) {
|
|
|
|
*count = 0;
|
2012-07-30 14:20:58 +00:00
|
|
|
*keys = nullptr;
|
2007-06-21 20:45:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mProperties->GetKeys(count, keys);
|
|
|
|
}
|
2007-10-19 00:36:34 +00:00
|
|
|
|
|
|
|
void
|
2014-11-28 03:56:00 +00:00
|
|
|
RasterImage::Discard()
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2013-03-01 23:17:24 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-11-28 03:55:57 +00:00
|
|
|
MOZ_ASSERT(CanDiscard(), "Asked to discard but can't");
|
2017-03-27 05:17:52 +00:00
|
|
|
MOZ_ASSERT(!mAnimationState || gfxPrefs::ImageMemAnimatedDiscardable(),
|
|
|
|
"Asked to discard for animated image");
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2015-01-07 21:07:23 +00:00
|
|
|
// Delete all the decoded frames.
|
2014-11-26 21:22:10 +00:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2017-03-16 08:06:04 +00:00
|
|
|
if (mAnimationState) {
|
2017-11-17 11:45:24 +00:00
|
|
|
ReleaseImageContainer();
|
2017-04-06 09:00:36 +00:00
|
|
|
gfx::IntRect rect =
|
|
|
|
mAnimationState->UpdateState(mAnimationFinished, this, mSize);
|
|
|
|
NotifyProgress(NoProgress, rect);
|
2017-03-16 08:06:04 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Notify that we discarded.
|
2014-11-28 03:56:00 +00:00
|
|
|
if (mProgressTracker) {
|
2014-11-15 04:10:47 +00:00
|
|
|
mProgressTracker->OnDiscard();
|
2014-11-26 21:22:10 +00:00
|
|
|
}
|
2007-10-19 00:36:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-05 13:57:16 +00:00
|
|
|
bool
|
2010-08-14 04:09:49 +00:00
|
|
|
RasterImage::CanDiscard() {
|
2017-03-27 05:17:52 +00:00
|
|
|
return mAllSourceData &&
|
|
|
|
// Can discard animated images if the pref is set
|
|
|
|
(!mAnimationState || gfxPrefs::ImageMemAnimatedDiscardable());
|
2014-01-21 23:19:22 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 05:57:43 +00:00
|
|
|
NS_IMETHODIMP
|
2016-11-26 07:56:26 +00:00
|
|
|
RasterImage::StartDecoding(uint32_t aFlags)
|
2015-10-29 05:57:43 +00:00
|
|
|
{
|
2015-10-29 23:37:42 +00:00
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHasSize) {
|
|
|
|
mWantFullDecode = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-26 07:56:26 +00:00
|
|
|
uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST;
|
|
|
|
return RequestDecodeForSize(mSize, flags);
|
2015-01-18 22:02:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 07:07:45 +00:00
|
|
|
bool
|
|
|
|
RasterImage::StartDecodingWithResult(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
if (mError) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHasSize) {
|
|
|
|
mWantFullDecode = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST;
|
|
|
|
DrawableSurface surface = RequestDecodeForSizeInternal(mSize, flags);
|
|
|
|
return surface && surface->IsFinished();
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:02:13 +00:00
|
|
|
NS_IMETHODIMP
|
2015-04-21 15:04:57 +00:00
|
|
|
RasterImage::RequestDecodeForSize(const IntSize& aSize, uint32_t aFlags)
|
2015-01-18 22:02:13 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
if (mError) {
|
2015-01-12 09:20:23 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-01-12 18:17:52 +00:00
|
|
|
}
|
2015-01-18 22:02:13 +00:00
|
|
|
|
2016-12-23 07:07:45 +00:00
|
|
|
RequestDecodeForSizeInternal(aSize, aFlags);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawableSurface
|
|
|
|
RasterImage::RequestDecodeForSizeInternal(const IntSize& aSize, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mError) {
|
|
|
|
return DrawableSurface();
|
|
|
|
}
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
if (!mHasSize) {
|
2016-12-01 21:52:06 +00:00
|
|
|
mWantFullDecode = true;
|
2016-12-23 07:07:45 +00:00
|
|
|
return DrawableSurface();
|
2015-01-12 18:17:52 +00:00
|
|
|
}
|
|
|
|
|
2015-02-03 05:40:35 +00:00
|
|
|
// Decide whether to sync decode images we can decode quickly. Here we are
|
|
|
|
// explicitly trading off flashing for responsiveness in the case that we're
|
|
|
|
// redecoding an image (see bug 845147).
|
|
|
|
bool shouldSyncDecodeIfFast =
|
|
|
|
!mHasBeenDecoded && (aFlags & FLAG_SYNC_DECODE_IF_FAST);
|
|
|
|
|
|
|
|
uint32_t flags = shouldSyncDecodeIfFast
|
|
|
|
? aFlags
|
|
|
|
: aFlags & ~FLAG_SYNC_DECODE_IF_FAST;
|
2015-01-18 22:02:13 +00:00
|
|
|
|
2016-08-18 07:06:41 +00:00
|
|
|
// Perform a frame lookup, which will implicitly start decoding if needed.
|
2017-11-17 11:45:27 +00:00
|
|
|
PlaybackType playbackType = mAnimationState ? PlaybackType::eAnimated
|
|
|
|
: PlaybackType::eStatic;
|
|
|
|
LookupResult result = LookupFrame(aSize, flags, playbackType);
|
|
|
|
return Move(result.Surface());
|
2015-01-12 18:17:52 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 19:15:41 +00:00
|
|
|
static bool
|
2016-06-29 20:43:19 +00:00
|
|
|
LaunchDecodingTask(IDecodingTask* aTask,
|
|
|
|
RasterImage* aImage,
|
|
|
|
uint32_t aFlags,
|
|
|
|
bool aHaveSourceData)
|
2015-07-23 05:39:51 +00:00
|
|
|
{
|
|
|
|
if (aHaveSourceData) {
|
2017-03-22 23:37:33 +00:00
|
|
|
nsCString uri(aImage->GetURIString());
|
|
|
|
|
2015-07-23 05:39:51 +00:00
|
|
|
// If we have all the data, we can sync decode if requested.
|
|
|
|
if (aFlags & imgIContainer::FLAG_SYNC_DECODE) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
DecodePool::Singleton()->SyncRunIfPossible(aTask, uri);
|
2016-12-22 19:15:41 +00:00
|
|
|
return true;
|
2015-07-23 05:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & imgIContainer::FLAG_SYNC_DECODE_IF_FAST) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 07:08:53 +00:00
|
|
|
return DecodePool::Singleton()->SyncRunIfPreferred(aTask, uri);
|
2015-07-23 05:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform an async decode. We also take this path if we don't have all the
|
|
|
|
// source data yet, since sync decoding is impossible in that situation.
|
2016-06-29 20:43:19 +00:00
|
|
|
DecodePool::Singleton()->AsyncRun(aTask);
|
2016-12-22 19:15:41 +00:00
|
|
|
return false;
|
2015-07-23 05:39:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-22 19:15:41 +00:00
|
|
|
bool
|
2016-08-18 07:06:41 +00:00
|
|
|
RasterImage::Decode(const IntSize& aSize,
|
|
|
|
uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType)
|
2015-01-15 23:11:36 +00:00
|
|
|
{
|
2015-07-23 05:39:51 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 18:17:52 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
if (mError) {
|
2016-12-22 19:15:41 +00:00
|
|
|
return false;
|
2015-01-12 18:17:52 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// If we don't have a size yet, we can't do any other decoding.
|
2015-07-23 05:39:51 +00:00
|
|
|
if (!mHasSize) {
|
2015-01-15 23:11:36 +00:00
|
|
|
mWantFullDecode = true;
|
2016-12-22 19:15:41 +00:00
|
|
|
return false;
|
2015-01-12 18:17:52 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 23:21:05 +00:00
|
|
|
// We're about to decode again, which may mean that some of the previous sizes
|
|
|
|
// we've decoded at aren't useful anymore. We can allow them to expire from
|
|
|
|
// the cache by unlocking them here. When the decode finishes, it will send an
|
|
|
|
// invalidation that will cause all instances of this image to redraw. If this
|
|
|
|
// image is locked, any surfaces that are still useful will become locked
|
|
|
|
// again when LookupFrame touches them, and the remainder will eventually
|
|
|
|
// expire.
|
2016-07-02 05:33:58 +00:00
|
|
|
SurfaceCache::UnlockEntries(ImageKey(this));
|
2015-07-23 05:39:51 +00:00
|
|
|
|
2015-08-15 00:56:44 +00:00
|
|
|
// Determine which flags we need to decode this image with.
|
|
|
|
DecoderFlags decoderFlags = DefaultDecoderFlags();
|
|
|
|
if (aFlags & FLAG_ASYNC_NOTIFY) {
|
|
|
|
decoderFlags |= DecoderFlags::ASYNC_NOTIFY;
|
|
|
|
}
|
|
|
|
if (mTransient) {
|
|
|
|
decoderFlags |= DecoderFlags::IMAGE_IS_TRANSIENT;
|
|
|
|
}
|
|
|
|
if (mHasBeenDecoded) {
|
|
|
|
decoderFlags |= DecoderFlags::IS_REDECODE;
|
|
|
|
}
|
2017-09-05 11:58:45 +00:00
|
|
|
if ((aFlags & FLAG_SYNC_DECODE) || !(aFlags & FLAG_HIGH_QUALITY_SCALING)) {
|
|
|
|
// Used SurfaceCache::Lookup instead of SurfaceCache::LookupBestMatch. That
|
|
|
|
// means the caller can handle a differently sized surface to be returned
|
|
|
|
// at any point.
|
|
|
|
decoderFlags |= DecoderFlags::CANNOT_SUBSTITUTE;
|
|
|
|
}
|
2015-08-15 00:56:44 +00:00
|
|
|
|
2015-10-06 00:06:34 +00:00
|
|
|
SurfaceFlags surfaceFlags = ToSurfaceFlags(aFlags);
|
|
|
|
if (IsOpaque()) {
|
|
|
|
// If there's no transparency, it doesn't matter whether we premultiply
|
|
|
|
// alpha or not.
|
|
|
|
surfaceFlags &= ~SurfaceFlags::NO_PREMULTIPLY_ALPHA;
|
|
|
|
}
|
|
|
|
|
2015-03-17 20:56:49 +00:00
|
|
|
// Create a decoder.
|
2016-06-26 07:09:24 +00:00
|
|
|
RefPtr<IDecodingTask> task;
|
2018-02-09 13:51:28 +00:00
|
|
|
nsresult rv;
|
|
|
|
bool animated = mAnimationState && aPlaybackType == PlaybackType::eAnimated;
|
|
|
|
if (animated) {
|
2018-02-28 18:34:52 +00:00
|
|
|
size_t currentFrame = mAnimationState->GetCurrentAnimationFrameIndex();
|
2018-02-09 13:51:28 +00:00
|
|
|
rv = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this),
|
|
|
|
mSourceBuffer, mSize,
|
|
|
|
decoderFlags, surfaceFlags,
|
2018-02-28 18:34:52 +00:00
|
|
|
currentFrame,
|
2018-02-09 13:51:28 +00:00
|
|
|
getter_AddRefs(task));
|
|
|
|
} else {
|
|
|
|
rv = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this),
|
|
|
|
mSourceBuffer, mSize, aSize,
|
|
|
|
decoderFlags, surfaceFlags,
|
|
|
|
getter_AddRefs(task));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv == NS_ERROR_ALREADY_INITIALIZED) {
|
|
|
|
// We raced with an already pending decoder, and it finished before we
|
|
|
|
// managed to insert the new decoder. Pretend we did a sync call to make
|
|
|
|
// the caller lookup in the surface cache again.
|
|
|
|
MOZ_ASSERT(!task);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animated) {
|
2017-06-01 07:19:55 +00:00
|
|
|
// We pass false for aAllowInvalidation because we may be asked to use
|
|
|
|
// async notifications. Any potential invalidation here will be sent when
|
|
|
|
// RequestRefresh is called, or NotifyDecodeComplete.
|
2017-05-04 02:20:35 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
gfx::IntRect rect =
|
|
|
|
#endif
|
2017-06-01 07:19:55 +00:00
|
|
|
mAnimationState->UpdateState(mAnimationFinished, this, mSize, false);
|
2017-05-04 02:20:35 +00:00
|
|
|
MOZ_ASSERT(rect.IsEmpty());
|
2015-08-14 07:37:13 +00:00
|
|
|
}
|
2015-07-23 05:39:51 +00:00
|
|
|
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
2018-02-09 13:51:28 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(!task);
|
2016-12-22 19:15:41 +00:00
|
|
|
return false;
|
2015-03-17 20:56:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-09 13:51:28 +00:00
|
|
|
MOZ_ASSERT(task);
|
2015-07-23 05:39:51 +00:00
|
|
|
mDecodeCount++;
|
2015-01-12 18:17:52 +00:00
|
|
|
|
2015-07-23 05:39:51 +00:00
|
|
|
// We're ready to decode; start the decoder.
|
2016-11-28 13:42:55 +00:00
|
|
|
return LaunchDecodingTask(task, this, aFlags, mAllSourceData);
|
2015-07-23 05:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::DecodeMetadata(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mHasSize, "Should not do unnecessary metadata decodes");
|
|
|
|
|
|
|
|
// Create a decoder.
|
2016-06-26 07:09:24 +00:00
|
|
|
RefPtr<IDecodingTask> task =
|
2016-06-27 04:50:43 +00:00
|
|
|
DecoderFactory::CreateMetadataDecoder(mDecoderType, WrapNotNull(this),
|
2016-10-19 00:05:29 +00:00
|
|
|
mSourceBuffer);
|
2015-07-23 05:39:51 +00:00
|
|
|
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
2016-06-26 07:09:24 +00:00
|
|
|
if (!task) {
|
2015-07-23 05:39:51 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're ready to decode; start the decoder.
|
2016-11-28 13:42:55 +00:00
|
|
|
LaunchDecodingTask(task, this, aFlags, mAllSourceData);
|
2015-01-15 23:11:36 +00:00
|
|
|
return NS_OK;
|
2007-10-19 00:36:34 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 00:38:36 +00:00
|
|
|
void
|
2015-08-18 17:19:14 +00:00
|
|
|
RasterImage::RecoverFromInvalidFrames(const IntSize& aSize, uint32_t aFlags)
|
2015-02-04 00:38:36 +00:00
|
|
|
{
|
|
|
|
if (!mHasSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-18 17:19:14 +00:00
|
|
|
NS_WARNING("A RasterImage's frames became invalid. Attempting to recover...");
|
2015-02-04 00:38:36 +00:00
|
|
|
|
|
|
|
// Discard all existing frames, since they're probably all now invalid.
|
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
|
2015-08-14 03:39:54 +00:00
|
|
|
// Relock the image if it's supposed to be locked.
|
|
|
|
if (mLockCount > 0) {
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2015-02-04 00:38:36 +00:00
|
|
|
// Animated images require some special handling, because we normally require
|
|
|
|
// that they never be discarded.
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mAnimationState) {
|
2016-08-18 07:06:41 +00:00
|
|
|
Decode(mSize, aFlags | FLAG_SYNC_DECODE, PlaybackType::eAnimated);
|
2015-02-04 00:38:36 +00:00
|
|
|
ResetAnimation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For non-animated images, it's fine to recover using an async decode.
|
2016-08-18 07:06:41 +00:00
|
|
|
Decode(aSize, aFlags, PlaybackType::eStatic);
|
2015-02-04 00:38:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 23:21:05 +00:00
|
|
|
static bool
|
|
|
|
HaveSkia()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_ENABLE_SKIA
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:02:14 +00:00
|
|
|
bool
|
2015-04-21 15:04:57 +00:00
|
|
|
RasterImage::CanDownscaleDuringDecode(const IntSize& aSize, uint32_t aFlags)
|
2015-01-18 22:02:14 +00:00
|
|
|
{
|
2015-09-19 23:21:05 +00:00
|
|
|
// Check basic requirements: downscale-during-decode is enabled, Skia is
|
|
|
|
// available, this image isn't transient, we have all the source data and know
|
|
|
|
// our size, and the flags allow us to do it.
|
|
|
|
if (!mHasSize || mTransient || !HaveSkia() ||
|
2015-09-19 23:20:56 +00:00
|
|
|
!gfxPrefs::ImageDownscaleDuringDecodeEnabled() ||
|
2015-01-18 22:02:14 +00:00
|
|
|
!(aFlags & imgIContainer::FLAG_HIGH_QUALITY_SCALING)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't downscale animated images during decode.
|
2016-07-19 06:26:58 +00:00
|
|
|
if (mAnimationState) {
|
2015-01-18 22:02:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Never upscale.
|
|
|
|
if (aSize.width >= mSize.width || aSize.height >= mSize.height) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Zero or negative width or height is unacceptable.
|
|
|
|
if (aSize.width < 1 || aSize.height < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's no point in scaling if we can't store the result.
|
2015-03-29 14:59:08 +00:00
|
|
|
if (!SurfaceCache::CanHold(aSize)) {
|
2015-01-18 22:02:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-11 15:37:59 +00:00
|
|
|
ImgDrawResult
|
2016-08-18 00:50:31 +00:00
|
|
|
RasterImage::DrawInternal(DrawableSurface&& aSurface,
|
2015-09-19 23:20:56 +00:00
|
|
|
gfxContext* aContext,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2016-05-25 16:01:18 +00:00
|
|
|
SamplingFilter aSamplingFilter,
|
2017-01-03 05:53:22 +00:00
|
|
|
uint32_t aFlags,
|
|
|
|
float aOpacity)
|
2015-09-19 23:20:56 +00:00
|
|
|
{
|
2014-09-13 01:29:27 +00:00
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
2014-08-22 20:12:38 +00:00
|
|
|
ImageRegion region(aRegion);
|
2016-08-18 00:50:31 +00:00
|
|
|
bool frameIsFinished = aSurface->IsFinished();
|
2014-08-22 20:12:38 +00:00
|
|
|
|
2017-06-14 22:11:48 +00:00
|
|
|
#ifdef DEBUG
|
2017-08-01 22:08:02 +00:00
|
|
|
NotifyDrawingObservers();
|
2017-06-14 22:11:48 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
// By now we may have a frame with the requested size. If not, we need to
|
|
|
|
// adjust the drawing parameters accordingly.
|
2016-08-18 00:50:31 +00:00
|
|
|
IntSize finalSize = aSurface->GetImageSize();
|
2015-02-04 21:50:56 +00:00
|
|
|
bool couldRedecodeForBetterFrame = false;
|
2015-03-29 14:59:15 +00:00
|
|
|
if (finalSize != aSize) {
|
2014-11-26 21:22:10 +00:00
|
|
|
gfx::Size scale(double(aSize.width) / finalSize.width,
|
|
|
|
double(aSize.height) / finalSize.height);
|
2014-08-22 20:12:38 +00:00
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
|
|
|
|
region.Scale(1.0 / scale.width, 1.0 / scale.height);
|
2015-02-04 21:50:56 +00:00
|
|
|
|
2015-09-19 23:21:05 +00:00
|
|
|
couldRedecodeForBetterFrame = CanDownscaleDuringDecode(aSize, aFlags);
|
2014-08-22 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-03 05:53:22 +00:00
|
|
|
if (!aSurface->Draw(aContext, region, aSamplingFilter, aFlags, aOpacity)) {
|
2015-08-18 17:19:14 +00:00
|
|
|
RecoverFromInvalidFrames(aSize, aFlags);
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2015-02-04 21:50:56 +00:00
|
|
|
}
|
2016-03-24 00:31:42 +00:00
|
|
|
if (!frameIsFinished) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::INCOMPLETE;
|
2015-02-04 00:38:36 +00:00
|
|
|
}
|
2015-02-04 21:50:56 +00:00
|
|
|
if (couldRedecodeForBetterFrame) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::WRONG_SIZE;
|
2015-02-04 21:50:56 +00:00
|
|
|
}
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2012-04-03 21:57:22 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
//******************************************************************************
|
2017-12-11 15:37:59 +00:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2014-08-22 20:12:38 +00:00
|
|
|
RasterImage::Draw(gfxContext* aContext,
|
2015-04-21 15:04:57 +00:00
|
|
|
const IntSize& aSize,
|
2014-08-22 20:12:38 +00:00
|
|
|
const ImageRegion& aRegion,
|
2013-03-11 01:43:37 +00:00
|
|
|
uint32_t aWhichFrame,
|
2016-05-25 16:01:18 +00:00
|
|
|
SamplingFilter aSamplingFilter,
|
2014-08-22 20:12:38 +00:00
|
|
|
const Maybe<SVGImageContext>& /*aSVGContext - ignored*/,
|
2017-01-03 05:53:22 +00:00
|
|
|
uint32_t aFlags,
|
|
|
|
float aOpacity)
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2015-03-31 17:49:00 +00:00
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2013-03-11 01:43:37 +00:00
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::BAD_IMAGE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2011-01-13 01:45:13 +00:00
|
|
|
// Illegal -- you can't draw with non-default decode flags.
|
|
|
|
// (Disabling colorspace conversion might make sense to allow, but
|
|
|
|
// we don't currently.)
|
2015-08-15 00:56:44 +00:00
|
|
|
if (ToSurfaceFlags(aFlags) != DefaultSurfaceFlags()) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2011-01-13 01:45:13 +00:00
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
if (!aContext) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-02-04 21:50:56 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2017-06-30 01:09:44 +00:00
|
|
|
if (mAnimationConsumers == 0) {
|
2016-11-17 06:25:53 +00:00
|
|
|
SendOnUnlockedDraw(aFlags);
|
2013-02-25 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 06:25:53 +00:00
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
// If we're not using SamplingFilter::GOOD, we shouldn't high-quality scale or
|
2015-10-06 00:12:46 +00:00
|
|
|
// downscale during decode.
|
2016-05-25 16:01:18 +00:00
|
|
|
uint32_t flags = aSamplingFilter == SamplingFilter::GOOD
|
2015-01-18 22:02:14 +00:00
|
|
|
? aFlags
|
|
|
|
: aFlags & ~FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
LookupResult result =
|
2016-08-18 07:06:41 +00:00
|
|
|
LookupFrame(aSize, flags, ToPlaybackType(aWhichFrame));
|
2017-11-17 11:45:27 +00:00
|
|
|
if (!result) {
|
2014-11-26 21:22:10 +00:00
|
|
|
// Getting the frame (above) touches the image and kicks off decoding.
|
2015-01-15 23:11:36 +00:00
|
|
|
if (mDrawStartTime.IsNull()) {
|
|
|
|
mDrawStartTime = TimeStamp::Now();
|
|
|
|
}
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::NOT_READY;
|
2009-09-12 22:44:18 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
bool shouldRecordTelemetry = !mDrawStartTime.IsNull() &&
|
2017-11-17 11:45:27 +00:00
|
|
|
result.Surface()->IsFinished();
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
auto drawResult = DrawInternal(Move(result.Surface()), aContext, aSize,
|
|
|
|
aRegion, aSamplingFilter, flags, aOpacity);
|
2014-02-25 03:37:51 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
if (shouldRecordTelemetry) {
|
2011-08-10 23:12:08 +00:00
|
|
|
TimeDuration drawLatency = TimeStamp::Now() - mDrawStartTime;
|
2015-01-15 23:11:36 +00:00
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_ON_DRAW_LATENCY,
|
|
|
|
int32_t(drawLatency.ToMicroseconds()));
|
2017-03-23 05:02:54 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_ANIMATED_DECODE_ON_DRAW_LATENCY,
|
|
|
|
int32_t(drawLatency.ToMicroseconds()));
|
|
|
|
|
|
|
|
}
|
2011-08-10 23:12:08 +00:00
|
|
|
mDrawStartTime = TimeStamp();
|
|
|
|
}
|
2012-04-03 21:57:22 +00:00
|
|
|
|
2017-11-17 11:45:27 +00:00
|
|
|
return drawResult;
|
2007-10-19 00:36:34 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
//******************************************************************************
|
2015-08-04 23:17:36 +00:00
|
|
|
|
2007-10-19 00:36:34 +00:00
|
|
|
NS_IMETHODIMP
|
2010-08-14 04:09:49 +00:00
|
|
|
RasterImage::LockImage()
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2013-09-28 18:28:43 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Main thread to encourage serialization with UnlockImage");
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
|
|
|
// Increment the lock count
|
|
|
|
mLockCount++;
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
// Lock this image's surfaces in the SurfaceCache.
|
|
|
|
if (mLockCount == 1) {
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2007-10-19 00:36:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
//******************************************************************************
|
2015-08-04 23:17:36 +00:00
|
|
|
|
2007-10-19 00:36:34 +00:00
|
|
|
NS_IMETHODIMP
|
2010-08-14 04:09:49 +00:00
|
|
|
RasterImage::UnlockImage()
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2013-09-28 18:28:43 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Main thread to encourage serialization with LockImage");
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
|
|
|
// It's an error to call this function if the lock count is 0
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(mLockCount > 0,
|
|
|
|
"Calling UnlockImage with mLockCount == 0!");
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mLockCount == 0) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return NS_ERROR_ABORT;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
|
|
|
// Decrement our lock count
|
|
|
|
mLockCount--;
|
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
// Unlock this image's surfaces in the SurfaceCache.
|
2015-01-07 09:40:23 +00:00
|
|
|
if (mLockCount == 0 ) {
|
2014-11-26 21:22:10 +00:00
|
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2007-10-19 00:36:34 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:29:28 +00:00
|
|
|
//******************************************************************************
|
2015-08-04 23:17:36 +00:00
|
|
|
|
2012-03-10 06:29:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::RequestDiscard()
|
|
|
|
{
|
2014-11-28 03:55:57 +00:00
|
|
|
if (mDiscardable && // Enabled at creation time...
|
|
|
|
mLockCount == 0 && // ...not temporarily disabled...
|
2014-11-28 03:56:00 +00:00
|
|
|
CanDiscard()) {
|
2014-11-28 03:55:57 +00:00
|
|
|
Discard();
|
2012-03-10 06:29:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-12 15:22:30 +00:00
|
|
|
// Indempotent error flagging routine. If a decoder is open, shuts it down.
|
2010-08-14 04:09:49 +00:00
|
|
|
void
|
|
|
|
RasterImage::DoError()
|
2007-10-19 00:36:34 +00:00
|
|
|
{
|
2009-09-12 22:44:18 +00:00
|
|
|
// If we've flagged an error before, we have nothing to do
|
2015-03-31 17:49:00 +00:00
|
|
|
if (mError) {
|
2009-09-12 22:44:18 +00:00
|
|
|
return;
|
2015-03-31 17:49:00 +00:00
|
|
|
}
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
// We can't safely handle errors off-main-thread, so dispatch a worker to
|
|
|
|
// do it.
|
2013-09-12 21:40:16 +00:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
HandleErrorWorker::DispatchIfNeeded(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the container in an error state.
|
2011-10-17 14:59:28 +00:00
|
|
|
mError = true;
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-05-07 16:25:12 +00:00
|
|
|
// Stop animation and release our FrameAnimator.
|
|
|
|
if (mAnimating) {
|
|
|
|
StopAnimation();
|
|
|
|
}
|
2016-07-19 06:26:58 +00:00
|
|
|
mAnimationState = Nothing();
|
|
|
|
mFrameAnimator = nullptr;
|
2015-05-07 16:25:12 +00:00
|
|
|
|
|
|
|
// Release all locks.
|
|
|
|
mLockCount = 0;
|
|
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
|
|
|
|
|
|
// Release all frames from the surface cache.
|
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
|
|
|
|
// Invalidate to get rid of any partially-drawn image content.
|
|
|
|
NotifyProgress(NoProgress, IntRect(0, 0, mSize.width, mSize.height));
|
|
|
|
|
2015-11-16 17:21:00 +00:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Error,
|
2015-07-21 16:42:27 +00:00
|
|
|
("RasterImage: [this=%p] Error detected for image\n", this));
|
2007-10-19 00:36:34 +00:00
|
|
|
}
|
|
|
|
|
2013-09-12 21:40:16 +00:00
|
|
|
/* static */ void
|
|
|
|
RasterImage::HandleErrorWorker::DispatchIfNeeded(RasterImage* aImage)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<HandleErrorWorker> worker = new HandleErrorWorker(aImage);
|
2015-01-15 23:11:36 +00:00
|
|
|
NS_DispatchToMainThread(worker);
|
2013-09-12 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RasterImage::HandleErrorWorker::HandleErrorWorker(RasterImage* aImage)
|
2017-06-12 19:34:10 +00:00
|
|
|
: Runnable("image::RasterImage::HandleErrorWorker")
|
|
|
|
, mImage(aImage)
|
2013-09-12 21:40:16 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mImage, "Should have image");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::HandleErrorWorker::Run()
|
|
|
|
{
|
|
|
|
mImage->DoError();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-05 13:57:16 +00:00
|
|
|
bool
|
2010-09-08 00:33:02 +00:00
|
|
|
RasterImage::ShouldAnimate()
|
|
|
|
{
|
2016-07-28 00:12:25 +00:00
|
|
|
return ImageResource::ShouldAnimate() &&
|
|
|
|
mAnimationState &&
|
|
|
|
mAnimationState->KnownFrameCount() >= 1 &&
|
2010-11-17 20:39:23 +00:00
|
|
|
!mAnimationFinished;
|
2010-09-08 00:33:02 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
2015-03-31 17:49:00 +00:00
|
|
|
RasterImage::GetFramesNotified(uint32_t* aFramesNotified)
|
2010-09-08 00:34:18 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFramesNotified);
|
|
|
|
|
|
|
|
*aFramesNotified = mFramesNotified;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
void
|
|
|
|
RasterImage::NotifyProgress(Progress aProgress,
|
2015-04-21 15:04:57 +00:00
|
|
|
const IntRect& aInvalidRect /* = IntRect() */,
|
2016-07-28 00:12:25 +00:00
|
|
|
const Maybe<uint32_t>& aFrameCount /* = Nothing() */,
|
2016-08-18 07:06:41 +00:00
|
|
|
DecoderFlags aDecoderFlags
|
|
|
|
/* = DefaultDecoderFlags() */,
|
2015-08-15 00:56:44 +00:00
|
|
|
SurfaceFlags aSurfaceFlags
|
|
|
|
/* = DefaultSurfaceFlags() */)
|
2015-01-12 18:17:52 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Ensure that we stay alive long enough to finish notifying.
|
2016-07-27 21:04:21 +00:00
|
|
|
RefPtr<RasterImage> image = this;
|
2013-01-18 21:47:18 +00:00
|
|
|
|
2016-07-27 21:04:21 +00:00
|
|
|
const bool wasDefaultFlags = aSurfaceFlags == DefaultSurfaceFlags();
|
2015-01-11 19:43:32 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
if (!aInvalidRect.IsEmpty() && wasDefaultFlags) {
|
2014-12-11 03:35:15 +00:00
|
|
|
// Update our image container since we're invalidating.
|
2017-11-17 11:45:25 +00:00
|
|
|
UpdateImageContainer();
|
2014-12-11 03:35:15 +00:00
|
|
|
}
|
2014-11-10 20:37:35 +00:00
|
|
|
|
2016-08-18 07:06:41 +00:00
|
|
|
if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY)) {
|
|
|
|
// We may have decoded new animation frames; update our animation state.
|
|
|
|
MOZ_ASSERT_IF(aFrameCount && *aFrameCount > 1, mAnimationState || mError);
|
|
|
|
if (mAnimationState && aFrameCount) {
|
|
|
|
mAnimationState->UpdateKnownFrameCount(*aFrameCount);
|
|
|
|
}
|
2016-07-28 00:12:25 +00:00
|
|
|
|
2016-08-18 07:06:41 +00:00
|
|
|
// If we should start animating right now, do so.
|
|
|
|
if (mAnimationState && aFrameCount == Some(1u) &&
|
|
|
|
mPendingAnimation && ShouldAnimate()) {
|
|
|
|
StartAnimation();
|
|
|
|
}
|
2016-07-28 00:12:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Tell the observers what happened.
|
|
|
|
image->mProgressTracker->SyncNotifyProgress(aProgress, aInvalidRect);
|
2015-01-15 23:11:36 +00:00
|
|
|
}
|
2013-02-02 01:06:34 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
void
|
2016-08-03 00:22:41 +00:00
|
|
|
RasterImage::NotifyDecodeComplete(const DecoderFinalStatus& aStatus,
|
|
|
|
const ImageMetadata& aMetadata,
|
|
|
|
const DecoderTelemetry& aTelemetry,
|
|
|
|
Progress aProgress,
|
|
|
|
const IntRect& aInvalidRect,
|
|
|
|
const Maybe<uint32_t>& aFrameCount,
|
2016-08-18 07:06:41 +00:00
|
|
|
DecoderFlags aDecoderFlags,
|
2016-08-03 00:22:41 +00:00
|
|
|
SurfaceFlags aSurfaceFlags)
|
2015-01-15 23:11:36 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-31 14:29:15 +00:00
|
|
|
|
|
|
|
// If the decoder detected an error, log it to the error console.
|
2016-09-21 11:13:08 +00:00
|
|
|
if (aStatus.mShouldReportError) {
|
2016-08-03 00:22:41 +00:00
|
|
|
ReportDecoderError();
|
2015-07-31 14:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Record all the metadata the decoder gathered about this image.
|
2016-08-03 00:12:36 +00:00
|
|
|
bool metadataOK = SetMetadata(aMetadata, aStatus.mWasMetadataDecode);
|
2015-09-23 23:53:40 +00:00
|
|
|
if (!metadataOK) {
|
|
|
|
// This indicates a serious error that requires us to discard all existing
|
|
|
|
// surfaces and redecode to recover. We'll drop the results from this
|
|
|
|
// decoder on the floor, since they aren't valid.
|
|
|
|
RecoverFromInvalidFrames(mSize,
|
2016-08-02 23:32:07 +00:00
|
|
|
FromSurfaceFlags(aSurfaceFlags));
|
2015-09-23 23:53:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-02 22:43:47 +00:00
|
|
|
MOZ_ASSERT(mError || mHasSize || !aMetadata.HasSize(),
|
2015-08-18 17:19:22 +00:00
|
|
|
"SetMetadata should've gotten a size");
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2016-09-21 11:13:08 +00:00
|
|
|
if (!aStatus.mWasMetadataDecode && aStatus.mFinished) {
|
2015-07-31 14:29:15 +00:00
|
|
|
// Flag that we've been decoded before.
|
|
|
|
mHasBeenDecoded = true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// Send out any final notifications.
|
2016-08-18 07:06:41 +00:00
|
|
|
NotifyProgress(aProgress, aInvalidRect, aFrameCount,
|
|
|
|
aDecoderFlags, aSurfaceFlags);
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2016-08-18 07:06:41 +00:00
|
|
|
if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY) &&
|
|
|
|
mHasBeenDecoded && mAnimationState) {
|
|
|
|
// We've finished a full decode of all animation frames and our AnimationState
|
|
|
|
// has been notified about them all, so let it know not to expect anymore.
|
2017-03-02 04:45:54 +00:00
|
|
|
mAnimationState->NotifyDecodeComplete();
|
2017-04-06 09:00:36 +00:00
|
|
|
gfx::IntRect rect = mAnimationState->UpdateState(mAnimationFinished, this, mSize);
|
|
|
|
if (!rect.IsEmpty()) {
|
|
|
|
NotifyProgress(NoProgress, rect);
|
|
|
|
}
|
2016-07-28 00:12:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-26 18:18:37 +00:00
|
|
|
// Do some telemetry if this isn't a metadata decode.
|
|
|
|
if (!aStatus.mWasMetadataDecode) {
|
|
|
|
if (aTelemetry.mChunkCount) {
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_CHUNKS, aTelemetry.mChunkCount);
|
|
|
|
}
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2016-09-26 18:18:37 +00:00
|
|
|
if (aStatus.mFinished) {
|
2015-01-15 23:11:36 +00:00
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_TIME,
|
2016-08-02 23:34:23 +00:00
|
|
|
int32_t(aTelemetry.mDecodeTime.ToMicroseconds()));
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2017-03-23 05:02:54 +00:00
|
|
|
if (mAnimationState) {
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_ANIMATED_DECODE_TIME,
|
|
|
|
int32_t(aTelemetry.mDecodeTime.ToMicroseconds()));
|
|
|
|
}
|
|
|
|
|
2016-08-02 23:45:22 +00:00
|
|
|
if (aTelemetry.mSpeedHistogram) {
|
|
|
|
Telemetry::Accumulate(*aTelemetry.mSpeedHistogram, aTelemetry.Speed());
|
2015-01-15 23:11:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-26 18:18:37 +00:00
|
|
|
}
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2016-09-26 18:18:37 +00:00
|
|
|
// Only act on errors if we have no usable frames from the decoder.
|
|
|
|
if (aStatus.mHadError &&
|
|
|
|
(!mAnimationState || mAnimationState->KnownFrameCount() == 0)) {
|
|
|
|
DoError();
|
|
|
|
} else if (aStatus.mWasMetadataDecode && !mHasSize) {
|
|
|
|
DoError();
|
|
|
|
}
|
2015-06-30 09:37:58 +00:00
|
|
|
|
2016-09-26 18:18:37 +00:00
|
|
|
// XXX(aosmond): Can we get this far without mFinished == true?
|
|
|
|
if (aStatus.mFinished && aStatus.mWasMetadataDecode) {
|
2015-06-30 09:37:58 +00:00
|
|
|
// If we were waiting to fire the load event, go ahead and fire it now.
|
2016-09-26 18:18:37 +00:00
|
|
|
if (mLoadProgress) {
|
2015-06-30 09:37:58 +00:00
|
|
|
NotifyForLoadEvent(*mLoadProgress);
|
|
|
|
mLoadProgress = Nothing();
|
|
|
|
}
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2016-09-26 18:18:37 +00:00
|
|
|
// If we were a metadata decode and a full decode was requested, do it.
|
|
|
|
if (mWantFullDecode) {
|
|
|
|
mWantFullDecode = false;
|
|
|
|
RequestDecodeForSize(mSize, DECODE_FLAGS_DEFAULT);
|
|
|
|
}
|
2015-01-15 23:11:36 +00:00
|
|
|
}
|
2013-01-18 21:47:18 +00:00
|
|
|
}
|
|
|
|
|
2015-07-31 14:29:15 +00:00
|
|
|
void
|
2016-08-03 00:22:41 +00:00
|
|
|
RasterImage::ReportDecoderError()
|
2015-07-31 14:29:15 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
|
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
|
|
|
2016-07-11 07:34:50 +00:00
|
|
|
if (consoleService && errorObject) {
|
2015-07-31 14:29:15 +00:00
|
|
|
nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated."));
|
|
|
|
nsAutoString src;
|
|
|
|
if (GetURI()) {
|
|
|
|
nsCString uri;
|
|
|
|
if (GetURI()->GetSpecTruncatedTo1k(uri) == ImageURL::TruncatedTo1k) {
|
|
|
|
msg += NS_LITERAL_STRING(" URI in this note truncated due to length.");
|
|
|
|
}
|
|
|
|
src = NS_ConvertUTF8toUTF16(uri);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(errorObject->InitWithWindowID(
|
|
|
|
msg,
|
|
|
|
src,
|
|
|
|
EmptyString(), 0, 0, nsIScriptError::errorFlag,
|
|
|
|
"Image", InnerWindowID()
|
|
|
|
))) {
|
|
|
|
consoleService->LogMessage(errorObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 03:50:26 +00:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
RasterImage::Unwrap()
|
|
|
|
{
|
|
|
|
nsCOMPtr<imgIContainer> self(this);
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2015-06-03 17:42:07 +00:00
|
|
|
void
|
|
|
|
RasterImage::PropagateUseCounters(nsIDocument*)
|
|
|
|
{
|
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2015-04-21 15:04:57 +00:00
|
|
|
IntSize
|
2014-07-28 21:27:39 +00:00
|
|
|
RasterImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
|
2016-05-25 16:01:18 +00:00
|
|
|
SamplingFilter aSamplingFilter, uint32_t aFlags)
|
2014-07-28 21:27:39 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDest.width >= 0 || ceil(aDest.width) <= INT32_MAX ||
|
|
|
|
aDest.height >= 0 || ceil(aDest.height) <= INT32_MAX,
|
|
|
|
"Unexpected destination size");
|
|
|
|
|
2014-09-16 23:18:49 +00:00
|
|
|
if (mSize.IsEmpty() || aDest.IsEmpty()) {
|
2015-04-21 15:04:57 +00:00
|
|
|
return IntSize(0, 0);
|
2014-07-28 21:27:39 +00:00
|
|
|
}
|
|
|
|
|
2016-07-26 14:48:30 +00:00
|
|
|
IntSize destSize = IntSize::Ceil(aDest.width, aDest.height);
|
2014-07-28 21:27:39 +00:00
|
|
|
|
2016-05-25 16:01:18 +00:00
|
|
|
if (aSamplingFilter == SamplingFilter::GOOD &&
|
|
|
|
CanDownscaleDuringDecode(destSize, aFlags)) {
|
2015-01-18 22:02:14 +00:00
|
|
|
return destSize;
|
2014-07-28 21:27:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 23:20:56 +00:00
|
|
|
// We can't scale to this size. Use our intrinsic size for now.
|
2014-07-28 21:27:39 +00:00
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-14 04:09:49 +00:00
|
|
|
} // namespace mozilla
|