OrientedImage.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_OrientedImage_h
  6. #define mozilla_image_OrientedImage_h
  7. #include "ImageWrapper.h"
  8. #include "mozilla/gfx/2D.h"
  9. #include "mozilla/RefPtr.h"
  10. #include "Orientation.h"
  11. namespace mozilla {
  12. namespace image {
  13. /**
  14. * An Image wrapper that rotates and/or flips an image according to a specified
  15. * Orientation.
  16. *
  17. * XXX(seth): There a known (performance, not correctness) issue with
  18. * GetImageContainer. See the comments for that method for more information.
  19. */
  20. class OrientedImage : public ImageWrapper
  21. {
  22. typedef gfx::SourceSurface SourceSurface;
  23. public:
  24. NS_DECL_ISUPPORTS_INHERITED
  25. NS_IMETHOD GetWidth(int32_t* aWidth) override;
  26. NS_IMETHOD GetHeight(int32_t* aHeight) override;
  27. NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override;
  28. NS_IMETHOD GetIntrinsicRatio(AspectRatio* aRatio) override;
  29. NS_IMETHOD_(already_AddRefed<SourceSurface>)
  30. GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override;
  31. NS_IMETHOD_(already_AddRefed<SourceSurface>)
  32. GetFrameAtSize(const gfx::IntSize& aSize,
  33. uint32_t aWhichFrame,
  34. uint32_t aFlags) override;
  35. NS_IMETHOD_(bool) IsImageContainerAvailable(layers::LayerManager* aManager,
  36. uint32_t aFlags) override;
  37. NS_IMETHOD_(already_AddRefed<layers::ImageContainer>)
  38. GetImageContainer(layers::LayerManager* aManager,
  39. uint32_t aFlags) override;
  40. NS_IMETHOD_(DrawResult) Draw(gfxContext* aContext,
  41. const nsIntSize& aSize,
  42. const ImageRegion& aRegion,
  43. uint32_t aWhichFrame,
  44. gfx::SamplingFilter aSamplingFilter,
  45. const Maybe<SVGImageContext>& aSVGContext,
  46. uint32_t aFlags) override;
  47. NS_IMETHOD_(nsIntRect) GetImageSpaceInvalidationRect(
  48. const nsIntRect& aRect) override;
  49. nsIntSize OptimalImageSizeForDest(const gfxSize& aDest,
  50. uint32_t aWhichFrame,
  51. gfx::SamplingFilter aSamplingFilter,
  52. uint32_t aFlags) override;
  53. protected:
  54. OrientedImage(Image* aImage, Orientation aOrientation)
  55. : ImageWrapper(aImage)
  56. , mOrientation(aOrientation)
  57. { }
  58. virtual ~OrientedImage() { }
  59. gfxMatrix OrientationMatrix(const nsIntSize& aSize, bool aInvert = false);
  60. private:
  61. Orientation mOrientation;
  62. friend class ImageOps;
  63. };
  64. } // namespace image
  65. } // namespace mozilla
  66. #endif // mozilla_image_OrientedImage_h