2001-03-10 01:11:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2007-03-20 23:56:50 +00:00
|
|
|
/** @file
|
2010-08-14 04:09:49 +00:00
|
|
|
* This file declares the RasterImage class, which
|
|
|
|
* handles static and animated rasterized images.
|
2007-03-20 23:56:50 +00:00
|
|
|
*
|
|
|
|
* @author Stuart Parmenter <pavlov@netscape.com>
|
|
|
|
* @author Chris Saari <saari@netscape.com>
|
|
|
|
* @author Arron Mogge <paper@animecity.nu>
|
|
|
|
* @author Andrew Smith <asmith15@learn.senecac.on.ca>
|
|
|
|
*/
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_RasterImage_h
|
|
|
|
#define mozilla_image_RasterImage_h
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
#include "Image.h"
|
2001-03-10 01:11:54 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2002-10-07 21:49:33 +00:00
|
|
|
#include "imgIContainer.h"
|
2005-01-12 20:16:07 +00:00
|
|
|
#include "nsIProperties.h"
|
2007-10-19 00:36:34 +00:00
|
|
|
#include "nsTArray.h"
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
#include "imgFrame.h"
|
2015-07-01 01:57:03 +00:00
|
|
|
#include "LookupResult.h"
|
2009-09-12 22:44:18 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2014-11-19 02:17:17 +00:00
|
|
|
#include "DecodePool.h"
|
2015-07-23 05:39:48 +00:00
|
|
|
#include "DecoderFactory.h"
|
2013-08-25 07:19:42 +00:00
|
|
|
#include "Orientation.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
#include "nsIObserver.h"
|
2015-02-03 05:40:35 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-11-26 21:22:10 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2015-03-18 02:40:16 +00:00
|
|
|
#include "mozilla/Pair.h"
|
2011-08-04 20:25:12 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-10-04 19:45:07 +00:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2014-09-09 13:39:00 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-01-12 04:14:09 +00:00
|
|
|
#include "ImageContainer.h"
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "imgIContainerDebug.h"
|
|
|
|
#endif
|
2001-03-27 02:42:51 +00:00
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
class nsIInputStream;
|
2013-09-07 13:01:08 +00:00
|
|
|
class nsIRequest;
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
#define NS_RASTERIMAGE_CID \
|
2010-08-05 14:53:43 +00:00
|
|
|
{ /* 376ff2c1-9bf6-418a-b143-3340c00112f7 */ \
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
0x376ff2c1, \
|
|
|
|
0x9bf6, \
|
|
|
|
0x418a, \
|
|
|
|
{0xb1, 0x43, 0x33, 0x40, 0xc0, 0x01, 0x12, 0xf7} \
|
2001-03-10 01:11:54 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 23:56:50 +00:00
|
|
|
/**
|
|
|
|
* Handles static and animated image containers.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @par A Quick Walk Through
|
|
|
|
* The decoder initializes this class and calls AppendFrame() to add a frame.
|
2010-08-14 04:09:49 +00:00
|
|
|
* Once RasterImage detects more than one frame, it starts the animation
|
2011-11-09 21:39:16 +00:00
|
|
|
* with StartAnimation(). Note that the invalidation events for RasterImage are
|
|
|
|
* generated automatically using nsRefreshDriver.
|
2007-03-20 23:56:50 +00:00
|
|
|
*
|
|
|
|
* @par
|
2011-11-09 21:39:16 +00:00
|
|
|
* StartAnimation() initializes the animation helper object and sets the time
|
|
|
|
* the first frame was displayed to the current clock time.
|
2007-03-20 23:56:50 +00:00
|
|
|
*
|
|
|
|
* @par
|
2011-11-09 21:39:16 +00:00
|
|
|
* When the refresh driver corresponding to the imgIContainer that this image is
|
|
|
|
* a part of notifies the RasterImage that it's time to invalidate,
|
|
|
|
* RequestRefresh() is called with a given TimeStamp to advance to. As long as
|
|
|
|
* the timeout of the given frame (the frame's "delay") plus the time that frame
|
|
|
|
* was first displayed is less than or equal to the TimeStamp given,
|
|
|
|
* RequestRefresh() calls AdvanceFrame().
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* AdvanceFrame() is responsible for advancing a single frame of the animation.
|
|
|
|
* It can return true, meaning that the frame advanced, or false, meaning that
|
|
|
|
* the frame failed to advance (usually because the next frame hasn't been
|
|
|
|
* decoded yet). It is also responsible for performing the final animation stop
|
|
|
|
* procedure if the final frame of a non-looping animation is reached.
|
2007-03-20 23:56:50 +00:00
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* Each frame can have a different method of removing itself. These are
|
2013-03-29 20:14:19 +00:00
|
|
|
* listed as imgIContainer::cDispose... constants. Notify() calls
|
2007-03-20 23:56:50 +00:00
|
|
|
* DoComposite() to handle any special frame destruction.
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* The basic path through DoComposite() is:
|
|
|
|
* 1) Calculate Area that needs updating, which is at least the area of
|
|
|
|
* aNextFrame.
|
|
|
|
* 2) Dispose of previous frame.
|
|
|
|
* 3) Draw new image onto compositingFrame.
|
|
|
|
* See comments in DoComposite() for more information and optimizations.
|
|
|
|
*
|
|
|
|
* @par
|
2010-08-14 04:09:49 +00:00
|
|
|
* The rest of the RasterImage specific functions are used by DoComposite to
|
2007-03-20 23:56:50 +00:00
|
|
|
* destroy the old frame and build the new one.
|
|
|
|
*
|
|
|
|
* @note
|
2010-05-13 12:19:50 +00:00
|
|
|
* <li> "Mask", "Alpha", and "Alpha Level" are interchangeable phrases in
|
2010-08-14 04:09:49 +00:00
|
|
|
* respects to RasterImage.
|
2007-03-20 23:56:50 +00:00
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* <li> GIFs never have more than a 1 bit alpha.
|
|
|
|
* <li> APNGs may have a full alpha channel.
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* <li> Background color specified in GIF is ignored by web browsers.
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* <li> If Frame 3 wants to dispose by restoring previous, what it wants is to
|
|
|
|
* restore the composition up to and including Frame 2, as well as Frame 2s
|
|
|
|
* disposal. So, in the middle of DoComposite when composing Frame 3, right
|
|
|
|
* after destroying Frame 2's area, we copy compositingFrame to
|
|
|
|
* prevCompositingFrame. When DoComposite gets called to do Frame 4, we
|
|
|
|
* copy prevCompositingFrame back, and then draw Frame 4 on top.
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* The mAnim structure has members only needed for animated images, so
|
|
|
|
* it's not allocated until the second frame is added.
|
|
|
|
*/
|
2010-08-14 04:09:49 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-12-17 22:04:31 +00:00
|
|
|
|
2011-11-09 03:14:41 +00:00
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
2012-09-24 20:31:30 +00:00
|
|
|
class Image;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace layers
|
2013-12-17 22:04:31 +00:00
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2010-08-23 02:30:46 +00:00
|
|
|
class Decoder;
|
2013-07-15 18:38:59 +00:00
|
|
|
class FrameAnimator;
|
2015-08-14 07:37:13 +00:00
|
|
|
class ImageMetadata;
|
2015-01-15 23:11:36 +00:00
|
|
|
class SourceBuffer;
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class RasterImage final : public ImageResource
|
2015-03-27 18:52:19 +00:00
|
|
|
, public nsIProperties
|
|
|
|
, public SupportsWeakPtr<RasterImage>
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-27 18:52:19 +00:00
|
|
|
, public imgIContainerDebug
|
2010-09-08 00:34:18 +00:00
|
|
|
#endif
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
2014-06-23 18:49:08 +00:00
|
|
|
// (no public constructor - use ImageFactory)
|
|
|
|
virtual ~RasterImage();
|
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
public:
|
2015-04-24 16:43:01 +00:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(RasterImage)
|
2013-07-19 02:23:31 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-06-21 20:45:49 +00:00
|
|
|
NS_DECL_NSIPROPERTIES
|
2012-10-19 20:27:11 +00:00
|
|
|
NS_DECL_IMGICONTAINER
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_DECL_IMGICONTAINERDEBUG
|
|
|
|
#endif
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult StartAnimation() override;
|
|
|
|
virtual nsresult StopAnimation() override;
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
// Methods inherited from Image
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void OnSurfaceDiscarded() override;
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2010-08-23 22:44:07 +00:00
|
|
|
/* The total number of frames in this image. */
|
2015-01-07 09:40:23 +00:00
|
|
|
uint32_t GetNumFrames() const { return mFrameCount; }
|
2010-08-23 22:44:07 +00:00
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf)
|
|
|
|
const override;
|
2015-04-28 18:46:17 +00:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const override;
|
2014-05-08 09:53:00 +00:00
|
|
|
|
2010-07-01 17:39:44 +00:00
|
|
|
/* Triggers discarding. */
|
2014-11-28 03:56:00 +00:00
|
|
|
void Discard();
|
2010-07-01 17:39:44 +00:00
|
|
|
|
2015-01-08 08:01:25 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Decoder callbacks.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OnAddedFrame(uint32_t aNewFrameCount, const nsIntRect& aNewRefreshArea);
|
2015-01-07 09:40:23 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
/**
|
|
|
|
* Sends the provided progress notifications to ProgressTracker.
|
|
|
|
*
|
|
|
|
* Main-thread only.
|
|
|
|
*
|
|
|
|
* @param aProgress The progress notifications to send.
|
|
|
|
* @param aInvalidRect An invalidation rect to send.
|
2015-08-15 00:56:44 +00:00
|
|
|
* @param aFlags The surface flags used by the decoder that generated
|
|
|
|
* these notifications, or DefaultSurfaceFlags() if the
|
2015-01-15 23:11:36 +00:00
|
|
|
* notifications don't come from a decoder.
|
|
|
|
*/
|
|
|
|
void NotifyProgress(Progress aProgress,
|
|
|
|
const nsIntRect& aInvalidRect = nsIntRect(),
|
2015-08-15 00:56:44 +00:00
|
|
|
SurfaceFlags aSurfaceFlags = DefaultSurfaceFlags());
|
2015-01-15 23:11:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Records telemetry and does final teardown of the provided decoder.
|
|
|
|
*
|
|
|
|
* Main-thread only.
|
|
|
|
*/
|
|
|
|
void FinalizeDecoder(Decoder* aDecoder);
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
// Helper method for FinalizeDecoder.
|
2015-07-31 14:29:15 +00:00
|
|
|
void ReportDecoderError(Decoder* aDecoder);
|
|
|
|
|
2015-01-08 08:01:25 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Network callbacks.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2012-12-17 22:05:18 +00:00
|
|
|
virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aCount) override;
|
2012-12-17 22:05:18 +00:00
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
2013-02-14 02:41:10 +00:00
|
|
|
nsresult aStatus,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aLastPart) override;
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2015-06-30 09:37:58 +00:00
|
|
|
void NotifyForLoadEvent(Progress aProgress);
|
2015-01-19 23:46:55 +00:00
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
/**
|
|
|
|
* A hint of the number of bytes of source data that the image contains. If
|
|
|
|
* called early on, this can help reduce copying and reallocations by
|
|
|
|
* appropriately preallocating the source data buffer.
|
|
|
|
*
|
|
|
|
* We take this approach rather than having the source data management code do
|
|
|
|
* something more complicated (like chunklisting) because HTTP is by far the
|
|
|
|
* dominant source of images, and the Content-Length header is quite reliable.
|
|
|
|
* Thus, pre-allocation simplifies code and reduces the total number of
|
|
|
|
* allocations.
|
|
|
|
*/
|
2015-01-15 23:11:36 +00:00
|
|
|
nsresult SetSourceSizeHint(uint32_t aSizeHint);
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2014-02-28 21:43:14 +00:00
|
|
|
/* Provide a hint for the requested dimension of the resulting image. */
|
|
|
|
void SetRequestedSampleSize(int requestedSampleSize) {
|
|
|
|
mRequestedSampleSize = requestedSampleSize;
|
|
|
|
}
|
|
|
|
|
2012-12-19 20:11:42 +00:00
|
|
|
nsCString GetURIString() {
|
2013-01-30 20:11:20 +00:00
|
|
|
nsCString spec;
|
|
|
|
if (GetURI()) {
|
|
|
|
GetURI()->GetSpec(spec);
|
|
|
|
}
|
|
|
|
return spec;
|
|
|
|
}
|
2010-09-12 15:22:31 +00:00
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
private:
|
2015-04-28 23:07:24 +00:00
|
|
|
nsresult Init(const char* aMimeType, uint32_t aFlags);
|
|
|
|
|
2015-09-19 23:20:56 +00:00
|
|
|
DrawResult DrawInternal(DrawableFrameRef&& aFrameRef,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2016-05-25 16:01:18 +00:00
|
|
|
gfx::SamplingFilter aSamplingFilter,
|
2015-09-19 23:20:56 +00:00
|
|
|
uint32_t aFlags);
|
2012-04-03 21:57:22 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
already_AddRefed<gfx::SourceSurface> CopyFrame(uint32_t aWhichFrame,
|
2015-02-03 05:40:35 +00:00
|
|
|
uint32_t aFlags);
|
2015-03-18 02:40:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
Pair<DrawResult, RefPtr<gfx::SourceSurface>>
|
2015-09-19 20:34:09 +00:00
|
|
|
GetFrameInternal(const gfx::IntSize& aSize,
|
|
|
|
uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags);
|
2014-09-27 01:50:24 +00:00
|
|
|
|
2015-07-01 01:57:03 +00:00
|
|
|
LookupResult LookupFrameInternal(uint32_t aFrameNum,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
uint32_t aFlags);
|
2014-11-26 21:22:10 +00:00
|
|
|
DrawableFrameRef LookupFrame(uint32_t aFrameNum,
|
|
|
|
const nsIntSize& aSize,
|
2015-02-03 05:40:35 +00:00
|
|
|
uint32_t aFlags);
|
2014-09-13 01:29:27 +00:00
|
|
|
uint32_t GetCurrentFrameIndex() const;
|
|
|
|
uint32_t GetRequestedFrameIndex(uint32_t aWhichFrame) const;
|
2012-10-14 02:17:40 +00:00
|
|
|
|
2014-11-10 20:37:35 +00:00
|
|
|
nsIntRect GetFirstFrameRect();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
Pair<DrawResult, RefPtr<layers::Image>>
|
2015-03-18 02:40:16 +00:00
|
|
|
GetCurrentImage(layers::ImageContainer* aContainer, uint32_t aFlags);
|
|
|
|
|
2012-09-24 20:31:30 +00:00
|
|
|
void UpdateImageContainer();
|
|
|
|
|
2013-04-26 19:58:17 +00:00
|
|
|
// We would like to just check if we have a zero lock count, but we can't do
|
|
|
|
// that for animated images because in EnsureAnimExists we lock the image and
|
|
|
|
// never unlock so that animated images always have their lock count >= 1. In
|
|
|
|
// that case we use our animation consumers count as a proxy for lock count.
|
2015-03-31 17:49:00 +00:00
|
|
|
bool IsUnlocked() {
|
|
|
|
return (mLockCount == 0 || (mAnim && mAnimationConsumers == 0));
|
|
|
|
}
|
2013-04-26 19:58:17 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Decoding.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-18 22:02:13 +00:00
|
|
|
/**
|
|
|
|
* Creates and runs a decoder, either synchronously or asynchronously
|
2015-07-23 05:39:51 +00:00
|
|
|
* according to @aFlags. Decodes at the provided target size @aSize, using
|
|
|
|
* decode flags @aFlags.
|
|
|
|
*
|
|
|
|
* It's an error to call Decode() before this image's intrinsic size is
|
|
|
|
* available. A metadata decode must successfully complete first.
|
2015-01-18 22:02:13 +00:00
|
|
|
*/
|
2015-07-23 05:39:51 +00:00
|
|
|
NS_IMETHOD Decode(const gfx::IntSize& aSize, uint32_t aFlags);
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2015-01-18 22:02:13 +00:00
|
|
|
/**
|
2015-07-23 05:39:51 +00:00
|
|
|
* Creates and runs a metadata decoder, either synchronously or
|
|
|
|
* asynchronously according to @aFlags.
|
2015-01-18 22:02:13 +00:00
|
|
|
*/
|
2015-07-23 05:39:51 +00:00
|
|
|
NS_IMETHOD DecodeMetadata(uint32_t aFlags);
|
2015-01-15 23:11:36 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
/**
|
|
|
|
* Sets the size, inherent orientation, animation metadata, and other
|
|
|
|
* information about the image gathered during decoding.
|
|
|
|
*
|
|
|
|
* This function may be called multiple times, but will throw an error if
|
|
|
|
* subsequent calls do not match the first.
|
|
|
|
*
|
|
|
|
* @param aMetadata The metadata to set on this image.
|
|
|
|
* @param aFromMetadataDecode True if this metadata came from a metadata
|
|
|
|
* decode; false if it came from a full decode.
|
2015-09-23 23:53:40 +00:00
|
|
|
* @return |true| unless a catastrophic failure was discovered. If |false| is
|
|
|
|
* returned, it indicates that the image is corrupt in a way that requires all
|
|
|
|
* surfaces to be discarded to recover.
|
2015-08-14 07:37:13 +00:00
|
|
|
*/
|
2015-09-23 23:53:40 +00:00
|
|
|
bool SetMetadata(const ImageMetadata& aMetadata, bool aFromMetadataDecode);
|
2015-08-14 07:37:13 +00:00
|
|
|
|
2015-02-04 00:38:36 +00:00
|
|
|
/**
|
2015-08-18 17:19:14 +00:00
|
|
|
* In catastrophic circumstances like a GPU driver crash, the contents of our
|
|
|
|
* frames may become invalid. If the information we gathered during the
|
|
|
|
* metadata decode proves to be wrong due to image corruption, the frames we
|
|
|
|
* have may violate this class's invariants. Either way, we need to
|
|
|
|
* immediately discard the invalid frames and redecode so that callers don't
|
|
|
|
* perceive that we've entered an invalid state.
|
|
|
|
*
|
|
|
|
* RecoverFromInvalidFrames discards all existing frames and redecodes using
|
|
|
|
* the provided @aSize and @aFlags.
|
2015-02-04 00:38:36 +00:00
|
|
|
*/
|
2015-08-18 17:19:14 +00:00
|
|
|
void RecoverFromInvalidFrames(const nsIntSize& aSize, uint32_t aFlags);
|
2015-02-04 00:38:36 +00:00
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 01:50:15 +00:00
|
|
|
private: // data
|
2007-03-20 23:56:50 +00:00
|
|
|
nsIntSize mSize;
|
2013-08-25 07:19:42 +00:00
|
|
|
Orientation mOrientation;
|
2011-01-13 01:45:13 +00:00
|
|
|
|
2015-06-30 09:37:58 +00:00
|
|
|
/// If this has a value, we're waiting for SetSize() to send the load event.
|
|
|
|
Maybe<Progress> mLoadProgress;
|
|
|
|
|
2014-08-22 20:49:54 +00:00
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
/// If this image is animated, a FrameAnimator which manages its animation.
|
2014-09-09 13:39:00 +00:00
|
|
|
UniquePtr<FrameAnimator> mAnim;
|
2013-03-29 20:14:19 +00:00
|
|
|
|
2014-11-28 03:55:57 +00:00
|
|
|
// Image locking.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLockCount;
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2015-07-21 16:42:30 +00:00
|
|
|
// The type of decoder this image needs. Computed from the MIME type in Init().
|
2015-07-23 05:39:48 +00:00
|
|
|
DecoderType mDecoderType;
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2011-09-08 18:05:11 +00:00
|
|
|
// How many times we've decoded this image.
|
|
|
|
// This is currently only used for statistics
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mDecodeCount;
|
2013-03-22 23:12:40 +00:00
|
|
|
|
2014-02-28 21:43:14 +00:00
|
|
|
// A hint for image decoder that directly scale the image to smaller buffer
|
|
|
|
int mRequestedSampleSize;
|
|
|
|
|
2015-01-16 22:11:23 +00:00
|
|
|
// A weak pointer to our ImageContainer, which stays alive only as long as
|
|
|
|
// the layer system needs it.
|
|
|
|
WeakPtr<layers::ImageContainer> mImageContainer;
|
2014-02-25 03:37:51 +00:00
|
|
|
|
2016-01-12 04:14:09 +00:00
|
|
|
layers::ImageContainer::ProducerID mImageProducerID;
|
|
|
|
layers::ImageContainer::FrameID mLastFrameID;
|
|
|
|
|
2015-03-18 02:40:16 +00:00
|
|
|
// If mImageContainer is non-null, this contains the DrawResult we obtained
|
|
|
|
// the last time we updated it.
|
|
|
|
DrawResult mLastImageContainerDrawResult;
|
|
|
|
|
2010-09-08 00:34:18 +00:00
|
|
|
#ifdef DEBUG
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mFramesNotified;
|
2010-09-08 00:34:18 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-15 23:11:36 +00:00
|
|
|
// The source data for this image.
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SourceBuffer> mSourceBuffer;
|
2013-03-01 23:17:24 +00:00
|
|
|
|
2015-01-07 09:40:23 +00:00
|
|
|
// The number of frames this image has.
|
|
|
|
uint32_t mFrameCount;
|
|
|
|
|
2010-05-12 21:41:47 +00:00
|
|
|
// Boolean flags (clustered together to conserve space):
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mHasSize:1; // Has SetSize() been called?
|
2015-01-07 09:37:20 +00:00
|
|
|
bool mTransient:1; // Is the image short-lived?
|
2015-06-30 09:37:58 +00:00
|
|
|
bool mSyncLoad:1; // Are we loading synchronously?
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDiscardable:1; // Is container discardable?
|
|
|
|
bool mHasSourceData:1; // Do we have source data?
|
2015-01-15 23:11:36 +00:00
|
|
|
bool mHasBeenDecoded:1; // Decoded at least once?
|
2010-05-12 21:41:47 +00:00
|
|
|
|
2014-11-26 21:22:10 +00:00
|
|
|
// Whether we're waiting to start animation. If we get a StartAnimation() call
|
|
|
|
// but we don't yet have more than one frame, mPendingAnimation is set so that
|
|
|
|
// we know to start animation later if/when we have more frames.
|
|
|
|
bool mPendingAnimation:1;
|
2010-05-12 21:41:47 +00:00
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
// Whether the animation can stop, due to running out
|
|
|
|
// of frames, or no more owning request
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mAnimationFinished:1;
|
2010-09-08 00:33:02 +00:00
|
|
|
|
2015-07-23 05:39:54 +00:00
|
|
|
// Whether, once we are done doing a metadata decode, we should immediately
|
|
|
|
// kick off a full decode.
|
2013-01-31 18:38:24 +00:00
|
|
|
bool mWantFullDecode:1;
|
|
|
|
|
2011-08-10 23:12:08 +00:00
|
|
|
TimeStamp mDrawStartTime;
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2012-10-12 22:24:47 +00:00
|
|
|
|
2014-09-19 21:53:29 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Scaling.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-04-03 21:57:22 +00:00
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
// Determines whether we can downscale during decode with the given
|
|
|
|
// parameters.
|
2015-01-18 22:02:14 +00:00
|
|
|
bool CanDownscaleDuringDecode(const nsIntSize& aSize, uint32_t aFlags);
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2013-09-12 21:40:16 +00:00
|
|
|
// Error handling.
|
2009-09-12 22:44:18 +00:00
|
|
|
void DoError();
|
2013-09-12 21:40:16 +00:00
|
|
|
|
2016-04-26 00:23:21 +00:00
|
|
|
class HandleErrorWorker : public Runnable
|
2013-09-12 21:40:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Called from decoder threads when DoError() is called, since errors can't
|
|
|
|
* be handled safely off-main-thread. Dispatches an event which reinvokes
|
|
|
|
* DoError on the main thread if there isn't one already pending.
|
|
|
|
*/
|
|
|
|
static void DispatchIfNeeded(RasterImage* aImage);
|
|
|
|
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
|
|
|
|
private:
|
2014-09-02 16:20:24 +00:00
|
|
|
explicit HandleErrorWorker(RasterImage* aImage);
|
2013-09-12 21:40:16 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<RasterImage> mImage;
|
2013-09-12 21:40:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helpers
|
2011-08-05 13:57:16 +00:00
|
|
|
bool CanDiscard();
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
protected:
|
2015-04-28 23:32:02 +00:00
|
|
|
explicit RasterImage(ImageURL* aURI = nullptr);
|
2012-12-18 02:35:46 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
bool ShouldAnimate() override;
|
2012-12-17 22:05:18 +00:00
|
|
|
|
|
|
|
friend class ImageFactory;
|
2009-09-12 22:44:18 +00:00
|
|
|
};
|
|
|
|
|
2015-03-31 17:49:00 +00:00
|
|
|
inline NS_IMETHODIMP
|
|
|
|
RasterImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
2012-10-19 20:27:11 +00:00
|
|
|
return GetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-14 04:09:49 +00:00
|
|
|
} // namespace mozilla
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif /* mozilla_image_RasterImage_h */
|