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
) 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(WindowRenderer
* aRenderer
,
42 uint32_t aFlags
) override
;
43 NS_IMETHOD_(ImgDrawResult
)
44 GetImageProvider(WindowRenderer
* aRenderer
, const gfx::IntSize
& aSize
,
45 const SVGImageContext
& aSVGContext
,
46 const Maybe
<ImageIntRegion
>& aRegion
, uint32_t aFlags
,
47 WebRenderImageProvider
** aProvider
) override
;
48 NS_IMETHOD_(ImgDrawResult
)
49 Draw(gfxContext
* aContext
, const nsIntSize
& aSize
, const ImageRegion
& aRegion
,
50 uint32_t aWhichFrame
, gfx::SamplingFilter aSamplingFilter
,
51 const SVGImageContext
& aSVGContext
, uint32_t aFlags
,
52 float aOpacity
) override
;
53 NS_IMETHOD_(nsIntRect
)
54 GetImageSpaceInvalidationRect(const nsIntRect
& aRect
) override
;
55 nsIntSize
OptimalImageSizeForDest(const gfxSize
& aDest
, uint32_t aWhichFrame
,
56 gfx::SamplingFilter aSamplingFilter
,
57 uint32_t aFlags
) override
;
60 * Computes a matrix that applies the rotation and reflection specified by
61 * aOrientation, or that matrix's inverse if aInvert is true.
63 * @param aSize The scaled size of the inner image. (When outside code
64 * specifies the scaled size, as with imgIContainer::Draw and its aSize
65 * parameter, it's necessary to swap the width and height if
66 * mOrientation.SwapsWidthAndHeight() is true.)
68 * @param aInvert If true, compute the inverse of the orientation matrix.
69 * Prefer this approach to OrientationMatrix(..).Invert(), because it's more
70 * numerically accurate.
72 static gfxMatrix
OrientationMatrix(Orientation aOrientation
,
73 const nsIntSize
& aSize
,
74 bool aInvert
= false);
77 * Returns a SourceSurface that is the result of rotating and flipping
78 * aSurface according to aOrientation.
80 static already_AddRefed
<SourceSurface
> OrientSurface(Orientation aOrientation
,
81 SourceSurface
* aSurface
);
84 OrientedImage(Image
* aImage
, Orientation aOrientation
)
85 : ImageWrapper(aImage
), mOrientation(aOrientation
) {}
87 virtual ~OrientedImage() {}
89 gfxMatrix
OrientationMatrix(const nsIntSize
& aSize
, bool aInvert
= false) {
90 return OrientationMatrix(mOrientation
, aSize
, aInvert
);
94 Orientation mOrientation
;
96 friend class ImageOps
;
100 } // namespace mozilla
102 #endif // mozilla_image_OrientedImage_h