diff --git a/image/src/ImageWrapper.cpp b/image/src/ImageWrapper.cpp new file mode 100644 index 000000000000..193aac3ffc1b --- /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 diff --git a/image/src/ImageWrapper.h b/image/src/ImageWrapper.h new file mode 100644 index 000000000000..068de35d7d5a --- /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 mInnerImage; +}; + +} // namespace image +} // namespace mozilla + +#endif // MOZILLA_IMAGELIB_IMAGEWRAPPER_H_ diff --git a/image/src/Makefile.in b/image/src/Makefile.in index 7643a8a579a7..1e3b69fed66d 100644 --- a/image/src/Makefile.in +++ b/image/src/Makefile.in @@ -27,6 +27,7 @@ EXPORTS = imgLoader.h \ CPPSRCS = \ Image.cpp \ ImageFactory.cpp \ + ImageWrapper.cpp \ Decoder.cpp \ DiscardTracker.cpp \ RasterImage.cpp \