tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FrozenImage.h (3396B)


      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_FrozenImage_h
      7 #define mozilla_image_FrozenImage_h
      8 
      9 #include "ImageWrapper.h"
     10 #include "mozilla/gfx/2D.h"
     11 
     12 namespace mozilla {
     13 namespace image {
     14 
     15 /**
     16 * An Image wrapper that disables animation, freezing the image at its first
     17 * frame. It does this using two strategies. If this is the only instance of the
     18 * image, animation will never start, because IncrementAnimationConsumers is
     19 * ignored. If there is another instance that is animated, that's still OK,
     20 * because any imgIContainer method that is affected by animation gets its
     21 * aWhichFrame argument set to FRAME_FIRST when it passes through FrozenImage.
     22 *
     23 * XXX(seth): There a known (performance, not correctness) issue with
     24 * GetImageContainer. See the comments for that method for more information.
     25 */
     26 class FrozenImage : public ImageWrapper {
     27  typedef gfx::SourceSurface SourceSurface;
     28 
     29 public:
     30  NS_INLINE_DECL_REFCOUNTING_INHERITED(FrozenImage, ImageWrapper)
     31 
     32  virtual void IncrementAnimationConsumers() override;
     33  virtual void DecrementAnimationConsumers() override;
     34 
     35  bool IsNonAnimated() const;
     36 
     37  NS_IMETHOD GetAnimated(bool* aAnimated) override;
     38  NS_IMETHOD_(already_AddRefed<SourceSurface>)
     39  GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
     40  NS_IMETHOD_(already_AddRefed<SourceSurface>)
     41  GetFrameAtSize(const gfx::IntSize& aSize, uint32_t aWhichFrame,
     42                 uint32_t aFlags) override;
     43  NS_IMETHOD_(bool)
     44  IsImageContainerAvailable(WindowRenderer* aRenderer,
     45                            uint32_t aFlags) override;
     46  NS_IMETHOD_(ImgDrawResult)
     47  GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize,
     48                   const SVGImageContext& aSVGContext,
     49                   const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags,
     50                   WebRenderImageProvider** aProvider) override;
     51  NS_IMETHOD_(ImgDrawResult)
     52  Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
     53       uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter,
     54       const SVGImageContext& aSVGContext, uint32_t aFlags,
     55       float aOpacity) override;
     56  NS_IMETHOD StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) override;
     57  NS_IMETHOD_(bool)
     58  StartDecodingWithResult(uint32_t aFlags, uint32_t aWhichFrame) override;
     59  NS_IMETHOD_(bool)
     60  HasDecodedPixels() override;
     61  NS_IMETHOD_(DecodeResult)
     62  RequestDecodeWithResult(uint32_t aFlags, uint32_t aWhichFrame) override;
     63  NS_IMETHOD RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
     64                                  uint32_t aWhichFrame) override;
     65  NS_IMETHOD_(void) RequestRefresh(const TimeStamp& aTime) override;
     66  NS_IMETHOD GetAnimationMode(uint16_t* aAnimationMode) override;
     67  NS_IMETHOD SetAnimationMode(uint16_t aAnimationMode) override;
     68  NS_IMETHOD ResetAnimation() override;
     69  NS_IMETHOD_(float) GetFrameIndex(uint32_t aWhichFrame) override;
     70 
     71 protected:
     72  explicit FrozenImage(Image* aImage) : ImageWrapper(aImage) {}
     73  virtual ~FrozenImage() {}
     74 
     75 private:
     76  friend class ImageOps;
     77 };
     78 
     79 }  // namespace image
     80 }  // namespace mozilla
     81 
     82 #endif  // mozilla_image_FrozenImage_h