FrozenImage.h 2.9 KB

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