Bug 843895 (Part 2) - Add ImageWrapper. r=joe
authorSeth Fowler <seth@mozilla.com>
Sun, 10 Mar 2013 18:43:38 -0700
changeset 124344 6e2d12e2be75171c2920f069373c3acd4145fb21
parent 124343 ef39bbfd87e00aac1310ffe3859222c1298412f9
child 124345 1b269c239a7537c95387cd2c929882a2a2e8d2ab
push id24417
push userryanvm@gmail.com
push dateMon, 11 Mar 2013 23:58:07 +0000
treeherdermozilla-central@7433bc4545c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe
bugs843895
milestone22.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 843895 (Part 2) - Add ImageWrapper. r=joe
image/src/ImageWrapper.cpp
image/src/ImageWrapper.h
image/src/Makefile.in
new file mode 100644
--- /dev/null
+++ b/image/src/ImageWrapper.cpp
@@ -0,0 +1,286 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "ImageWrapper.h"
+
+using mozilla::layers::LayerManager;
+using mozilla::layers::ImageContainer;
+
+namespace mozilla {
+namespace image {
+
+// Inherited methods from Image.
+
+nsresult
+ImageWrapper::Init(const char* aMimeType, uint32_t aFlags)
+{
+  return mInnerImage->Init(aMimeType, aFlags);
+}
+
+imgStatusTracker&
+ImageWrapper::GetStatusTracker()
+{
+  return mInnerImage->GetStatusTracker();
+}
+
+nsIntRect
+ImageWrapper::FrameRect(uint32_t aWhichFrame)
+{
+  return mInnerImage->FrameRect(aWhichFrame);
+}
+
+uint32_t
+ImageWrapper::SizeOfData()
+{
+  return mInnerImage->SizeOfData();
+}
+
+size_t
+ImageWrapper::HeapSizeOfSourceWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const
+{
+  return mInnerImage->HeapSizeOfSourceWithComputedFallback(aMallocSizeOf);
+}
+
+size_t
+ImageWrapper::HeapSizeOfDecodedWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const
+{
+  return mInnerImage->HeapSizeOfDecodedWithComputedFallback(aMallocSizeOf);
+}
+
+size_t
+ImageWrapper::NonHeapSizeOfDecoded() const
+{
+  return mInnerImage->NonHeapSizeOfDecoded();
+}
+
+size_t
+ImageWrapper::OutOfProcessSizeOfDecoded() const
+{
+  return mInnerImage->OutOfProcessSizeOfDecoded();
+}
+
+void
+ImageWrapper::IncrementAnimationConsumers()
+{
+  mInnerImage->IncrementAnimationConsumers();
+}
+
+void
+ImageWrapper::DecrementAnimationConsumers()
+{
+  mInnerImage->DecrementAnimationConsumers();
+}
+
+#ifdef DEBUG
+uint32_t
+ImageWrapper::GetAnimationConsumers()
+{
+  return mInnerImage->GetAnimationConsumers();
+}
+#endif
+
+nsresult
+ImageWrapper::OnImageDataAvailable(nsIRequest* aRequest,
+                                   nsISupports* aContext,
+                                   nsIInputStream* aInStr,
+                                   uint64_t aSourceOffset,
+                                   uint32_t aCount)
+{
+  return mInnerImage->OnImageDataAvailable(aRequest, aContext, aInStr,
+                                           aSourceOffset, aCount);
+}
+
+nsresult
+ImageWrapper::OnImageDataComplete(nsIRequest* aRequest,
+                                  nsISupports* aContext,
+                                  nsresult aStatus,
+                                  bool aLastPart)
+{
+  return mInnerImage->OnImageDataComplete(aRequest, aContext, aStatus, aLastPart);
+}
+
+nsresult
+ImageWrapper::OnNewSourceData()
+{
+  return mInnerImage->OnNewSourceData();
+}
+
+void
+ImageWrapper::SetInnerWindowID(uint64_t aInnerWindowId)
+{
+  mInnerImage->SetInnerWindowID(aInnerWindowId);
+}
+
+uint64_t
+ImageWrapper::InnerWindowID() const
+{
+  return mInnerImage->InnerWindowID();
+}
+
+bool
+ImageWrapper::HasError()
+{
+  return mInnerImage->HasError();
+}
+
+void
+ImageWrapper::SetHasError()
+{
+  mInnerImage->SetHasError();
+}
+
+nsIURI*
+ImageWrapper::GetURI()
+{
+  return mInnerImage->GetURI();
+}
+
+// Methods inherited from XPCOM interfaces.
+
+NS_IMPL_ISUPPORTS1(ImageWrapper, imgIContainer)
+
+NS_IMETHODIMP
+ImageWrapper::GetWidth(int32_t* aWidth)
+{
+  return mInnerImage->GetWidth(aWidth);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetHeight(int32_t* aHeight)
+{
+  return mInnerImage->GetHeight(aHeight);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetIntrinsicSize(nsSize* aSize)
+{
+  return mInnerImage->GetIntrinsicSize(aSize);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetIntrinsicRatio(nsSize* aSize)
+{
+  return mInnerImage->GetIntrinsicRatio(aSize);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetType(uint16_t* aType)
+{
+  return mInnerImage->GetType(aType);
+}
+
+NS_IMETHODIMP_(uint16_t)
+ImageWrapper::GetType()
+{
+  return mInnerImage->GetType();
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetAnimated(bool* aAnimated)
+{
+  return mInnerImage->GetAnimated(aAnimated);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetFrame(uint32_t aWhichFrame,
+                       uint32_t aFlags,
+                       gfxASurface** _retval)
+{
+  return mInnerImage->GetFrame(aWhichFrame, aFlags, _retval);
+}
+
+NS_IMETHODIMP_(bool)
+ImageWrapper::FrameIsOpaque(uint32_t aWhichFrame)
+{
+  return mInnerImage->FrameIsOpaque(aWhichFrame);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetImageContainer(LayerManager* aManager, ImageContainer** _retval)
+{
+  return mInnerImage->GetImageContainer(aManager, _retval);
+}
+
+NS_IMETHODIMP
+ImageWrapper::ExtractFrame(uint32_t aWhichFrame,
+                           const nsIntRect& aRegion,
+                           uint32_t aFlags,
+                           imgIContainer** _retval)
+{
+  return mInnerImage->ExtractFrame(aWhichFrame, aRegion, aFlags, _retval);
+}
+
+NS_IMETHODIMP
+ImageWrapper::Draw(gfxContext* aContext,
+                   gfxPattern::GraphicsFilter aFilter,
+                   const gfxMatrix& aUserSpaceToImageSpace,
+                   const gfxRect& aFill,
+                   const nsIntRect& aSubimage,
+                   const nsIntSize& aViewportSize,
+                   const SVGImageContext* aSVGContext,
+                   uint32_t aWhichFrame,
+                   uint32_t aFlags)
+{
+  return mInnerImage->Draw(aContext, aFilter, aUserSpaceToImageSpace, aFill,
+                           aSubimage, aViewportSize, aSVGContext, aWhichFrame,
+                           aFlags);
+}
+
+NS_IMETHODIMP
+ImageWrapper::RequestDecode()
+{
+  return mInnerImage->RequestDecode();
+}
+
+NS_IMETHODIMP
+ImageWrapper::StartDecoding()
+{
+  return mInnerImage->StartDecoding();
+}
+
+NS_IMETHODIMP
+ImageWrapper::LockImage()
+{
+  return mInnerImage->LockImage();
+}
+
+NS_IMETHODIMP
+ImageWrapper::UnlockImage()
+{
+  return mInnerImage->UnlockImage();
+}
+
+NS_IMETHODIMP
+ImageWrapper::RequestDiscard()
+{
+  return mInnerImage->RequestDiscard();
+}
+
+NS_IMETHODIMP_(void)
+ImageWrapper::RequestRefresh(const mozilla::TimeStamp& aTime)
+{
+  return mInnerImage->RequestRefresh(aTime);
+}
+
+NS_IMETHODIMP
+ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode)
+{
+  return mInnerImage->GetAnimationMode(aAnimationMode);
+}
+
+NS_IMETHODIMP
+ImageWrapper::SetAnimationMode(uint16_t aAnimationMode)
+{
+  return mInnerImage->SetAnimationMode(aAnimationMode);
+}
+
+NS_IMETHODIMP
+ImageWrapper::ResetAnimation()
+{
+  return mInnerImage->ResetAnimation();
+}
+
+} // namespace image
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/image/src/ImageWrapper.h
@@ -0,0 +1,81 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#ifndef MOZILLA_IMAGELIB_IMAGEWRAPPER_H_
+#define MOZILLA_IMAGELIB_IMAGEWRAPPER_H_
+
+#include "Image.h"
+
+namespace mozilla {
+namespace image {
+
+/**
+ * Abstract superclass for Images that wrap other Images.
+ */
+class ImageWrapper : public Image
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_IMGICONTAINER
+
+  virtual ~ImageWrapper() { }
+
+  // Inherited methods from Image.
+  virtual nsresult Init(const char* aMimeType, uint32_t aFlags) MOZ_OVERRIDE;
+
+  virtual imgStatusTracker& GetStatusTracker() MOZ_OVERRIDE;
+  virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
+
+  virtual uint32_t SizeOfData() MOZ_OVERRIDE;
+  virtual size_t HeapSizeOfSourceWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
+  virtual size_t HeapSizeOfDecodedWithComputedFallback(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
+  virtual size_t NonHeapSizeOfDecoded() const MOZ_OVERRIDE;
+  virtual size_t OutOfProcessSizeOfDecoded() const MOZ_OVERRIDE;
+
+  virtual void IncrementAnimationConsumers() MOZ_OVERRIDE;
+  virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
+#ifdef DEBUG
+  virtual uint32_t GetAnimationConsumers() MOZ_OVERRIDE;
+#endif
+
+  virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
+                                        nsISupports* aContext,
+                                        nsIInputStream* aInStr,
+                                        uint64_t aSourceOffset,
+                                        uint32_t aCount) MOZ_OVERRIDE;
+  virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
+                                       nsISupports* aContext,
+                                       nsresult aStatus,
+                                       bool aLastPart) MOZ_OVERRIDE;
+  virtual nsresult OnNewSourceData() MOZ_OVERRIDE;
+
+  virtual void SetInnerWindowID(uint64_t aInnerWindowId) MOZ_OVERRIDE;
+  virtual uint64_t InnerWindowID() const MOZ_OVERRIDE;
+
+  virtual bool HasError() MOZ_OVERRIDE;
+  virtual void SetHasError() MOZ_OVERRIDE;
+
+  virtual nsIURI* GetURI() MOZ_OVERRIDE;
+
+protected:
+  ImageWrapper(Image* aInnerImage)
+    : mInnerImage(aInnerImage)
+  {
+    NS_ABORT_IF_FALSE(aInnerImage, "Cannot wrap a null image");
+  }
+
+  /**
+   * Returns a weak reference to the inner image wrapped by this ImageWrapper.
+   */
+  Image* InnerImage() { return mInnerImage.get(); }
+
+private:
+  nsRefPtr<Image> mInnerImage;
+};
+
+} // namespace image
+} // namespace mozilla
+
+#endif // MOZILLA_IMAGELIB_IMAGEWRAPPER_H_
--- a/image/src/Makefile.in
+++ b/image/src/Makefile.in
@@ -22,16 +22,17 @@ FAIL_ON_WARNINGS = 1
 EXPORTS		=  imgLoader.h \
 		   imgRequest.h \
 		   imgRequestProxy.h \
 		   $(NULL)
 
 CPPSRCS		= \
 			Image.cpp \
 			ImageFactory.cpp \
+			ImageWrapper.cpp \
 			Decoder.cpp \
 			DiscardTracker.cpp \
 			RasterImage.cpp \
 			ScriptedNotificationObserver.cpp \
 			SVGDocumentWrapper.cpp \
 			VectorImage.cpp \
 			imgFrame.cpp \
 			imgLoader.cpp    \