2001-03-10 01:11:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-10-07 21:49:33 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* 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.
|
2002-10-07 21:49:33 +00:00
|
|
|
*
|
2001-03-10 01:11:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
2002-10-07 21:49:33 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* 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.
|
2002-10-07 21:49:33 +00:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-03-10 01:11:54 +00:00
|
|
|
* Stuart Parmenter <pavlov@netscape.com>
|
|
|
|
* Chris Saari <saari@netscape.com>
|
2007-10-19 00:36:34 +00:00
|
|
|
* Federico Mena-Quintero <federico@novell.com>
|
2009-09-12 22:44:18 +00:00
|
|
|
* Bobby Holley <bobbyholley@gmail.com>
|
2004-04-18 22:01:16 +00: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 ***** */
|
2001-03-10 01:11:54 +00:00
|
|
|
|
2007-03-20 23:56:50 +00:00
|
|
|
/** @file
|
|
|
|
* This file declares the imgContainer class, which
|
|
|
|
* handles static and animated image containers.
|
|
|
|
*
|
|
|
|
* @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>
|
|
|
|
*/
|
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
#ifndef __imgContainer_h__
|
|
|
|
#define __imgContainer_h__
|
|
|
|
|
2007-03-20 23:56:50 +00:00
|
|
|
#include "nsCOMArray.h"
|
2001-03-10 01:11:54 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2002-10-07 21:49:33 +00:00
|
|
|
#include "imgIContainer.h"
|
2009-09-12 22:44:18 +00:00
|
|
|
#include "imgIDecoder.h"
|
2005-01-12 20:16:07 +00:00
|
|
|
#include "nsIProperties.h"
|
2007-03-20 23:56:50 +00:00
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsWeakReference.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"
|
2009-09-12 22:44:18 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2001-03-27 02:42:51 +00:00
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
#define NS_IMGCONTAINER_CID \
|
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
|
|
|
{ /* c76ff2c1-9bf6-418a-b143-3340c00112f7 */ \
|
|
|
|
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.
|
|
|
|
* Once imgContainer detects more than one frame, it starts the animation
|
|
|
|
* with StartAnimation().
|
|
|
|
*
|
|
|
|
* @par
|
|
|
|
* StartAnimation() checks if animating is allowed, and creates a timer. The
|
|
|
|
* timer calls Notify when the specified frame delay time is up.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* The rest of the imgContainer specific functions are used by DoComposite to
|
|
|
|
* 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
|
2007-10-04 03:07:38 +00:00
|
|
|
* respects to imgContainer.
|
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.
|
|
|
|
*
|
|
|
|
* @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().
|
|
|
|
*/
|
2009-09-12 22:44:18 +00:00
|
|
|
class imgDecodeWorker;
|
2007-03-20 23:56:50 +00:00
|
|
|
class imgContainer : public imgIContainer,
|
2009-09-12 22:44:18 +00:00
|
|
|
public nsITimerCallback,
|
|
|
|
public nsIProperties,
|
|
|
|
public nsSupportsWeakReference
|
2001-03-10 01:11:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_IMGICONTAINER
|
2007-03-20 23:56:50 +00:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2007-06-21 20:45:49 +00:00
|
|
|
NS_DECL_NSIPROPERTIES
|
2001-03-10 01:11:54 +00:00
|
|
|
|
|
|
|
imgContainer();
|
|
|
|
virtual ~imgContainer();
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
static NS_METHOD WriteToContainer(nsIInputStream* in, void* closure,
|
|
|
|
const char* fromRawSegment,
|
|
|
|
PRUint32 toOffset, PRUint32 count,
|
|
|
|
PRUint32 *writeCount);
|
|
|
|
|
2001-03-10 01:11:54 +00:00
|
|
|
private:
|
2007-03-20 23:56:50 +00:00
|
|
|
struct Anim
|
|
|
|
{
|
|
|
|
//! Area of the first frame that needs to be redrawn on subsequent loops.
|
|
|
|
nsIntRect firstFrameRefreshArea;
|
|
|
|
// Note this doesn't hold a proper value until frame 2 finished decoding.
|
2009-09-12 22:44:18 +00:00
|
|
|
PRUint32 currentDecodingFrameIndex; // 0 to numFrames-1
|
|
|
|
PRUint32 currentAnimationFrameIndex; // 0 to numFrames-1
|
2007-03-20 23:56:50 +00: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-21 01:50:15 +00:00
|
|
|
nsAutoPtr<imgFrame> compositingFrame;
|
2007-03-20 23:56:50 +00: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-21 01:50:15 +00:00
|
|
|
nsAutoPtr<imgFrame> compositingPrevFrame;
|
2007-03-20 23:56:50 +00:00
|
|
|
//! Timer to animate multiframed images
|
|
|
|
nsCOMPtr<nsITimer> timer;
|
2010-05-12 21:41:47 +00:00
|
|
|
//! Whether we can assume there will be no more frames
|
|
|
|
//! (and thus loop the animation)
|
|
|
|
PRPackedBool doneDecoding;
|
|
|
|
//! Are we currently animating the image?
|
|
|
|
PRPackedBool animating;
|
|
|
|
|
2007-03-20 23:56:50 +00:00
|
|
|
Anim() :
|
|
|
|
firstFrameRefreshArea(),
|
|
|
|
currentDecodingFrameIndex(0),
|
|
|
|
currentAnimationFrameIndex(0),
|
|
|
|
lastCompositedFrameIndex(-1),
|
|
|
|
doneDecoding(PR_FALSE),
|
|
|
|
animating(PR_FALSE)
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
~Anim()
|
|
|
|
{
|
|
|
|
if (timer)
|
|
|
|
timer->Cancel();
|
|
|
|
}
|
|
|
|
};
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2010-03-08 19:01:04 +00: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-21 01:50:15 +00:00
|
|
|
imgFrame* GetImgFrame(PRUint32 framenum);
|
2009-11-12 23:18:40 +00: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-21 01:50:15 +00:00
|
|
|
imgFrame* GetCurrentImgFrame();
|
2009-11-12 23:18:40 +00:00
|
|
|
imgFrame* GetCurrentDrawableImgFrame();
|
2009-09-12 22:44:18 +00:00
|
|
|
PRUint32 GetCurrentImgFrameIndex() const;
|
2007-03-20 23:56:50 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
inline Anim* ensureAnimExists()
|
|
|
|
{
|
|
|
|
if (!mAnim) {
|
|
|
|
|
|
|
|
// Create the animation context
|
2007-03-20 23:56:50 +00:00
|
|
|
mAnim = new Anim();
|
2009-09-12 22:44:18 +00:00
|
|
|
|
2009-09-16 00:30:52 +00: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 22:44:18 +00:00
|
|
|
}
|
2007-03-20 23:56:50 +00: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-21 01:50:15 +00:00
|
|
|
nsresult DoComposite(imgFrame** aFrameToUse, nsIntRect* aDirtyRect,
|
|
|
|
imgFrame* aPrevFrame,
|
|
|
|
imgFrame* aNextFrame,
|
2007-03-20 23:56:50 +00:00
|
|
|
PRInt32 aNextFrameIndex);
|
|
|
|
|
2007-06-07 15:10:25 +00:00
|
|
|
/** Clears an area of <aFrame> with transparent black.
|
2007-04-25 21:21:28 +00:00
|
|
|
*
|
|
|
|
* @param aFrame Target Frame
|
|
|
|
*
|
2007-06-07 15:10:25 +00:00
|
|
|
* @note Does also clears the transparancy mask
|
2007-04-25 21:21:28 +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
|
|
|
static void ClearFrame(imgFrame* aFrame);
|
2007-06-07 15:10:25 +00:00
|
|
|
|
2007-04-25 21:21:28 +00: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-21 01:50:15 +00:00
|
|
|
static void ClearFrame(imgFrame* aFrame, nsIntRect &aRect);
|
2007-04-25 21:21:28 +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
|
|
|
//! Copy one frames's image and mask into another
|
|
|
|
static PRBool CopyFrameImage(imgFrame *aSrcFrame,
|
|
|
|
imgFrame *aDstFrame);
|
2007-03-20 23:56:50 +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
|
|
|
/** Draws one frames's image to into another,
|
2007-08-25 19:18:44 +00: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-21 01:50:15 +00:00
|
|
|
static nsresult DrawFrameTo(imgFrame *aSrcFrame,
|
|
|
|
imgFrame *aDstFrame,
|
2007-08-25 19:18:44 +00: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-21 01:50:15 +00: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-20 23:56:50 +00: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-21 01:50:15 +00:00
|
|
|
//! All the frames of the image
|
2009-09-12 22:44:18 +00: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-21 01:50:15 +00:00
|
|
|
nsTArray<imgFrame *> mFrames;
|
2007-03-20 23:56:50 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProperties> mProperties;
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2009-09-12 22:44:18 +00: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).
|
2007-03-20 23:56:50 +00:00
|
|
|
imgContainer::Anim* mAnim;
|
|
|
|
|
|
|
|
//! See imgIContainer for mode constants
|
|
|
|
PRUint16 mAnimationMode;
|
|
|
|
|
|
|
|
//! # loops remaining before animation stops (-1 no stop)
|
|
|
|
PRInt32 mLoopCount;
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
//! imgIDecoderObserver
|
2007-03-20 23:56:50 +00:00
|
|
|
nsWeakPtr mObserver;
|
2007-10-19 00:36:34 +00:00
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// Discard members
|
|
|
|
PRUint32 mLockCount;
|
2007-10-19 00:36:34 +00:00
|
|
|
nsCOMPtr<nsITimer> mDiscardTimer;
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
// Source data members
|
|
|
|
nsTArray<char> mSourceData;
|
|
|
|
nsCString mSourceDataMimeType;
|
|
|
|
|
|
|
|
friend class imgDecodeWorker;
|
|
|
|
|
|
|
|
// Decoder and friends
|
|
|
|
nsCOMPtr<imgIDecoder> mDecoder;
|
|
|
|
nsRefPtr<imgDecodeWorker> mWorker;
|
|
|
|
PRUint32 mBytesDecoded;
|
|
|
|
PRUint32 mDecoderFlags;
|
|
|
|
|
2010-05-12 21:41:47 +00: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 mInitialized:1; // Have we been initalized?
|
|
|
|
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 22:44:18 +00:00
|
|
|
|
|
|
|
// Discard code
|
|
|
|
nsresult ResetDiscardTimer();
|
|
|
|
static void sDiscardTimerCallback(nsITimer *aTimer, void *aClosure);
|
|
|
|
|
|
|
|
// Decoding
|
|
|
|
nsresult WantDecodedFrames();
|
|
|
|
nsresult SyncDecode();
|
|
|
|
nsresult InitDecoder(PRUint32 dFlags);
|
|
|
|
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();
|
|
|
|
PRBool StoringSourceData();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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;
|
2001-03-10 01:11:54 +00:00
|
|
|
};
|
|
|
|
|
2009-09-12 22:44:18 +00: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-03-13 02:10:09 +00:00
|
|
|
#endif /* __imgContainer_h__ */
|