2001-03-10 04:11:54 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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 04:11:54 +03:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
// Must #include ImageLogging.h before any IPDL-generated files or other files
|
|
|
|
// that #include prlog.h
|
2012-04-04 01:57:22 +04:00
|
|
|
#include "ImageLogging.h"
|
2014-04-15 22:02:23 +04:00
|
|
|
|
|
|
|
#include "RasterImage.h"
|
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
2005-01-12 23:16:07 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2018-02-13 14:43:31 +03:00
|
|
|
#include "DecodePool.h"
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2007-10-19 04:36:34 +04:00
|
|
|
#include "prenv.h"
|
2013-03-02 03:17:24 +04:00
|
|
|
#include "prsystem.h"
|
2016-06-29 23:43:19 +03:00
|
|
|
#include "IDecodingTask.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "ImageRegion.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "Layers.h"
|
2015-07-01 04:57:03 +03:00
|
|
|
#include "LookupResult.h"
|
2015-07-31 17:29:15 +03:00
|
|
|
#include "nsIConsoleService.h"
|
2015-07-23 08:39:48 +03:00
|
|
|
#include "nsIInputStream.h"
|
2015-07-31 17:29:15 +03:00
|
|
|
#include "nsIScriptError.h"
|
2015-08-14 10:37:13 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2018-05-09 16:31:07 +03:00
|
|
|
#include "nsMemory.h"
|
2013-01-11 07:38:34 +04:00
|
|
|
#include "nsPresContext.h"
|
2015-01-16 02:11:36 +03:00
|
|
|
#include "SourceBuffer.h"
|
2014-09-20 01:53:29 +04:00
|
|
|
#include "SurfaceCache.h"
|
2013-07-15 22:38:59 +04:00
|
|
|
#include "FrameAnimator.h"
|
2007-03-21 02:56:50 +03:00
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2014-04-15 22:02:23 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-01-19 01:02:13 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-01-20 02:46:55 +03:00
|
|
|
#include "mozilla/Likely.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-09-12 12:12:55 +04:00
|
|
|
#include "mozilla/Move.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-03-02 03:17:24 +04:00
|
|
|
#include "mozilla/Services.h"
|
2018-03-28 02:44:49 +03:00
|
|
|
#include "mozilla/SizeOfState.h"
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2012-01-11 12:23:07 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-08-12 09:50:33 +03:00
|
|
|
#include "mozilla/Tuple.h"
|
2012-02-10 00:04:30 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2012-04-04 01:57:22 +04:00
|
|
|
#include "mozilla/gfx/Scale.h"
|
|
|
|
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2014-09-23 01:30:20 +04:00
|
|
|
#include "gfxPrefs.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-10-04 00:36:26 +04:00
|
|
|
|
2014-07-10 19:00:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
using namespace layers;
|
|
|
|
|
|
|
|
namespace image {
|
2014-10-16 00:52:20 +04:00
|
|
|
|
2014-07-29 01:27:39 +04:00
|
|
|
using std::ceil;
|
2014-10-16 00:52:20 +04:00
|
|
|
using std::min;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifndef DEBUG
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties)
|
2010-09-08 04:34:18 +04:00
|
|
|
#else
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties,
|
|
|
|
imgIContainerDebug)
|
2010-09-08 04:34:18 +04:00
|
|
|
#endif
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2001-03-24 05:44:26 +03:00
|
|
|
//******************************************************************************
|
2018-06-06 03:42:56 +03:00
|
|
|
RasterImage::RasterImage(nsIURI* aURI /* = nullptr */) :
|
2018-04-13 16:01:28 +03:00
|
|
|
ImageResource(aURI), // invoke superclass's constructor
|
|
|
|
mSize(0,0),
|
|
|
|
mLockCount(0),
|
2018-06-14 08:21:37 +03:00
|
|
|
mDecoderType(DecoderType::UNKNOWN),
|
2018-04-13 16:01:28 +03:00
|
|
|
mDecodeCount(0),
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
2018-04-13 16:01:28 +03:00
|
|
|
mFramesNotified(0),
|
2010-09-08 04:34:18 +04:00
|
|
|
#endif
|
2018-04-13 16:01:28 +03:00
|
|
|
mSourceBuffer(MakeNotNull<SourceBuffer*>()),
|
|
|
|
mHasSize(false),
|
|
|
|
mTransient(false),
|
|
|
|
mSyncLoad(false),
|
|
|
|
mDiscardable(false),
|
|
|
|
mSomeSourceData(false),
|
|
|
|
mAllSourceData(false),
|
|
|
|
mHasBeenDecoded(false),
|
|
|
|
mPendingAnimation(false),
|
|
|
|
mAnimationFinished(false),
|
|
|
|
mWantFullDecode(false)
|
2009-09-13 02:44:18 +04:00
|
|
|
{
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2001-03-24 05:44:26 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::~RasterImage()
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2015-01-16 02:11:36 +03: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-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Release all frames from the surface cache.
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2016-05-03 19:07:45 +03:00
|
|
|
|
|
|
|
// Record Telemetry.
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_COUNT, mDecodeCount);
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
nsresult
|
2013-02-13 07:00:03 +04:00
|
|
|
RasterImage::Init(const char* aMimeType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
2009-09-13 02:44:18 +04:00
|
|
|
{
|
|
|
|
// We don't support re-initialization
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mInitialized) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// Not sure an error can happen before init, but be safe
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2001-03-10 04:11:54 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2015-07-15 04:16:31 +03:00
|
|
|
// We want to avoid redecodes for transient images.
|
2015-09-20 02:21:05 +03:00
|
|
|
MOZ_ASSERT_IF(aFlags & INIT_FLAG_TRANSIENT,
|
|
|
|
!(aFlags & INIT_FLAG_DISCARDABLE));
|
2008-01-19 11:10:26 +03:00
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
// Store initialization data
|
2010-05-26 02:27:29 +04:00
|
|
|
mDiscardable = !!(aFlags & INIT_FLAG_DISCARDABLE);
|
2015-04-08 02:44:29 +03:00
|
|
|
mWantFullDecode = !!(aFlags & INIT_FLAG_DECODE_IMMEDIATELY);
|
2015-01-07 12:37:20 +03:00
|
|
|
mTransient = !!(aFlags & INIT_FLAG_TRANSIENT);
|
2015-06-30 12:37:58 +03:00
|
|
|
mSyncLoad = !!(aFlags & INIT_FLAG_SYNC_LOAD);
|
2015-01-19 01:02:13 +03:00
|
|
|
|
2015-07-21 19:42:30 +03: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 08:39:48 +03:00
|
|
|
mDecoderType = DecoderFactory::GetDecoderType(aMimeType);
|
|
|
|
if (mDecoderType == DecoderType::UNKNOWN) {
|
2015-07-21 19:42:30 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Lock this image's surfaces in the SurfaceCache if we're not discardable.
|
|
|
|
if (!mDiscardable) {
|
2015-03-18 05:40:17 +03:00
|
|
|
mLockCount++;
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
// Mark us as initialized
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = true;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:15 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-17 02:25:43 +04:00
|
|
|
RasterImage::RequestRefresh(const TimeStamp& aTime)
|
2011-11-10 01:39:15 +04:00
|
|
|
{
|
2014-05-08 22:37:39 +04:00
|
|
|
if (HadRecentRefresh(aTime)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 00:20:15 +04:00
|
|
|
EvaluateAnimation();
|
|
|
|
|
|
|
|
if (!mAnimating) {
|
2011-11-10 01:39:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-20 04:20:13 +03:00
|
|
|
RefreshResult res;
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
|
|
|
MOZ_ASSERT(mFrameAnimator);
|
2017-03-26 08:04:53 +03:00
|
|
|
res = mFrameAnimator->RequestRefresh(*mAnimationState, aTime, mAnimationFinished);
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
|
2016-07-20 04:20:13 +03:00
|
|
|
if (res.mFrameAdvanced) {
|
2011-11-10 01:39:16 +04: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 04:20:13 +03:00
|
|
|
NotifyProgress(NoProgress, res.mDirtyRect);
|
2013-07-15 22:38:59 +04:00
|
|
|
}
|
|
|
|
|
2016-07-20 04:20:13 +03:00
|
|
|
if (res.mAnimationFinished) {
|
2013-07-15 22:38:59 +04:00
|
|
|
mAnimationFinished = true;
|
|
|
|
EvaluateAnimation();
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
2011-11-10 01:39:15 +04:00
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetWidth(int32_t* aWidth)
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2008-03-20 08:54:30 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
2002-10-08 01:49:33 +04:00
|
|
|
|
2010-10-07 02:18:52 +04:00
|
|
|
if (mError) {
|
|
|
|
*aWidth = 0;
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-07 02:18:52 +04:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
*aWidth = mSize.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetHeight(int32_t* aHeight)
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2008-03-20 08:54:30 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
2002-10-08 01:49:33 +04:00
|
|
|
|
2010-10-07 02:18:52 +04:00
|
|
|
if (mError) {
|
|
|
|
*aHeight = 0;
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-07 02:18:52 +04:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
*aHeight = mSize.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-02 03:17:24 +04:00
|
|
|
|
2017-03-22 16:05:36 +03: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 07:38:34 +04:00
|
|
|
//******************************************************************************
|
2017-09-05 14:58:44 +03:00
|
|
|
size_t
|
|
|
|
RasterImage::GetNativeSizesLength() const
|
|
|
|
{
|
|
|
|
if (mError || !mHasSize) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNativeSizes.IsEmpty()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mNativeSizes.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
2013-01-11 07:38:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::GetIntrinsicSize(nsSize* aSize)
|
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2013-01-11 07:38:34 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-01-11 07:38:34 +04:00
|
|
|
|
|
|
|
*aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(mSize.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::GetIntrinsicRatio(nsSize* aRatio)
|
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2013-01-11 07:38:34 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-01-11 07:38:34 +04:00
|
|
|
|
|
|
|
*aRatio = nsSize(mSize.width, mSize.height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2013-08-25 11:19:42 +04:00
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
RasterImage::GetOrientation()
|
|
|
|
{
|
|
|
|
return mOrientation;
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetType(uint16_t* aType)
|
2010-08-14 08:09:49 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
|
|
|
|
2015-03-19 17:12:52 +03:00
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
2010-08-14 08:09:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-01 04:57:03 +03:00
|
|
|
LookupResult
|
2016-08-18 10:06:41 +03:00
|
|
|
RasterImage::LookupFrameInternal(const IntSize& aSize,
|
|
|
|
uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType)
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2016-08-18 10:06:41 +03:00
|
|
|
if (mAnimationState && aPlaybackType == PlaybackType::eAnimated) {
|
2016-07-19 09:26:58 +03:00
|
|
|
MOZ_ASSERT(mFrameAnimator);
|
2015-08-15 03:56:44 +03:00
|
|
|
MOZ_ASSERT(ToSurfaceFlags(aFlags) == DefaultSurfaceFlags(),
|
|
|
|
"Can't composite frames with non-default surface flags");
|
2016-11-29 10:01:43 +03:00
|
|
|
return mFrameAnimator->GetCompositedFrame(*mAnimationState);
|
2015-01-07 12:40:23 +03:00
|
|
|
}
|
2014-11-27 00:22:10 +03:00
|
|
|
|
2015-10-06 03:06:34 +03:00
|
|
|
SurfaceFlags surfaceFlags = ToSurfaceFlags(aFlags);
|
2015-01-19 01:02:14 +03:00
|
|
|
|
2016-03-08 04:17:16 +03: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 03:06:34 +03:00
|
|
|
// SurfaceCache::Lookup in this case.
|
2016-03-08 04:17:16 +03:00
|
|
|
if ((aFlags & FLAG_SYNC_DECODE) || !(aFlags & FLAG_HIGH_QUALITY_SCALING)) {
|
2015-01-19 01:02:14 +03:00
|
|
|
return SurfaceCache::Lookup(ImageKey(this),
|
|
|
|
RasterSurfaceKey(aSize,
|
2015-10-06 03:06:34 +03:00
|
|
|
surfaceFlags,
|
2016-08-18 10:06:41 +03:00
|
|
|
PlaybackType::eStatic));
|
2015-01-19 01:02:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We'll return the best match we can find to the requested frame.
|
|
|
|
return SurfaceCache::LookupBestMatch(ImageKey(this),
|
|
|
|
RasterSurfaceKey(aSize,
|
2015-10-06 03:06:34 +03:00
|
|
|
surfaceFlags,
|
2016-08-18 10:06:41 +03: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 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
LookupResult
|
2016-08-18 10:06:41 +03:00
|
|
|
RasterImage::LookupFrame(const IntSize& aSize,
|
|
|
|
uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType)
|
2011-07-21 22:14:41 +04:00
|
|
|
{
|
2014-11-27 00:22:10 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-10-06 03:06:34 +03: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-19 01:02:14 +03:00
|
|
|
IntSize requestedSize = CanDownscaleDuringDecode(aSize, aFlags)
|
2015-03-29 17:59:08 +03:00
|
|
|
? aSize : mSize;
|
2015-10-30 02:37:42 +03:00
|
|
|
if (requestedSize.IsEmpty()) {
|
2017-11-17 14:45:27 +03:00
|
|
|
// Can't decode to a surface of zero size.
|
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-10-30 02:37:42 +03:00
|
|
|
}
|
2014-09-13 05:29:27 +04:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
LookupResult result =
|
|
|
|
LookupFrameInternal(requestedSize, aFlags, aPlaybackType);
|
2014-11-28 06:56:00 +03:00
|
|
|
|
2015-07-01 04:57:03 +03:00
|
|
|
if (!result && !mHasSize) {
|
2015-01-19 01:02:13 +03:00
|
|
|
// We can't request a decode without knowing our intrinsic size. Give up.
|
2017-11-17 14:45:27 +03:00
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-01-19 01:02:13 +03:00
|
|
|
}
|
|
|
|
|
2015-07-20 04:39:44 +03:00
|
|
|
if (result.Type() == MatchType::NOT_FOUND ||
|
|
|
|
result.Type() == MatchType::SUBSTITUTE_BECAUSE_NOT_FOUND ||
|
|
|
|
((aFlags & FLAG_SYNC_DECODE) && !result)) {
|
2015-07-20 04:39:40 +03:00
|
|
|
// We don't have a copy of this frame, and there's no decoder working on
|
2015-07-20 04:39:44 +03: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 10:06:41 +03:00
|
|
|
MOZ_ASSERT(aPlaybackType != PlaybackType::eAnimated ||
|
2017-03-27 08:17:52 +03:00
|
|
|
gfxPrefs::ImageMemAnimatedDiscardable() ||
|
2016-08-18 10:06:41 +03:00
|
|
|
!mAnimationState || mAnimationState->KnownFrameCount() < 1,
|
2016-07-19 09:26:58 +03:00
|
|
|
"Animated frames should be locked");
|
2014-09-27 05:50:24 +04:00
|
|
|
|
2017-09-05 14:58:45 +03: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 22:15:41 +03:00
|
|
|
bool ranSync = Decode(requestedSize, aFlags, aPlaybackType);
|
2014-09-27 05:50:24 +04:00
|
|
|
|
2016-12-22 22:15:41 +03:00
|
|
|
// If we can or did sync decode, we should already have the frame.
|
|
|
|
if (ranSync || (aFlags & FLAG_SYNC_DECODE)) {
|
2016-08-18 10:06:41 +03:00
|
|
|
result = LookupFrameInternal(requestedSize, aFlags, aPlaybackType);
|
2015-01-12 17:35:17 +03:00
|
|
|
}
|
2013-04-05 02:05:19 +04:00
|
|
|
}
|
2009-11-13 02:18:40 +03:00
|
|
|
|
2015-07-01 04:57:03 +03:00
|
|
|
if (!result) {
|
2015-01-19 01:02:14 +03:00
|
|
|
// We still weren't able to get a frame. Give up.
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2015-01-19 01:02:14 +03:00
|
|
|
}
|
|
|
|
|
2016-08-18 03:50:31 +03:00
|
|
|
if (result.Surface()->GetCompositingFailed()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
DrawableSurface tmp = std::move(result.Surface());
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2014-09-13 05:29:27 +04:00
|
|
|
}
|
2013-07-26 18:41:57 +04:00
|
|
|
|
2016-08-18 03:50:31 +03:00
|
|
|
MOZ_ASSERT(!result.Surface()->GetIsPaletted(),
|
2016-08-16 03:58:35 +03:00
|
|
|
"Should not have a paletted frame");
|
2015-01-07 12:40:23 +03:00
|
|
|
|
2015-01-12 06:28:02 +03: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 16:42:55 +03:00
|
|
|
if (mAllSourceData && (aFlags & FLAG_SYNC_DECODE)) {
|
2016-08-18 03:50:31 +03:00
|
|
|
result.Surface()->WaitUntilFinished();
|
2015-01-12 06:28:02 +03:00
|
|
|
}
|
|
|
|
|
2016-04-01 20:44:17 +03: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 03:50:31 +03:00
|
|
|
result.Surface()->IsAborted()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
DrawableSurface tmp = std::move(result.Surface());
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2016-04-01 20:44:17 +03:00
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2009-11-13 02:18:40 +03:00
|
|
|
}
|
|
|
|
|
2016-08-23 05:15:38 +03:00
|
|
|
bool
|
2014-11-25 10:42:43 +03:00
|
|
|
RasterImage::IsOpaque()
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2014-11-25 10:42:43 +03:00
|
|
|
if (mError) {
|
2013-02-05 02:22:30 +04: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 05:50:15 +04:00
|
|
|
|
2014-11-25 10:42:43 +03: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 05:50:15 +04:00
|
|
|
|
2014-11-25 10:42:43 +03:00
|
|
|
// If we haven't yet finished decoding, the safe answer is "not opaque".
|
|
|
|
if (!(progress & FLAG_DECODE_COMPLETE)) {
|
2013-02-05 02:22:30 +04:00
|
|
|
return false;
|
2014-11-25 10:42:43 +03:00
|
|
|
}
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2014-11-25 10:42:43 +03: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 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2016-08-23 05:15:38 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::WillDrawOpaqueNow()
|
|
|
|
{
|
|
|
|
if (!IsOpaque()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-06 12:00:36 +03: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 05:15:38 +03: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 04:09:44 +03:00
|
|
|
if (mLockCount == 0) {
|
2016-08-23 05:15:38 +03: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 06:55:57 +03:00
|
|
|
void
|
2017-03-16 11:06:06 +03:00
|
|
|
RasterImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey)
|
2014-11-28 06:55:57 +03:00
|
|
|
{
|
2015-02-01 02:29:48 +03:00
|
|
|
MOZ_ASSERT(mProgressTracker);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
bool animatedFramesDiscarded =
|
|
|
|
mAnimationState && aSurfaceKey.Playback() == PlaybackType::eAnimated;
|
|
|
|
|
2017-08-15 03:26:40 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> eventTarget;
|
|
|
|
if (mProgressTracker) {
|
|
|
|
eventTarget = mProgressTracker->GetEventTarget();
|
|
|
|
} else {
|
|
|
|
eventTarget = do_GetMainThread();
|
|
|
|
}
|
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
RefPtr<RasterImage> image = this;
|
2017-08-15 03:26:40 +03:00
|
|
|
nsCOMPtr<nsIRunnable> ev = NS_NewRunnableFunction(
|
2017-03-25 10:16:21 +03:00
|
|
|
"RasterImage::OnSurfaceDiscarded",
|
|
|
|
[=]() -> void {
|
|
|
|
image->OnSurfaceDiscardedInternal(animatedFramesDiscarded);
|
2017-08-15 03:26:40 +03:00
|
|
|
});
|
|
|
|
eventTarget->Dispatch(ev.forget(), NS_DISPATCH_NORMAL);
|
2017-03-25 10:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RasterImage::OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (aAnimatedFramesDiscarded && mAnimationState) {
|
2017-03-16 11:06:04 +03:00
|
|
|
MOZ_ASSERT(gfxPrefs::ImageMemAnimatedDiscardable());
|
2017-11-17 14:45:24 +03:00
|
|
|
ReleaseImageContainer();
|
2017-04-06 12:00:36 +03:00
|
|
|
gfx::IntRect rect =
|
|
|
|
mAnimationState->UpdateState(mAnimationFinished, this, mSize);
|
|
|
|
NotifyProgress(NoProgress, rect);
|
2017-03-16 11:06:04 +03:00
|
|
|
}
|
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
if (mProgressTracker) {
|
|
|
|
mProgressTracker->OnDiscard();
|
|
|
|
}
|
2014-11-28 06:55:57 +03:00
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03: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 05:50:15 +04:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04: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 05:50:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aAnimated);
|
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
// If we have an AnimationState, we can know for sure.
|
|
|
|
if (mAnimationState) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aAnimated = true;
|
2009-10-07 08:39:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we need to have been decoded to know for sure, since if we were
|
2016-07-19 09:26:58 +03: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 20:49:00 +03:00
|
|
|
if (!mHasBeenDecoded) {
|
2009-10-07 08:39:30 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-10-07 08:39:30 +04:00
|
|
|
|
|
|
|
// We know for sure
|
2011-10-17 18:59:28 +04:00
|
|
|
*aAnimated = false;
|
2009-10-07 08:39:30 +04: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 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-17 21:42:20 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(int32_t)
|
|
|
|
RasterImage::GetFirstFrameDelay()
|
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2013-05-17 21:42:20 +04:00
|
|
|
return -1;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-05-17 21:42:20 +04:00
|
|
|
|
|
|
|
bool animated = false;
|
2015-03-31 20:49:00 +03:00
|
|
|
if (NS_FAILED(GetAnimated(&animated)) || !animated) {
|
2013-05-17 21:42:20 +04:00
|
|
|
return -1;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-05-17 21:42:20 +04:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
MOZ_ASSERT(mAnimationState, "Animated images should have an AnimationState");
|
2016-07-19 23:51:01 +03:00
|
|
|
return mAnimationState->FirstFrameTimeout().AsEncodedValueDeprecated();
|
2013-05-17 21:42:20 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
2012-08-22 19:56:38 +04:00
|
|
|
RasterImage::GetFrame(uint32_t aWhichFrame,
|
2013-12-13 12:34:24 +04:00
|
|
|
uint32_t aFlags)
|
2014-09-27 05:50:24 +04:00
|
|
|
{
|
2017-02-08 23:48:59 +03:00
|
|
|
return GetFrameAtSize(mSize, aWhichFrame, aFlags);
|
2015-09-19 23:34:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
|
|
RasterImage::GetFrameAtSize(const IntSize& aSize,
|
|
|
|
uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-08-02 01:08:02 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
NotifyDrawingObservers();
|
|
|
|
#endif
|
|
|
|
|
2017-11-17 22:08:52 +03:00
|
|
|
auto result = GetFrameInternal(aSize, Nothing(), aWhichFrame, aFlags);
|
2018-02-12 15:59:58 +03:00
|
|
|
return mozilla::Get<2>(result).forget();
|
2014-09-27 05:50:24 +04:00
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
Tuple<ImgDrawResult, IntSize, RefPtr<SourceSurface>>
|
2015-09-19 23:34:09 +03:00
|
|
|
RasterImage::GetFrameInternal(const IntSize& aSize,
|
2017-11-17 22:08:52 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2015-09-19 23:34:09 +03: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 05:50:15 +04:00
|
|
|
{
|
2013-12-13 12:34:24 +04:00
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
if (aSize.IsEmpty() || aWhichFrame > FRAME_MAX_VALUE) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return MakeTuple(ImgDrawResult::BAD_ARGS, aSize,
|
2017-11-17 14:45:27 +03:00
|
|
|
RefPtr<SourceSurface>());
|
2015-03-18 05:40:16 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
if (mError) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return MakeTuple(ImgDrawResult::BAD_IMAGE, aSize,
|
2017-11-17 14:45:27 +03:00
|
|
|
RefPtr<SourceSurface>());
|
2015-03-18 05:40:16 +03: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 05:50:15 +04:00
|
|
|
|
2009-09-13 02:44:18 +04: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 10:06:41 +03:00
|
|
|
// FLAG_SYNC_DECODE.
|
2017-11-17 14:45:27 +03:00
|
|
|
LookupResult result =
|
2016-08-18 10:06:41 +03:00
|
|
|
LookupFrame(aSize, aFlags, ToPlaybackType(aWhichFrame));
|
2017-11-17 14:45:27 +03: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 05:50:24 +04:00
|
|
|
// The OS threw this frame away and we couldn't redecode it.
|
2017-12-11 18:37:59 +03:00
|
|
|
return MakeTuple(ImgDrawResult::TEMPORARY_ERROR, suggestedSize,
|
2017-11-17 14:45:27 +03:00
|
|
|
RefPtr<SourceSurface>());
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
RefPtr<SourceSurface> surface = result.Surface()->GetSourceSurface();
|
|
|
|
if (!result.Surface()->IsFinished()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
return MakeTuple(ImgDrawResult::INCOMPLETE, suggestedSize, std::move(surface));
|
2015-03-18 05:40:16 +03:00
|
|
|
}
|
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
return MakeTuple(ImgDrawResult::SUCCESS, suggestedSize, std::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 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2018-08-14 19:03:18 +03:00
|
|
|
IntSize
|
2017-11-17 14:45:26 +03:00
|
|
|
RasterImage::GetImageContainerSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2018-08-14 19:03:18 +03:00
|
|
|
if (!IsImageContainerAvailableAtSize(aManager, aSize, aFlags)) {
|
|
|
|
return IntSize(0, 0);
|
2017-11-17 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!CanDownscaleDuringDecode(aSize, aFlags)) {
|
2018-08-14 19:03:18 +03:00
|
|
|
return mSize;
|
2017-11-17 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
2018-08-14 19:03:18 +03:00
|
|
|
return aSize;
|
2017-11-17 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 10:23:44 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
|
|
{
|
2017-11-17 14:45:26 +03:00
|
|
|
return IsImageContainerAvailableAtSize(aManager, mSize, aFlags);
|
2015-05-13 10:23:44 +03:00
|
|
|
}
|
2012-09-25 00:31:30 +04:00
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
RasterImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
2012-09-25 00:31:30 +04:00
|
|
|
{
|
2018-08-14 19:03:18 +03:00
|
|
|
return GetImageContainerImpl(aManager, mSize, Nothing(), aFlags);
|
2012-09-25 00:31:30 +04:00
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:26 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2017-11-17 14:45:26 +03: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 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
2018-08-14 19:03:18 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
RasterImage::GetImageContainerAtSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
2017-11-17 22:08:52 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2018-08-14 19:03:18 +03:00
|
|
|
uint32_t aFlags)
|
2017-11-17 14:45:26 +03:00
|
|
|
{
|
2017-12-01 14:59:21 +03: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.
|
2018-08-14 19:03:18 +03:00
|
|
|
return GetImageContainerImpl(aManager, aSize, Nothing(), aFlags);
|
2017-11-17 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
2012-02-20 07:51:48 +04:00
|
|
|
size_t
|
2017-07-28 13:10:04 +03:00
|
|
|
RasterImage::SizeOfSourceWithComputedFallback(SizeOfState& aState) const
|
2012-02-20 07:51:48 +04:00
|
|
|
{
|
2017-07-28 13:10:04 +03:00
|
|
|
return mSourceBuffer->SizeOfIncludingThisWithComputedFallback(
|
|
|
|
aState.mMallocSizeOf);
|
2012-02-20 07:51:48 +04:00
|
|
|
}
|
2011-07-18 17:20:27 +04:00
|
|
|
|
2015-04-28 21:46:17 +03:00
|
|
|
void
|
|
|
|
RasterImage::CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const
|
2010-05-22 08:10:14 +04:00
|
|
|
{
|
2015-04-28 21:46:17 +03:00
|
|
|
SurfaceCache::CollectSizeOfSurfaces(ImageKey(this), aCounters, aMallocSizeOf);
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mFrameAnimator) {
|
|
|
|
mFrameAnimator->CollectSizeOfCompositingSurfaces(aCounters, aMallocSizeOf);
|
2014-11-27 00:22:11 +03:00
|
|
|
}
|
2011-07-18 17:20:27 +04:00
|
|
|
}
|
|
|
|
|
2015-09-24 02:53:40 +03:00
|
|
|
bool
|
2015-08-14 10:37:13 +03:00
|
|
|
RasterImage::SetMetadata(const ImageMetadata& aMetadata,
|
|
|
|
bool aFromMetadataDecode)
|
2009-09-13 02:44:18 +04:00
|
|
|
{
|
2013-03-02 03:17:24 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2015-09-24 02:53:40 +03:00
|
|
|
return true;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
if (aMetadata.HasSize()) {
|
|
|
|
IntSize size = aMetadata.GetSize();
|
|
|
|
if (size.width < 0 || size.height < 0) {
|
2015-08-18 20:19:28 +03:00
|
|
|
NS_WARNING("Image has negative intrinsic size");
|
|
|
|
DoError();
|
2015-09-24 02:53:40 +03:00
|
|
|
return true;
|
2015-08-14 10:37:13 +03: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-24 02:53:40 +03:00
|
|
|
return true;
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the size and flag that we have it.
|
|
|
|
mSize = size;
|
|
|
|
mOrientation = orientation;
|
2017-03-22 16:05:36 +03:00
|
|
|
mNativeSizes = aMetadata.GetNativeSizes();
|
2015-08-14 10:37:13 +03:00
|
|
|
mHasSize = true;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mHasSize && aMetadata.HasAnimation() && !mAnimationState) {
|
2015-08-14 10:37:13 +03:00
|
|
|
// We're becoming animated, so initialize animation stuff.
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState.emplace(mAnimationMode);
|
|
|
|
mFrameAnimator = MakeUnique<FrameAnimator>(this, mSize);
|
2015-08-14 10:37:13 +03:00
|
|
|
|
2017-03-27 08:17:52 +03: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 10:37:13 +03: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-24 02:53:40 +03:00
|
|
|
return false;
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
|
|
|
mAnimationState->SetLoopCount(aMetadata.GetLoopCount());
|
|
|
|
mAnimationState->SetFirstFrameTimeout(aMetadata.GetFirstFrameTimeout());
|
2016-07-20 03:14:30 +03:00
|
|
|
|
|
|
|
if (aMetadata.HasLoopLength()) {
|
|
|
|
mAnimationState->SetLoopLength(aMetadata.GetLoopLength());
|
|
|
|
}
|
2016-07-20 09:35:41 +03:00
|
|
|
if (aMetadata.HasFirstFrameRefreshArea()) {
|
|
|
|
mAnimationState
|
|
|
|
->SetFirstFrameRefreshArea(aMetadata.GetFirstFrameRefreshArea());
|
|
|
|
}
|
2015-08-14 10:37:13 +03: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-24 02:53:40 +03:00
|
|
|
|
|
|
|
return true;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 22:38:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::SetAnimationMode(uint16_t aAnimationMode)
|
|
|
|
{
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
|
|
|
mAnimationState->SetAnimationMode(aAnimationMode);
|
2013-07-15 22:38:59 +04:00
|
|
|
}
|
|
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2001-04-26 11:11:52 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
nsresult
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::StartAnimation()
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(ShouldAnimate(), "Should not animate!");
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2015-08-14 10:37:13 +03: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 03:12:25 +03:00
|
|
|
mPendingAnimation = !mAnimationState || mAnimationState->KnownFrameCount() < 1;
|
2014-11-27 00:22:10 +03:00
|
|
|
if (mPendingAnimation) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2016-07-20 02:22:34 +03:00
|
|
|
// Don't bother to animate if we're displaying the first frame forever.
|
2016-08-18 10:06:41 +03:00
|
|
|
if (mAnimationState->GetCurrentAnimationFrameIndex() == 0 &&
|
2016-07-19 23:51:01 +03:00
|
|
|
mAnimationState->FirstFrameTimeout() == FrameTimeout::Forever()) {
|
2013-09-20 16:12:10 +04:00
|
|
|
mAnimationFinished = true;
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
|
2015-01-08 00:07:23 +03:00
|
|
|
// We need to set the time that this initial frame was first displayed, as
|
|
|
|
// this is used in AdvanceFrame().
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState->InitAnimationFrameTimeIfNecessary();
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-09-08 04:33:02 +04:00
|
|
|
nsresult
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::StopAnimation()
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mAnimating, "Should be animating!");
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2013-09-20 16:12:10 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mError) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState->SetAnimationFrameTime(TimeStamp());
|
2013-09-20 16:12:10 +04:00
|
|
|
}
|
2013-09-04 00:20:15 +04:00
|
|
|
|
2013-09-20 16:12:10 +04:00
|
|
|
mAnimating = false;
|
|
|
|
return rv;
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2007-03-21 02:56:50 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::ResetAnimation()
|
2007-03-21 02:56:50 +03:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
mPendingAnimation = false;
|
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationMode == kDontAnimMode || !mAnimationState ||
|
|
|
|
mAnimationState->GetCurrentAnimationFrameIndex() == 0) {
|
2007-03-21 02:56:50 +03:00
|
|
|
return NS_OK;
|
2014-11-27 00:22:10 +03:00
|
|
|
}
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mAnimationFinished = false;
|
2011-04-01 01:05:31 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mAnimating) {
|
2010-09-08 04:33:02 +04:00
|
|
|
StopAnimation();
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
MOZ_ASSERT(mAnimationState, "Should have AnimationState");
|
2018-02-28 21:34:52 +03:00
|
|
|
MOZ_ASSERT(mFrameAnimator, "Should have FrameAnimator");
|
|
|
|
mFrameAnimator->ResetAnimation(*mAnimationState);
|
2013-06-18 00:49:04 +04:00
|
|
|
|
2016-07-20 09:35:41 +03:00
|
|
|
NotifyProgress(NoProgress, mAnimationState->FirstFrameRefreshArea());
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2013-09-20 16:12:10 +04:00
|
|
|
// Start the animation again. It may not have been running before, if
|
|
|
|
// mAnimationFinished was true before entering this function.
|
|
|
|
EvaluateAnimation();
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2008-03-20 08:54:30 +03:00
|
|
|
return NS_OK;
|
2007-03-21 02:56:50 +03:00
|
|
|
}
|
|
|
|
|
2013-05-18 00:57:20 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-17 02:25:43 +04:00
|
|
|
RasterImage::SetAnimationStartTime(const TimeStamp& aTime)
|
2013-05-18 00:57:20 +04:00
|
|
|
{
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mError || mAnimationMode == kDontAnimMode || mAnimating || !mAnimationState) {
|
2013-05-18 00:57:20 +04:00
|
|
|
return;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-05-18 00:57:20 +04:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState->SetAnimationFrameTime(aTime);
|
2013-05-18 00:57:20 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:20 +04:00
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
RasterImage::GetFrameIndex(uint32_t aWhichFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
|
2016-07-19 09:26:58 +03:00
|
|
|
return (aWhichFrame == FRAME_FIRST || !mAnimationState)
|
2013-04-26 02:58:20 +04:00
|
|
|
? 0.0f
|
2016-07-19 09:26:58 +03:00
|
|
|
: mAnimationState->GetCurrentAnimationFrameIndex();
|
2013-04-26 02:58:20 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
NS_IMETHODIMP_(IntRect)
|
|
|
|
RasterImage::GetImageSpaceInvalidationRect(const IntRect& aRect)
|
2014-06-27 03:02:04 +04:00
|
|
|
{
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
nsresult
|
2015-01-16 02:11:36 +03:00
|
|
|
RasterImage::OnImageDataComplete(nsIRequest*, nsISupports*, nsresult aStatus,
|
|
|
|
bool aLastPart)
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2013-03-02 03:17:24 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Record that we have all the data we're going to get now.
|
2016-11-28 16:42:55 +03:00
|
|
|
mAllSourceData = true;
|
2013-02-14 06:41:10 +04:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Let decoders know that there won't be any more data coming.
|
|
|
|
mSourceBuffer->Complete(aStatus);
|
2015-01-11 22:43:32 +03:00
|
|
|
|
2015-07-23 08:39:51 +03: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-09 01:52:51 +03:00
|
|
|
|
2015-07-23 08:39:51 +03:00
|
|
|
if (canSyncDecodeMetadata && !mHasSize) {
|
2015-06-30 12:37:58 +03: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 08:39:51 +03:00
|
|
|
// synchronous metadata decode here.
|
|
|
|
DecodeMetadata(FLAG_SYNC_DECODE);
|
2015-01-11 22:43:32 +03:00
|
|
|
}
|
2015-01-11 16:34:20 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Determine our final status, giving precedence to Necko failure codes. We
|
2015-07-23 08:39:51 +03:00
|
|
|
// check after running the metadata decode in case it triggered an error.
|
2015-01-16 02:11:36 +03:00
|
|
|
nsresult finalStatus = mError ? NS_ERROR_FAILURE : NS_OK;
|
|
|
|
if (NS_FAILED(aStatus)) {
|
2015-01-12 21:17:52 +03:00
|
|
|
finalStatus = aStatus;
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
2015-01-12 21:17:52 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// If loading failed, report an error.
|
|
|
|
if (NS_FAILED(finalStatus)) {
|
|
|
|
DoError();
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
2015-01-12 12:20:23 +03:00
|
|
|
|
2015-06-30 12:37:58 +03: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 08:39:51 +03:00
|
|
|
MOZ_ASSERT(!canSyncDecodeMetadata,
|
|
|
|
"Firing load async after metadata sync decode?");
|
2015-06-30 12:37:58 +03:00
|
|
|
mLoadProgress = Some(loadProgress);
|
|
|
|
return finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyForLoadEvent(loadProgress);
|
|
|
|
|
|
|
|
return finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RasterImage::NotifyForLoadEvent(Progress aProgress)
|
|
|
|
{
|
2015-01-16 02:11:36 +03: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-20 02:46:55 +03:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
// If we encountered an error, make sure we notify for that as well.
|
|
|
|
if (mError) {
|
|
|
|
aProgress |= FLAG_HAS_ERROR;
|
|
|
|
}
|
2015-06-26 05:57:00 +03:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
// Notify our listeners, which will fire this image's load event.
|
|
|
|
NotifyProgress(aProgress);
|
2013-02-14 06:41:10 +04:00
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
nsresult
|
2012-12-18 02:05:18 +04:00
|
|
|
RasterImage::OnImageDataAvailable(nsIRequest*,
|
|
|
|
nsISupports*,
|
2015-08-01 04:10:29 +03:00
|
|
|
nsIInputStream* aInputStream,
|
|
|
|
uint64_t,
|
2012-12-18 02:05:18 +04:00
|
|
|
uint32_t aCount)
|
|
|
|
{
|
2015-08-01 04:10:29 +03:00
|
|
|
nsresult rv = mSourceBuffer->AppendFromInputStream(aInputStream, aCount);
|
2016-11-28 16:42:55 +03: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 17:09:35 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2015-08-01 04:10:29 +03:00
|
|
|
DoError();
|
|
|
|
}
|
2012-12-18 02:05:18 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
nsresult
|
2015-01-16 02:11:36 +03:00
|
|
|
RasterImage::SetSourceSizeHint(uint32_t aSizeHint)
|
2010-06-25 22:21:40 +04:00
|
|
|
{
|
2018-05-09 16:31:07 +03:00
|
|
|
if (aSizeHint == 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mSourceBuffer->ExpectLength(aSizeHint);
|
|
|
|
if (rv == NS_ERROR_OUT_OF_MEMORY) {
|
|
|
|
// Flush memory, try to get some back, and try again.
|
|
|
|
rv = nsMemory::HeapMinimize(true);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mSourceBuffer->ExpectLength(aSizeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2010-06-25 22:21:40 +04:00
|
|
|
}
|
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
/********* Methods to implement lazy allocation of nsIProperties object *******/
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::Get(const char* prop, const nsIID& iid, void** result)
|
2007-06-22 00:45:49 +04:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (!mProperties) {
|
2007-06-22 00:45:49 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2007-06-22 00:45:49 +04:00
|
|
|
return mProperties->Get(prop, iid, result);
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::Set(const char* prop, nsISupports* value)
|
2007-06-22 00:45:49 +04:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (!mProperties) {
|
2007-06-22 00:45:49 +04:00
|
|
|
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
|
|
|
if (!mProperties) {
|
2007-06-22 00:45:49 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2007-06-22 00:45:49 +04:00
|
|
|
return mProperties->Set(prop, value);
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::Has(const char* prop, bool* _retval)
|
2007-06-22 00:45:49 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
|
|
if (!mProperties) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2007-06-22 00:45:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mProperties->Has(prop, _retval);
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::Undefine(const char* prop)
|
2007-06-22 00:45:49 +04:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (!mProperties) {
|
2007-06-22 00:45:49 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2007-06-22 00:45:49 +04:00
|
|
|
return mProperties->Undefine(prop);
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetKeys(uint32_t* count, char*** keys)
|
2007-06-22 00:45:49 +04:00
|
|
|
{
|
|
|
|
if (!mProperties) {
|
|
|
|
*count = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
*keys = nullptr;
|
2007-06-22 00:45:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return mProperties->GetKeys(count, keys);
|
|
|
|
}
|
2007-10-19 04:36:34 +04:00
|
|
|
|
|
|
|
void
|
2014-11-28 06:56:00 +03:00
|
|
|
RasterImage::Discard()
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2013-03-02 03:17:24 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-11-28 06:55:57 +03:00
|
|
|
MOZ_ASSERT(CanDiscard(), "Asked to discard but can't");
|
2017-03-27 08:17:52 +03:00
|
|
|
MOZ_ASSERT(!mAnimationState || gfxPrefs::ImageMemAnimatedDiscardable(),
|
|
|
|
"Asked to discard for animated image");
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2015-01-08 00:07:23 +03:00
|
|
|
// Delete all the decoded frames.
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2017-03-16 11:06:04 +03:00
|
|
|
if (mAnimationState) {
|
2017-11-17 14:45:24 +03:00
|
|
|
ReleaseImageContainer();
|
2017-04-06 12:00:36 +03:00
|
|
|
gfx::IntRect rect =
|
|
|
|
mAnimationState->UpdateState(mAnimationFinished, this, mSize);
|
|
|
|
NotifyProgress(NoProgress, rect);
|
2017-03-16 11:06:04 +03:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Notify that we discarded.
|
2014-11-28 06:56:00 +03:00
|
|
|
if (mProgressTracker) {
|
2014-11-15 07:10:47 +03:00
|
|
|
mProgressTracker->OnDiscard();
|
2014-11-27 00:22:10 +03:00
|
|
|
}
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2011-08-05 17:57:16 +04:00
|
|
|
bool
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::CanDiscard() {
|
2017-03-27 08:17:52 +03:00
|
|
|
return mAllSourceData &&
|
|
|
|
// Can discard animated images if the pref is set
|
|
|
|
(!mAnimationState || gfxPrefs::ImageMemAnimatedDiscardable());
|
2014-01-22 03:19:22 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 08:57:43 +03:00
|
|
|
NS_IMETHODIMP
|
2016-11-26 10:56:26 +03:00
|
|
|
RasterImage::StartDecoding(uint32_t aFlags)
|
2015-10-29 08:57:43 +03:00
|
|
|
{
|
2015-10-30 02:37:42 +03:00
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHasSize) {
|
|
|
|
mWantFullDecode = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-26 10:56:26 +03:00
|
|
|
uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST;
|
|
|
|
return RequestDecodeForSize(mSize, flags);
|
2015-01-19 01:02:13 +03:00
|
|
|
}
|
|
|
|
|
2016-12-23 10:07:45 +03: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-19 01:02:13 +03:00
|
|
|
NS_IMETHODIMP
|
2015-04-21 18:04:57 +03:00
|
|
|
RasterImage::RequestDecodeForSize(const IntSize& aSize, uint32_t aFlags)
|
2015-01-19 01:02:13 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (mError) {
|
2015-01-12 12:20:23 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
2015-01-19 01:02:13 +03:00
|
|
|
|
2016-12-23 10:07:45 +03: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-16 02:11:36 +03:00
|
|
|
if (!mHasSize) {
|
2016-12-02 00:52:06 +03:00
|
|
|
mWantFullDecode = true;
|
2016-12-23 10:07:45 +03:00
|
|
|
return DrawableSurface();
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2015-02-03 08:40:35 +03: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-19 01:02:13 +03:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
// Perform a frame lookup, which will implicitly start decoding if needed.
|
2017-11-17 14:45:27 +03:00
|
|
|
PlaybackType playbackType = mAnimationState ? PlaybackType::eAnimated
|
|
|
|
: PlaybackType::eStatic;
|
|
|
|
LookupResult result = LookupFrame(aSize, flags, playbackType);
|
2018-05-30 22:15:35 +03:00
|
|
|
return std::move(result.Surface());
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2016-12-22 22:15:41 +03:00
|
|
|
static bool
|
2016-06-29 23:43:19 +03:00
|
|
|
LaunchDecodingTask(IDecodingTask* aTask,
|
|
|
|
RasterImage* aImage,
|
|
|
|
uint32_t aFlags,
|
|
|
|
bool aHaveSourceData)
|
2015-07-23 08:39:51 +03:00
|
|
|
{
|
|
|
|
if (aHaveSourceData) {
|
2017-03-23 02:37:33 +03:00
|
|
|
nsCString uri(aImage->GetURIString());
|
|
|
|
|
2015-07-23 08:39:51 +03: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 10:08:53 +03:00
|
|
|
DecodePool::Singleton()->SyncRunIfPossible(aTask, uri);
|
2016-12-22 22:15:41 +03:00
|
|
|
return true;
|
2015-07-23 08:39:51 +03: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 10:08:53 +03:00
|
|
|
return DecodePool::Singleton()->SyncRunIfPreferred(aTask, uri);
|
2015-07-23 08:39:51 +03: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 23:43:19 +03:00
|
|
|
DecodePool::Singleton()->AsyncRun(aTask);
|
2016-12-22 22:15:41 +03:00
|
|
|
return false;
|
2015-07-23 08:39:51 +03:00
|
|
|
}
|
|
|
|
|
2016-12-22 22:15:41 +03:00
|
|
|
bool
|
2016-08-18 10:06:41 +03:00
|
|
|
RasterImage::Decode(const IntSize& aSize,
|
|
|
|
uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType)
|
2015-01-16 02:11:36 +03:00
|
|
|
{
|
2015-07-23 08:39:51 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 21:17:52 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (mError) {
|
2016-12-22 22:15:41 +03:00
|
|
|
return false;
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// If we don't have a size yet, we can't do any other decoding.
|
2015-07-23 08:39:51 +03:00
|
|
|
if (!mHasSize) {
|
2015-01-16 02:11:36 +03:00
|
|
|
mWantFullDecode = true;
|
2016-12-22 22:15:41 +03:00
|
|
|
return false;
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2015-09-20 02:21:05 +03: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 08:33:58 +03:00
|
|
|
SurfaceCache::UnlockEntries(ImageKey(this));
|
2015-07-23 08:39:51 +03:00
|
|
|
|
2015-08-15 03:56:44 +03: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 14:58:45 +03: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 03:56:44 +03:00
|
|
|
|
2015-10-06 03:06:34 +03: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 23:56:49 +03:00
|
|
|
// Create a decoder.
|
2016-06-26 10:09:24 +03:00
|
|
|
RefPtr<IDecodingTask> task;
|
2018-02-09 16:51:28 +03:00
|
|
|
nsresult rv;
|
|
|
|
bool animated = mAnimationState && aPlaybackType == PlaybackType::eAnimated;
|
|
|
|
if (animated) {
|
2018-02-28 21:34:52 +03:00
|
|
|
size_t currentFrame = mAnimationState->GetCurrentAnimationFrameIndex();
|
2018-02-09 16:51:28 +03:00
|
|
|
rv = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this),
|
|
|
|
mSourceBuffer, mSize,
|
|
|
|
decoderFlags, surfaceFlags,
|
2018-02-28 21:34:52 +03:00
|
|
|
currentFrame,
|
2018-02-09 16:51:28 +03: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 10:19:55 +03: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 05:20:35 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
gfx::IntRect rect =
|
|
|
|
#endif
|
2017-06-01 10:19:55 +03:00
|
|
|
mAnimationState->UpdateState(mAnimationFinished, this, mSize, false);
|
2017-05-04 05:20:35 +03:00
|
|
|
MOZ_ASSERT(rect.IsEmpty());
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
2015-07-23 08:39:51 +03:00
|
|
|
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
2018-02-09 16:51:28 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(!task);
|
2016-12-22 22:15:41 +03:00
|
|
|
return false;
|
2015-03-17 23:56:49 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:51:28 +03:00
|
|
|
MOZ_ASSERT(task);
|
2015-07-23 08:39:51 +03:00
|
|
|
mDecodeCount++;
|
2015-01-12 21:17:52 +03:00
|
|
|
|
2015-07-23 08:39:51 +03:00
|
|
|
// We're ready to decode; start the decoder.
|
2016-11-28 16:42:55 +03:00
|
|
|
return LaunchDecodingTask(task, this, aFlags, mAllSourceData);
|
2015-07-23 08:39:51 +03: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 10:09:24 +03:00
|
|
|
RefPtr<IDecodingTask> task =
|
2016-06-27 07:50:43 +03:00
|
|
|
DecoderFactory::CreateMetadataDecoder(mDecoderType, WrapNotNull(this),
|
2016-10-19 03:05:29 +03:00
|
|
|
mSourceBuffer);
|
2015-07-23 08:39:51 +03:00
|
|
|
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
2016-06-26 10:09:24 +03:00
|
|
|
if (!task) {
|
2015-07-23 08:39:51 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're ready to decode; start the decoder.
|
2016-11-28 16:42:55 +03:00
|
|
|
LaunchDecodingTask(task, this, aFlags, mAllSourceData);
|
2015-01-16 02:11:36 +03:00
|
|
|
return NS_OK;
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2015-02-04 03:38:36 +03:00
|
|
|
void
|
2015-08-18 20:19:14 +03:00
|
|
|
RasterImage::RecoverFromInvalidFrames(const IntSize& aSize, uint32_t aFlags)
|
2015-02-04 03:38:36 +03:00
|
|
|
{
|
|
|
|
if (!mHasSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-18 20:19:14 +03:00
|
|
|
NS_WARNING("A RasterImage's frames became invalid. Attempting to recover...");
|
2015-02-04 03:38:36 +03:00
|
|
|
|
|
|
|
// Discard all existing frames, since they're probably all now invalid.
|
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
|
2015-08-14 06:39:54 +03:00
|
|
|
// Relock the image if it's supposed to be locked.
|
|
|
|
if (mLockCount > 0) {
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2015-02-04 03:38:36 +03:00
|
|
|
// Animated images require some special handling, because we normally require
|
|
|
|
// that they never be discarded.
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
2016-08-18 10:06:41 +03:00
|
|
|
Decode(mSize, aFlags | FLAG_SYNC_DECODE, PlaybackType::eAnimated);
|
2015-02-04 03:38:36 +03:00
|
|
|
ResetAnimation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For non-animated images, it's fine to recover using an async decode.
|
2016-08-18 10:06:41 +03:00
|
|
|
Decode(aSize, aFlags, PlaybackType::eStatic);
|
2015-02-04 03:38:36 +03:00
|
|
|
}
|
|
|
|
|
2015-09-20 02:21:05 +03:00
|
|
|
static bool
|
|
|
|
HaveSkia()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_ENABLE_SKIA
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-01-19 01:02:14 +03:00
|
|
|
bool
|
2015-04-21 18:04:57 +03:00
|
|
|
RasterImage::CanDownscaleDuringDecode(const IntSize& aSize, uint32_t aFlags)
|
2015-01-19 01:02:14 +03:00
|
|
|
{
|
2015-09-20 02:21:05 +03: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-20 02:20:56 +03:00
|
|
|
!gfxPrefs::ImageDownscaleDuringDecodeEnabled() ||
|
2015-01-19 01:02:14 +03:00
|
|
|
!(aFlags & imgIContainer::FLAG_HIGH_QUALITY_SCALING)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't downscale animated images during decode.
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
2015-01-19 01:02:14 +03: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 17:59:08 +03:00
|
|
|
if (!SurfaceCache::CanHold(aSize)) {
|
2015-01-19 01:02:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult
|
2016-08-18 03:50:31 +03:00
|
|
|
RasterImage::DrawInternal(DrawableSurface&& aSurface,
|
2015-09-20 02:20:56 +03:00
|
|
|
gfxContext* aContext,
|
|
|
|
const IntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags,
|
|
|
|
float aOpacity)
|
2015-09-20 02:20:56 +03:00
|
|
|
{
|
2014-09-13 05:29:27 +04:00
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
2014-08-23 00:12:38 +04:00
|
|
|
ImageRegion region(aRegion);
|
2016-08-18 03:50:31 +03:00
|
|
|
bool frameIsFinished = aSurface->IsFinished();
|
2014-08-23 00:12:38 +04:00
|
|
|
|
2017-06-15 01:11:48 +03:00
|
|
|
#ifdef DEBUG
|
2017-08-02 01:08:02 +03:00
|
|
|
NotifyDrawingObservers();
|
2017-06-15 01:11:48 +03:00
|
|
|
#endif
|
|
|
|
|
2014-08-23 00:12:38 +04: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 03:50:31 +03:00
|
|
|
IntSize finalSize = aSurface->GetImageSize();
|
2015-02-05 00:50:56 +03:00
|
|
|
bool couldRedecodeForBetterFrame = false;
|
2015-03-29 17:59:15 +03:00
|
|
|
if (finalSize != aSize) {
|
2014-11-27 00:22:10 +03:00
|
|
|
gfx::Size scale(double(aSize.width) / finalSize.width,
|
|
|
|
double(aSize.height) / finalSize.height);
|
2014-08-23 00:12:38 +04:00
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
|
|
|
|
region.Scale(1.0 / scale.width, 1.0 / scale.height);
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2015-09-20 02:21:05 +03:00
|
|
|
couldRedecodeForBetterFrame = CanDownscaleDuringDecode(aSize, aFlags);
|
2014-08-23 00:12:38 +04:00
|
|
|
}
|
|
|
|
|
2017-01-03 08:53:22 +03:00
|
|
|
if (!aSurface->Draw(aContext, region, aSamplingFilter, aFlags, aOpacity)) {
|
2015-08-18 20:19:14 +03:00
|
|
|
RecoverFromInvalidFrames(aSize, aFlags);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2016-03-24 03:31:42 +03:00
|
|
|
if (!frameIsFinished) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::INCOMPLETE;
|
2015-02-04 03:38:36 +03:00
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
if (couldRedecodeForBetterFrame) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::WRONG_SIZE;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2012-04-04 01:57:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
//******************************************************************************
|
2017-12-11 18:37:59 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2014-08-23 00:12:38 +04:00
|
|
|
RasterImage::Draw(gfxContext* aContext,
|
2015-04-21 18:04:57 +03:00
|
|
|
const IntSize& aSize,
|
2014-08-23 00:12:38 +04:00
|
|
|
const ImageRegion& aRegion,
|
2013-03-11 05:43:37 +04:00
|
|
|
uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2014-08-23 00:12:38 +04:00
|
|
|
const Maybe<SVGImageContext>& /*aSVGContext - ignored*/,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags,
|
|
|
|
float aOpacity)
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2015-03-31 20:49:00 +03:00
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-03-11 05:43:37 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_IMAGE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2011-01-13 04:45:13 +03: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 03:56:44 +03:00
|
|
|
if (ToSurfaceFlags(aFlags) != DefaultSurfaceFlags()) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2011-01-13 04:45:13 +03:00
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
if (!aContext) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2017-06-30 04:09:44 +03:00
|
|
|
if (mAnimationConsumers == 0) {
|
2016-11-17 09:25:53 +03:00
|
|
|
SendOnUnlockedDraw(aFlags);
|
2013-02-25 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
2016-11-17 09:25:53 +03:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
// If we're not using SamplingFilter::GOOD, we shouldn't high-quality scale or
|
2015-10-06 03:12:46 +03:00
|
|
|
// downscale during decode.
|
2016-05-25 19:01:18 +03:00
|
|
|
uint32_t flags = aSamplingFilter == SamplingFilter::GOOD
|
2015-01-19 01:02:14 +03:00
|
|
|
? aFlags
|
|
|
|
: aFlags & ~FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
LookupResult result =
|
2016-08-18 10:06:41 +03:00
|
|
|
LookupFrame(aSize, flags, ToPlaybackType(aWhichFrame));
|
2017-11-17 14:45:27 +03:00
|
|
|
if (!result) {
|
2014-11-27 00:22:10 +03:00
|
|
|
// Getting the frame (above) touches the image and kicks off decoding.
|
2015-01-16 02:11:36 +03:00
|
|
|
if (mDrawStartTime.IsNull()) {
|
|
|
|
mDrawStartTime = TimeStamp::Now();
|
|
|
|
}
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::NOT_READY;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
bool shouldRecordTelemetry = !mDrawStartTime.IsNull() &&
|
2017-11-17 14:45:27 +03:00
|
|
|
result.Surface()->IsFinished();
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
auto drawResult = DrawInternal(std::move(result.Surface()), aContext, aSize,
|
2017-11-17 14:45:27 +03:00
|
|
|
aRegion, aSamplingFilter, flags, aOpacity);
|
2014-02-25 07:37:51 +04:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (shouldRecordTelemetry) {
|
2011-08-11 03:12:08 +04:00
|
|
|
TimeDuration drawLatency = TimeStamp::Now() - mDrawStartTime;
|
2015-01-16 02:11:36 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_ON_DRAW_LATENCY,
|
|
|
|
int32_t(drawLatency.ToMicroseconds()));
|
2011-08-11 03:12:08 +04:00
|
|
|
mDrawStartTime = TimeStamp();
|
|
|
|
}
|
2012-04-04 01:57:22 +04:00
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
return drawResult;
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
NS_IMETHODIMP
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::LockImage()
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2013-09-28 22:28:43 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Main thread to encourage serialization with UnlockImage");
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// Increment the lock count
|
|
|
|
mLockCount++;
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Lock this image's surfaces in the SurfaceCache.
|
|
|
|
if (mLockCount == 1) {
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
NS_IMETHODIMP
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::UnlockImage()
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2013-09-28 22:28:43 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Main thread to encourage serialization with LockImage");
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// It's an error to call this function if the lock count is 0
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0,
|
|
|
|
"Calling UnlockImage with mLockCount == 0!");
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mLockCount == 0) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_ABORT;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// Decrement our lock count
|
|
|
|
mLockCount--;
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Unlock this image's surfaces in the SurfaceCache.
|
2015-01-07 12:40:23 +03:00
|
|
|
if (mLockCount == 0 ) {
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 10:29:28 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2012-03-10 10:29:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::RequestDiscard()
|
|
|
|
{
|
2014-11-28 06:55:57 +03:00
|
|
|
if (mDiscardable && // Enabled at creation time...
|
|
|
|
mLockCount == 0 && // ...not temporarily disabled...
|
2014-11-28 06:56:00 +03:00
|
|
|
CanDiscard()) {
|
2014-11-28 06:55:57 +03:00
|
|
|
Discard();
|
2012-03-10 10:29:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-12 19:22:30 +04:00
|
|
|
// Indempotent error flagging routine. If a decoder is open, shuts it down.
|
2010-08-14 08:09:49 +04:00
|
|
|
void
|
|
|
|
RasterImage::DoError()
|
2007-10-19 04:36:34 +04:00
|
|
|
{
|
2009-09-13 02:44:18 +04:00
|
|
|
// If we've flagged an error before, we have nothing to do
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
// We can't safely handle errors off-main-thread, so dispatch a worker to
|
|
|
|
// do it.
|
2013-09-13 01:40:16 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
HandleErrorWorker::DispatchIfNeeded(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the container in an error state.
|
2011-10-17 18:59:28 +04:00
|
|
|
mError = true;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-05-07 19:25:12 +03:00
|
|
|
// Stop animation and release our FrameAnimator.
|
|
|
|
if (mAnimating) {
|
|
|
|
StopAnimation();
|
|
|
|
}
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState = Nothing();
|
|
|
|
mFrameAnimator = nullptr;
|
2015-05-07 19:25:12 +03: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 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Error,
|
2015-07-21 19:42:27 +03:00
|
|
|
("RasterImage: [this=%p] Error detected for image\n", this));
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2013-09-13 01:40:16 +04:00
|
|
|
/* static */ void
|
|
|
|
RasterImage::HandleErrorWorker::DispatchIfNeeded(RasterImage* aImage)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HandleErrorWorker> worker = new HandleErrorWorker(aImage);
|
2015-01-16 02:11:36 +03:00
|
|
|
NS_DispatchToMainThread(worker);
|
2013-09-13 01:40:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RasterImage::HandleErrorWorker::HandleErrorWorker(RasterImage* aImage)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("image::RasterImage::HandleErrorWorker")
|
|
|
|
, mImage(aImage)
|
2013-09-13 01:40:16 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mImage, "Should have image");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::HandleErrorWorker::Run()
|
|
|
|
{
|
|
|
|
mImage->DoError();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-05 17:57:16 +04:00
|
|
|
bool
|
2010-09-08 04:33:02 +04:00
|
|
|
RasterImage::ShouldAnimate()
|
|
|
|
{
|
2016-07-28 03:12:25 +03:00
|
|
|
return ImageResource::ShouldAnimate() &&
|
|
|
|
mAnimationState &&
|
|
|
|
mAnimationState->KnownFrameCount() >= 1 &&
|
2010-11-17 23:39:23 +03:00
|
|
|
!mAnimationFinished;
|
2010-09-08 04:33:02 +04:00
|
|
|
}
|
|
|
|
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetFramesNotified(uint32_t* aFramesNotified)
|
2010-09-08 04:34:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFramesNotified);
|
|
|
|
|
|
|
|
*aFramesNotified = mFramesNotified;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
void
|
|
|
|
RasterImage::NotifyProgress(Progress aProgress,
|
2015-04-21 18:04:57 +03:00
|
|
|
const IntRect& aInvalidRect /* = IntRect() */,
|
2016-07-28 03:12:25 +03:00
|
|
|
const Maybe<uint32_t>& aFrameCount /* = Nothing() */,
|
2016-08-18 10:06:41 +03:00
|
|
|
DecoderFlags aDecoderFlags
|
|
|
|
/* = DefaultDecoderFlags() */,
|
2015-08-15 03:56:44 +03:00
|
|
|
SurfaceFlags aSurfaceFlags
|
|
|
|
/* = DefaultSurfaceFlags() */)
|
2015-01-12 21:17:52 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Ensure that we stay alive long enough to finish notifying.
|
2016-07-28 00:04:21 +03:00
|
|
|
RefPtr<RasterImage> image = this;
|
2013-01-19 01:47:18 +04:00
|
|
|
|
2016-07-28 00:04:21 +03:00
|
|
|
const bool wasDefaultFlags = aSurfaceFlags == DefaultSurfaceFlags();
|
2015-01-11 22:43:32 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (!aInvalidRect.IsEmpty() && wasDefaultFlags) {
|
2014-12-11 06:35:15 +03:00
|
|
|
// Update our image container since we're invalidating.
|
2017-11-17 14:45:25 +03:00
|
|
|
UpdateImageContainer();
|
2014-12-11 06:35:15 +03:00
|
|
|
}
|
2014-11-10 23:37:35 +03:00
|
|
|
|
2016-08-18 10:06:41 +03: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 03:12:25 +03:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
// If we should start animating right now, do so.
|
|
|
|
if (mAnimationState && aFrameCount == Some(1u) &&
|
|
|
|
mPendingAnimation && ShouldAnimate()) {
|
|
|
|
StartAnimation();
|
|
|
|
}
|
2016-07-28 03:12:25 +03:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Tell the observers what happened.
|
|
|
|
image->mProgressTracker->SyncNotifyProgress(aProgress, aInvalidRect);
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
2013-02-02 05:06:34 +04:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
void
|
2016-08-03 03:22:41 +03: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 10:06:41 +03:00
|
|
|
DecoderFlags aDecoderFlags,
|
2016-08-03 03:22:41 +03:00
|
|
|
SurfaceFlags aSurfaceFlags)
|
2015-01-16 02:11:36 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-31 17:29:15 +03:00
|
|
|
|
|
|
|
// If the decoder detected an error, log it to the error console.
|
2016-09-21 14:13:08 +03:00
|
|
|
if (aStatus.mShouldReportError) {
|
2016-08-03 03:22:41 +03:00
|
|
|
ReportDecoderError();
|
2015-07-31 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Record all the metadata the decoder gathered about this image.
|
2016-08-03 03:12:36 +03:00
|
|
|
bool metadataOK = SetMetadata(aMetadata, aStatus.mWasMetadataDecode);
|
2015-09-24 02:53:40 +03: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-03 02:32:07 +03:00
|
|
|
FromSurfaceFlags(aSurfaceFlags));
|
2015-09-24 02:53:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-03 01:43:47 +03:00
|
|
|
MOZ_ASSERT(mError || mHasSize || !aMetadata.HasSize(),
|
2015-08-18 20:19:22 +03:00
|
|
|
"SetMetadata should've gotten a size");
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-21 14:13:08 +03:00
|
|
|
if (!aStatus.mWasMetadataDecode && aStatus.mFinished) {
|
2015-07-31 17:29:15 +03:00
|
|
|
// Flag that we've been decoded before.
|
|
|
|
mHasBeenDecoded = true;
|
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Send out any final notifications.
|
2016-08-18 10:06:41 +03:00
|
|
|
NotifyProgress(aProgress, aInvalidRect, aFrameCount,
|
|
|
|
aDecoderFlags, aSurfaceFlags);
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-08-18 10:06:41 +03: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 07:45:54 +03:00
|
|
|
mAnimationState->NotifyDecodeComplete();
|
2017-04-06 12:00:36 +03:00
|
|
|
gfx::IntRect rect = mAnimationState->UpdateState(mAnimationFinished, this, mSize);
|
|
|
|
if (!rect.IsEmpty()) {
|
|
|
|
NotifyProgress(NoProgress, rect);
|
|
|
|
}
|
2016-07-28 03:12:25 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 21:18:37 +03: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-16 02:11:36 +03:00
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
if (aStatus.mFinished) {
|
2015-01-16 02:11:36 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_TIME,
|
2016-08-03 02:34:23 +03:00
|
|
|
int32_t(aTelemetry.mDecodeTime.ToMicroseconds()));
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2018-07-04 15:50:02 +03:00
|
|
|
if (aTelemetry.mSpeedHistogram && aTelemetry.mBytesDecoded) {
|
2016-08-03 02:45:22 +03:00
|
|
|
Telemetry::Accumulate(*aTelemetry.mSpeedHistogram, aTelemetry.Speed());
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-26 21:18:37 +03:00
|
|
|
}
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-26 21:18:37 +03: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 12:37:58 +03:00
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
// XXX(aosmond): Can we get this far without mFinished == true?
|
|
|
|
if (aStatus.mFinished && aStatus.mWasMetadataDecode) {
|
2015-06-30 12:37:58 +03:00
|
|
|
// If we were waiting to fire the load event, go ahead and fire it now.
|
2016-09-26 21:18:37 +03:00
|
|
|
if (mLoadProgress) {
|
2015-06-30 12:37:58 +03:00
|
|
|
NotifyForLoadEvent(*mLoadProgress);
|
|
|
|
mLoadProgress = Nothing();
|
|
|
|
}
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-26 21:18:37 +03: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-16 02:11:36 +03:00
|
|
|
}
|
2013-01-19 01:47:18 +04:00
|
|
|
}
|
|
|
|
|
2015-07-31 17:29:15 +03:00
|
|
|
void
|
2016-08-03 03:22:41 +03:00
|
|
|
RasterImage::ReportDecoderError()
|
2015-07-31 17:29:15 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
|
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
|
|
|
2016-07-11 10:34:50 +03:00
|
|
|
if (consoleService && errorObject) {
|
2015-07-31 17:29:15 +03:00
|
|
|
nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated."));
|
|
|
|
nsAutoString src;
|
|
|
|
if (GetURI()) {
|
2018-06-06 03:42:56 +03:00
|
|
|
nsAutoCString uri;
|
|
|
|
if (!GetSpecTruncatedTo1k(uri)) {
|
2015-07-31 17:29:15 +03:00
|
|
|
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 07:50:26 +04:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
RasterImage::Unwrap()
|
|
|
|
{
|
|
|
|
nsCOMPtr<imgIContainer> self(this);
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2015-06-03 20:42:07 +03:00
|
|
|
void
|
|
|
|
RasterImage::PropagateUseCounters(nsIDocument*)
|
|
|
|
{
|
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
IntSize
|
2014-07-29 01:27:39 +04:00
|
|
|
RasterImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter, uint32_t aFlags)
|
2014-07-29 01:27:39 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDest.width >= 0 || ceil(aDest.width) <= INT32_MAX ||
|
|
|
|
aDest.height >= 0 || ceil(aDest.height) <= INT32_MAX,
|
|
|
|
"Unexpected destination size");
|
|
|
|
|
2014-09-17 03:18:49 +04:00
|
|
|
if (mSize.IsEmpty() || aDest.IsEmpty()) {
|
2015-04-21 18:04:57 +03:00
|
|
|
return IntSize(0, 0);
|
2014-07-29 01:27:39 +04:00
|
|
|
}
|
|
|
|
|
2016-07-26 17:48:30 +03:00
|
|
|
IntSize destSize = IntSize::Ceil(aDest.width, aDest.height);
|
2014-07-29 01:27:39 +04:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
if (aSamplingFilter == SamplingFilter::GOOD &&
|
|
|
|
CanDownscaleDuringDecode(destSize, aFlags)) {
|
2015-01-19 01:02:14 +03:00
|
|
|
return destSize;
|
2014-07-29 01:27:39 +04:00
|
|
|
}
|
|
|
|
|
2015-09-20 02:20:56 +03:00
|
|
|
// We can't scale to this size. Use our intrinsic size for now.
|
2014-07-29 01:27:39 +04:00
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-14 08:09:49 +04:00
|
|
|
} // namespace mozilla
|