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_OrientedImage_h
7 #define mozilla_image_OrientedImage_h
9 #include "ImageWrapper.h"
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/RefPtr.h"
12 #include "Orientation.h"
18 * An Image wrapper that rotates and/or flips an image according to a specified
21 * XXX(seth): There a known (performance, not correctness) issue with
22 * GetImageContainer. See the comments for that method for more information.
24 class OrientedImage
: public ImageWrapper
{
25 typedef gfx::SourceSurface SourceSurface
;
28 NS_INLINE_DECL_REFCOUNTING_INHERITED(OrientedImage
, ImageWrapper
)
30 NS_IMETHOD
GetWidth(int32_t* aWidth
) override
;
31 NS_IMETHOD
GetHeight(int32_t* aHeight
) override
;
32 nsresult
GetNativeSizes(nsTArray
<gfx::IntSize
>& aNativeSizes
) const override
;
33 NS_IMETHOD
GetIntrinsicSize(nsSize
* aSize
) override
;
34 Maybe
<AspectRatio
> GetIntrinsicRatio() override
;
35 NS_IMETHOD_(already_AddRefed
<SourceSurface
>)
36 GetFrame(uint32_t aWhichFrame
, uint32_t aFlags
) override
;
37 NS_IMETHOD_(already_AddRefed
<SourceSurface
>)
38 GetFrameAtSize(const gfx::IntSize
& aSize
, uint32_t aWhichFrame
,
39 uint32_t aFlags
) override
;
41 IsImageContainerAvailable(layers::LayerManager
* aManager
,
42 uint32_t aFlags
) override
;
43 NS_IMETHOD_(already_AddRefed
<layers::ImageContainer
>)
44 GetImageContainer(layers::LayerManager
* aManager
, uint32_t aFlags
) override
;
46 IsImageContainerAvailableAtSize(layers::LayerManager
* aManager
,
47 const gfx::IntSize
& aSize
,
48 uint32_t aFlags
) override
;
49 NS_IMETHOD_(ImgDrawResult
)
50 GetImageContainerAtSize(layers::LayerManager
* aManager
,
51 const gfx::IntSize
& aSize
,
52 const Maybe
<SVGImageContext
>& aSVGContext
,
54 layers::ImageContainer
** aOutContainer
) override
;
55 NS_IMETHOD_(ImgDrawResult
)
56 Draw(gfxContext
* aContext
, const nsIntSize
& aSize
, const ImageRegion
& aRegion
,
57 uint32_t aWhichFrame
, gfx::SamplingFilter aSamplingFilter
,
58 const Maybe
<SVGImageContext
>& aSVGContext
, uint32_t aFlags
,
59 float aOpacity
) override
;
60 NS_IMETHOD_(nsIntRect
)
61 GetImageSpaceInvalidationRect(const nsIntRect
& aRect
) override
;
62 nsIntSize
OptimalImageSizeForDest(const gfxSize
& aDest
, uint32_t aWhichFrame
,
63 gfx::SamplingFilter aSamplingFilter
,
64 uint32_t aFlags
) override
;
67 * Computes a matrix that applies the rotation and reflection specified by
68 * aOrientation, or that matrix's inverse if aInvert is true.
70 * @param aSize The scaled size of the inner image. (When outside code
71 * specifies the scaled size, as with imgIContainer::Draw and its aSize
72 * parameter, it's necessary to swap the width and height if
73 * mOrientation.SwapsWidthAndHeight() is true.)
75 * @param aInvert If true, compute the inverse of the orientation matrix.
76 * Prefer this approach to OrientationMatrix(..).Invert(), because it's more
77 * numerically accurate.
79 static gfxMatrix
OrientationMatrix(Orientation aOrientation
,
80 const nsIntSize
& aSize
,
81 bool aInvert
= false);
84 * Returns a SourceSurface that is the result of rotating and flipping
85 * aSurface according to aOrientation.
87 static already_AddRefed
<SourceSurface
> OrientSurface(Orientation aOrientation
,
88 SourceSurface
* aSurface
);
91 OrientedImage(Image
* aImage
, Orientation aOrientation
)
92 : ImageWrapper(aImage
), mOrientation(aOrientation
) {}
94 virtual ~OrientedImage() {}
96 gfxMatrix
OrientationMatrix(const nsIntSize
& aSize
, bool aInvert
= false) {
97 return OrientationMatrix(mOrientation
, aSize
, aInvert
);
101 Orientation mOrientation
;
103 friend class ImageOps
;
107 } // namespace mozilla
109 #endif // mozilla_image_OrientedImage_h