1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_imagelib_VectorImage_h_
7 #define mozilla_imagelib_VectorImage_h_
10 #include "nsIStreamListener.h"
11 #include "mozilla/MemoryReporting.h"
23 struct SVGDrawingParameters
;
24 class SVGDocumentWrapper
;
25 class SVGRootRenderingObserver
;
26 class SVGLoadEventListener
;
27 class SVGParseCompleteListener
;
29 class VectorImage MOZ_FINAL
: public ImageResource
,
30 public nsIStreamListener
34 NS_DECL_NSIREQUESTOBSERVER
35 NS_DECL_NSISTREAMLISTENER
38 // (no public constructor - use ImageFactory)
40 // Methods inherited from Image
41 nsresult
Init(const char* aMimeType
,
42 uint32_t aFlags
) MOZ_OVERRIDE
;
44 virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf
) const MOZ_OVERRIDE
;
45 virtual size_t SizeOfDecoded(gfxMemoryLocation aLocation
,
46 MallocSizeOf aMallocSizeOf
) const MOZ_OVERRIDE
;
48 virtual nsresult
OnImageDataAvailable(nsIRequest
* aRequest
,
49 nsISupports
* aContext
,
50 nsIInputStream
* aInStr
,
51 uint64_t aSourceOffset
,
52 uint32_t aCount
) MOZ_OVERRIDE
;
53 virtual nsresult
OnImageDataComplete(nsIRequest
* aRequest
,
54 nsISupports
* aContext
,
56 bool aLastPart
) MOZ_OVERRIDE
;
59 * Callback for SVGRootRenderingObserver.
61 * This just sets a dirty flag that we check in VectorImage::RequestRefresh,
62 * which is called under the ticks of the refresh driver of any observing
63 * documents that we may have. Only then (after all animations in this image
64 * have been updated) do we send out "frame changed" notifications,
66 void InvalidateObserversOnNextRefreshDriverTick();
68 // Callback for SVGParseCompleteListener.
69 void OnSVGDocumentParsed();
71 // Callbacks for SVGLoadEventListener.
72 void OnSVGDocumentLoaded();
73 void OnSVGDocumentError();
76 explicit VectorImage(ProgressTracker
* aProgressTracker
= nullptr,
77 ImageURL
* aURI
= nullptr);
78 virtual ~VectorImage();
80 virtual nsresult
StartAnimation() MOZ_OVERRIDE
;
81 virtual nsresult
StopAnimation() MOZ_OVERRIDE
;
82 virtual bool ShouldAnimate() MOZ_OVERRIDE
;
84 void CreateSurfaceAndShow(const SVGDrawingParameters
& aParams
);
85 void Show(gfxDrawable
* aDrawable
, const SVGDrawingParameters
& aParams
);
89 * In catastrophic circumstances like a GPU driver crash, we may lose our
90 * surfaces even if they're locked. RecoverFromLossOfSurfaces discards all
91 * existing surfaces, allowing us to recover.
93 void RecoverFromLossOfSurfaces();
95 void CancelAllListeners();
96 void SendInvalidationNotifications();
98 nsRefPtr
<SVGDocumentWrapper
> mSVGDocumentWrapper
;
99 nsRefPtr
<SVGRootRenderingObserver
> mRenderingObserver
;
100 nsRefPtr
<SVGLoadEventListener
> mLoadEventListener
;
101 nsRefPtr
<SVGParseCompleteListener
> mParseCompleteListener
;
103 bool mIsInitialized
; // Have we been initalized?
104 bool mIsFullyLoaded
; // Has the SVG document finished loading?
105 bool mIsDrawing
; // Are we currently drawing?
106 bool mHaveAnimations
; // Is our SVG content SMIL-animated?
107 // (Only set after mIsFullyLoaded.)
108 bool mHasPendingInvalidation
; // Invalidate observers next refresh
111 // Initializes ProgressTracker and resets it on RasterImage destruction.
112 nsAutoPtr
<ProgressTrackerInit
> mProgressTrackerInit
;
114 friend class ImageFactory
;
117 inline NS_IMETHODIMP
VectorImage::GetAnimationMode(uint16_t *aAnimationMode
) {
118 return GetAnimationModeInternal(aAnimationMode
);
121 inline NS_IMETHODIMP
VectorImage::SetAnimationMode(uint16_t aAnimationMode
) {
122 return SetAnimationModeInternal(aAnimationMode
);
126 } // namespace mozilla
128 #endif // mozilla_imagelib_VectorImage_h_