Bug 859377 (Part 1) - Add imgIContainer::GetFrameIndex. r=joe sr=bz
authorSeth Fowler <seth@mozilla.com>
Thu, 25 Apr 2013 15:58:20 -0700
changeset 140933 6a20e50fd0bed51ef01ab33de97e31a232de072d
parent 140932 0ae79e3f9e6f9ef159f3b629a1970c6dc85d2dd7
child 140934 ef02b23cf07eb9bbad2677a0cec0d2e1d733a31b
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe, bz
bugs859377
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 859377 (Part 1) - Add imgIContainer::GetFrameIndex. r=joe sr=bz
image/public/imgIContainer.idl
image/src/FrozenImage.cpp
image/src/FrozenImage.h
image/src/ImageWrapper.cpp
image/src/RasterImage.cpp
image/src/VectorImage.cpp
--- a/image/public/imgIContainer.idl
+++ b/image/public/imgIContainer.idl
@@ -52,17 +52,17 @@ native nsSize(nsSize);
 
 /**
  * imgIContainer is the interface that represents an image. It allows
  * access to frames as Thebes surfaces. It also allows drawing of images
  * onto Thebes contexts.
  *
  * Internally, imgIContainer also manages animation of images.
  */
-[scriptable, builtinclass, uuid(55531bcd-7d4a-4da0-ab87-7c64c5ae5e12)]
+[scriptable, builtinclass, uuid(e385f907-9a59-419b-8e15-e2a96d8ce044)]
 interface imgIContainer : nsISupports
 {
   /**
    * The width of the container rectangle.  In the case of any error,
    * zero is returned, and an exception will be thrown.
    */
   readonly attribute int32_t width;
 
@@ -274,9 +274,23 @@ interface imgIContainer : nsISupports
   const short kNormalAnimMode   = 0;
   const short kDontAnimMode     = 1;
   const short kLoopOnceAnimMode = 2;
 
   attribute unsigned short animationMode;
 
   /* Methods to control animation */
   void resetAnimation();
+
+  /*
+   * Returns an index for the requested animation frame (either FRAME_FIRST or
+   * FRAME_CURRENT).
+   *
+   * The units of the index aren't specified, and may vary between different
+   * types of images. What you can rely on is that on all occasions when
+   * getFrameIndex(FRAME_CURRENT) returns a certain value,
+   * draw(..FRAME_CURRENT..) will draw the same frame. The same holds for
+   * FRAME_FIRST as well.
+   *
+   * @param aWhichFrame Frame specifier of the FRAME_* variety.
+   */
+  [notxpcom] float getFrameIndex(in uint32_t aWhichFrame);
 };
--- a/image/src/FrozenImage.cpp
+++ b/image/src/FrozenImage.cpp
@@ -106,10 +106,17 @@ FrozenImage::SetAnimationMode(uint16_t a
 
 NS_IMETHODIMP
 FrozenImage::ResetAnimation()
 {
   // Do nothing.
   return NS_OK;
 }
 
+NS_IMETHODIMP_(float)
+FrozenImage::GetFrameIndex(uint32_t aWhichFrame)
+{
+  MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
+  return 0;
+}
+
 } // namespace image
 } // namespace mozilla
--- a/image/src/FrozenImage.h
+++ b/image/src/FrozenImage.h
@@ -48,16 +48,17 @@ public:
                   const nsIntSize& aViewportSize,
                   const SVGImageContext* aSVGContext,
                   uint32_t aWhichFrame,
                   uint32_t aFlags) MOZ_OVERRIDE;
   NS_IMETHOD_(void) RequestRefresh(const mozilla::TimeStamp& aTime) MOZ_OVERRIDE;
   NS_IMETHOD GetAnimationMode(uint16_t* aAnimationMode) MOZ_OVERRIDE;
   NS_IMETHOD SetAnimationMode(uint16_t aAnimationMode) MOZ_OVERRIDE;
   NS_IMETHOD ResetAnimation() MOZ_OVERRIDE;
+  NS_IMETHOD_(float) GetFrameIndex(uint32_t aWhichFrame) MOZ_OVERRIDE;
 
 protected:
   FrozenImage(Image* aImage) : ImageWrapper(aImage) { }
 
 private:
   friend class ImageOps;
 };
 
--- a/image/src/ImageWrapper.cpp
+++ b/image/src/ImageWrapper.cpp
@@ -268,10 +268,16 @@ ImageWrapper::SetAnimationMode(uint16_t 
 }
 
 NS_IMETHODIMP
 ImageWrapper::ResetAnimation()
 {
   return mInnerImage->ResetAnimation();
 }
 
+NS_IMETHODIMP_(float)
+ImageWrapper::GetFrameIndex(uint32_t aWhichFrame)
+{
+  return mInnerImage->GetFrameIndex(aWhichFrame);
+}
+
 } // namespace image
 } // namespace mozilla
--- a/image/src/RasterImage.cpp
+++ b/image/src/RasterImage.cpp
@@ -1589,16 +1589,25 @@ RasterImage::ResetAnimation()
     // was false (before we changed it to true in this function). So, mark the
     // animation as running.
     mAnimating = true;
   }
 
   return NS_OK;
 }
 
+NS_IMETHODIMP_(float)
+RasterImage::GetFrameIndex(uint32_t aWhichFrame)
+{
+  MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
+  return (aWhichFrame == FRAME_FIRST || !mAnim)
+         ? 0.0f
+         : mAnim->currentAnimationFrameIndex;
+}
+
 void
 RasterImage::SetLoopCount(int32_t aLoopCount)
 {
   if (mError)
     return;
 
   // -1  infinite
   //  0  no looping, one iteration
--- a/image/src/VectorImage.cpp
+++ b/image/src/VectorImage.cpp
@@ -750,16 +750,25 @@ VectorImage::ResetAnimation()
     return NS_OK; // There are no animations to be reset.
   }
 
   mSVGDocumentWrapper->ResetAnimation();
 
   return NS_OK;
 }
 
+NS_IMETHODIMP_(float)
+VectorImage::GetFrameIndex(uint32_t aWhichFrame)
+{
+  MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
+  return aWhichFrame == FRAME_FIRST
+         ? 0.0f
+         : mSVGDocumentWrapper->GetCurrentTime();
+}
+
 //------------------------------------------------------------------------------
 // nsIRequestObserver methods
 
 //******************************************************************************
 /* void onStartRequest(in nsIRequest request, in nsISupports ctxt); */
 NS_IMETHODIMP
 VectorImage::OnStartRequest(nsIRequest* aRequest, nsISupports* aCtxt)
 {