Bug 1755481: correct documentation of `nsIClipboard::getData`. r=mccr8
[gecko.git] / image / VectorImage.h
blobec9951d5c17eb422d747319d29abc2446b2fa803
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_image_VectorImage_h
7 #define mozilla_image_VectorImage_h
9 #include "Image.h"
10 #include "nsIStreamListener.h"
11 #include "mozilla/gfx/Point.h"
12 #include "mozilla/MemoryReporting.h"
14 class nsIRequest;
15 class gfxDrawable;
17 namespace mozilla {
18 struct MediaFeatureChange;
20 namespace image {
22 class SourceSurfaceBlobImage;
23 struct SVGDrawingParameters;
24 class SVGDocumentWrapper;
25 class SVGRootRenderingObserver;
26 class SVGLoadEventListener;
27 class SVGParseCompleteListener;
29 class VectorImage final : public ImageResource, public nsIStreamListener {
30 public:
31 NS_DECL_ISUPPORTS
32 NS_DECL_NSIREQUESTOBSERVER
33 NS_DECL_NSISTREAMLISTENER
34 NS_DECL_IMGICONTAINER
36 // (no public constructor - use ImageFactory)
38 // Methods inherited from Image
39 void MediaFeatureValuesChangedAllDocuments(const MediaFeatureChange&) final;
40 nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
41 size_t GetNativeSizesLength() const override;
42 virtual size_t SizeOfSourceWithComputedFallback(
43 SizeOfState& aState) const override;
45 virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
46 nsIInputStream* aInStr,
47 uint64_t aSourceOffset,
48 uint32_t aCount) override;
49 virtual nsresult OnImageDataComplete(nsIRequest* aRequest, nsresult aResult,
50 bool aLastPart) override;
52 virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
54 /**
55 * Callback for SVGRootRenderingObserver.
57 * This just sets a dirty flag that we check in VectorImage::RequestRefresh,
58 * which is called under the ticks of the refresh driver of any observing
59 * documents that we may have. Only then (after all animations in this image
60 * have been updated) do we send out "frame changed" notifications,
62 void InvalidateObserversOnNextRefreshDriverTick();
64 // Callback for SVGParseCompleteListener.
65 void OnSVGDocumentParsed();
67 // Callbacks for SVGLoadEventListener.
68 void OnSVGDocumentLoaded();
69 void OnSVGDocumentError();
71 protected:
72 explicit VectorImage(nsIURI* aURI = nullptr);
73 virtual ~VectorImage();
75 virtual nsresult StartAnimation() override;
76 virtual nsresult StopAnimation() override;
77 virtual bool ShouldAnimate() override;
79 private:
80 friend class SourceSurfaceBlobImage;
82 /**
83 * Attempt to find a matching cached surface in the SurfaceCache. Returns the
84 * cached surface, if found, and the size to rasterize at, if applicable.
85 * If we cannot rasterize, it will be the requested size to draw at (aSize).
87 Tuple<RefPtr<gfx::SourceSurface>, gfx::IntSize> LookupCachedSurface(
88 const gfx::IntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
89 uint32_t aFlags);
91 bool MaybeRestrictSVGContext(Maybe<SVGImageContext>& aNewSVGContext,
92 const Maybe<SVGImageContext>& aSVGContext,
93 uint32_t aFlags);
95 /// Create a gfxDrawable which callbacks into the SVG document.
96 already_AddRefed<gfxDrawable> CreateSVGDrawable(
97 const SVGDrawingParameters& aParams);
99 /// Rasterize the SVG into a surface. aWillCache will be set to whether or
100 /// not the new surface was put into the cache.
101 already_AddRefed<gfx::SourceSurface> CreateSurface(
102 const SVGDrawingParameters& aParams, gfxDrawable* aSVGDrawable,
103 bool& aWillCache);
105 /// Send a frame complete notification if appropriate. Must be called only
106 /// after all drawing has been completed.
107 void SendFrameComplete(bool aDidCache, uint32_t aFlags);
109 void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
111 nsresult Init(const char* aMimeType, uint32_t aFlags);
114 * In catastrophic circumstances like a GPU driver crash, we may lose our
115 * surfaces even if they're locked. RecoverFromLossOfSurfaces discards all
116 * existing surfaces, allowing us to recover.
118 void RecoverFromLossOfSurfaces();
120 void CancelAllListeners();
121 void SendInvalidationNotifications();
123 void ReportDocumentUseCounters();
125 RefPtr<SVGDocumentWrapper> mSVGDocumentWrapper;
126 RefPtr<SVGRootRenderingObserver> mRenderingObserver;
127 RefPtr<SVGLoadEventListener> mLoadEventListener;
128 RefPtr<SVGParseCompleteListener> mParseCompleteListener;
130 /// Count of locks on this image (roughly correlated to visible instances).
131 uint32_t mLockCount;
133 // Stored result from the Necko load of the image, which we save in
134 // OnImageDataComplete if the underlying SVG document isn't loaded. If we save
135 // this, we actually notify this progress (and clear this value) in
136 // OnSVGDocumentLoaded or OnSVGDocumentError.
137 Maybe<Progress> mLoadProgress;
139 bool mIsInitialized; // Have we been initialized?
140 bool mDiscardable; // Are we discardable?
141 bool mIsFullyLoaded; // Has the SVG document finished
142 // loading?
143 bool mHaveAnimations; // Is our SVG content SMIL-animated?
144 // (Only set after mIsFullyLoaded.)
145 bool mHasPendingInvalidation; // Invalidate observers next refresh
146 // driver tick.
148 friend class ImageFactory;
151 inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t* aAnimationMode) {
152 return GetAnimationModeInternal(aAnimationMode);
155 inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) {
156 return SetAnimationModeInternal(aAnimationMode);
159 } // namespace image
160 } // namespace mozilla
162 #endif // mozilla_image_VectorImage_h