1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/src/VectorImage.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_imagelib_VectorImage_h_ 1.10 +#define mozilla_imagelib_VectorImage_h_ 1.11 + 1.12 +#include "Image.h" 1.13 +#include "nsIStreamListener.h" 1.14 +#include "mozilla/MemoryReporting.h" 1.15 + 1.16 +class nsIRequest; 1.17 +class gfxDrawable; 1.18 + 1.19 +namespace mozilla { 1.20 +namespace layers { 1.21 +class LayerManager; 1.22 +class ImageContainer; 1.23 +} 1.24 +namespace image { 1.25 + 1.26 +struct SVGDrawingParameters; 1.27 +class SVGDocumentWrapper; 1.28 +class SVGRootRenderingObserver; 1.29 +class SVGLoadEventListener; 1.30 +class SVGParseCompleteListener; 1.31 + 1.32 +class VectorImage : public ImageResource, 1.33 + public nsIStreamListener 1.34 +{ 1.35 +public: 1.36 + NS_DECL_ISUPPORTS 1.37 + NS_DECL_NSIREQUESTOBSERVER 1.38 + NS_DECL_NSISTREAMLISTENER 1.39 + NS_DECL_IMGICONTAINER 1.40 + 1.41 + // (no public constructor - use ImageFactory) 1.42 + virtual ~VectorImage(); 1.43 + 1.44 + // Methods inherited from Image 1.45 + nsresult Init(const char* aMimeType, 1.46 + uint32_t aFlags); 1.47 + virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE; 1.48 + 1.49 + virtual size_t HeapSizeOfSourceWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const; 1.50 + virtual size_t HeapSizeOfDecodedWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const; 1.51 + virtual size_t NonHeapSizeOfDecoded() const; 1.52 + virtual size_t OutOfProcessSizeOfDecoded() const; 1.53 + 1.54 + virtual nsresult OnImageDataAvailable(nsIRequest* aRequest, 1.55 + nsISupports* aContext, 1.56 + nsIInputStream* aInStr, 1.57 + uint64_t aSourceOffset, 1.58 + uint32_t aCount) MOZ_OVERRIDE; 1.59 + virtual nsresult OnImageDataComplete(nsIRequest* aRequest, 1.60 + nsISupports* aContext, 1.61 + nsresult aResult, 1.62 + bool aLastPart) MOZ_OVERRIDE; 1.63 + virtual nsresult OnNewSourceData() MOZ_OVERRIDE; 1.64 + 1.65 + /** 1.66 + * Callback for SVGRootRenderingObserver. 1.67 + * 1.68 + * This just sets a dirty flag that we check in VectorImage::RequestRefresh, 1.69 + * which is called under the ticks of the refresh driver of any observing 1.70 + * documents that we may have. Only then (after all animations in this image 1.71 + * have been updated) do we send out "frame changed" notifications, 1.72 + */ 1.73 + void InvalidateObserversOnNextRefreshDriverTick(); 1.74 + 1.75 + // Callback for SVGParseCompleteListener. 1.76 + void OnSVGDocumentParsed(); 1.77 + 1.78 + // Callbacks for SVGLoadEventListener. 1.79 + void OnSVGDocumentLoaded(); 1.80 + void OnSVGDocumentError(); 1.81 + 1.82 +protected: 1.83 + VectorImage(imgStatusTracker* aStatusTracker = nullptr, 1.84 + ImageURL* aURI = nullptr); 1.85 + 1.86 + virtual nsresult StartAnimation(); 1.87 + virtual nsresult StopAnimation(); 1.88 + virtual bool ShouldAnimate(); 1.89 + 1.90 + void CreateDrawableAndShow(const SVGDrawingParameters& aParams); 1.91 + void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams); 1.92 + 1.93 +private: 1.94 + void CancelAllListeners(); 1.95 + void SendInvalidationNotifications(); 1.96 + 1.97 + nsRefPtr<SVGDocumentWrapper> mSVGDocumentWrapper; 1.98 + nsRefPtr<SVGRootRenderingObserver> mRenderingObserver; 1.99 + nsRefPtr<SVGLoadEventListener> mLoadEventListener; 1.100 + nsRefPtr<SVGParseCompleteListener> mParseCompleteListener; 1.101 + 1.102 + bool mIsInitialized; // Have we been initalized? 1.103 + bool mIsFullyLoaded; // Has the SVG document finished loading? 1.104 + bool mIsDrawing; // Are we currently drawing? 1.105 + bool mHaveAnimations; // Is our SVG content SMIL-animated? 1.106 + // (Only set after mIsFullyLoaded.) 1.107 + bool mHasPendingInvalidation; // Invalidate observers next refresh 1.108 + // driver tick. 1.109 + 1.110 + // Initializes imgStatusTracker and resets it on RasterImage destruction. 1.111 + nsAutoPtr<imgStatusTrackerInit> mStatusTrackerInit; 1.112 + 1.113 + friend class ImageFactory; 1.114 +}; 1.115 + 1.116 +inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t *aAnimationMode) { 1.117 + return GetAnimationModeInternal(aAnimationMode); 1.118 +} 1.119 + 1.120 +inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) { 1.121 + return SetAnimationModeInternal(aAnimationMode); 1.122 +} 1.123 + 1.124 +} // namespace image 1.125 +} // namespace mozilla 1.126 + 1.127 +#endif // mozilla_imagelib_VectorImage_h_