Bug 584841 patch 11: Move remaining imagelib-private methods from imgIContainer interface to Image abstract class. r=bholley sr=vlad a=blocking
authorDaniel Holbert <dholbert@cs.stanford.edu>
Fri, 13 Aug 2010 21:09:49 -0700
changeset 50555 f99cedbbc5f62173bda44b20e163af17e94151cf
parent 50554 7695eea587d4c56bc6d67c2a7c61ef5d6ffda11b
child 50556 85ed3b142c0816e41d53940c7737eb7c08406378
push idunknown
push userunknown
push dateunknown
reviewersbholley, vlad, blocking
bugs584841
milestone2.0b4pre
Bug 584841 patch 11: Move remaining imagelib-private methods from imgIContainer interface to Image abstract class. r=bholley sr=vlad a=blocking
modules/libpr0n/public/imgIContainer.idl
modules/libpr0n/src/Image.h
modules/libpr0n/src/RasterImage.cpp
modules/libpr0n/src/RasterImage.h
modules/libpr0n/src/imgRequest.cpp
--- a/modules/libpr0n/public/imgIContainer.idl
+++ b/modules/libpr0n/public/imgIContainer.idl
@@ -66,17 +66,17 @@ native gfxGraphicsFilter(gfxPattern::Gra
 /**
  * imgIContainer is the interface that represents an image. It allows
  * access to frames as Thebes surfaces, and permits users to extract subregions
  * as other imgIContainers. It also allows drawing of images on to Thebes
  * contexts.
  *
  * Internally, imgIContainer also manages animation of images.
  */
-[scriptable, uuid(e6984403-1253-48fa-8a16-a350f76ab6c9)]
+[scriptable, uuid(362e5b5f-f677-49e0-9a3c-03249c794624)]
 interface imgIContainer : nsISupports
 {
   /**
    * The width of the container rectangle.
    */
   readonly attribute PRInt32 width;
 
   /**
@@ -224,84 +224,25 @@ interface imgIContainer : nsISupports
     * the image is allowed to discard its frame data to save memory.
     *
     * Upon instantiation images have a lock count of zero. It is an error to
     * call this method without first having made a matching lockImage() call.
     * In other words, the lock count is not allowed to be negative.
     */
   void unlockImage();
 
-  /************ Internal libpr0n use only below here. *****************/
-
-  /**
-   * Flags for imgIContainer initialization.
-   *
-   * Meanings:
-   *
-   * INIT_FLAG_NONE: Lack of flags
-   *
-   * INIT_FLAG_DISCARDABLE: The container should be discardable
-   *
-   * INIT_FLAG_DECODE_ON_DRAW: The container should decode on draw rather than
-   * decoding on load.
-   *
-   * INIT_FLAG_MULTIPART: The container will be used to display a stream of
-   * images in a multipart channel. If this flag is set, INIT_FLAG_DISCARDABLE
-   * and INIT_FLAG_DECODE_ON_DRAW must not be set.
-   */
-
-  const long INIT_FLAG_NONE           = 0x0;
-  const long INIT_FLAG_DISCARDABLE    = 0x1;
-  const long INIT_FLAG_DECODE_ON_DRAW = 0x2;
-  const long INIT_FLAG_MULTIPART      = 0x4;
-
-  /**
-   * Creates a new image container.
-   *
-   * @param aObserver Observer to send decoder and animation notifications to.
-   * @param aMimeType The mimetype of the image.
-   * @param aFlags Initialization flags of the INIT_FLAG_* variety.
-   */
-  void init(in imgIDecoderObserver aObserver,
-            in string aMimeType,
-            in PRUint32 aFlags);
-
   /**
    * Animation mode Constants
    *   0 = normal
    *   1 = don't animate
    *   2 = loop once
    */
   const short kNormalAnimMode   = 0;
   const short kDontAnimMode     = 1;
   const short kLoopOnceAnimMode = 2;
 
   attribute unsigned short animationMode;
 
-  /**
-   * The rectangle defining the location and size of the currently displayed frame.
-   * Should be an attribute, but can't be because of reference/pointer
-   * conflicts with native types in xpidl.
-   */
-  [noscript] void getCurrentFrameRect(in nsIntRect aFrameRect);
-
-  /**
-   * The index of the current frame that would be drawn if the image was to be
-   * drawn now.
-   */
-  readonly attribute unsigned long currentFrameIndex;
-
-  /**
-   * The total number of frames in this image.
-   */
-  readonly attribute unsigned long numFrames;
-
-  /**
-   * The size, in bytes, occupied by the significant data portions of the image.
-   * This includes both compressed source data and decoded frames.
-   */
-  readonly attribute unsigned long dataSize;
-
   /* Methods to control animation */
   void startAnimation();
   void stopAnimation();
   void resetAnimation();
 };
--- a/modules/libpr0n/src/Image.h
+++ b/modules/libpr0n/src/Image.h
@@ -46,16 +46,72 @@ namespace mozilla {
 namespace imagelib {
 
 class Image : public imgIContainer
 {
 public:
   imgStatusTracker& GetStatusTracker() { return mStatusTracker; }
   PRBool IsInitialized() const { return mInitialized; }
 
+  /**
+   * Flags for Image initialization.
+   *
+   * Meanings:
+   *
+   * INIT_FLAG_NONE: Lack of flags
+   *
+   * INIT_FLAG_DISCARDABLE: The container should be discardable
+   *
+   * INIT_FLAG_DECODE_ON_DRAW: The container should decode on draw rather than
+   * decoding on load.
+   *
+   * INIT_FLAG_MULTIPART: The container will be used to display a stream of
+   * images in a multipart channel. If this flag is set, INIT_FLAG_DISCARDABLE
+   * and INIT_FLAG_DECODE_ON_DRAW must not be set.
+   */
+  static const PRUint32 INIT_FLAG_NONE           = 0x0;
+  static const PRUint32 INIT_FLAG_DISCARDABLE    = 0x1;
+  static const PRUint32 INIT_FLAG_DECODE_ON_DRAW = 0x2;
+  static const PRUint32 INIT_FLAG_MULTIPART      = 0x4;
+
+  /**
+   * Creates a new image container.
+   *
+   * @param aObserver Observer to send decoder and animation notifications to.
+   * @param aMimeType The mimetype of the image.
+   * @param aFlags Initialization flags of the INIT_FLAG_* variety.
+   */
+  virtual nsresult Init(imgIDecoderObserver* aObserver,
+                        const char* aMimeType,
+                        PRUint32 aFlags) = 0;
+
+  /**
+   * The rectangle defining the location and size of the currently displayed
+   * frame.  Should be an attribute, but can't be because of reference/pointer
+   * conflicts with native types in xpidl.
+   */
+  virtual nsresult GetCurrentFrameRect(nsIntRect& aRect) = 0;
+
+  /**
+   * The index of the current frame that would be drawn if the image was to be
+   * drawn now.
+   */
+  virtual nsresult GetCurrentFrameIndex(PRUint32* aCurrentFrameIdx) = 0;
+
+  /**
+   * The total number of frames in this image.
+   */
+  virtual nsresult GetNumFrames(PRUint32* aNumFrames) = 0;
+
+  /**
+   * The size, in bytes, occupied by the significant data portions of the image.
+   * This includes both compressed source data and decoded frames.
+   */
+  virtual nsresult GetDataSize(PRUint32* aDataSize) = 0;
+
 protected:
   Image();
 
   // Member data shared by all implementations of this abstract class
   imgStatusTracker   mStatusTracker;
   PRPackedBool       mInitialized;   // Have we been initalized?
 };
 
--- a/modules/libpr0n/src/RasterImage.cpp
+++ b/modules/libpr0n/src/RasterImage.cpp
@@ -206,20 +206,17 @@ RasterImage::~RasterImage()
       NS_WARNING("Failed to shut down decoder in destructor!");
   }
 
   // Total statistics
   num_containers--;
   total_source_bytes -= mSourceData.Length();
 }
 
-//******************************************************************************
-/* void init(in imgIDecoderObserver aObserver, in string aMimeType,
-             in PRUint32 aFlags); */
-NS_IMETHODIMP
+nsresult
 RasterImage::Init(imgIDecoderObserver *aObserver,
                   const char* aMimeType,
                   PRUint32 aFlags)
 {
   // We don't support re-initialization
   if (mInitialized)
     return NS_ERROR_ILLEGAL_VALUE;
 
@@ -463,19 +460,17 @@ RasterImage::GetCurrentFrameIsOpaque(PRB
     // entire area.
     nsIntRect framerect = curframe->GetRect();
     *aIsOpaque = *aIsOpaque && (framerect != nsIntRect(0, 0, mSize.width, mSize.height));
   }
 
   return NS_OK;
 }
 
-//******************************************************************************
-/* [noscript] void getCurrentFrameRect(nsIntRect rect); */
-NS_IMETHODIMP
+nsresult
 RasterImage::GetCurrentFrameRect(nsIntRect &aRect)
 {
   if (mError)
     return NS_ERROR_FAILURE;
 
   // Get the current frame
   imgFrame *curframe = GetCurrentImgFrame();
 
@@ -491,34 +486,30 @@ RasterImage::GetCurrentFrameRect(nsIntRe
   else {
     aRect.MoveTo(0, 0);
     aRect.SizeTo(0, 0);
   }
 
   return NS_OK;
 }
 
-//******************************************************************************
-/* readonly attribute unsigned long currentFrameIndex; */
-NS_IMETHODIMP
+nsresult
 RasterImage::GetCurrentFrameIndex(PRUint32 *aCurrentFrameIdx)
 {
   if (mError)
     return NS_ERROR_FAILURE;
 
   NS_ENSURE_ARG_POINTER(aCurrentFrameIdx);
   
   *aCurrentFrameIdx = GetCurrentImgFrameIndex();
 
   return NS_OK;
 }
 
-//******************************************************************************
-/* readonly attribute unsigned long numFrames; */
-NS_IMETHODIMP
+nsresult
 RasterImage::GetNumFrames(PRUint32 *aNumFrames)
 {
   if (mError)
     return NS_ERROR_FAILURE;
 
   NS_ENSURE_ARG_POINTER(aNumFrames);
 
   *aNumFrames = mFrames.Length();
@@ -667,19 +658,17 @@ RasterImage::GetFrame(PRUint32 aWhichFra
     framesurf = imgsurf;
   }
 
   *_retval = framesurf.forget().get();
 
   return rv;
 }
 
-//******************************************************************************
-/* readonly attribute unsigned long dataSize; */
-NS_IMETHODIMP
+nsresult
 RasterImage::GetDataSize(PRUint32 *_retval)
 {
   if (mError)
     return NS_ERROR_FAILURE;
 
   NS_ENSURE_ARG_POINTER(_retval);
 
   // Start with 0
--- a/modules/libpr0n/src/RasterImage.h
+++ b/modules/libpr0n/src/RasterImage.h
@@ -156,16 +156,26 @@ public:
   NS_DECL_NSIPROPERTIES
 
   RasterImage();
   virtual ~RasterImage();
 
   // C++-only version of imgIContainer::GetType, for convenience
   virtual PRUint16 GetType() { return imgIContainer::TYPE_RASTER; }
 
+  // Methods inherited from Image
+  nsresult Init(imgIDecoderObserver *aObserver,
+                const char* aMimeType,
+                PRUint32 aFlags);
+  nsresult GetCurrentFrameRect(nsIntRect& aRect);
+  nsresult GetCurrentFrameIndex(PRUint32* aCurrentFrameIdx);
+  nsresult GetNumFrames(PRUint32* aNumFrames);
+  nsresult GetDataSize(PRUint32* aDataSize);
+
+  // Raster-specific methods
   static NS_METHOD WriteToContainer(nsIInputStream* in, void* closure,
                                     const char* fromRawSegment,
                                     PRUint32 toOffset, PRUint32 count,
                                     PRUint32 *writeCount);
 
   PRUint32 GetDecodedDataSize();
   PRUint32 GetSourceDataSize();
 
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -1015,23 +1015,23 @@ NS_IMETHODIMP imgRequest::OnDataAvailabl
       isDiscardable = doDecodeOnDraw = PR_FALSE;
 
     // For multipart/x-mixed-replace, we basically want a direct channel to the
     // decoder. Disable both for this case as well.
     if (mIsMultiPartChannel)
       isDiscardable = doDecodeOnDraw = PR_FALSE;
 
     // We have all the information we need
-    PRUint32 containerFlags = imgIContainer::INIT_FLAG_NONE;
+    PRUint32 containerFlags = Image::INIT_FLAG_NONE;
     if (isDiscardable)
-      containerFlags |= imgIContainer::INIT_FLAG_DISCARDABLE;
+      containerFlags |= Image::INIT_FLAG_DISCARDABLE;
     if (doDecodeOnDraw)
-      containerFlags |= imgIContainer::INIT_FLAG_DECODE_ON_DRAW;
+      containerFlags |= Image::INIT_FLAG_DECODE_ON_DRAW;
     if (mIsMultiPartChannel)
-      containerFlags |= imgIContainer::INIT_FLAG_MULTIPART;
+      containerFlags |= Image::INIT_FLAG_MULTIPART;
 
     // Initialize the image that we created in OnStartRequest(). This
     // instantiates a decoder behind the scenes, so if we don't have a decoder
     // for this mimetype we'll find out about it here.
     rv = mImage->Init(this, mContentType.get(), containerFlags);
     if (NS_FAILED(rv)) { // Probably bad mimetype
 
       this->Cancel(rv);