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
|
|
|
|
2007-03-21 02:56:50 +03:00
|
|
|
/** @file
|
2010-08-14 08:09:49 +04:00
|
|
|
* This file declares the RasterImage class, which
|
|
|
|
* handles static and animated rasterized images.
|
2007-03-21 02:56:50 +03: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 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_RasterImage_h
|
|
|
|
#define mozilla_image_RasterImage_h
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
#include "Image.h"
|
2001-03-10 04:11:54 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2002-10-08 01:49:33 +04:00
|
|
|
#include "imgIContainer.h"
|
2005-01-12 23:16:07 +03:00
|
|
|
#include "nsIProperties.h"
|
2007-10-19 04:36:34 +04:00
|
|
|
#include "nsTArray.h"
|
2015-07-01 04:57:03 +03:00
|
|
|
#include "LookupResult.h"
|
2009-09-13 02:44:18 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2015-07-23 08:39:48 +03:00
|
|
|
#include "DecoderFactory.h"
|
2016-07-19 09:26:58 +03:00
|
|
|
#include "FrameAnimator.h"
|
2016-08-03 01:43:47 +03:00
|
|
|
#include "ImageMetadata.h"
|
2016-08-18 03:50:31 +03:00
|
|
|
#include "ISurfaceProvider.h"
|
2013-08-25 11:19:42 +04:00
|
|
|
#include "Orientation.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsIObserver.h"
|
2015-02-03 08:40:35 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-11-27 00:22:10 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-06-27 07:50:43 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2011-08-05 00:25:12 +04:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-10-04 23:45:07 +04:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2014-09-09 17:39:00 +04:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2016-01-12 07:14:09 +03:00
|
|
|
#include "ImageContainer.h"
|
2016-08-18 10:06:41 +03:00
|
|
|
#include "PlaybackType.h"
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "imgIContainerDebug.h"
|
|
|
|
#endif
|
2001-03-27 06:42:51 +04:00
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
class nsIInputStream;
|
2013-09-07 17:01:08 +04:00
|
|
|
class nsIRequest;
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
#define NS_RASTERIMAGE_CID \
|
2010-08-05 18:53:43 +04: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 05:50:15 +04:00
|
|
|
0x376ff2c1, 0x9bf6, 0x418a, { \
|
|
|
|
0xb1, 0x43, 0x33, 0x40, 0xc0, 0x01, 0x12, 0xf7 \
|
|
|
|
} \
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2007-03-21 02:56:50 +03: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 08:09:49 +04:00
|
|
|
* Once RasterImage detects more than one frame, it starts the animation
|
2011-11-10 01:39:16 +04:00
|
|
|
* with StartAnimation(). Note that the invalidation events for RasterImage are
|
|
|
|
* generated automatically using nsRefreshDriver.
|
2007-03-21 02:56:50 +03:00
|
|
|
*
|
|
|
|
* @par
|
2011-11-10 01:39:16 +04:00
|
|
|
* StartAnimation() initializes the animation helper object and sets the time
|
|
|
|
* the first frame was displayed to the current clock time.
|
2007-03-21 02:56:50 +03:00
|
|
|
*
|
|
|
|
* @par
|
2011-11-10 01:39:16 +04: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-21 02:56:50 +03:00
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* Each frame can have a different method of removing itself. These are
|
2013-03-30 00:14:19 +04:00
|
|
|
* listed as imgIContainer::cDispose... constants. Notify() calls
|
2007-03-21 02:56:50 +03: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 08:09:49 +04:00
|
|
|
* The rest of the RasterImage specific functions are used by DoComposite to
|
2007-03-21 02:56:50 +03:00
|
|
|
* destroy the old frame and build the new one.
|
|
|
|
*
|
|
|
|
* @note
|
2010-05-13 16:19:50 +04:00
|
|
|
* <li> "Mask", "Alpha", and "Alpha Level" are interchangeable phrases in
|
2010-08-14 08:09:49 +04:00
|
|
|
* respects to RasterImage.
|
2007-03-21 02:56:50 +03: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 08:09:49 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-12-18 02:04:31 +04:00
|
|
|
|
2011-11-09 07:14:41 +04:00
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
2012-09-25 00:31:30 +04:00
|
|
|
class Image;
|
2017-11-17 14:45:26 +03:00
|
|
|
class LayersManager;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2013-12-18 02:04:31 +04:00
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
class Decoder;
|
2016-08-03 03:12:36 +03:00
|
|
|
struct DecoderFinalStatus;
|
2016-08-03 02:34:23 +03:00
|
|
|
struct DecoderTelemetry;
|
2015-08-14 10:37:13 +03:00
|
|
|
class ImageMetadata;
|
2015-01-16 02:11:36 +03:00
|
|
|
class SourceBuffer;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class RasterImage final : public ImageResource,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIProperties,
|
|
|
|
public SupportsWeakPtr<RasterImage>
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
2015-03-27 21:52:19 +03:00
|
|
|
,
|
|
|
|
public imgIContainerDebug
|
2010-09-08 04:34:18 +04:00
|
|
|
#endif
|
2001-03-10 04:11:54 +03:00
|
|
|
{
|
2014-06-23 22:49:08 +04:00
|
|
|
// (no public constructor - use ImageFactory)
|
|
|
|
virtual ~RasterImage();
|
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
public:
|
2015-04-24 19:43:01 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(RasterImage)
|
2013-07-19 06:23:31 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-06-22 00:45:49 +04:00
|
|
|
NS_DECL_NSIPROPERTIES
|
2012-10-20 00:27:11 +04:00
|
|
|
NS_DECL_IMGICONTAINER
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_DECL_IMGICONTAINERDEBUG
|
|
|
|
#endif
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
|
2017-09-05 14:58:44 +03:00
|
|
|
size_t GetNativeSizesLength() const override;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult StartAnimation() override;
|
|
|
|
virtual nsresult StopAnimation() override;
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
// Methods inherited from Image
|
2017-03-16 11:06:06 +03:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2017-07-28 13:10:04 +03:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const override;
|
2015-04-28 21:46:17 +03:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const override;
|
2014-05-08 13:53:00 +04:00
|
|
|
|
2010-07-01 21:39:44 +04:00
|
|
|
/* Triggers discarding. */
|
2014-11-28 06:56:00 +03:00
|
|
|
void Discard();
|
2010-07-01 21:39:44 +04:00
|
|
|
|
2015-01-08 11:01:25 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Decoder callbacks.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-16 02:11:36 +03: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.
|
2016-07-28 03:12:25 +03:00
|
|
|
* @param aFrameCount If Some(), an updated count of the number of frames of
|
2018-11-28 12:16:55 +03:00
|
|
|
* animation the decoder has finished decoding so far.
|
|
|
|
* This is a lower bound for the total number of
|
|
|
|
* animation frames this image has.
|
2016-08-18 10:06:41 +03:00
|
|
|
* @param aDecoderFlags The decoder flags used by the decoder that generated
|
|
|
|
* these notifications, or DefaultDecoderFlags() if the
|
|
|
|
* notifications don't come from a decoder.
|
|
|
|
* @param aSurfaceFlags The surface flags used by the decoder that generated
|
|
|
|
* these notifications, or DefaultSurfaceFlags() if the
|
|
|
|
* notifications don't come from a decoder.
|
2015-01-16 02:11:36 +03:00
|
|
|
*/
|
|
|
|
void NotifyProgress(Progress aProgress,
|
2016-07-28 03:12:25 +03:00
|
|
|
const gfx::IntRect& aInvalidRect = nsIntRect(),
|
|
|
|
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-16 02:11:36 +03:00
|
|
|
|
|
|
|
/**
|
2016-08-03 03:22:41 +03:00
|
|
|
* Records decoding results, sends out any final notifications, updates the
|
|
|
|
* state of this image, and records telemetry.
|
2015-01-16 02:11:36 +03:00
|
|
|
*
|
|
|
|
* Main-thread only.
|
2016-08-03 03:22:41 +03:00
|
|
|
*
|
2016-08-18 10:06:41 +03:00
|
|
|
* @param aStatus Final status information about the decoder. (Whether
|
|
|
|
* it encountered an error, etc.)
|
|
|
|
* @param aMetadata Metadata about this image that the decoder gathered.
|
|
|
|
* @param aTelemetry Telemetry data about the decoder.
|
|
|
|
* @param aProgress Any final progress notifications to send.
|
|
|
|
* @param aInvalidRect Any final invalidation rect to send.
|
|
|
|
* @param aFrameCount If Some(), a final updated count of the number of
|
|
|
|
* frames of animation the decoder has finished decoding so far. This is a
|
|
|
|
* lower bound for the total number of animation frames this image has.
|
|
|
|
* @param aDecoderFlags The decoder flags used by the decoder.
|
|
|
|
* @param aSurfaceFlags The surface flags used by the decoder.
|
2015-01-16 02:11:36 +03:00
|
|
|
*/
|
2016-08-03 03:22:41 +03:00
|
|
|
void NotifyDecodeComplete(
|
|
|
|
const DecoderFinalStatus& aStatus, const ImageMetadata& aMetadata,
|
|
|
|
const DecoderTelemetry& aTelemetry, Progress aProgress,
|
|
|
|
const gfx::IntRect& aInvalidRect, const Maybe<uint32_t>& aFrameCount,
|
|
|
|
DecoderFlags aDecoderFlags, SurfaceFlags aSurfaceFlags);
|
|
|
|
|
|
|
|
// Helper method for NotifyDecodeComplete.
|
|
|
|
void ReportDecoderError();
|
2015-07-31 17:29:15 +03:00
|
|
|
|
2015-01-08 11:01:25 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Network callbacks.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2012-12-18 02:05:18 +04:00
|
|
|
virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aCount) override;
|
2012-12-18 02:05:18 +04:00
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext, nsresult aStatus,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aLastPart) override;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
void NotifyForLoadEvent(Progress aProgress);
|
2015-01-20 02:46:55 +03:00
|
|
|
|
2010-08-14 08:09:49 +04: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-16 02:11:36 +03:00
|
|
|
nsresult SetSourceSizeHint(uint32_t aSizeHint);
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2012-12-20 00:11:42 +04:00
|
|
|
nsCString GetURIString() {
|
2013-01-31 00:11:20 +04:00
|
|
|
nsCString spec;
|
|
|
|
if (GetURI()) {
|
|
|
|
GetURI()->GetSpec(spec);
|
|
|
|
}
|
|
|
|
return spec;
|
|
|
|
}
|
2010-09-12 19:22:31 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
private:
|
2015-04-29 02:07:24 +03:00
|
|
|
nsresult Init(const char* aMimeType, uint32_t aFlags);
|
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
/**
|
|
|
|
* Tries to retrieve a surface for this image with size @aSize, surface flags
|
|
|
|
* matching @aFlags, and a playback type of @aPlaybackType.
|
|
|
|
*
|
|
|
|
* If @aFlags specifies FLAG_SYNC_DECODE and we already have all the image
|
|
|
|
* data, we'll attempt a sync decode if no matching surface is found. If
|
|
|
|
* FLAG_SYNC_DECODE was not specified and no matching surface was found, we'll
|
|
|
|
* kick off an async decode so that the surface is (hopefully) available next
|
2018-10-13 08:31:02 +03:00
|
|
|
* time it's requested. aMarkUsed determines if we mark the surface used in
|
|
|
|
* the surface cache or not.
|
2016-08-18 10:06:41 +03:00
|
|
|
*
|
|
|
|
* @return a drawable surface, which may be empty if the requested surface
|
|
|
|
* could not be found.
|
|
|
|
*/
|
2017-11-17 14:45:27 +03:00
|
|
|
LookupResult LookupFrame(const gfx::IntSize& aSize, uint32_t aFlags,
|
2018-10-13 08:31:02 +03:00
|
|
|
PlaybackType aPlaybackType, bool aMarkUsed);
|
2016-08-18 10:06:41 +03:00
|
|
|
|
|
|
|
/// Helper method for LookupFrame().
|
|
|
|
LookupResult LookupFrameInternal(const gfx::IntSize& aSize, uint32_t aFlags,
|
2018-10-13 08:31:02 +03:00
|
|
|
PlaybackType aPlaybackType, bool aMarkUsed);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult DrawInternal(DrawableSurface&& aFrameRef, gfxContext* aContext,
|
2015-09-20 02:20:56 +03:00
|
|
|
const nsIntSize& aSize, const ImageRegion& aRegion,
|
2016-05-25 19:01:18 +03:00
|
|
|
gfx::SamplingFilter aSamplingFilter,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags, float aOpacity);
|
2012-04-04 01:57:22 +04:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
Tuple<ImgDrawResult, gfx::IntSize, RefPtr<gfx::SourceSurface>>
|
2015-09-19 23:34:09 +03:00
|
|
|
GetFrameInternal(const gfx::IntSize& aSize,
|
2017-11-17 22:08:52 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 14:45:24 +03:00
|
|
|
uint32_t aWhichFrame, uint32_t aFlags) override;
|
2012-09-25 00:31:30 +04:00
|
|
|
|
2018-09-14 02:48:21 +03:00
|
|
|
Tuple<ImgDrawResult, gfx::IntSize> GetImageContainerSize(
|
|
|
|
layers::LayerManager* aManager, const gfx::IntSize& aSize,
|
|
|
|
uint32_t aFlags) override;
|
2017-11-17 14:45:26 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Decoding.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-19 01:02:13 +03:00
|
|
|
/**
|
|
|
|
* Creates and runs a decoder, either synchronously or asynchronously
|
2015-07-23 08:39:51 +03:00
|
|
|
* according to @aFlags. Decodes at the provided target size @aSize, using
|
2016-08-18 10:06:41 +03:00
|
|
|
* decode flags @aFlags. Performs a single-frame decode of this image unless
|
|
|
|
* we know the image is animated *and* @aPlaybackType is
|
|
|
|
* PlaybackType::eAnimated.
|
2015-07-23 08:39:51 +03:00
|
|
|
*
|
|
|
|
* It's an error to call Decode() before this image's intrinsic size is
|
|
|
|
* available. A metadata decode must successfully complete first.
|
2016-12-22 22:15:41 +03:00
|
|
|
*
|
|
|
|
* Returns true of the decode was run synchronously.
|
2015-01-19 01:02:13 +03:00
|
|
|
*/
|
2016-12-22 22:15:41 +03:00
|
|
|
bool Decode(const gfx::IntSize& aSize, uint32_t aFlags,
|
|
|
|
PlaybackType aPlaybackType);
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2015-01-19 01:02:13 +03:00
|
|
|
/**
|
2015-07-23 08:39:51 +03:00
|
|
|
* Creates and runs a metadata decoder, either synchronously or
|
|
|
|
* asynchronously according to @aFlags.
|
2015-01-19 01:02:13 +03:00
|
|
|
*/
|
2015-07-23 08:39:51 +03:00
|
|
|
NS_IMETHOD DecodeMetadata(uint32_t aFlags);
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2015-08-14 10:37:13 +03: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-24 02:53:40 +03: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 10:37:13 +03:00
|
|
|
*/
|
2015-09-24 02:53:40 +03:00
|
|
|
bool SetMetadata(const ImageMetadata& aMetadata, bool aFromMetadataDecode);
|
2015-08-14 10:37:13 +03:00
|
|
|
|
2015-02-04 03:38:36 +03:00
|
|
|
/**
|
2015-08-18 20:19:14 +03: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
|
2017-07-06 15:00:35 +03:00
|
|
|
* perceive that we've entered an invalid state.
|
2015-08-18 20:19:14 +03:00
|
|
|
*
|
|
|
|
* RecoverFromInvalidFrames discards all existing frames and redecodes using
|
|
|
|
* the provided @aSize and @aFlags.
|
2015-02-04 03:38:36 +03:00
|
|
|
*/
|
2015-08-18 20:19:14 +03:00
|
|
|
void RecoverFromInvalidFrames(const nsIntSize& aSize, uint32_t aFlags);
|
2015-02-04 03:38:36 +03:00
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
void OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded);
|
|
|
|
|
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
|
|
|
private: // data
|
2007-03-21 02:56:50 +03:00
|
|
|
nsIntSize mSize;
|
2017-03-22 16:05:36 +03:00
|
|
|
nsTArray<nsIntSize> mNativeSizes;
|
2013-08-25 11:19:42 +04:00
|
|
|
Orientation mOrientation;
|
2011-01-13 04:45:13 +03:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
/// If this has a value, we're waiting for SetSize() to send the load event.
|
|
|
|
Maybe<Progress> mLoadProgress;
|
|
|
|
|
2014-08-23 00:49:54 +04:00
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
/// If this image is animated, a FrameAnimator which manages its animation.
|
2016-07-19 09:26:58 +03:00
|
|
|
UniquePtr<FrameAnimator> mFrameAnimator;
|
|
|
|
|
|
|
|
/// Animation timeline and other state for animation images.
|
|
|
|
Maybe<AnimationState> mAnimationState;
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2014-11-28 06:55:57 +03:00
|
|
|
// Image locking.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mLockCount;
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2015-07-21 19:42:30 +03:00
|
|
|
// The type of decoder this image needs. Computed from the MIME type in
|
|
|
|
// Init().
|
2015-07-23 08:39:48 +03:00
|
|
|
DecoderType mDecoderType;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2011-09-08 22:05:11 +04:00
|
|
|
// How many times we've decoded this image.
|
|
|
|
// This is currently only used for statistics
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mDecodeCount;
|
2013-03-23 03:12:40 +04:00
|
|
|
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mFramesNotified;
|
2010-09-08 04:34:18 +04:00
|
|
|
#endif
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// The source data for this image.
|
2016-06-27 07:50:43 +03:00
|
|
|
NotNull<RefPtr<SourceBuffer>> mSourceBuffer;
|
2013-03-02 03:17:24 +04:00
|
|
|
|
2010-05-13 01:41:47 +04:00
|
|
|
// Boolean flags (clustered together to conserve space):
|
2016-11-28 16:42:55 +03:00
|
|
|
bool mHasSize : 1; // Has SetSize() been called?
|
|
|
|
bool mTransient : 1; // Is the image short-lived?
|
|
|
|
bool mSyncLoad : 1; // Are we loading synchronously?
|
|
|
|
bool mDiscardable : 1; // Is container discardable?
|
|
|
|
bool mSomeSourceData : 1; // Do we have some source data?
|
|
|
|
bool mAllSourceData : 1; // Do we have all the source data?
|
2015-01-16 02:11:36 +03:00
|
|
|
bool mHasBeenDecoded : 1; // Decoded at least once?
|
2010-05-13 01:41:47 +04:00
|
|
|
|
2014-11-27 00:22:10 +03: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-13 01:41:47 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
// Whether the animation can stop, due to running out
|
|
|
|
// of frames, or no more owning request
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAnimationFinished : 1;
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2015-07-23 08:39:54 +03:00
|
|
|
// Whether, once we are done doing a metadata decode, we should immediately
|
|
|
|
// kick off a full decode.
|
2013-01-31 22:38:24 +04:00
|
|
|
bool mWantFullDecode : 1;
|
|
|
|
|
2011-08-11 03:12:08 +04:00
|
|
|
TimeStamp mDrawStartTime;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2014-09-20 01:53:29 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Scaling.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-04-04 01:57:22 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
// Determines whether we can downscale during decode with the given
|
|
|
|
// parameters.
|
2015-01-19 01:02:14 +03:00
|
|
|
bool CanDownscaleDuringDecode(const nsIntSize& aSize, uint32_t aFlags);
|
|
|
|
|
2013-09-13 01:40:16 +04:00
|
|
|
// Error handling.
|
2009-09-13 02:44:18 +04:00
|
|
|
void DoError();
|
2013-09-13 01:40:16 +04:00
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class HandleErrorWorker : public Runnable {
|
2013-09-13 01:40:16 +04: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);
|
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2013-09-13 01:40:16 +04:00
|
|
|
|
|
|
|
private:
|
2014-09-02 20:20:24 +04:00
|
|
|
explicit HandleErrorWorker(RasterImage* aImage);
|
2013-09-13 01:40:16 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RasterImage> mImage;
|
2013-09-13 01:40:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helpers
|
2011-08-05 17:57:16 +04:00
|
|
|
bool CanDiscard();
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2016-08-23 05:15:38 +03:00
|
|
|
bool IsOpaque();
|
|
|
|
|
2016-12-23 10:07:45 +03:00
|
|
|
DrawableSurface RequestDecodeForSizeInternal(const gfx::IntSize& aSize,
|
|
|
|
uint32_t aFlags);
|
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
protected:
|
2018-06-06 03:42:56 +03:00
|
|
|
explicit RasterImage(nsIURI* aURI = nullptr);
|
2012-12-18 06:35:46 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool ShouldAnimate() override;
|
2012-12-18 02:05:18 +04:00
|
|
|
|
|
|
|
friend class ImageFactory;
|
2009-09-13 02:44:18 +04:00
|
|
|
};
|
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
inline NS_IMETHODIMP RasterImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
2012-10-20 00:27:11 +04:00
|
|
|
return GetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-14 08:09:49 +04:00
|
|
|
} // namespace mozilla
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2016-06-30 01:56:41 +03:00
|
|
|
/**
|
|
|
|
* Casting RasterImage to nsISupports is ambiguous. This method handles that.
|
|
|
|
*/
|
|
|
|
inline nsISupports* ToSupports(mozilla::image::RasterImage* p) {
|
|
|
|
return NS_ISUPPORTS_CAST(mozilla::image::ImageResource*, p);
|
|
|
|
}
|
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif /* mozilla_image_RasterImage_h */
|