2010-09-09 00:40:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-09 00:40:39 +04:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_VectorImage_h
|
|
|
|
#define mozilla_image_VectorImage_h
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
#include "Image.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2021-01-04 17:20:22 +03:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2013-09-07 17:01:08 +04:00
|
|
|
class nsIRequest;
|
2013-10-22 15:38:08 +04:00
|
|
|
class gfxDrawable;
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2019-12-13 05:04:07 +03:00
|
|
|
struct MediaFeatureChange;
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2021-05-13 19:24:06 +03:00
|
|
|
class SourceSurfaceBlobImage;
|
2013-10-22 15:38:08 +04:00
|
|
|
struct SVGDrawingParameters;
|
|
|
|
class SVGDocumentWrapper;
|
|
|
|
class SVGRootRenderingObserver;
|
|
|
|
class SVGLoadEventListener;
|
|
|
|
class SVGParseCompleteListener;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class VectorImage final : public ImageResource, public nsIStreamListener {
|
2010-09-09 00:40:39 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2012-10-20 00:27:11 +04:00
|
|
|
NS_DECL_IMGICONTAINER
|
2010-11-17 23:37:08 +03:00
|
|
|
|
2012-12-18 02:05:18 +04:00
|
|
|
// (no public constructor - use ImageFactory)
|
2010-09-09 00:40:39 +04:00
|
|
|
|
|
|
|
// Methods inherited from Image
|
2019-12-13 05:04:07 +03:00
|
|
|
void MediaFeatureValuesChangedAllDocuments(const MediaFeatureChange&) final;
|
2017-03-22 16:05:36 +03:00
|
|
|
nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
|
2017-09-05 14:58:44 +03:00
|
|
|
size_t GetNativeSizesLength() const override;
|
2017-07-28 13:10:04 +03:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const override;
|
2015-04-28 21:46:17 +03:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const override;
|
2014-05-08 13:53:00 +04:00
|
|
|
|
2012-12-18 02:05:18 +04:00
|
|
|
virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
2015-03-21 19:28:04 +03:00
|
|
|
uint32_t aCount) override;
|
2012-12-18 02:05:18 +04:00
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext, nsresult aResult,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aLastPart) override;
|
2012-12-18 02:05:18 +04:00
|
|
|
|
2017-03-16 11:06:06 +03:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
|
2015-03-28 06:17:23 +03:00
|
|
|
|
2013-09-04 14:39:30 +04: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-09 00:40:40 +04:00
|
|
|
|
2013-02-14 06:04:08 +04:00
|
|
|
// Callback for SVGParseCompleteListener.
|
|
|
|
void OnSVGDocumentParsed();
|
|
|
|
|
|
|
|
// Callbacks for SVGLoadEventListener.
|
|
|
|
void OnSVGDocumentLoaded();
|
|
|
|
void OnSVGDocumentError();
|
|
|
|
|
2010-09-09 00:40:39 +04:00
|
|
|
protected:
|
2018-06-06 03:42:56 +03:00
|
|
|
explicit VectorImage(nsIURI* aURI = nullptr);
|
2014-06-23 22:49:08 +04:00
|
|
|
virtual ~VectorImage();
|
2012-12-18 02:05:18 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult StartAnimation() override;
|
|
|
|
virtual nsresult StopAnimation() override;
|
|
|
|
virtual bool ShouldAnimate() override;
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2016-08-18 07:46:25 +03:00
|
|
|
private:
|
2021-05-13 19:24:06 +03:00
|
|
|
friend class SourceSurfaceBlobImage;
|
|
|
|
|
2021-01-04 17:20:22 +03:00
|
|
|
Tuple<ImgDrawResult, gfx::IntSize, RefPtr<gfx::SourceSurface>>
|
|
|
|
GetFrameInternal(const gfx::IntSize& aSize,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2021-05-13 19:24:07 +03:00
|
|
|
const Maybe<ImageIntRegion>& aRegion, uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) override;
|
2017-11-17 22:08:52 +03:00
|
|
|
|
2021-01-04 17:20:22 +03:00
|
|
|
Tuple<ImgDrawResult, gfx::IntSize> GetImageContainerSize(
|
2021-08-25 04:41:35 +03:00
|
|
|
layers::LayerManager* aManager, const gfx::IntSize& aSize,
|
2018-09-14 02:48:21 +03:00
|
|
|
uint32_t aFlags) override;
|
2017-11-17 22:08:52 +03:00
|
|
|
|
2018-09-21 03:22:06 +03: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).
|
|
|
|
*/
|
2021-01-04 17:20:22 +03:00
|
|
|
Tuple<RefPtr<gfx::SourceSurface>, gfx::IntSize> LookupCachedSurface(
|
|
|
|
const gfx::IntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 22:08:51 +03:00
|
|
|
uint32_t aFlags);
|
2016-08-18 07:46:25 +03:00
|
|
|
|
2017-11-17 22:08:52 +03:00
|
|
|
bool MaybeRestrictSVGContext(Maybe<SVGImageContext>& aNewSVGContext,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
uint32_t aFlags);
|
|
|
|
|
2017-12-02 02:50:07 +03:00
|
|
|
/// Create a gfxDrawable which callbacks into the SVG document.
|
|
|
|
already_AddRefed<gfxDrawable> CreateSVGDrawable(
|
|
|
|
const SVGDrawingParameters& aParams);
|
2017-12-01 15:00:20 +03:00
|
|
|
|
2017-12-02 02:50:07 +03:00
|
|
|
/// Rasterize the SVG into a surface. aWillCache will be set to whether or
|
|
|
|
/// not the new surface was put into the cache.
|
2021-01-04 17:20:22 +03:00
|
|
|
already_AddRefed<gfx::SourceSurface> CreateSurface(
|
2017-12-02 02:50:07 +03: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 22:08:52 +03:00
|
|
|
|
2014-08-07 02:43:25 +04:00
|
|
|
void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
|
2013-10-22 15:38:08 +04:00
|
|
|
|
2015-04-29 02:07:24 +03:00
|
|
|
nsresult Init(const char* aMimeType, uint32_t aFlags);
|
|
|
|
|
2015-02-04 03:38:39 +03: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 06:04:08 +04:00
|
|
|
void CancelAllListeners();
|
2013-11-21 05:21:50 +04:00
|
|
|
void SendInvalidationNotifications();
|
2013-02-14 06:04:08 +04:00
|
|
|
|
2020-10-12 01:15:06 +03:00
|
|
|
void ReportDocumentUseCounters();
|
Bug 1656114 - Part 4: Accumulate page use counters in the parent process. r=emilio,nika
This changes the way we deal with page use counters so that we can
handle out of process iframes.
Currently, when a parent document is being destroyed, we poke into all
of the sub-documents to merge their use counters into the parent's page
use counters, which we then report via Telemetry. With Fission enabled,
the sub-documents may be out of process. We can't simply turn these
into async IPC calls, since the parent document will be destroyed
shortly, as might the content processes holding the sub-documents.
So instead, each document during its initialization identifies which
ancestor document it will contribute its page use counters to, and
stores its WindowContext id to identify that ancestor. A message is
sent to the parent process to notify it that page use counter data will
be sent at some later point. That later point is when the document
loses its window. It doesn't matter if the ancestor document has
already been destroyed at this point, since all we need is its
WindowContext id to uniquely identify it. Once the parent process has
received all of the use counters it expects to accumulate to a given
WindowContext Id, it reports them via Telemetry.
Reporting of document use counters remains unchanged and is done by each
document in their content process.
While we're here, we also:
* Limit use counters to be reported for a pre-defined set of document
URL schemes, rather than be based on the document principal.
* Add proper MOZ_LOG logging for use counters instead of printfs.
Differential Revision: https://phabricator.services.mozilla.com/D87188
2020-10-12 01:03:43 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SVGDocumentWrapper> mSVGDocumentWrapper;
|
|
|
|
RefPtr<SVGRootRenderingObserver> mRenderingObserver;
|
|
|
|
RefPtr<SVGLoadEventListener> mLoadEventListener;
|
|
|
|
RefPtr<SVGParseCompleteListener> mParseCompleteListener;
|
2010-09-09 00:40:39 +04:00
|
|
|
|
2015-03-28 06:17:23 +03:00
|
|
|
/// Count of locks on this image (roughly correlated to visible instances).
|
|
|
|
uint32_t mLockCount;
|
|
|
|
|
2015-06-19 00:48:41 +03: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 22:58:00 +03:00
|
|
|
bool mIsInitialized; // Have we been initialized?
|
2015-03-28 06:17:23 +03:00
|
|
|
bool mDiscardable; // Are we discardable?
|
2015-04-04 22:58:00 +03:00
|
|
|
bool mIsFullyLoaded; // Has the SVG document finished
|
|
|
|
// loading?
|
2013-03-01 10:44:57 +04:00
|
|
|
bool mHaveAnimations; // Is our SVG content SMIL-animated?
|
2010-09-09 00:40:39 +04:00
|
|
|
// (Only set after mIsFullyLoaded.)
|
2013-09-04 14:39:30 +04:00
|
|
|
bool mHasPendingInvalidation; // Invalidate observers next refresh
|
|
|
|
// driver tick.
|
2012-12-18 02:05:18 +04:00
|
|
|
|
|
|
|
friend class ImageFactory;
|
2010-09-09 00:40:39 +04:00
|
|
|
};
|
|
|
|
|
2015-04-04 22:58:00 +03:00
|
|
|
inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
2012-10-20 00:27:11 +04:00
|
|
|
return GetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) {
|
|
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-09-09 00:40:39 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_VectorImage_h
|