LCOV - code coverage report
Current view: top level - image - AnimationSurfaceProvider.h (source / functions) Hit Total Coverage
Test: output.info Lines: 5 5 100.0 %
Date: 2017-07-14 16:53:18 Functions: 6 6 100.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             : /**
       7             :  * An ISurfaceProvider for animated images.
       8             :  */
       9             : 
      10             : #ifndef mozilla_image_AnimationSurfaceProvider_h
      11             : #define mozilla_image_AnimationSurfaceProvider_h
      12             : 
      13             : #include "FrameAnimator.h"
      14             : #include "IDecodingTask.h"
      15             : #include "ISurfaceProvider.h"
      16             : 
      17             : namespace mozilla {
      18             : namespace image {
      19             : 
      20             : /**
      21             :  * An ISurfaceProvider that manages the decoding of animated images and
      22             :  * dynamically generates surfaces for the current playback state of the
      23             :  * animation.
      24             :  */
      25             : class AnimationSurfaceProvider final
      26             :   : public ISurfaceProvider
      27             :   , public IDecodingTask
      28             : {
      29             : public:
      30          64 :   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AnimationSurfaceProvider, override)
      31             : 
      32             :   AnimationSurfaceProvider(NotNull<RasterImage*> aImage,
      33             :                            const SurfaceKey& aSurfaceKey,
      34             :                            NotNull<Decoder*> aDecoder);
      35             : 
      36             : 
      37             :   //////////////////////////////////////////////////////////////////////////////
      38             :   // ISurfaceProvider implementation.
      39             :   //////////////////////////////////////////////////////////////////////////////
      40             : 
      41             : public:
      42             :   // We use the ISurfaceProvider constructor of DrawableSurface to indicate that
      43             :   // our surfaces are computed lazily.
      44          23 :   DrawableSurface Surface() override { return DrawableSurface(WrapNotNull(this)); }
      45             : 
      46             :   bool IsFinished() const override;
      47             :   size_t LogicalSizeInBytes() const override;
      48             :   void AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
      49             :                               size_t& aHeapSizeOut,
      50             :                               size_t& aNonHeapSizeOut,
      51             :                               size_t& aSharedHandlesOut) override;
      52             : 
      53             : protected:
      54             :   DrawableFrameRef DrawableRef(size_t aFrame) override;
      55             : 
      56             :   // Animation frames are always locked. This is because we only want to release
      57             :   // their memory atomically (due to the surface cache discarding them). If they
      58             :   // were unlocked, the OS could end up releasing the memory of random frames
      59             :   // from the middle of the animation, which is not worth the complexity of
      60             :   // dealing with.
      61          29 :   bool IsLocked() const override { return true; }
      62           2 :   void SetLocked(bool) override { }
      63             : 
      64             : 
      65             :   //////////////////////////////////////////////////////////////////////////////
      66             :   // IDecodingTask implementation.
      67             :   //////////////////////////////////////////////////////////////////////////////
      68             : 
      69             : public:
      70             :   void Run() override;
      71             :   bool ShouldPreferSyncRun() const override;
      72             : 
      73             :   // Full decodes are low priority compared to metadata decodes because they
      74             :   // don't block layout or page load.
      75           2 :   TaskPriority Priority() const override { return TaskPriority::eLow; }
      76             : 
      77             : private:
      78             :   virtual ~AnimationSurfaceProvider();
      79             : 
      80             :   void DropImageReference();
      81             :   void CheckForNewFrameAtYield();
      82             :   void CheckForNewFrameAtTerminalState();
      83             :   void AnnounceSurfaceAvailable();
      84             :   void FinishDecoding();
      85             : 
      86             :   /// The image associated with our decoder.
      87             :   RefPtr<RasterImage> mImage;
      88             : 
      89             :   /// A mutex to protect mDecoder. Always taken before mFramesMutex.
      90             :   mutable Mutex mDecodingMutex;
      91             : 
      92             :   /// The decoder used to decode this animation.
      93             :   RefPtr<Decoder> mDecoder;
      94             : 
      95             :   /// A mutex to protect mFrames. Always taken after mDecodingMutex.
      96             :   mutable Mutex mFramesMutex;
      97             : 
      98             :   /// The frames of this animation, in order.
      99             :   nsTArray<RawAccessFrameRef> mFrames;
     100             : };
     101             : 
     102             : } // namespace image
     103             : } // namespace mozilla
     104             : 
     105             : #endif // mozilla_image_AnimationSurfaceProvider_h

Generated by: LCOV version 1.13