2010-09-08 20:40:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_VectorImage_h
|
|
|
|
#define mozilla_image_VectorImage_h
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
#include "Image.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-09-07 13:01:08 +00:00
|
|
|
class nsIRequest;
|
2013-10-22 11:38:08 +00:00
|
|
|
class gfxDrawable;
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-10-22 11:38:08 +00:00
|
|
|
struct SVGDrawingParameters;
|
|
|
|
class SVGDocumentWrapper;
|
|
|
|
class SVGRootRenderingObserver;
|
|
|
|
class SVGLoadEventListener;
|
|
|
|
class SVGParseCompleteListener;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class VectorImage final : public ImageResource, public nsIStreamListener {
|
2010-09-08 20:40:39 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2012-10-19 20:27:11 +00:00
|
|
|
NS_DECL_IMGICONTAINER
|
2010-11-17 20:37:08 +00:00
|
|
|
|
2012-12-17 22:05:18 +00:00
|
|
|
// (no public constructor - use ImageFactory)
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
// Methods inherited from Image
|
2017-03-22 13:05:36 +00:00
|
|
|
nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
|
2017-09-05 11:58:44 +00:00
|
|
|
size_t GetNativeSizesLength() const override;
|
2017-07-28 10:10:04 +00:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const override;
|
2015-04-28 18:46:17 +00:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const override;
|
2014-05-08 09:53:00 +00:00
|
|
|
|
2012-12-17 22:05:18 +00:00
|
|
|
virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
2015-03-21 16:28:04 +00:00
|
|
|
uint32_t aCount) override;
|
2012-12-17 22:05:18 +00:00
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext, nsresult aResult,
|
2015-03-21 16:28:04 +00:00
|
|
|
bool aLastPart) override;
|
2012-12-17 22:05:18 +00:00
|
|
|
|
2017-03-16 08:06:06 +00:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
|
2015-03-28 03:17:23 +00:00
|
|
|
|
2013-09-04 10:39:30 +00:00
|
|
|
/**
|
|
|
|
* Callback for SVGRootRenderingObserver.
|
|
|
|
*
|
|
|
|
* This just sets a dirty flag that we check in VectorImage::RequestRefresh,
|
|
|
|
* which is called under the ticks of the refresh driver of any observing
|
|
|
|
* documents that we may have. Only then (after all animations in this image
|
|
|
|
* have been updated) do we send out "frame changed" notifications,
|
|
|
|
*/
|
|
|
|
void InvalidateObserversOnNextRefreshDriverTick();
|
2010-09-08 20:40:40 +00:00
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
// Callback for SVGParseCompleteListener.
|
|
|
|
void OnSVGDocumentParsed();
|
|
|
|
|
|
|
|
// Callbacks for SVGLoadEventListener.
|
|
|
|
void OnSVGDocumentLoaded();
|
|
|
|
void OnSVGDocumentError();
|
|
|
|
|
2015-03-17 19:25:35 +00:00
|
|
|
virtual void ReportUseCounters() override;
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
protected:
|
2018-06-06 00:42:56 +00:00
|
|
|
explicit VectorImage(nsIURI* aURI = nullptr);
|
2014-06-23 18:49:08 +00:00
|
|
|
virtual ~VectorImage();
|
2012-12-17 22:05:18 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult StartAnimation() override;
|
|
|
|
virtual nsresult StopAnimation() override;
|
|
|
|
virtual bool ShouldAnimate() override;
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2016-08-18 04:46:25 +00:00
|
|
|
private:
|
2017-12-11 15:37:59 +00:00
|
|
|
Tuple<ImgDrawResult, IntSize, RefPtr<SourceSurface>> GetFrameInternal(
|
2017-11-17 19:08:52 +00:00
|
|
|
const IntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 19:08:52 +00:00
|
|
|
uint32_t aWhichFrame, uint32_t aFlags) override;
|
|
|
|
|
2018-09-13 23:48:21 +00:00
|
|
|
Tuple<ImgDrawResult, IntSize> GetImageContainerSize(
|
|
|
|
layers::LayerManager* aManager, const IntSize& aSize,
|
|
|
|
uint32_t aFlags) override;
|
2017-11-17 19:08:52 +00:00
|
|
|
|
2018-09-21 00:22:06 +00:00
|
|
|
/**
|
|
|
|
* Attempt to find a matching cached surface in the SurfaceCache. Returns the
|
|
|
|
* cached surface, if found, and the size to rasterize at, if applicable.
|
|
|
|
* If we cannot rasterize, it will be the requested size to draw at (aSize).
|
|
|
|
*/
|
|
|
|
Tuple<RefPtr<SourceSurface>, IntSize> LookupCachedSurface(
|
2017-11-17 19:08:51 +00:00
|
|
|
const IntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
uint32_t aFlags);
|
2016-08-18 04:46:25 +00:00
|
|
|
|
2017-11-17 19:08:52 +00:00
|
|
|
bool MaybeRestrictSVGContext(Maybe<SVGImageContext>& aNewSVGContext,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
uint32_t aFlags);
|
|
|
|
|
2017-12-01 23:50:07 +00:00
|
|
|
/// Create a gfxDrawable which callbacks into the SVG document.
|
|
|
|
already_AddRefed<gfxDrawable> CreateSVGDrawable(
|
|
|
|
const SVGDrawingParameters& aParams);
|
2017-12-01 12:00:20 +00:00
|
|
|
|
2018-09-21 00:22:06 +00:00
|
|
|
/// Returns true if we use the surface cache to store rasterized copies.
|
|
|
|
bool UseSurfaceCacheForSize(const IntSize& aSize) const;
|
|
|
|
|
2017-12-01 23:50:07 +00:00
|
|
|
/// Rasterize the SVG into a surface. aWillCache will be set to whether or
|
|
|
|
/// not the new surface was put into the cache.
|
2017-12-01 16:29:16 +00:00
|
|
|
already_AddRefed<SourceSurface> CreateSurface(
|
2017-12-01 23:50:07 +00:00
|
|
|
const SVGDrawingParameters& aParams, gfxDrawable* aSVGDrawable,
|
|
|
|
bool& aWillCache);
|
|
|
|
|
|
|
|
/// Send a frame complete notification if appropriate. Must be called only
|
|
|
|
/// after all drawing has been completed.
|
|
|
|
void SendFrameComplete(bool aDidCache, uint32_t aFlags);
|
2017-11-17 19:08:52 +00:00
|
|
|
|
2014-08-06 22:43:25 +00:00
|
|
|
void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2015-04-28 23:07:24 +00:00
|
|
|
nsresult Init(const char* aMimeType, uint32_t aFlags);
|
|
|
|
|
2015-02-04 00:38:39 +00:00
|
|
|
/**
|
|
|
|
* In catastrophic circumstances like a GPU driver crash, we may lose our
|
|
|
|
* surfaces even if they're locked. RecoverFromLossOfSurfaces discards all
|
|
|
|
* existing surfaces, allowing us to recover.
|
|
|
|
*/
|
|
|
|
void RecoverFromLossOfSurfaces();
|
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
void CancelAllListeners();
|
2013-11-21 01:21:50 +00:00
|
|
|
void SendInvalidationNotifications();
|
2013-02-14 02:04:08 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<SVGDocumentWrapper> mSVGDocumentWrapper;
|
|
|
|
RefPtr<SVGRootRenderingObserver> mRenderingObserver;
|
|
|
|
RefPtr<SVGLoadEventListener> mLoadEventListener;
|
|
|
|
RefPtr<SVGParseCompleteListener> mParseCompleteListener;
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2015-03-28 03:17:23 +00:00
|
|
|
/// Count of locks on this image (roughly correlated to visible instances).
|
|
|
|
uint32_t mLockCount;
|
|
|
|
|
2015-06-18 21:48:41 +00:00
|
|
|
// Stored result from the Necko load of the image, which we save in
|
|
|
|
// OnImageDataComplete if the underlying SVG document isn't loaded. If we save
|
|
|
|
// this, we actually notify this progress (and clear this value) in
|
|
|
|
// OnSVGDocumentLoaded or OnSVGDocumentError.
|
|
|
|
Maybe<Progress> mLoadProgress;
|
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
bool mIsInitialized; // Have we been initialized?
|
2015-03-28 03:17:23 +00:00
|
|
|
bool mDiscardable; // Are we discardable?
|
2015-04-04 19:58:00 +00:00
|
|
|
bool mIsFullyLoaded; // Has the SVG document finished
|
|
|
|
// loading?
|
2013-03-01 06:44:57 +00:00
|
|
|
bool mIsDrawing; // Are we currently drawing?
|
|
|
|
bool mHaveAnimations; // Is our SVG content SMIL-animated?
|
2010-09-08 20:40:39 +00:00
|
|
|
// (Only set after mIsFullyLoaded.)
|
2013-09-04 10:39:30 +00:00
|
|
|
bool mHasPendingInvalidation; // Invalidate observers next refresh
|
|
|
|
// driver tick.
|
2012-12-17 22:05:18 +00:00
|
|
|
|
|
|
|
friend class ImageFactory;
|
2010-09-08 20:40:39 +00:00
|
|
|
};
|
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
2012-10-19 20:27:11 +00:00
|
|
|
return GetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) {
|
|
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-09-08 20:40:39 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_VectorImage_h
|