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"
|
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
|
|
|
#include "imgFrame.h"
|
2015-07-01 04:57:03 +03:00
|
|
|
#include "LookupResult.h"
|
2009-09-13 02:44:18 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2014-11-19 05:17:17 +03:00
|
|
|
#include "DecodePool.h"
|
2015-07-23 08:39:48 +03:00
|
|
|
#include "DecoderFactory.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"
|
2015-03-18 05:40:16 +03:00
|
|
|
#include "mozilla/Pair.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"
|
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;
|
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;
|
2013-07-15 22:38:59 +04:00
|
|
|
class FrameAnimator;
|
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
|
|
|
|
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
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void OnSurfaceDiscarded() override;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2010-08-24 02:44:07 +04:00
|
|
|
/* The total number of frames in this image. */
|
2015-01-07 12:40:23 +03:00
|
|
|
uint32_t GetNumFrames() const { return mFrameCount; }
|
2010-08-24 02:44:07 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf)
|
|
|
|
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.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void OnAddedFrame(uint32_t aNewFrameCount, const nsIntRect& aNewRefreshArea);
|
2015-01-07 12:40:23 +03:00
|
|
|
|
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.
|
2015-08-15 03:56:44 +03:00
|
|
|
* @param aFlags The surface flags used by the decoder that generated
|
|
|
|
* these notifications, or DefaultSurfaceFlags() if the
|
2015-01-16 02:11:36 +03:00
|
|
|
* notifications don't come from a decoder.
|
|
|
|
*/
|
|
|
|
void NotifyProgress(Progress aProgress,
|
|
|
|
const nsIntRect& aInvalidRect = nsIntRect(),
|
2015-08-15 03:56:44 +03:00
|
|
|
SurfaceFlags aSurfaceFlags = DefaultSurfaceFlags());
|
2015-01-16 02:11:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Records telemetry and does final teardown of the provided decoder.
|
|
|
|
*
|
|
|
|
* Main-thread only.
|
|
|
|
*/
|
|
|
|
void FinalizeDecoder(Decoder* aDecoder);
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
// Helper method for FinalizeDecoder.
|
2015-07-31 17:29:15 +03:00
|
|
|
void ReportDecoderError(Decoder* aDecoder);
|
|
|
|
|
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,
|
2013-02-14 06:41:10 +04:00
|
|
|
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
|
|
|
|
2013-03-23 03:12:40 +04:00
|
|
|
/* Provide a hint for the requested resolution of the resulting image. */
|
|
|
|
void SetRequestedResolution(const nsIntSize requestedResolution) {
|
|
|
|
mRequestedResolution = requestedResolution;
|
|
|
|
}
|
|
|
|
|
2014-03-01 01:43:14 +04:00
|
|
|
/* Provide a hint for the requested dimension of the resulting image. */
|
|
|
|
void SetRequestedSampleSize(int requestedSampleSize) {
|
|
|
|
mRequestedSampleSize = requestedSampleSize;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
DrawResult DrawWithPreDownscaleIfNeeded(DrawableFrameRef&& aFrameRef,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
|
|
|
GraphicsFilter aFilter,
|
|
|
|
uint32_t aFlags);
|
2012-04-04 01:57:22 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> CopyFrame(uint32_t aWhichFrame,
|
2015-02-03 08:40:35 +03:00
|
|
|
uint32_t aFlags);
|
2015-03-18 05:40:16 +03:00
|
|
|
|
|
|
|
Pair<DrawResult, RefPtr<gfx::SourceSurface>>
|
|
|
|
GetFrameInternal(uint32_t aWhichFrame, uint32_t aFlags);
|
2014-09-27 05:50:24 +04:00
|
|
|
|
2015-07-01 04:57:03 +03:00
|
|
|
LookupResult LookupFrameInternal(uint32_t aFrameNum,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
uint32_t aFlags);
|
2014-11-27 00:22:10 +03:00
|
|
|
DrawableFrameRef LookupFrame(uint32_t aFrameNum,
|
|
|
|
const nsIntSize& aSize,
|
2015-02-03 08:40:35 +03:00
|
|
|
uint32_t aFlags);
|
2014-09-13 05:29:27 +04:00
|
|
|
uint32_t GetCurrentFrameIndex() const;
|
|
|
|
uint32_t GetRequestedFrameIndex(uint32_t aWhichFrame) const;
|
2012-10-14 06:17:40 +04:00
|
|
|
|
2014-11-10 23:37:35 +03:00
|
|
|
nsIntRect GetFirstFrameRect();
|
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
Pair<DrawResult, nsRefPtr<layers::Image>>
|
|
|
|
GetCurrentImage(layers::ImageContainer* aContainer, uint32_t aFlags);
|
|
|
|
|
2012-09-25 00:31:30 +04:00
|
|
|
void UpdateImageContainer();
|
|
|
|
|
2013-04-26 23:58:17 +04: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 20:49:00 +03:00
|
|
|
bool IsUnlocked() {
|
|
|
|
return (mLockCount == 0 || (mAnim && mAnimationConsumers == 0));
|
|
|
|
}
|
2013-04-26 23:58:17 +04: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
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* If downscale-during-decode is not enabled for this image (i.e., if
|
|
|
|
* mDownscaleDuringDecode is false), it is an error to pass an @aSize value
|
|
|
|
* different from this image's intrinsic size.
|
2015-01-19 01:02:13 +03:00
|
|
|
*/
|
2015-07-23 08:39:51 +03:00
|
|
|
NS_IMETHOD Decode(const gfx::IntSize& aSize, uint32_t aFlags);
|
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-08-18 20:19:26 +03:00
|
|
|
void 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
|
|
|
|
* perceive that we've entered an invalid state.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
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;
|
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.
|
2014-09-09 17:39:00 +04:00
|
|
|
UniquePtr<FrameAnimator> mAnim;
|
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;
|
2011-09-08 22:05:11 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
// If the image contains multiple resolutions, a hint as to which one
|
|
|
|
// should be used
|
2013-03-23 03:12:40 +04:00
|
|
|
nsIntSize mRequestedResolution;
|
|
|
|
|
2014-03-01 01:43:14 +04:00
|
|
|
// A hint for image decoder that directly scale the image to smaller buffer
|
|
|
|
int mRequestedSampleSize;
|
|
|
|
|
2015-01-17 01:11:23 +03: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 07:37:51 +04:00
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
// If mImageContainer is non-null, this contains the DrawResult we obtained
|
|
|
|
// the last time we updated it.
|
|
|
|
DrawResult mLastImageContainerDrawResult;
|
|
|
|
|
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.
|
|
|
|
nsRefPtr<SourceBuffer> mSourceBuffer;
|
2013-03-02 03:17:24 +04:00
|
|
|
|
2015-01-07 12:40:23 +03:00
|
|
|
// The number of frames this image has.
|
|
|
|
uint32_t mFrameCount;
|
|
|
|
|
2010-05-13 01:41:47 +04:00
|
|
|
// Boolean flags (clustered together to conserve space):
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasSize:1; // Has SetSize() been called?
|
2015-01-07 12:37:20 +03:00
|
|
|
bool mTransient:1; // Is the image short-lived?
|
2015-06-30 12:37:58 +03:00
|
|
|
bool mSyncLoad:1; // Are we loading synchronously?
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDiscardable:1; // Is container discardable?
|
|
|
|
bool mHasSourceData:1; // Do we have source data?
|
2015-01-16 02:11:36 +03:00
|
|
|
bool mHasBeenDecoded:1; // Decoded at least once?
|
2015-01-19 01:02:13 +03:00
|
|
|
bool mDownscaleDuringDecode:1;
|
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
|
|
|
|
2012-10-13 02:24:47 +04:00
|
|
|
|
2014-09-20 01:53:29 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Scaling.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2012-04-04 01:57:22 +04:00
|
|
|
|
2014-09-20 01:53:29 +04:00
|
|
|
// Initiates an HQ scale for the given frame, if possible.
|
|
|
|
void RequestScale(imgFrame* aFrame, uint32_t aFlags, const nsIntSize& aSize);
|
2012-10-13 02:20:22 +04:00
|
|
|
|
2014-09-20 01:53:29 +04:00
|
|
|
// Determines whether we can perform an HQ scale with the given parameters.
|
2015-03-31 20:49:00 +03:00
|
|
|
bool CanScale(GraphicsFilter aFilter, const nsIntSize& aSize,
|
|
|
|
uint32_t aFlags);
|
2014-09-15 08:51:20 +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);
|
|
|
|
|
2014-09-20 01:53:29 +04:00
|
|
|
// Called by the HQ scaler when a new scaled frame is ready.
|
|
|
|
void NotifyNewScaledFrame();
|
|
|
|
|
|
|
|
friend class ScaleRunner;
|
2013-09-28 22:28:44 +04:00
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
|
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
|
|
|
|
|
|
|
class HandleErrorWorker : public nsRunnable
|
|
|
|
{
|
|
|
|
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 20:20:24 +04:00
|
|
|
explicit HandleErrorWorker(RasterImage* aImage);
|
2013-09-13 01:40:16 +04:00
|
|
|
|
|
|
|
nsRefPtr<RasterImage> mImage;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Helpers
|
2011-08-05 17:57:16 +04:00
|
|
|
bool CanDiscard();
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
protected:
|
2015-04-29 02:32:02 +03:00
|
|
|
explicit RasterImage(ImageURL* 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
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif /* mozilla_image_RasterImage_h */
|