LCOV - code coverage report
Current view: top level - image - VectorImage.h (source / functions) Hit Total Coverage
Test: output.info Lines: 2 4 50.0 %
Date: 2017-07-14 16:53:18 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       5             : 
       6             : #ifndef mozilla_image_VectorImage_h
       7             : #define mozilla_image_VectorImage_h
       8             : 
       9             : #include "Image.h"
      10             : #include "nsIStreamListener.h"
      11             : #include "mozilla/MemoryReporting.h"
      12             : 
      13             : class nsIRequest;
      14             : class gfxDrawable;
      15             : 
      16             : namespace mozilla {
      17             : namespace image {
      18             : 
      19             : struct SVGDrawingParameters;
      20             : class  SVGDocumentWrapper;
      21             : class  SVGRootRenderingObserver;
      22             : class  SVGLoadEventListener;
      23             : class  SVGParseCompleteListener;
      24             : 
      25             : class VectorImage final : public ImageResource,
      26             :                           public nsIStreamListener
      27             : {
      28             : public:
      29             :   NS_DECL_ISUPPORTS
      30             :   NS_DECL_NSIREQUESTOBSERVER
      31             :   NS_DECL_NSISTREAMLISTENER
      32             :   NS_DECL_IMGICONTAINER
      33             : 
      34             :   // (no public constructor - use ImageFactory)
      35             : 
      36             :   // Methods inherited from Image
      37             :   nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) const override;
      38             :   virtual size_t SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf)
      39             :     const override;
      40             :   virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
      41             :                                      MallocSizeOf aMallocSizeOf) const override;
      42             : 
      43             :   virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
      44             :                                         nsISupports* aContext,
      45             :                                         nsIInputStream* aInStr,
      46             :                                         uint64_t aSourceOffset,
      47             :                                         uint32_t aCount) override;
      48             :   virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
      49             :                                        nsISupports* aContext,
      50             :                                        nsresult aResult,
      51             :                                        bool aLastPart) override;
      52             : 
      53             :   virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
      54             : 
      55             :   /**
      56             :    * Callback for SVGRootRenderingObserver.
      57             :    *
      58             :    * This just sets a dirty flag that we check in VectorImage::RequestRefresh,
      59             :    * which is called under the ticks of the refresh driver of any observing
      60             :    * documents that we may have. Only then (after all animations in this image
      61             :    * have been updated) do we send out "frame changed" notifications,
      62             :    */
      63             :   void InvalidateObserversOnNextRefreshDriverTick();
      64             : 
      65             :   // Callback for SVGParseCompleteListener.
      66             :   void OnSVGDocumentParsed();
      67             : 
      68             :   // Callbacks for SVGLoadEventListener.
      69             :   void OnSVGDocumentLoaded();
      70             :   void OnSVGDocumentError();
      71             : 
      72             :   virtual void ReportUseCounters() override;
      73             : 
      74             : protected:
      75             :   explicit VectorImage(ImageURL* aURI = nullptr);
      76             :   virtual ~VectorImage();
      77             : 
      78             :   virtual nsresult StartAnimation() override;
      79             :   virtual nsresult StopAnimation() override;
      80             :   virtual bool     ShouldAnimate() override;
      81             : 
      82             : private:
      83             :   /// Attempt to find a cached surface matching @aParams in the SurfaceCache.
      84             :   already_AddRefed<gfxDrawable>
      85             :     LookupCachedSurface(const SVGDrawingParameters& aParams);
      86             : 
      87             :   void CreateSurfaceAndShow(const SVGDrawingParameters& aParams,
      88             :                             gfx::BackendType aBackend);
      89             :   void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
      90             : 
      91             :   nsresult Init(const char* aMimeType, uint32_t aFlags);
      92             : 
      93             :   /**
      94             :    * In catastrophic circumstances like a GPU driver crash, we may lose our
      95             :    * surfaces even if they're locked. RecoverFromLossOfSurfaces discards all
      96             :    * existing surfaces, allowing us to recover.
      97             :    */
      98             :   void RecoverFromLossOfSurfaces();
      99             : 
     100             :   void CancelAllListeners();
     101             :   void SendInvalidationNotifications();
     102             : 
     103             :   RefPtr<SVGDocumentWrapper>       mSVGDocumentWrapper;
     104             :   RefPtr<SVGRootRenderingObserver> mRenderingObserver;
     105             :   RefPtr<SVGLoadEventListener>     mLoadEventListener;
     106             :   RefPtr<SVGParseCompleteListener> mParseCompleteListener;
     107             : 
     108             :   /// Count of locks on this image (roughly correlated to visible instances).
     109             :   uint32_t mLockCount;
     110             : 
     111             :   // Stored result from the Necko load of the image, which we save in
     112             :   // OnImageDataComplete if the underlying SVG document isn't loaded. If we save
     113             :   // this, we actually notify this progress (and clear this value) in
     114             :   // OnSVGDocumentLoaded or OnSVGDocumentError.
     115             :   Maybe<Progress> mLoadProgress;
     116             : 
     117             :   bool           mIsInitialized;          // Have we been initialized?
     118             :   bool           mDiscardable;            // Are we discardable?
     119             :   bool           mIsFullyLoaded;          // Has the SVG document finished
     120             :                                           // loading?
     121             :   bool           mIsDrawing;              // Are we currently drawing?
     122             :   bool           mHaveAnimations;         // Is our SVG content SMIL-animated?
     123             :                                           // (Only set after mIsFullyLoaded.)
     124             :   bool           mHasPendingInvalidation; // Invalidate observers next refresh
     125             :                                           // driver tick.
     126             : 
     127             :   friend class ImageFactory;
     128             : };
     129             : 
     130           0 : inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t* aAnimationMode) {
     131           0 :   return GetAnimationModeInternal(aAnimationMode);
     132             : }
     133             : 
     134          21 : inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) {
     135          21 :   return SetAnimationModeInternal(aAnimationMode);
     136             : }
     137             : 
     138             : } // namespace image
     139             : } // namespace mozilla
     140             : 
     141             : #endif // mozilla_image_VectorImage_h

Generated by: LCOV version 1.13