michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_imagelib_VectorImage_h_ michael@0: #define mozilla_imagelib_VectorImage_h_ michael@0: michael@0: #include "Image.h" michael@0: #include "nsIStreamListener.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: michael@0: class nsIRequest; michael@0: class gfxDrawable; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: class LayerManager; michael@0: class ImageContainer; michael@0: } michael@0: namespace image { michael@0: michael@0: struct SVGDrawingParameters; michael@0: class SVGDocumentWrapper; michael@0: class SVGRootRenderingObserver; michael@0: class SVGLoadEventListener; michael@0: class SVGParseCompleteListener; michael@0: michael@0: class VectorImage : public ImageResource, michael@0: public nsIStreamListener michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSISTREAMLISTENER michael@0: NS_DECL_IMGICONTAINER michael@0: michael@0: // (no public constructor - use ImageFactory) michael@0: virtual ~VectorImage(); michael@0: michael@0: // Methods inherited from Image michael@0: nsresult Init(const char* aMimeType, michael@0: uint32_t aFlags); michael@0: virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE; michael@0: michael@0: virtual size_t HeapSizeOfSourceWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: virtual size_t HeapSizeOfDecodedWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: virtual size_t NonHeapSizeOfDecoded() const; michael@0: virtual size_t OutOfProcessSizeOfDecoded() const; michael@0: michael@0: virtual nsresult OnImageDataAvailable(nsIRequest* aRequest, michael@0: nsISupports* aContext, michael@0: nsIInputStream* aInStr, michael@0: uint64_t aSourceOffset, michael@0: uint32_t aCount) MOZ_OVERRIDE; michael@0: virtual nsresult OnImageDataComplete(nsIRequest* aRequest, michael@0: nsISupports* aContext, michael@0: nsresult aResult, michael@0: bool aLastPart) MOZ_OVERRIDE; michael@0: virtual nsresult OnNewSourceData() MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Callback for SVGRootRenderingObserver. michael@0: * michael@0: * This just sets a dirty flag that we check in VectorImage::RequestRefresh, michael@0: * which is called under the ticks of the refresh driver of any observing michael@0: * documents that we may have. Only then (after all animations in this image michael@0: * have been updated) do we send out "frame changed" notifications, michael@0: */ michael@0: void InvalidateObserversOnNextRefreshDriverTick(); michael@0: michael@0: // Callback for SVGParseCompleteListener. michael@0: void OnSVGDocumentParsed(); michael@0: michael@0: // Callbacks for SVGLoadEventListener. michael@0: void OnSVGDocumentLoaded(); michael@0: void OnSVGDocumentError(); michael@0: michael@0: protected: michael@0: VectorImage(imgStatusTracker* aStatusTracker = nullptr, michael@0: ImageURL* aURI = nullptr); michael@0: michael@0: virtual nsresult StartAnimation(); michael@0: virtual nsresult StopAnimation(); michael@0: virtual bool ShouldAnimate(); michael@0: michael@0: void CreateDrawableAndShow(const SVGDrawingParameters& aParams); michael@0: void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams); michael@0: michael@0: private: michael@0: void CancelAllListeners(); michael@0: void SendInvalidationNotifications(); michael@0: michael@0: nsRefPtr mSVGDocumentWrapper; michael@0: nsRefPtr mRenderingObserver; michael@0: nsRefPtr mLoadEventListener; michael@0: nsRefPtr mParseCompleteListener; michael@0: michael@0: bool mIsInitialized; // Have we been initalized? michael@0: bool mIsFullyLoaded; // Has the SVG document finished loading? michael@0: bool mIsDrawing; // Are we currently drawing? michael@0: bool mHaveAnimations; // Is our SVG content SMIL-animated? michael@0: // (Only set after mIsFullyLoaded.) michael@0: bool mHasPendingInvalidation; // Invalidate observers next refresh michael@0: // driver tick. michael@0: michael@0: // Initializes imgStatusTracker and resets it on RasterImage destruction. michael@0: nsAutoPtr mStatusTrackerInit; michael@0: michael@0: friend class ImageFactory; michael@0: }; michael@0: michael@0: inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t *aAnimationMode) { michael@0: return GetAnimationModeInternal(aAnimationMode); michael@0: } michael@0: michael@0: inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) { michael@0: return SetAnimationModeInternal(aAnimationMode); michael@0: } michael@0: michael@0: } // namespace image michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_imagelib_VectorImage_h_