OrientedImage.h (3992B)
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_OrientedImage_h 7 #define mozilla_image_OrientedImage_h 8 9 #include "ImageWrapper.h" 10 #include "mozilla/gfx/2D.h" 11 #include "Orientation.h" 12 13 namespace mozilla { 14 namespace image { 15 16 /** 17 * An Image wrapper that rotates and/or flips an image according to a specified 18 * Orientation. 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 OrientedImage : public ImageWrapper { 24 typedef gfx::SourceSurface SourceSurface; 25 26 public: 27 NS_INLINE_DECL_REFCOUNTING_INHERITED(OrientedImage, ImageWrapper) 28 29 NS_IMETHOD GetWidth(int32_t* aWidth) override; 30 NS_IMETHOD GetHeight(int32_t* aHeight) override; 31 nsresult GetNativeSizes(nsTArray<gfx::IntSize>& aNativeSizes) override; 32 NS_IMETHOD GetIntrinsicSizeInAppUnits(nsSize* aSize) override; 33 AspectRatio GetIntrinsicRatio() override; 34 NS_IMETHOD_(already_AddRefed<SourceSurface>) 35 GetFrame(uint32_t aWhichFrame, uint32_t aFlags) override; 36 NS_IMETHOD_(already_AddRefed<SourceSurface>) 37 GetFrameAtSize(const gfx::IntSize& aSize, uint32_t aWhichFrame, 38 uint32_t aFlags) override; 39 NS_IMETHOD_(bool) 40 IsImageContainerAvailable(WindowRenderer* aRenderer, 41 uint32_t aFlags) override; 42 NS_IMETHOD_(ImgDrawResult) 43 GetImageProvider(WindowRenderer* aRenderer, const gfx::IntSize& aSize, 44 const SVGImageContext& aSVGContext, 45 const Maybe<ImageIntRegion>& aRegion, uint32_t aFlags, 46 WebRenderImageProvider** aProvider) override; 47 NS_IMETHOD_(ImgDrawResult) 48 Draw(gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion, 49 uint32_t aWhichFrame, gfx::SamplingFilter aSamplingFilter, 50 const SVGImageContext& aSVGContext, uint32_t aFlags, 51 float aOpacity) override; 52 NS_IMETHOD_(nsIntRect) 53 GetImageSpaceInvalidationRect(const nsIntRect& aRect) override; 54 nsIntSize OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame, 55 gfx::SamplingFilter aSamplingFilter, 56 uint32_t aFlags) override; 57 58 /** 59 * Computes a matrix that applies the rotation and reflection specified by 60 * aOrientation, or that matrix's inverse if aInvert is true. 61 * 62 * @param aSize The scaled size of the inner image. (When outside code 63 * specifies the scaled size, as with imgIContainer::Draw and its aSize 64 * parameter, it's necessary to swap the width and height if 65 * mOrientation.SwapsWidthAndHeight() is true.) 66 * 67 * @param aInvert If true, compute the inverse of the orientation matrix. 68 * Prefer this approach to OrientationMatrix(..).Invert(), because it's more 69 * numerically accurate. 70 */ 71 static gfxMatrix OrientationMatrix(Orientation aOrientation, 72 const nsIntSize& aSize, 73 bool aInvert = false); 74 75 /** 76 * Returns a SourceSurface that is the result of rotating and flipping 77 * aSurface according to aOrientation. 78 */ 79 static already_AddRefed<SourceSurface> OrientSurface(Orientation aOrientation, 80 SourceSurface* aSurface); 81 82 protected: 83 OrientedImage(Image* aImage, Orientation aOrientation) 84 : ImageWrapper(aImage), mOrientation(aOrientation) {} 85 86 virtual ~OrientedImage() {} 87 88 gfxMatrix OrientationMatrix(const nsIntSize& aSize, bool aInvert = false) { 89 return OrientationMatrix(mOrientation, aSize, aInvert); 90 } 91 92 private: 93 Orientation mOrientation; 94 95 friend class ImageOps; 96 }; 97 98 } // namespace image 99 } // namespace mozilla 100 101 #endif // mozilla_image_OrientedImage_h