2010-09-08 13:40:39 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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 13:40:39 -07:00
|
|
|
|
2015-04-04 12:58:00 -07:00
|
|
|
#ifndef mozilla_image_src_VectorImage_h
|
|
|
|
#define mozilla_image_src_VectorImage_h
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
#include "Image.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2013-09-07 06:01:08 -07:00
|
|
|
class nsIRequest;
|
2013-10-22 04:38:08 -07:00
|
|
|
class gfxDrawable;
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2013-10-22 04:38:08 -07:00
|
|
|
struct SVGDrawingParameters;
|
|
|
|
class SVGDocumentWrapper;
|
|
|
|
class SVGRootRenderingObserver;
|
|
|
|
class SVGLoadEventListener;
|
|
|
|
class SVGParseCompleteListener;
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class VectorImage final : public ImageResource,
|
2015-03-27 11:52:19 -07:00
|
|
|
public nsIStreamListener
|
2010-09-08 13:40:39 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2012-10-19 13:27:11 -07:00
|
|
|
NS_DECL_IMGICONTAINER
|
2010-11-17 12:37:08 -08:00
|
|
|
|
2012-12-17 14:05:18 -08:00
|
|
|
// (no public constructor - use ImageFactory)
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
// Methods inherited from Image
|
2015-04-04 12:58:00 -07:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf)
|
|
|
|
const override;
|
2015-04-28 11:46:17 -07:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const override;
|
2014-05-08 02:53:00 -07:00
|
|
|
|
2012-12-17 14:05:18 -08:00
|
|
|
virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint32_t aCount) override;
|
2012-12-17 14:05:18 -08:00
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
2013-02-13 18:41:10 -08:00
|
|
|
nsresult aResult,
|
2015-03-21 09:28:04 -07:00
|
|
|
bool aLastPart) override;
|
2012-12-17 14:05:18 -08:00
|
|
|
|
2015-03-27 20:17:23 -07:00
|
|
|
void OnSurfaceDiscarded() override;
|
|
|
|
|
2013-09-04 03:39:30 -07: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 13:40:40 -07:00
|
|
|
|
2013-02-13 18:04:08 -08:00
|
|
|
// Callback for SVGParseCompleteListener.
|
|
|
|
void OnSVGDocumentParsed();
|
|
|
|
|
|
|
|
// Callbacks for SVGLoadEventListener.
|
|
|
|
void OnSVGDocumentLoaded();
|
|
|
|
void OnSVGDocumentError();
|
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
protected:
|
2015-04-28 16:32:02 -07:00
|
|
|
explicit VectorImage(ImageURL* aURI = nullptr);
|
2014-06-23 11:49:08 -07:00
|
|
|
virtual ~VectorImage();
|
2012-12-17 14:05:18 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult StartAnimation() override;
|
|
|
|
virtual nsresult StopAnimation() override;
|
|
|
|
virtual bool ShouldAnimate() override;
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2014-09-14 15:22:45 -07:00
|
|
|
void CreateSurfaceAndShow(const SVGDrawingParameters& aParams);
|
2014-08-06 15:43:25 -07:00
|
|
|
void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
|
2013-10-22 04:38:08 -07:00
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
private:
|
2015-04-28 16:07:24 -07:00
|
|
|
nsresult Init(const char* aMimeType, uint32_t aFlags);
|
|
|
|
|
2015-02-03 16:38:39 -08: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-13 18:04:08 -08:00
|
|
|
void CancelAllListeners();
|
2013-11-20 17:21:50 -08:00
|
|
|
void SendInvalidationNotifications();
|
2013-02-13 18:04:08 -08:00
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
nsRefPtr<SVGDocumentWrapper> mSVGDocumentWrapper;
|
2010-09-08 13:40:40 -07:00
|
|
|
nsRefPtr<SVGRootRenderingObserver> mRenderingObserver;
|
2013-02-13 18:04:08 -08:00
|
|
|
nsRefPtr<SVGLoadEventListener> mLoadEventListener;
|
|
|
|
nsRefPtr<SVGParseCompleteListener> mParseCompleteListener;
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2015-03-27 20:17:23 -07:00
|
|
|
/// Count of locks on this image (roughly correlated to visible instances).
|
|
|
|
uint32_t mLockCount;
|
|
|
|
|
2015-04-04 12:58:00 -07:00
|
|
|
bool mIsInitialized; // Have we been initialized?
|
2015-03-27 20:17:23 -07:00
|
|
|
bool mDiscardable; // Are we discardable?
|
2015-04-04 12:58:00 -07:00
|
|
|
bool mIsFullyLoaded; // Has the SVG document finished
|
|
|
|
// loading?
|
2013-02-28 22:44:57 -08:00
|
|
|
bool mIsDrawing; // Are we currently drawing?
|
|
|
|
bool mHaveAnimations; // Is our SVG content SMIL-animated?
|
2010-09-08 13:40:39 -07:00
|
|
|
// (Only set after mIsFullyLoaded.)
|
2013-09-04 03:39:30 -07:00
|
|
|
bool mHasPendingInvalidation; // Invalidate observers next refresh
|
|
|
|
// driver tick.
|
2012-12-17 14:05:18 -08:00
|
|
|
|
|
|
|
friend class ImageFactory;
|
2010-09-08 13:40:39 -07:00
|
|
|
};
|
|
|
|
|
2015-04-04 12:58:00 -07:00
|
|
|
inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
2012-10-19 13:27:11 -07:00
|
|
|
return GetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) {
|
|
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-09-08 13:40:39 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-04 12:58:00 -07:00
|
|
|
#endif // mozilla_image_src_VectorImage_h
|