2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Stuart Parmenter <pavlov@netscape.com>
|
|
|
|
* Chris Saari <saari@netscape.com>
|
2007-10-18 17:36:34 -07:00
|
|
|
* Federico Mena-Quintero <federico@novell.com>
|
2009-09-12 15:44:18 -07:00
|
|
|
* Bobby Holley <bobbyholley@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/** @file
|
2010-08-13 21:09:49 -07:00
|
|
|
* This file declares the RasterImage class, which
|
|
|
|
* handles static and animated rasterized images.
|
2007-03-22 10:30:00 -07: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>
|
|
|
|
*/
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
#ifndef mozilla_imagelib_RasterImage_h_
|
|
|
|
#define mozilla_imagelib_RasterImage_h_
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
#include "Image.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIProperties.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsWeakReference.h"
|
2007-10-18 17:36:34 -07: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-20 18:50:15 -07:00
|
|
|
#include "imgFrame.h"
|
2009-09-12 15:44:18 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2010-08-13 21:09:49 -07:00
|
|
|
#include "DiscardTracker.h"
|
2010-09-07 17:34:18 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include "imgIContainerDebug.h"
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 21:09:48 -07:00
|
|
|
class imgIDecoder;
|
|
|
|
class nsIInputStream;
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
#define NS_RASTERIMAGE_CID \
|
2010-08-05 07:53:43 -07: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-20 18:50:15 -07:00
|
|
|
0x376ff2c1, \
|
|
|
|
0x9bf6, \
|
|
|
|
0x418a, \
|
|
|
|
{0xb1, 0x43, 0x33, 0x40, 0xc0, 0x01, 0x12, 0xf7} \
|
2007-03-22 10:30:00 -07: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-13 21:09:49 -07:00
|
|
|
* Once RasterImage detects more than one frame, it starts the animation
|
2007-03-22 10:30:00 -07:00
|
|
|
* with StartAnimation().
|
|
|
|
*
|
|
|
|
* @par
|
2010-09-07 17:33:02 -07:00
|
|
|
* StartAnimation() creates a timer. The timer calls Notify when the
|
|
|
|
* specified frame delay time is up.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* Notify() moves on to the next frame, sets up the new timer delay, destroys
|
|
|
|
* the old frame, and forces a redraw via observer->FrameChanged().
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* Each frame can have a different method of removing itself. These are
|
|
|
|
* listed as imgIContainer::cDispose... constants. Notify() calls
|
|
|
|
* 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-13 21:09:49 -07:00
|
|
|
* The rest of the RasterImage specific functions are used by DoComposite to
|
2007-03-22 10:30:00 -07:00
|
|
|
* destroy the old frame and build the new one.
|
|
|
|
*
|
|
|
|
* @note
|
2010-05-13 05:19:50 -07:00
|
|
|
* <li> "Mask", "Alpha", and "Alpha Level" are interchangeable phrases in
|
2010-08-13 21:09:49 -07:00
|
|
|
* respects to RasterImage.
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*
|
|
|
|
* @note
|
|
|
|
* mAnimationMode, mLoopCount and mObserver are not in the mAnim structure
|
|
|
|
* because the first two have public setters and the observer we only get
|
|
|
|
* in Init().
|
|
|
|
*/
|
2010-08-13 21:09:49 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace imagelib {
|
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
class imgDecodeWorker;
|
2010-08-22 19:30:46 -07:00
|
|
|
class Decoder;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
2010-09-07 17:34:18 -07:00
|
|
|
class RasterImage : public mozilla::imagelib::Image
|
|
|
|
, public nsITimerCallback
|
|
|
|
, public nsIProperties
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
#ifdef DEBUG
|
|
|
|
, public imgIContainerDebug
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_IMGICONTAINER
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2007-06-21 13:45:49 -07:00
|
|
|
NS_DECL_NSIPROPERTIES
|
2010-09-07 17:34:18 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_DECL_IMGICONTAINERDEBUG
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-23 15:44:07 -07:00
|
|
|
RasterImage(imgStatusTracker* aStatusTracker = nsnull);
|
2010-08-13 21:09:49 -07:00
|
|
|
virtual ~RasterImage();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
virtual nsresult StartAnimation();
|
|
|
|
virtual nsresult StopAnimation();
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
// C++-only version of imgIContainer::GetType, for convenience
|
|
|
|
virtual PRUint16 GetType() { return imgIContainer::TYPE_RASTER; }
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
// Methods inherited from Image
|
2010-08-23 15:44:07 -07:00
|
|
|
nsresult Init(imgIDecoderObserver* aObserver,
|
2010-08-13 21:09:49 -07:00
|
|
|
const char* aMimeType,
|
2010-09-12 08:22:26 -07:00
|
|
|
const char* aURIString,
|
2010-08-13 21:09:49 -07:00
|
|
|
PRUint32 aFlags);
|
2010-08-23 15:44:07 -07:00
|
|
|
void GetCurrentFrameRect(nsIntRect& aRect);
|
2010-08-22 19:30:44 -07:00
|
|
|
PRUint32 GetDataSize();
|
2010-08-13 21:09:49 -07:00
|
|
|
|
|
|
|
// Raster-specific methods
|
2010-08-13 21:09:51 -07:00
|
|
|
static NS_METHOD WriteToRasterImage(nsIInputStream* aIn, void* aClosure,
|
|
|
|
const char* aFromRawSegment,
|
|
|
|
PRUint32 aToOffset, PRUint32 aCount,
|
|
|
|
PRUint32* aWriteCount);
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2010-08-23 15:44:07 -07:00
|
|
|
/* The index of the current frame that would be drawn if the image was to be
|
|
|
|
* drawn now. */
|
|
|
|
PRUint32 GetCurrentFrameIndex();
|
|
|
|
|
|
|
|
/* The total number of frames in this image. */
|
|
|
|
PRUint32 GetNumFrames();
|
|
|
|
|
2010-05-21 21:10:14 -07:00
|
|
|
PRUint32 GetDecodedDataSize();
|
|
|
|
PRUint32 GetSourceDataSize();
|
|
|
|
|
2010-07-01 10:39:44 -07:00
|
|
|
/* Triggers discarding. */
|
|
|
|
void Discard();
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
/* Callbacks for decoders */
|
|
|
|
nsresult SetFrameDisposalMethod(PRUint32 aFrameNum,
|
|
|
|
PRInt32 aDisposalMethod);
|
|
|
|
nsresult SetFrameTimeout(PRUint32 aFrameNum, PRInt32 aTimeout);
|
|
|
|
nsresult SetFrameBlendMethod(PRUint32 aFrameNum, PRInt32 aBlendMethod);
|
|
|
|
nsresult SetFrameHasNoAlpha(PRUint32 aFrameNum);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the size of the container. This should only be called by the
|
|
|
|
* decoder. This function may be called multiple times, but will throw an
|
|
|
|
* error if subsequent calls do not match the first.
|
|
|
|
*/
|
|
|
|
nsresult SetSize(PRInt32 aWidth, PRInt32 aHeight);
|
|
|
|
|
|
|
|
nsresult EnsureCleanFrame(PRUint32 aFramenum, PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aWidth, PRInt32 aHeight,
|
|
|
|
gfxASurface::gfxImageFormat aFormat,
|
|
|
|
PRUint8** imageData,
|
|
|
|
PRUint32* imageLength);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds to the end of the list of frames.
|
|
|
|
*/
|
|
|
|
nsresult AppendFrame(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aWidth, PRInt32 aHeight,
|
|
|
|
gfxASurface::gfxImageFormat aFormat,
|
|
|
|
PRUint8** imageData,
|
|
|
|
PRUint32* imageLength);
|
|
|
|
|
|
|
|
nsresult AppendPalettedFrame(PRInt32 aX, PRInt32 aY,
|
|
|
|
PRInt32 aWidth, PRInt32 aHeight,
|
|
|
|
gfxASurface::gfxImageFormat aFormat,
|
|
|
|
PRUint8 aPaletteDepth,
|
|
|
|
PRUint8** imageData,
|
|
|
|
PRUint32* imageLength,
|
|
|
|
PRUint32** paletteData,
|
|
|
|
PRUint32* paletteLength);
|
|
|
|
|
2010-08-24 14:12:04 -07:00
|
|
|
void FrameUpdated(PRUint32 aFrameNum, nsIntRect& aUpdatedRect);
|
2010-08-13 21:09:49 -07:00
|
|
|
|
|
|
|
/* notification that the entire image has been decoded */
|
|
|
|
nsresult DecodingComplete();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of times to loop the image.
|
|
|
|
* @note -1 means forever.
|
|
|
|
*/
|
|
|
|
void SetLoopCount(PRInt32 aLoopCount);
|
|
|
|
|
|
|
|
/* Add compressed source data to the imgContainer.
|
|
|
|
*
|
|
|
|
* The decoder will use this data, either immediately or at draw time, to
|
|
|
|
* decode the image.
|
|
|
|
*
|
|
|
|
* XXX This method's only caller (WriteToContainer) ignores the return
|
|
|
|
* value. Should this just return void?
|
|
|
|
*/
|
|
|
|
nsresult AddSourceData(const char *aBuffer, PRUint32 aCount);
|
|
|
|
|
|
|
|
/* Called after the all the source data has been added with addSourceData. */
|
|
|
|
virtual nsresult SourceDataComplete();
|
|
|
|
|
|
|
|
/* Called for multipart images when there's a new source image to add. */
|
|
|
|
virtual nsresult NewSourceData();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
virtual nsresult SetSourceSizeHint(PRUint32 sizeHint);
|
|
|
|
|
|
|
|
// "Blend" method indicates how the current image is combined with the
|
|
|
|
// previous image.
|
|
|
|
enum {
|
|
|
|
// All color components of the frame, including alpha, overwrite the current
|
|
|
|
// contents of the frame's output buffer region
|
|
|
|
kBlendSource = 0,
|
|
|
|
|
|
|
|
// The frame should be composited onto the output buffer based on its alpha,
|
|
|
|
// using a simple OVER operation
|
|
|
|
kBlendOver
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kDisposeClearAll = -1, // Clear the whole image, revealing
|
|
|
|
// what was there before the gif displayed
|
|
|
|
kDisposeNotSpecified, // Leave frame, let new frame draw on top
|
|
|
|
kDisposeKeep, // Leave frame, let new frame draw on top
|
|
|
|
kDisposeClear, // Clear the frame's area, revealing bg
|
|
|
|
kDisposeRestorePrevious // Restore the previous (composited) frame
|
|
|
|
};
|
|
|
|
|
2010-08-25 15:58:27 -07:00
|
|
|
// Progressive decoding knobs
|
|
|
|
static void SetDecodeBytesAtATime(PRUint32 aBytesAtATime);
|
|
|
|
static void SetMaxMSBeforeYield(PRUint32 aMaxMS);
|
2010-08-26 15:54:21 -07:00
|
|
|
static void SetMaxBytesForSyncDecode(PRUint32 aMaxBytes);
|
2010-08-25 15:58:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
struct Anim
|
|
|
|
{
|
|
|
|
//! Area of the first frame that needs to be redrawn on subsequent loops.
|
|
|
|
nsIntRect firstFrameRefreshArea;
|
2009-09-12 15:44:18 -07:00
|
|
|
PRUint32 currentAnimationFrameIndex; // 0 to numFrames-1
|
2007-03-22 10:30:00 -07:00
|
|
|
//! Track the last composited frame for Optimizations (See DoComposite code)
|
|
|
|
PRInt32 lastCompositedFrameIndex;
|
|
|
|
/** For managing blending of frames
|
|
|
|
*
|
|
|
|
* Some animations will use the compositingFrame to composite images
|
|
|
|
* and just hand this back to the caller when it is time to draw the frame.
|
|
|
|
* NOTE: When clearing compositingFrame, remember to set
|
|
|
|
* lastCompositedFrameIndex to -1. Code assume that if
|
|
|
|
* lastCompositedFrameIndex >= 0 then compositingFrame exists.
|
|
|
|
*/
|
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-20 18:50:15 -07:00
|
|
|
nsAutoPtr<imgFrame> compositingFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
/** the previous composited frame, for DISPOSE_RESTORE_PREVIOUS
|
|
|
|
*
|
|
|
|
* The Previous Frame (all frames composited up to the current) needs to be
|
|
|
|
* stored in cases where the image specifies it wants the last frame back
|
|
|
|
* when it's done with the current frame.
|
|
|
|
*/
|
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-20 18:50:15 -07:00
|
|
|
nsAutoPtr<imgFrame> compositingPrevFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
//! Timer to animate multiframed images
|
|
|
|
nsCOMPtr<nsITimer> timer;
|
2010-05-12 14:41:47 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
Anim() :
|
|
|
|
firstFrameRefreshArea(),
|
|
|
|
currentAnimationFrameIndex(0),
|
2010-09-12 08:22:30 -07:00
|
|
|
lastCompositedFrameIndex(-1)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
~Anim()
|
|
|
|
{
|
|
|
|
if (timer)
|
|
|
|
timer->Cancel();
|
|
|
|
}
|
|
|
|
};
|
2007-10-18 17:36:34 -07:00
|
|
|
|
2010-03-08 11:01:04 -08:00
|
|
|
/**
|
|
|
|
* Deletes and nulls out the frame in mFrames[framenum].
|
|
|
|
*
|
|
|
|
* Does not change the size of mFrames.
|
|
|
|
*
|
|
|
|
* @param framenum The index of the frame to be deleted.
|
|
|
|
* Must lie in [0, mFrames.Length() )
|
|
|
|
*/
|
|
|
|
void DeleteImgFrame(PRUint32 framenum);
|
|
|
|
|
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-20 18:50:15 -07:00
|
|
|
imgFrame* GetImgFrame(PRUint32 framenum);
|
2009-11-12 15:18:40 -08:00
|
|
|
imgFrame* GetDrawableImgFrame(PRUint32 framenum);
|
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-20 18:50:15 -07:00
|
|
|
imgFrame* GetCurrentImgFrame();
|
2009-11-12 15:18:40 -08:00
|
|
|
imgFrame* GetCurrentDrawableImgFrame();
|
2009-09-12 15:44:18 -07:00
|
|
|
PRUint32 GetCurrentImgFrameIndex() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
inline Anim* ensureAnimExists()
|
|
|
|
{
|
|
|
|
if (!mAnim) {
|
|
|
|
|
|
|
|
// Create the animation context
|
2007-03-22 10:30:00 -07:00
|
|
|
mAnim = new Anim();
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2009-09-15 17:30:52 -07:00
|
|
|
// We don't support discarding animated images (See bug 414259).
|
|
|
|
// Lock the image and throw away the key.
|
|
|
|
//
|
|
|
|
// Note that this is inefficient, since we could get rid of the source
|
|
|
|
// data too. However, doing this is actually hard, because we're probably
|
|
|
|
// calling ensureAnimExists mid-decode, and thus we're decoding out of
|
|
|
|
// the source buffer. Since we're going to fix this anyway later, and
|
|
|
|
// since we didn't kill the source data in the old world either, locking
|
|
|
|
// is acceptable for the moment.
|
|
|
|
LockImage();
|
2009-09-12 15:44:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return mAnim;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Function for doing the frame compositing of animations
|
|
|
|
*
|
|
|
|
* @param aFrameToUse Set by DoComposite
|
|
|
|
* (aNextFrame, compositingFrame, or compositingPrevFrame)
|
|
|
|
* @param aDirtyRect Area that the display will need to update
|
|
|
|
* @param aPrevFrame Last Frame seen/processed
|
|
|
|
* @param aNextFrame Frame we need to incorperate/display
|
|
|
|
* @param aNextFrameIndex Position of aNextFrame in mFrames list
|
|
|
|
*/
|
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-20 18:50:15 -07:00
|
|
|
nsresult DoComposite(imgFrame** aFrameToUse, nsIntRect* aDirtyRect,
|
|
|
|
imgFrame* aPrevFrame,
|
|
|
|
imgFrame* aNextFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 aNextFrameIndex);
|
|
|
|
|
2007-06-07 08:10:25 -07:00
|
|
|
/** Clears an area of <aFrame> with transparent black.
|
2007-04-25 14:21:28 -07:00
|
|
|
*
|
|
|
|
* @param aFrame Target Frame
|
|
|
|
*
|
2007-06-07 08:10:25 -07:00
|
|
|
* @note Does also clears the transparancy mask
|
2007-04-25 14:21:28 -07: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-20 18:50:15 -07:00
|
|
|
static void ClearFrame(imgFrame* aFrame);
|
2007-06-07 08:10:25 -07:00
|
|
|
|
2007-04-25 14:21:28 -07:00
|
|
|
//! @overload
|
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-20 18:50:15 -07:00
|
|
|
static void ClearFrame(imgFrame* aFrame, nsIntRect &aRect);
|
2007-04-25 14:21:28 -07: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-20 18:50:15 -07:00
|
|
|
//! Copy one frames's image and mask into another
|
|
|
|
static PRBool CopyFrameImage(imgFrame *aSrcFrame,
|
|
|
|
imgFrame *aDstFrame);
|
2007-03-22 10:30:00 -07: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-20 18:50:15 -07:00
|
|
|
/** Draws one frames's image to into another,
|
2007-08-25 12:18:44 -07:00
|
|
|
* at the position specified by aRect
|
|
|
|
*
|
|
|
|
* @param aSrcFrame Frame providing the source image
|
|
|
|
* @param aDstFrame Frame where the image is drawn into
|
|
|
|
* @param aRect The position and size to draw the image
|
|
|
|
*/
|
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-20 18:50:15 -07:00
|
|
|
static nsresult DrawFrameTo(imgFrame *aSrcFrame,
|
|
|
|
imgFrame *aDstFrame,
|
2007-08-25 12:18:44 -07:00
|
|
|
nsIntRect& aRect);
|
|
|
|
|
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-20 18:50:15 -07:00
|
|
|
nsresult InternalAddFrameHelper(PRUint32 framenum, imgFrame *frame,
|
|
|
|
PRUint8 **imageData, PRUint32 *imageLength,
|
|
|
|
PRUint32 **paletteData, PRUint32 *paletteLength);
|
|
|
|
nsresult InternalAddFrame(PRUint32 framenum, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight,
|
|
|
|
gfxASurface::gfxImageFormat aFormat, PRUint8 aPaletteDepth,
|
|
|
|
PRUint8 **imageData, PRUint32 *imageLength,
|
|
|
|
PRUint32 **paletteData, PRUint32 *paletteLength);
|
|
|
|
|
|
|
|
private: // data
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIntSize mSize;
|
|
|
|
|
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-20 18:50:15 -07:00
|
|
|
//! All the frames of the image
|
2009-09-12 15:44:18 -07:00
|
|
|
// IMPORTANT: if you use mFrames in a method, call EnsureImageIsDecoded() first
|
|
|
|
// to ensure that the frames actually exist (they may have been discarded to save
|
|
|
|
// memory, or we may be decoding on draw).
|
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-20 18:50:15 -07:00
|
|
|
nsTArray<imgFrame *> mFrames;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2007-10-18 17:36:34 -07:00
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// IMPORTANT: if you use mAnim in a method, call EnsureImageIsDecoded() first to ensure
|
|
|
|
// that the frames actually exist (they may have been discarded to save memory, or
|
|
|
|
// we maybe decoding on draw).
|
2010-08-13 21:09:49 -07:00
|
|
|
RasterImage::Anim* mAnim;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//! See imgIContainer for mode constants
|
|
|
|
PRUint16 mAnimationMode;
|
|
|
|
|
|
|
|
//! # loops remaining before animation stops (-1 no stop)
|
|
|
|
PRInt32 mLoopCount;
|
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
//! imgIDecoderObserver
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWeakPtr mObserver;
|
2007-10-18 17:36:34 -07:00
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// Discard members
|
|
|
|
PRUint32 mLockCount;
|
2010-08-13 21:09:49 -07:00
|
|
|
DiscardTrackerNode mDiscardTrackerNode;
|
2007-10-18 17:36:34 -07:00
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// Source data members
|
|
|
|
nsTArray<char> mSourceData;
|
|
|
|
nsCString mSourceDataMimeType;
|
2010-09-12 08:22:26 -07:00
|
|
|
nsCString mURIString;
|
2009-09-12 15:44:18 -07:00
|
|
|
|
|
|
|
friend class imgDecodeWorker;
|
2010-08-13 21:09:49 -07:00
|
|
|
friend class DiscardTracker;
|
2009-09-12 15:44:18 -07:00
|
|
|
|
|
|
|
// Decoder and friends
|
2010-08-22 19:30:46 -07:00
|
|
|
nsRefPtr<Decoder> mDecoder;
|
2009-09-12 15:44:18 -07:00
|
|
|
nsRefPtr<imgDecodeWorker> mWorker;
|
|
|
|
PRUint32 mBytesDecoded;
|
|
|
|
|
2010-09-07 17:34:18 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRUint32 mFramesNotified;
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 14:41:47 -07:00
|
|
|
// Boolean flags (clustered together to conserve space):
|
|
|
|
PRPackedBool mHasSize:1; // Has SetSize() been called?
|
|
|
|
PRPackedBool mDecodeOnDraw:1; // Decoding on draw?
|
|
|
|
PRPackedBool mMultipart:1; // Multipart?
|
|
|
|
PRPackedBool mDiscardable:1; // Is container discardable?
|
|
|
|
PRPackedBool mHasSourceData:1; // Do we have source data?
|
|
|
|
|
|
|
|
// Do we have the frames in decoded form?
|
|
|
|
PRPackedBool mDecoded:1;
|
|
|
|
PRPackedBool mHasBeenDecoded:1;
|
|
|
|
|
|
|
|
// Helpers for decoder
|
|
|
|
PRPackedBool mWorkerPending:1;
|
|
|
|
PRPackedBool mInDecoder:1;
|
|
|
|
|
|
|
|
PRPackedBool mError:1; // Error handling
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
// Whether the animation can stop, due to running out
|
|
|
|
// of frames, or no more owning request
|
|
|
|
PRPackedBool mAnimationFinished:1;
|
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// Decoding
|
|
|
|
nsresult WantDecodedFrames();
|
|
|
|
nsresult SyncDecode();
|
2010-08-22 19:30:46 -07:00
|
|
|
nsresult InitDecoder(bool aDoSizeDecode);
|
2009-09-12 15:44:18 -07:00
|
|
|
nsresult WriteToDecoder(const char *aBuffer, PRUint32 aCount);
|
|
|
|
nsresult DecodeSomeData(PRUint32 aMaxBytes);
|
|
|
|
PRBool IsDecodeFinished();
|
|
|
|
|
|
|
|
// Decoder shutdown
|
|
|
|
enum eShutdownIntent {
|
|
|
|
eShutdownIntent_Done = 0,
|
|
|
|
eShutdownIntent_Interrupted = 1,
|
|
|
|
eShutdownIntent_Error = 2,
|
|
|
|
eShutdownIntent_AllCount = 3
|
|
|
|
};
|
|
|
|
nsresult ShutdownDecoder(eShutdownIntent aIntent);
|
|
|
|
|
|
|
|
// Helpers
|
|
|
|
void DoError();
|
|
|
|
PRBool CanDiscard();
|
2010-07-01 10:39:44 -07:00
|
|
|
PRBool DiscardingActive();
|
2009-09-12 15:44:18 -07:00
|
|
|
PRBool StoringSourceData();
|
|
|
|
|
2010-09-07 17:33:02 -07:00
|
|
|
protected:
|
|
|
|
PRBool ShouldAnimate();
|
2009-09-12 15:44:18 -07:00
|
|
|
};
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
// XXXdholbert These helper classes should move to be inside the
|
|
|
|
// scope of the RasterImage class.
|
2009-09-12 15:44:18 -07:00
|
|
|
// Decoding Helper Class
|
|
|
|
//
|
|
|
|
// We use this class to mimic the interactivity benefits of threading
|
|
|
|
// in a single-threaded event loop. We want to progressively decode
|
|
|
|
// and keep a responsive UI while we're at it, so we have a runnable
|
|
|
|
// class that does a bit of decoding, and then "yields" by dispatching
|
|
|
|
// itself to the end of the event queue.
|
|
|
|
class imgDecodeWorker : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgDecodeWorker(imgIContainer* aContainer) {
|
|
|
|
mContainer = do_GetWeakReference(aContainer);
|
|
|
|
}
|
|
|
|
NS_IMETHOD Run();
|
|
|
|
NS_METHOD Dispatch();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsWeakPtr mContainer;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// Asynchronous Decode Requestor
|
|
|
|
//
|
|
|
|
// We use this class when someone calls requestDecode() from within a decode
|
|
|
|
// notification. Since requestDecode() involves modifying the decoder's state
|
|
|
|
// (for example, possibly shutting down a header-only decode and starting a
|
|
|
|
// full decode), we don't want to do this from inside a decoder.
|
|
|
|
class imgDecodeRequestor : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
imgDecodeRequestor(imgIContainer *aContainer) {
|
|
|
|
mContainer = do_GetWeakReference(aContainer);
|
|
|
|
}
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsCOMPtr<imgIContainer> con = do_QueryReferent(mContainer);
|
|
|
|
if (con)
|
|
|
|
con->RequestDecode();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsWeakPtr mContainer;
|
|
|
|
};
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
} // namespace imagelib
|
|
|
|
} // namespace mozilla
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
#endif /* mozilla_imagelib_RasterImage_h_ */
|