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